Siegfried Gevatter has proposed merging lp:~zeitgeist/zeitgeist/884193 into lp:zeitgeist.
Requested reviews: Zeitgeist Framework Team (zeitgeist) Related bugs: Bug #884193 in Zeitgeist Framework: "Add a way to query only a specific class - and NOT sub classes" https://bugs.launchpad.net/zeitgeist/+bug/884193 For more details, see: https://code.launchpad.net/~zeitgeist/zeitgeist/884193/+merge/84412 -- https://code.launchpad.net/~zeitgeist/zeitgeist/884193/+merge/84412 Your team Zeitgeist Framework Team is requested to review the proposed merge of lp:~zeitgeist/zeitgeist/884193 into lp:zeitgeist.
=== modified file 'src/engine.vala' --- src/engine.vala 2011-12-04 22:14:33 +0000 +++ src/engine.vala 2011-12-04 23:01:23 +0000 @@ -861,6 +861,7 @@ string val = template.origin; bool like = parse_wildcard (ref val); bool negated = parse_negation (ref val); + assert_no_noexpand (val, "origin"); if (like) where.add_wildcard_condition ("origin", val, negated); @@ -904,6 +905,7 @@ string val = subject_template.mimetype; bool like = parse_wildcard (ref val); bool negated = parse_negation (ref val); + assert_no_noexpand (val, "mime-type"); if (like) where.add_wildcard_condition ( @@ -919,6 +921,7 @@ string val = subject_template.uri; bool like = parse_wildcard (ref val); bool negated = parse_negation (ref val); + assert_no_noexpand (val, "uri"); if (like) where.add_wildcard_condition ("subj_id", val, negated); @@ -932,6 +935,7 @@ string val = subject_template.origin; bool like = parse_wildcard (ref val); bool negated = parse_negation (ref val); + assert_no_noexpand (val, "subject origin"); if (like) where.add_wildcard_condition ( @@ -944,8 +948,8 @@ // Text if (subject_template.text != "") { - // Negation and prefix search isn't supported for - // subject texts, but "!" and "*" are valid as + // Negation, noexpand and prefix search aren't supported + // for subject texts, but "!", "+" and "*" are valid as // plain text characters. where.add_text_condition_subquery ("subj_text_id", subject_template.text, false); @@ -957,6 +961,7 @@ string val = subject_template.current_uri; bool like = parse_wildcard (ref val); bool negated = parse_negation (ref val); + assert_no_noexpand (val, "current_uri"); if (like) where.add_wildcard_condition ( @@ -972,6 +977,7 @@ string val = subject_template.storage; assert_no_negation ("subject storage", val); assert_no_wildcard ("subject storage", val); + assert_no_noexpand (val, "subject storage"); where.add_text_condition_subquery ("subj_storage_id", val); } } @@ -1011,6 +1017,38 @@ // Used by get_where_clause_from_event_templates /** + * Check if the value starts with the noexpand operator. If it does, + * remove the operator from the value and return true. Otherwise, + * return false. + * + * Check for the negation operator before calling this function. + */ + public static bool parse_noexpand (ref string val) + { + if (!val.has_prefix ("+")) + return false; + val = val.substring (1); + return true; + } + + // Used by get_where_clause_from_event_templates + /** + * If the value starts with the negation operator, throw an + * error. + */ + protected void assert_no_noexpand (string field, string val) + throws EngineError + { + if (!val.has_prefix ("+")) + return; + string error_message = + "Field '%s' doesn't support the no-expand operator".printf (field); + warning (error_message); + throw new EngineError.INVALID_ARGUMENT (error_message); + } + + // Used by get_where_clause_from_event_templates + /** * Check if the value ends with the wildcard character. If it does, * remove the wildcard character from the value and return true. * Otherwise, return false. @@ -1044,7 +1082,12 @@ { string _symbol = symbol; bool negated = parse_negation (ref _symbol); - List<unowned string> symbols = Symbol.get_all_children (_symbol); + bool noexpand = parse_noexpand (ref _symbol); + List<unowned string> symbols; + if (noexpand) + symbols = new List<unowned string> (); + else + symbols = Symbol.get_all_children (_symbol); symbols.prepend (_symbol); WhereClause subwhere = new WhereClause( === modified file 'test/dbus/remote-test.py' --- test/dbus/remote-test.py 2011-10-13 14:13:58 +0000 +++ test/dbus/remote-test.py 2011-12-04 23:01:23 +0000 @@ -190,6 +190,30 @@ self.assertEquals(len(results[1].get_subjects()), 1) self.assertEquals(len(results[0].get_subjects()), 1) + def testFindEventsWithNoexpandOperator(self): + events = parse_events("test/data/three_events.js") + ids = self.insertEventsAndWait(events) + + template = Event.new_for_values( + subject_interpretation=Interpretation.MEDIA) + results = self.findEventsForTemplatesAndWait([template], + num_events=5) + self.assertEquals(3, len(results)) + + template = Event.new_for_values( + subject_interpretation='+%s' % Interpretation.MEDIA) + results = self.findEventsForTemplatesAndWait([template], + num_events=5) + self.assertEquals(0, len(results)) + + template = Event.new_for_values( + subject_interpretation='+%s' % Interpretation.AUDIO) + results = self.findEventsForTemplatesAndWait([template], + num_events=5) + self.assertEquals(1, len(results)) + self.assertEquals(results[0].get_subjects()[0].interpretation, + Interpretation.AUDIO) + def testFindEventsLimitWhenDuplicates(self): events = parse_events("test/data/three_events.js") ids = self.insertEventsAndWait(events) === modified file 'test/direct/query-operators-test.vala' --- test/direct/query-operators-test.vala 2011-09-02 20:41:31 +0000 +++ test/direct/query-operators-test.vala 2011-12-04 23:01:23 +0000 @@ -28,6 +28,8 @@ Test.add_func ("/ParseNegation/main", parse_negation_test); Test.add_func ("/ParseNegation/assert", assert_no_negation_test); + Test.add_func ("/ParseNoexpand/main", parse_noexpand_test); + Test.add_func ("/ParseNoexpand/assert", assert_no_noexpand_test); Test.add_func ("/ParseWildcard/main", parse_wildcard_test); Test.add_func ("/ParseWildlcard/assert", assert_no_wildcard_test); @@ -47,6 +49,17 @@ assert_no_negation (field, val); } + public bool PUBLIC_parse_noexpand (ref string val) + { + return parse_noexpand (ref val); + } + + public void PUBLIC_assert_no_noexpand (string field, string val) + throws Zeitgeist.EngineError + { + assert_no_noexpand (field, val); + } + public bool PUBLIC_parse_wildcard (ref string val) { return parse_wildcard (ref val); @@ -99,6 +112,45 @@ } } +public void parse_noexpand_test () +{ + PublicEngine engine = new PublicEngine (); + string val; + + // Test string without a negation + val = "no expand"; + assert (engine.PUBLIC_parse_noexpand (ref val) == false); + assert (val == "no expand"); + + // Test string with a valid noexpand + val = "+noexpand"; + assert (engine.PUBLIC_parse_noexpand (ref val) == true); + assert (val == "noexpand"); + + // Test negation character in a meaningless position + val = "some + chars++"; + assert (engine.PUBLIC_parse_noexpand (ref val) == false); + assert (val == "some + chars++"); +} + +public void assert_no_noexpand_test () +{ + PublicEngine engine = new PublicEngine (); + + engine.PUBLIC_assert_no_noexpand ("field name", "good"); + engine.PUBLIC_assert_no_noexpand ("field name", "good+"); + engine.PUBLIC_assert_no_noexpand ("field name", "go+od"); + + try + { + engine.PUBLIC_assert_no_noexpand ("field name", "+bad"); + assert_not_reached (); + } + catch (Zeitgeist.EngineError.INVALID_ARGUMENT e) + { + } +} + public void parse_wildcard_test () { PublicEngine engine = new PublicEngine ();
_______________________________________________ Mailing list: https://launchpad.net/~zeitgeist Post to : zeitgeist@lists.launchpad.net Unsubscribe : https://launchpad.net/~zeitgeist More help : https://help.launchpad.net/ListHelp