diff options
-rw-r--r-- | .gitignore | 22 | ||||
-rw-r--r-- | libcontextprovider/Makefile.fragment | 2 | ||||
-rw-r--r-- | libcontextprovider/group.vala | 19 | ||||
-rw-r--r-- | libcontextprovider/groups.vala (renamed from libcontextprovider/providers.vala) | 0 | ||||
-rw-r--r-- | tests/unit_tests/test_value_compare.vala | 92 |
5 files changed, 126 insertions, 9 deletions
@@ -91,18 +91,24 @@ libcontextprovider/key_usage_counter.c libcontextprovider/key_usage_counter.h libcontextprovider/manager.c libcontextprovider/manager.h -libcontextprovider/provider_interface.c -libcontextprovider/provider_interface.h -libcontextprovider/providers.c -libcontextprovider/providers.h libcontextprovider/string_set.c libcontextprovider/string_set.h libcontextprovider/subscriber.c libcontextprovider/subscriber.h libcontextprovider/context_provider.c libcontextprovider/context_provider.h -libcontextprovider/cprovider.h -libcontextprovider/cprovider.c +libcontextprovider/groups.c +libcontextprovider/groups.h +libcontextprovider/group.c +libcontextprovider/group.h m4/gtk-doc.m4 -/contextprovider-1.0.pc -/doc/context-providers.html +contextprovider-1.0.pc +doc/context-providers.html +libcontextprovider/libcontextprovider.vala.stamp +libcontextprovider/value_compare.c +libcontextprovider/value_compare.h +tests/unit_tests/test_value_compare.c +tests/unit_tests/test_value_compare.h +tests/unit_tests/value_compare +tests/unit_tests/value_compare.vala.stamp +spec/context-provider-schema.html diff --git a/libcontextprovider/Makefile.fragment b/libcontextprovider/Makefile.fragment index a1b1be6d..30b8aedb 100644 --- a/libcontextprovider/Makefile.fragment +++ b/libcontextprovider/Makefile.fragment @@ -3,7 +3,7 @@ lib_LTLIBRARIES = libcontextprovider.la libcontextprovider_VALASOURCES_PRIV = \ libcontextprovider/dbus_interface.vala \ libcontextprovider/manager.vala \ - libcontextprovider/providers.vala \ + libcontextprovider/groups.vala \ libcontextprovider/key_usage_counter.vala \ libcontextprovider/subscriber.vala \ libcontextprovider/value_compare.vala \ diff --git a/libcontextprovider/group.vala b/libcontextprovider/group.vala new file mode 100644 index 00000000..3cb75d3d --- /dev/null +++ b/libcontextprovider/group.vala @@ -0,0 +1,19 @@ +namespace ContextProvider { + public class Group { + public SubscriptionChangedCallback callback; + public StringSet keys; + public bool subscribed; + + public Group (string[] keys, SubscriptionChangedCallback cb) { + this.keys = new StringSet.from_array(keys); + this.callback = cb; + this.subscribed = false; + } + public void subscribe (bool subscribed) { + if (subscribed != this.subscribed) { + this.subscribed = subscribed; + callback (subscribed); + } + } + } +} diff --git a/libcontextprovider/providers.vala b/libcontextprovider/groups.vala index ecf7a057..ecf7a057 100644 --- a/libcontextprovider/providers.vala +++ b/libcontextprovider/groups.vala diff --git a/tests/unit_tests/test_value_compare.vala b/tests/unit_tests/test_value_compare.vala new file mode 100644 index 00000000..11a15bc5 --- /dev/null +++ b/tests/unit_tests/test_value_compare.vala @@ -0,0 +1,92 @@ +/* value_compare.vala +* +* Copyright (C) 2008 Rob Taylor +* +* This library 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 library 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 Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library. If not, see <http://www.gnu.org/licenses/>. +* +* Author: +* Rob Taylor <rob.taylor@codethink.co.uk> +*/ + +using GLib; +using ContextProvider; + +void test_value_compare_null() { + Value? v1 = null; + Value? v2 = null; + assert(value_compare(v1,v2)); + v1 = Value (typeof(int)); + v1.set_int (12); + assert(!value_compare(v1,v2)); + v2 = v1; + v1 = null; + assert(!value_compare(v1,v2)); +} + +void test_value_compare_int() { + Value v1 = Value (typeof(int)); + v1.set_int (12); + Value v2 = Value (typeof(int)); + v2.set_int (12); + assert(value_compare(v1,v2)); + + v2.set_int (24); + assert(!value_compare(v1,v2)); +} + +void test_value_compare_bool() { + Value v1 = Value (typeof(bool)); + v1.set_boolean (false); + Value v2 = Value (typeof(bool)); + v2.set_boolean (true); + assert(!value_compare(v1,v2)); + + v2.set_boolean (false); + assert(value_compare(v1,v2)); +} + +void test_value_compare_double() { + Value v1 = Value (typeof(double)); + v1.set_double (245.42); + Value v2 = Value (typeof(double)); + v2.set_double (245.42); + assert(value_compare(v1,v2)); + + v2.set_double (12345.98723); + assert(!value_compare(v1,v2)); +} + +void test_value_compare_string() { + Value v1 = Value (typeof(string)); + v1.set_string ("foo bar baz"); + Value v2 = Value (typeof(string)); + v2.set_string ("buz bong fu"); + assert(!value_compare(v1,v2)); + + v2.set_string ("foo bar baz"); + assert(value_compare(v1,v2)); +} + + + +public static void main (string[] args) { + Test.init (ref args); + Test.add_func("/contextkit/value_compare/null", test_value_compare_null); + Test.add_func("/contextkit/value_compare/int", test_value_compare_int); + Test.add_func("/contextkit/value_compare/bool", test_value_compare_bool); + Test.add_func("/contextkit/value_compare/double", test_value_compare_double); + Test.add_func("/contextkit/value_compare/string", test_value_compare_string); + Test.run (); +} + |