Merge lp:~rainct/zeitgeist/matches-template into lp:~zeitgeist/zeitgeist/bluebird

Proposed by Siegfried Gevatter
Status: Merged
Approved by: Michal Hruby
Approved revision: 406
Merged at revision: 406
Proposed branch: lp:~rainct/zeitgeist/matches-template
Merge into: lp:~zeitgeist/zeitgeist/bluebird
Diff against target: 304 lines (+147/-32)
3 files modified
src/datamodel.vala (+69/-31)
test/direct/Makefile.am (+8/-1)
test/direct/datamodel-test.vala (+70/-0)
To merge this branch: bzr merge lp:~rainct/zeitgeist/matches-template
Reviewer Review Type Date Requested Status
Michal Hruby (community) Approve
Review via email: mp+93279@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Michal Hruby (mhr3) wrote :

115 + // FIXME: change this to va_list once Vala bug #647097 is fixed
116 + public Event.full (string? interpretation=null,
117 + string? manifestation=null, string? actor=null,
118 + string? origin=null, GenericArray<Subject>? subjects=null)

This is very close to public API, I'd prefer this didn't change, so if we want a variant with a PtrArray, let's call it something else (for example full_from_ptrarray)

328 + // FIXME: figure out how we want to treat multiple subjects in the template

Same way engine does, ie AND them within one event.

review: Needs Fixing
Revision history for this message
Siegfried Gevatter (rainct) wrote :

2012/2/17 Michal Hruby <email address hidden>:
> This is very close to public API, I'd prefer this didn't change, so if we want a variant with a PtrArray, let's call it something else (for example full_from_ptrarray)

I don't want PtrArray, it's just a workaround since Vala is br0ken.

> 328     +    // FIXME: figure out how we want to treat multiple subjects in the template
> Same way engine does, ie AND them within one event.

Yeah, that's not what I mean, but rather: if there's two empty
subjects, does that mean anything (ie. I want events with exactly two
subject) or are they just ignored? But I retract the question, the
former would just be confusing.

Revision history for this message
Michal Hruby (mhr3) wrote :

> I don't want PtrArray, it's just a workaround since Vala is br0ken.

Then don't add that method yet.

406. By Siegfried Gevatter

Leave va_list there but don't use it.

