Merge lp:~rainct/zeitgeist/matches-template into lp:~zeitgeist/zeitgeist/bluebird
- matches-template
- Merge into bluebird
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 | ||||||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Michal Hruby (community) | Approve | ||
Review via email: mp+93279@code.launchpad.net |
Commit message
Description of the change
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.
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.
Michal Hruby (mhr3) : | # |
Preview Diff
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 | 4 | * By Seif Lotfy <seif@lotfy.com> | 4 | * By Seif Lotfy <seif@lotfy.com> |
6 | 5 | * By Siegfried-Angel Gevatter Pujals <siegfried@gevatter.com> | 5 | * By Siegfried-Angel Gevatter Pujals <siegfried@gevatter.com> |
7 | 6 | * Copyright © 2011 Manish Sinha <manishsinha@ubuntu.com> | 6 | * Copyright © 2011 Manish Sinha <manishsinha@ubuntu.com> |
8 | 7 | * Copyright © 2012 Canonical Ltd. | ||
9 | 8 | * By Siegfried-A. Gevatter <siegfried.gevatter@collabora.co.uk> | ||
10 | 7 | * | 9 | * |
11 | 8 | * This program is free software: you can redistribute it and/or modify | 10 | * This program is free software: you can redistribute it and/or modify |
12 | 9 | * it under the terms of the GNU Lesser General Public License as published by | 11 | * it under the terms of the GNU Lesser General Public License as published by |
13 | @@ -262,15 +264,18 @@ | |||
14 | 262 | ANY = 2 // The event subjects may or may not be available | 264 | ANY = 2 // The event subjects may or may not be available |
15 | 263 | } | 265 | } |
16 | 264 | 266 | ||
19 | 265 | private bool check_field_match (string property, | 267 | private bool check_field_match (string? property, |
20 | 266 | string template_property, bool is_symbol = false, | 268 | string? template_property, bool is_symbol = false, |
21 | 267 | bool can_wildcard = false) | 269 | bool can_wildcard = false) |
22 | 268 | { | 270 | { |
23 | 269 | var matches = false; | 271 | var matches = false; |
24 | 272 | var is_negated = false; | ||
25 | 270 | var parsed = template_property; | 273 | var parsed = template_property; |
29 | 271 | var is_negated = Utils.parse_negation (ref parsed); | 274 | |
30 | 272 | 275 | if (parsed != null) | |
31 | 273 | if (parsed == "") | 276 | is_negated = Utils.parse_negation (ref parsed); |
32 | 277 | |||
33 | 278 | if (Utils.is_empty_string (parsed)) | ||
34 | 274 | { | 279 | { |
35 | 275 | return true; | 280 | return true; |
36 | 276 | } | 281 | } |
37 | @@ -278,14 +283,15 @@ | |||
38 | 278 | { | 283 | { |
39 | 279 | matches = true; | 284 | matches = true; |
40 | 280 | } | 285 | } |
42 | 281 | else if (is_symbol && | 286 | else if (is_symbol && property != null && |
43 | 282 | Symbol.get_all_parents (property).find_custom (parsed, strcmp) != null) | 287 | Symbol.get_all_parents (property).find_custom (parsed, strcmp) != null) |
44 | 283 | { | 288 | { |
45 | 284 | matches = true; | 289 | matches = true; |
46 | 285 | } | 290 | } |
47 | 286 | else if (can_wildcard && Utils.parse_wildcard (ref parsed)) | 291 | else if (can_wildcard && Utils.parse_wildcard (ref parsed)) |
48 | 287 | { | 292 | { |
50 | 288 | if (property.has_prefix (parsed)) matches = true; | 293 | if (property != null && property.has_prefix (parsed)) |
51 | 294 | matches = true; | ||
52 | 289 | } | 295 | } |
53 | 290 | 296 | ||
54 | 291 | return (is_negated) ? !matches : matches; | 297 | return (is_negated) ? !matches : matches; |
55 | @@ -297,27 +303,27 @@ | |||
56 | 297 | 303 | ||
57 | 298 | public uint32 id { get; set; } | 304 | public uint32 id { get; set; } |
58 | 299 | public int64 timestamp { get; set; } | 305 | public int64 timestamp { get; set; } |
60 | 300 | public string origin { get; set; } | 306 | public string? origin { get; set; } |
61 | 301 | 307 | ||
63 | 302 | public string actor | 308 | public string? actor |
64 | 303 | { | 309 | { |
65 | 304 | get { return _actor; } | 310 | get { return _actor; } |
67 | 305 | set { _actor = url_store.insert_const (value); } | 311 | set { _actor = (value != null) ? url_store.insert_const (value) : null; } |
68 | 306 | } | 312 | } |
70 | 307 | public string interpretation | 313 | public string? interpretation |
71 | 308 | { | 314 | { |
72 | 309 | get { return _interpretation; } | 315 | get { return _interpretation; } |
74 | 310 | set { _interpretation = url_store.insert_const (value); } | 316 | set { _interpretation = (value != null) ? url_store.insert_const (value) : null; } |
75 | 311 | } | 317 | } |
77 | 312 | public string manifestation | 318 | public string? manifestation |
78 | 313 | { | 319 | { |
79 | 314 | get { return _manifestation; } | 320 | get { return _manifestation; } |
81 | 315 | set { _manifestation = url_store.insert_const (value); } | 321 | set { _manifestation = (value != null) ? url_store.insert_const (value) : null; } |
82 | 316 | } | 322 | } |
83 | 317 | 323 | ||
87 | 318 | private unowned string _actor; | 324 | private unowned string? _actor; |
88 | 319 | private unowned string _interpretation; | 325 | private unowned string? _interpretation; |
89 | 320 | private unowned string _manifestation; | 326 | private unowned string? _manifestation; |
90 | 321 | 327 | ||
91 | 322 | public GenericArray<Subject> subjects { get; set; } | 328 | public GenericArray<Subject> subjects { get; set; } |
92 | 323 | public ByteArray? payload { get; set; } | 329 | public ByteArray? payload { get; set; } |
93 | @@ -342,6 +348,24 @@ | |||
94 | 342 | subjects.add (subject); | 348 | subjects.add (subject); |
95 | 343 | } | 349 | } |
96 | 344 | 350 | ||
97 | 351 | public Event.full (string? interpretation=null, | ||
98 | 352 | string? manifestation=null, string? actor=null, | ||
99 | 353 | string? origin=null, ...) | ||
100 | 354 | { | ||
101 | 355 | this.interpretation = interpretation; | ||
102 | 356 | this.manifestation = manifestation; | ||
103 | 357 | this.actor = actor; | ||
104 | 358 | this.origin = origin; | ||
105 | 359 | |||
106 | 360 | // FIXME: We can't use this until Vala bug #647097 is fixed | ||
107 | 361 | /* | ||
108 | 362 | var subjects = va_list (); | ||
109 | 363 | unowned Subject subject; | ||
110 | 364 | while ((subject = subjects.arg ()) != null) | ||
111 | 365 | add_subject (subject); | ||
112 | 366 | */ | ||
113 | 367 | } | ||
114 | 368 | |||
115 | 345 | public Event.from_variant (Variant event_variant) throws EngineError { | 369 | public Event.from_variant (Variant event_variant) throws EngineError { |
116 | 346 | assert_sig (event_variant.get_type_string () == "(" + | 370 | assert_sig (event_variant.get_type_string () == "(" + |
117 | 347 | Utils.SIG_EVENT + ")", "Invalid D-Bus signature."); | 371 | Utils.SIG_EVENT + ")", "Invalid D-Bus signature."); |
118 | @@ -560,39 +584,53 @@ | |||
119 | 560 | { | 584 | { |
120 | 561 | private static StringChunk url_store; | 585 | private static StringChunk url_store; |
121 | 562 | 586 | ||
126 | 563 | public string uri { get; set; } | 587 | public string? uri { get; set; } |
127 | 564 | public string origin { get; set; } | 588 | public string? origin { get; set; } |
128 | 565 | public string text { get; set; } | 589 | public string? text { get; set; } |
129 | 566 | public string storage { get; set; } | 590 | public string? storage { get; set; } |
130 | 567 | // FIXME: current_uri is often the same as uri, we don't need to waste | 591 | // FIXME: current_uri is often the same as uri, we don't need to waste |
131 | 568 | // memory for it | 592 | // memory for it |
133 | 569 | public string current_uri { get; set; } | 593 | public string? current_uri { get; set; } |
134 | 570 | 594 | ||
136 | 571 | public string mimetype | 595 | public string? mimetype |
137 | 572 | { | 596 | { |
138 | 573 | get { return _mimetype; } | 597 | get { return _mimetype; } |
140 | 574 | set { _mimetype = url_store.insert_const (value); } | 598 | set { _mimetype = (value != null) ? url_store.insert_const (value) : null; } |
141 | 575 | } | 599 | } |
143 | 576 | public string interpretation | 600 | public string? interpretation |
144 | 577 | { | 601 | { |
145 | 578 | get { return _interpretation; } | 602 | get { return _interpretation; } |
147 | 579 | set { _interpretation = url_store.insert_const (value); } | 603 | set { _interpretation = (value != null) ? url_store.insert_const (value) : null; } |
148 | 580 | } | 604 | } |
150 | 581 | public string manifestation | 605 | public string? manifestation |
151 | 582 | { | 606 | { |
152 | 583 | get { return _manifestation; } | 607 | get { return _manifestation; } |
154 | 584 | set { _manifestation = url_store.insert_const (value); } | 608 | set { _manifestation = (value != null) ? url_store.insert_const (value) : null; } |
155 | 585 | } | 609 | } |
156 | 586 | 610 | ||
160 | 587 | private unowned string _mimetype; | 611 | private unowned string? _mimetype; |
161 | 588 | private unowned string _interpretation; | 612 | private unowned string? _interpretation; |
162 | 589 | private unowned string _manifestation; | 613 | private unowned string? _manifestation; |
163 | 590 | 614 | ||
164 | 591 | static construct | 615 | static construct |
165 | 592 | { | 616 | { |
166 | 593 | url_store = new StringChunk (4096); | 617 | url_store = new StringChunk (4096); |
167 | 594 | } | 618 | } |
168 | 595 | 619 | ||
169 | 620 | public Subject.full (string? uri=null, | ||
170 | 621 | string? interpretation=null, string? manifestation=null, | ||
171 | 622 | string? mimetype=null, string? origin=null, string? text=null, | ||
172 | 623 | string? storage=null, string? current_uri=null) | ||
173 | 624 | { | ||
174 | 625 | this.interpretation = interpretation; | ||
175 | 626 | this.manifestation = manifestation; | ||
176 | 627 | this.mimetype = mimetype; | ||
177 | 628 | this.origin = origin; | ||
178 | 629 | this.text = text; | ||
179 | 630 | this.storage = storage; | ||
180 | 631 | this.current_uri = current_uri; | ||
181 | 632 | } | ||
182 | 633 | |||
183 | 596 | public Subject.from_variant (Variant subject_variant) | 634 | public Subject.from_variant (Variant subject_variant) |
184 | 597 | throws EngineError | 635 | throws EngineError |
185 | 598 | { | 636 | { |
186 | 599 | 637 | ||
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 | 6 | --pkg gmodule-2.0 \ | 6 | --pkg gmodule-2.0 \ |
192 | 7 | $(srcdir)/assertions.vapi \ | 7 | $(srcdir)/assertions.vapi \ |
193 | 8 | --Xcc=-w \ | 8 | --Xcc=-w \ |
194 | 9 | -g \ | ||
195 | 9 | $(NULL) | 10 | $(NULL) |
196 | 10 | 11 | ||
197 | 11 | TESTS = \ | 12 | TESTS = \ |
198 | 13 | datamodel-test \ | ||
199 | 12 | marshalling-test \ | 14 | marshalling-test \ |
200 | 13 | mimetype-test \ | 15 | mimetype-test \ |
201 | 14 | query-operators-test \ | 16 | query-operators-test \ |
202 | @@ -36,6 +38,9 @@ | |||
203 | 36 | $(top_srcdir)/src/mimetype.vala \ | 38 | $(top_srcdir)/src/mimetype.vala \ |
204 | 37 | $(NULL) | 39 | $(NULL) |
205 | 38 | 40 | ||
206 | 41 | datamodel-test: datamodel-test.vala $(SRC_FILES) | ||
207 | 42 | $(VALA_V)$(VALAC) $(VALAFLAGS) -o $@ $^ | ||
208 | 43 | |||
209 | 39 | marshalling-test: marshalling-test.vala $(SRC_FILES) | 44 | marshalling-test: marshalling-test.vala $(SRC_FILES) |
210 | 40 | $(VALA_V)$(VALAC) $(VALAFLAGS) -o $@ $^ | 45 | $(VALA_V)$(VALAC) $(VALAFLAGS) -o $@ $^ |
211 | 41 | 46 | ||
212 | @@ -54,7 +59,8 @@ | |||
213 | 54 | clean-local: | 59 | clean-local: |
214 | 55 | rm -f *.~[0-9]~ | 60 | rm -f *.~[0-9]~ |
215 | 56 | 61 | ||
217 | 57 | DISTCLEANFILES = \ | 62 | CLEANFILES = \ |
218 | 63 | datamodel-test \ | ||
219 | 58 | marshalling-test \ | 64 | marshalling-test \ |
220 | 59 | mimetype-test \ | 65 | mimetype-test \ |
221 | 60 | query-operators-test \ | 66 | query-operators-test \ |
222 | @@ -64,6 +70,7 @@ | |||
223 | 64 | 70 | ||
224 | 65 | EXTRA_DIST = \ | 71 | EXTRA_DIST = \ |
225 | 66 | assertions.vapi \ | 72 | assertions.vapi \ |
226 | 73 | datamodel-test.vala \ | ||
227 | 67 | marshalling-test.vala \ | 74 | marshalling-test.vala \ |
228 | 68 | mimetype-test.vala \ | 75 | mimetype-test.vala \ |
229 | 69 | query-operators-test.vala \ | 76 | query-operators-test.vala \ |
230 | 70 | 77 | ||
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 | 1 | /* datamodel-test.vala | ||
236 | 2 | * | ||
237 | 3 | * Copyright © 2012 Canonical Ltd. | ||
238 | 4 | * By Siegfried-A. Gevatter <siegfried.gevatter@collabora.co.uk> | ||
239 | 5 | * | ||
240 | 6 | * This program is free software: you can redistribute it and/or modify | ||
241 | 7 | * it under the terms of the GNU Lesser General Public License as published by | ||
242 | 8 | * the Free Software Foundation, either version 2.1 of the License, or | ||
243 | 9 | * (at your option) any later version. | ||
244 | 10 | * | ||
245 | 11 | * This program is distributed in the hope that it will be useful, | ||
246 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
247 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
248 | 14 | * GNU General Public License for more details. | ||
249 | 15 | * | ||
250 | 16 | * You should have received a copy of the GNU Lesser General Public License | ||
251 | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
252 | 18 | * | ||
253 | 19 | */ | ||
254 | 20 | |||
255 | 21 | using Zeitgeist; | ||
256 | 22 | |||
257 | 23 | int main (string[] argv) | ||
258 | 24 | { | ||
259 | 25 | Test.init (ref argv); | ||
260 | 26 | |||
261 | 27 | Test.add_func ("/Datamodel/MatchesTemplate/anything", matches_template_anything_test); | ||
262 | 28 | |||
263 | 29 | return Test.run (); | ||
264 | 30 | } | ||
265 | 31 | |||
266 | 32 | void matches_template_anything_test () | ||
267 | 33 | { | ||
268 | 34 | // Let's get a template with everything null | ||
269 | 35 | var templ = new Event.full (); | ||
270 | 36 | var event = new Event.full ("interp", "manif", "actor", "origin"); | ||
271 | 37 | |||
272 | 38 | // Test with zero subjects | ||
273 | 39 | assert (templ.matches_template (templ)); | ||
274 | 40 | assert (event.matches_template (templ)); | ||
275 | 41 | |||
276 | 42 | var subject = new Subject.full (); | ||
277 | 43 | event.add_subject (subject); | ||
278 | 44 | |||
279 | 45 | // Test with one subject | ||
280 | 46 | assert (event.matches_template (templ)); | ||
281 | 47 | |||
282 | 48 | var subject2 = new Subject.full ("uri", "interp", "manif", "mimetype", | ||
283 | 49 | "origin", "text", "storage", "current_uri"); | ||
284 | 50 | event.add_subject (subject2); | ||
285 | 51 | |||
286 | 52 | // Test with two subjects | ||
287 | 53 | assert (event.matches_template (templ)); | ||
288 | 54 | |||
289 | 55 | // Let's ensure that empty strings are also working... | ||
290 | 56 | templ.interpretation = ""; | ||
291 | 57 | assert (event.matches_template (templ)); | ||
292 | 58 | |||
293 | 59 | // As well as just a wildcard | ||
294 | 60 | templ.actor = "*"; | ||
295 | 61 | assert (event.matches_template (templ)); | ||
296 | 62 | |||
297 | 63 | // FIXME: figure out how we want to treat multiple subjects in the template | ||
298 | 64 | |||
299 | 65 | // Now check something that doesn't match | ||
300 | 66 | templ.manifestation = "No thanks!"; | ||
301 | 67 | assert (!event.matches_template (templ)); | ||
302 | 68 | } | ||
303 | 69 | |||
304 | 70 | // vim:expandtab:ts=4:sw=4 |
115 + // FIXME: change this to va_list once Vala bug #647097 is fixed null, Subject> ? subjects=null)
116 + public Event.full (string? interpretation=
117 + string? manifestation=null, string? actor=null,
118 + string? origin=null, GenericArray<
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.