diff options
author | Christian Dywan <christian@twotoasts.de> | 2012-08-22 01:50:23 +0200 |
---|---|---|
committer | Seif Lotfy <seif@lotfy.com> | 2012-08-27 14:27:42 +0200 |
commit | 2615138b3064fd7f22f5156c1ddd176d18464113 (patch) | |
tree | 78673c4433ec78194a5ca02e4e22466f87127c9b | |
parent | 480eb5cb9d0d705e7b30ba287d1514d93b98126c (diff) |
Port symbol test from libzeitgeist1
Signed-off-by: Seif Lotfy <seif@lotfy.com>
-rw-r--r-- | test/direct/Makefile.am | 6 | ||||
-rw-r--r-- | test/direct/symbol-test.vala | 137 |
2 files changed, 143 insertions, 0 deletions
diff --git a/test/direct/Makefile.am b/test/direct/Makefile.am index 1173da5b..efd47bf7 100644 --- a/test/direct/Makefile.am +++ b/test/direct/Makefile.am @@ -18,6 +18,7 @@ TESTS = \ mimetype-test \ monitor-test \ query-operators-test \ + symbol-test \ table-lookup-test \ where-clause-test \ $(NULL) @@ -69,6 +70,9 @@ marshalling-test: marshalling-test.vala $(SRC_FILES) query-operators-test: query-operators-test.vala $(SRC_FILES) $(VALA_V)$(VALAC) $(VALAFLAGS) -o $@ $^ +symbol-test: symbol-test.vala $(SRC_FILES) + $(VALA_V)$(VALAC) $(VALAFLAGS) -o $@ $^ + where-clause-test: where-clause-test.vala $(SRC_FILES) $(VALA_V)$(VALAC) $(VALAFLAGS) -o $@ $^ @@ -93,6 +97,7 @@ CLEANFILES = \ mimetype-test \ monitor-test \ query-operators-test \ + symbol-test \ table-lookup-test \ where-clause-test \ $(NULL) @@ -107,6 +112,7 @@ EXTRA_DIST = \ mimetype-test.vala \ monitor-test.vala \ query-operators-test.vala \ + symbol-test.vala \ table-lookup-test.vala \ where-clause-test.vala \ $(NULL) diff --git a/test/direct/symbol-test.vala b/test/direct/symbol-test.vala new file mode 100644 index 00000000..a49f2783 --- /dev/null +++ b/test/direct/symbol-test.vala @@ -0,0 +1,137 @@ +/* datamodel-test.vala + * + * Copyright © 2012 Canonical Ltd. + * By Siegfried-A. Gevatter <siegfried.gevatter@collabora.co.uk> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2.1 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +using Zeitgeist; +using Assertions; + +int main (string[] argv) +{ + Test.init (ref argv); + + Test.add_func ("/Symbols/NullNull", null_null_test); + Test.add_func ("/Symbols/NullFirst", null_first_test); + Test.add_func ("/Symbols/NullSecond", null_second_test); + Test.add_func ("/Symbols/NotUri", not_uri_test); + Test.add_func ("/Symbols/NotUriEqual", not_uri_equal_test); + Test.add_func ("/Symbols/UriEqual", uri_equal_test); + Test.add_func ("/Symbols/ValidParent", vector_image_media_test); + Test.add_func ("/Symbols/ValidChild", media_vector_image_test); + Test.add_func ("/Symbols/Unrelated", media_software_test); + Test.add_func ("/Symbols/GetChildren", media_children_test); + Test.add_func ("/Symbols/GetAllChildren", media_all_children_test); + Test.add_func ("/Symbols/GetParents", vector_image_parents_test); + Test.add_func ("/Symbols/SymbolInfo", media_complex_test); + + return Test.run (); +} + +void null_null_test () +{ + // shouldn't crash: null, null will hit assertions + assert (!Symbol.is_a ("", "")); +} + +void null_first_test () +{ + assert (!Symbol.is_a ("", NFO.MEDIA)); +} + +void null_second_test () +{ + assert (!Symbol.is_a (NFO.MEDIA, "")); +} + +void not_uri_test () +{ + assert (!Symbol.is_a ("first", "second")); +} + +void not_uri_equal_test () +{ + assert (!Symbol.is_a ("something", "something")); +} + +void uri_equal_test () +{ + assert (Symbol.is_a (NFO.AUDIO, NFO.AUDIO)); +} + +void vector_image_media_test () +{ + assert (Symbol.is_a (NFO.VECTOR_IMAGE, NFO.MEDIA)); +} + +void media_vector_image_test () +{ + assert (!Symbol.is_a (NFO.MEDIA, NFO.VECTOR_IMAGE)); +} + +void media_software_test () +{ + assert (!Symbol.is_a (NFO.MEDIA, NFO.SOFTWARE)); +} + +void is_uri_valid (string uri) +{ + string SEM_D_URI = "http://www.semanticdesktop.org/ontologies"; + assert (uri != null && uri.has_prefix (SEM_D_URI)); + // string str = "%s".printf ("%s", uri); +} + +void media_children_test () +{ + var children = Symbol.get_children (NFO.MEDIA); + assert_cmpuint (children.length (), OperatorType.GREATER_THAN, 0); + foreach (string uri in children) + is_uri_valid (uri); +} + +void media_all_children_test () +{ + var children = Symbol.get_all_children (NFO.MEDIA); + assert_cmpuint (children.length (), OperatorType.GREATER_THAN, 0); + foreach (string uri in children) + is_uri_valid (uri); +} + +void vector_image_parents_test () +{ + var children = Symbol.get_all_children (NFO.VECTOR_IMAGE); + assert_cmpuint (children.length (), OperatorType.GREATER_THAN, 0); + foreach (string uri in children) + is_uri_valid (uri); +} + +void media_complex_test () +{ + var children = Symbol.get_children (NFO.MEDIA); + var all_ch = Symbol.get_all_children (NFO.MEDIA); + + assert_cmpuint (children.length (), OperatorType.GREATER_THAN, 0); + assert_cmpuint (all_ch.length (), OperatorType.GREATER_THAN, children.length ()); + + foreach (string uri in children) + { + // check that it's also in all children + assert (all_ch.find_custom (uri, strcmp) != null); + } +} + +// vim:expandtab:ts=4:sw=4 |