Revision history for this message
Michal Hruby (mhr3) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/datamodel.vala'
2--- src/datamodel.vala 2012-02-15 18:27:21 +0000
3+++ src/datamodel.vala 2012-02-18 21:37:18 +0000
4@@ -4,6 +4,8 @@
5 * By Seif Lotfy <seif@lotfy.com>
6 * By Siegfried-Angel Gevatter Pujals <siegfried@gevatter.com>
7 * Copyright © 2011 Manish Sinha <manishsinha@ubuntu.com>
8+ * Copyright © 2012 Canonical Ltd.
9+ * By Siegfried-A. Gevatter <siegfried.gevatter@collabora.co.uk>
10 *
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13@@ -262,15 +264,18 @@
14 ANY = 2 // The event subjects may or may not be available
15 }
16
17- private bool check_field_match (string property,
18- string template_property, bool is_symbol = false,
19+ private bool check_field_match (string? property,
20+ string? template_property, bool is_symbol = false,
21 bool can_wildcard = false)
22 {
23 var matches = false;
24+ var is_negated = false;
25 var parsed = template_property;
26- var is_negated = Utils.parse_negation (ref parsed);
27-
28- if (parsed == "")
29+
30+ if (parsed != null)
31+ is_negated = Utils.parse_negation (ref parsed);
32+
33+ if (Utils.is_empty_string (parsed))
34 {
35 return true;
36 }
37@@ -278,14 +283,15 @@
38 {
39 matches = true;
40 }
41- else if (is_symbol &&
42+ else if (is_symbol && property != null &&
43 Symbol.get_all_parents (property).find_custom (parsed, strcmp) != null)
44 {
45 matches = true;
46 }
47 else if (can_wildcard && Utils.parse_wildcard (ref parsed))
48 {
49- if (property.has_prefix (parsed)) matches = true;
50+ if (property != null && property.has_prefix (parsed))
51+ matches = true;
52 }
53
54 return (is_negated) ? !matches : matches;
55@@ -297,27 +303,27 @@
56
57 public uint32 id { get; set; }
58 public int64 timestamp { get; set; }
59- public string origin { get; set; }
60+ public string? origin { get; set; }
61
62- public string actor
63+ public string? actor
64 {
65 get { return _actor; }
66- set { _actor = url_store.insert_const (value); }
67+ set { _actor = (value != null) ? url_store.insert_const (value) : null; }
68 }
69- public string interpretation
70+ public string? interpretation
71 {
72 get { return _interpretation; }
73- set { _interpretation = url_store.insert_const (value); }
74+ set { _interpretation = (value != null) ? url_store.insert_const (value) : null; }
75 }
76- public string manifestation
77+ public string? manifestation
78 {
79 get { return _manifestation; }
80- set { _manifestation = url_store.insert_const (value); }
81+ set { _manifestation = (value != null) ? url_store.insert_const (value) : null; }
82 }
83
84- private unowned string _actor;
85- private unowned string _interpretation;
86- private unowned string _manifestation;
87+ private unowned string? _actor;
88+ private unowned string? _interpretation;
89+ private unowned string? _manifestation;
90
91 public GenericArray<Subject> subjects { get; set; }
92 public ByteArray? payload { get; set; }
93@@ -342,6 +348,24 @@
94 subjects.add (subject);
95 }
96
97+ public Event.full (string? interpretation=null,
98+ string? manifestation=null, string? actor=null,
99+ string? origin=null, ...)
100+ {
101+ this.interpretation = interpretation;
102+ this.manifestation = manifestation;
103+ this.actor = actor;
104+ this.origin = origin;
105+
106+ // FIXME: We can't use this until Vala bug #647097 is fixed
107+ /*
108+ var subjects = va_list ();
109+ unowned Subject subject;
110+ while ((subject = subjects.arg ()) != null)
111+ add_subject (subject);
112+ */
113+ }
114+
115 public Event.from_variant (Variant event_variant) throws EngineError {
116 assert_sig (event_variant.get_type_string () == "(" +
117 Utils.SIG_EVENT + ")", "Invalid D-Bus signature.");
118@@ -560,39 +584,53 @@
119 {
120 private static StringChunk url_store;
121
122- public string uri { get; set; }
123- public string origin { get; set; }
124- public string text { get; set; }
125- public string storage { get; set; }
126+ public string? uri { get; set; }
127+ public string? origin { get; set; }
128+ public string? text { get; set; }
129+ public string? storage { get; set; }
130 // FIXME: current_uri is often the same as uri, we don't need to waste
131 // memory for it
132- public string current_uri { get; set; }
133+ public string? current_uri { get; set; }
134
135- public string mimetype
136+ public string? mimetype
137 {
138 get { return _mimetype; }
139- set { _mimetype = url_store.insert_const (value); }
140+ set { _mimetype = (value != null) ? url_store.insert_const (value) : null; }
141 }
142- public string interpretation
143+ public string? interpretation
144 {
145 get { return _interpretation; }
146- set { _interpretation = url_store.insert_const (value); }
147+ set { _interpretation = (value != null) ? url_store.insert_const (value) : null; }
148 }
149- public string manifestation
150+ public string? manifestation
151 {
152 get { return _manifestation; }
153- set { _manifestation = url_store.insert_const (value); }
154+ set { _manifestation = (value != null) ? url_store.insert_const (value) : null; }
155 }
156
157- private unowned string _mimetype;
158- private unowned string _interpretation;
159- private unowned string _manifestation;
160+ private unowned string? _mimetype;
161+ private unowned string? _interpretation;
162+ private unowned string? _manifestation;
163
164 static construct
165 {
166 url_store = new StringChunk (4096);
167 }
168
169+ public Subject.full (string? uri=null,
170+ string? interpretation=null, string? manifestation=null,
171+ string? mimetype=null, string? origin=null, string? text=null,
172+ string? storage=null, string? current_uri=null)
173+ {
174+ this.interpretation = interpretation;
175+ this.manifestation = manifestation;
176+ this.mimetype = mimetype;
177+ this.origin = origin;
178+ this.text = text;
179+ this.storage = storage;
180+ this.current_uri = current_uri;
181+ }
182+
183 public Subject.from_variant (Variant subject_variant)
184 throws EngineError
185 {
186
187=== modified file 'test/direct/Makefile.am'
188--- test/direct/Makefile.am 2012-02-13 19:43:15 +0000
189+++ test/direct/Makefile.am 2012-02-18 21:37:18 +0000
190@@ -6,9 +6,11 @@
191 --pkg gmodule-2.0 \
192 $(srcdir)/assertions.vapi \
193 --Xcc=-w \
194+ -g \
195 $(NULL)
196
197 TESTS = \
198+ datamodel-test \
199 marshalling-test \
200 mimetype-test \
201 query-operators-test \
202@@ -36,6 +38,9 @@
203 $(top_srcdir)/src/mimetype.vala \
204 $(NULL)
205
206+datamodel-test: datamodel-test.vala $(SRC_FILES)
207+ $(VALA_V)$(VALAC) $(VALAFLAGS) -o $@ $^
208+
209 marshalling-test: marshalling-test.vala $(SRC_FILES)
210 $(VALA_V)$(VALAC) $(VALAFLAGS) -o $@ $^
211
212@@ -54,7 +59,8 @@
213 clean-local:
214 rm -f *.~[0-9]~
215
216-DISTCLEANFILES = \
217+CLEANFILES = \
218+ datamodel-test \
219 marshalling-test \
220 mimetype-test \
221 query-operators-test \
222@@ -64,6 +70,7 @@
223
224 EXTRA_DIST = \
225 assertions.vapi \
226+ datamodel-test.vala \
227 marshalling-test.vala \
228 mimetype-test.vala \
229 query-operators-test.vala \
230
231=== added file 'test/direct/datamodel-test.vala'
232--- test/direct/datamodel-test.vala 1970-01-01 00:00:00 +0000
233+++ test/direct/datamodel-test.vala 2012-02-18 21:37:18 +0000
234@@ -0,0 +1,70 @@
235+/* datamodel-test.vala
236+ *
237+ * Copyright © 2012 Canonical Ltd.
238+ * By Siegfried-A. Gevatter <siegfried.gevatter@collabora.co.uk>
239+ *
240+ * This program is free software: you can redistribute it and/or modify
241+ * it under the terms of the GNU Lesser General Public License as published by
242+ * the Free Software Foundation, either version 2.1 of the License, or
243+ * (at your option) any later version.
244+ *
245+ * This program is distributed in the hope that it will be useful,
246+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
247+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
248+ * GNU General Public License for more details.
249+ *
250+ * You should have received a copy of the GNU Lesser General Public License
251+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
252+ *
253+ */
254+
255+using Zeitgeist;
256+
257+int main (string[] argv)
258+{
259+ Test.init (ref argv);
260+
261+ Test.add_func ("/Datamodel/MatchesTemplate/anything", matches_template_anything_test);
262+
263+ return Test.run ();
264+}
265+
266+void matches_template_anything_test ()
267+{
268+ // Let's get a template with everything null
269+ var templ = new Event.full ();
270+ var event = new Event.full ("interp", "manif", "actor", "origin");
271+
272+ // Test with zero subjects
273+ assert (templ.matches_template (templ));
274+ assert (event.matches_template (templ));
275+
276+ var subject = new Subject.full ();
277+ event.add_subject (subject);
278+
279+ // Test with one subject
280+ assert (event.matches_template (templ));
281+
282+ var subject2 = new Subject.full ("uri", "interp", "manif", "mimetype",
283+ "origin", "text", "storage", "current_uri");
284+ event.add_subject (subject2);
285+
286+ // Test with two subjects
287+ assert (event.matches_template (templ));
288+
289+ // Let's ensure that empty strings are also working...
290+ templ.interpretation = "";
291+ assert (event.matches_template (templ));
292+
293+ // As well as just a wildcard
294+ templ.actor = "*";
295+ assert (event.matches_template (templ));
296+
297+ // FIXME: figure out how we want to treat multiple subjects in the template
298+
299+ // Now check something that doesn't match
300+ templ.manifestation = "No thanks!";
301+ assert (!event.matches_template (templ));
302+}
303+
304+// vim:expandtab:ts=4:sw=4

Subscribers

People subscribed via source and target branches