diff options
Diffstat (limited to 'tests/unit_tests/intset.c')
-rw-r--r-- | tests/unit_tests/intset.c | 164 |
1 files changed, 164 insertions, 0 deletions
diff --git a/tests/unit_tests/intset.c b/tests/unit_tests/intset.c new file mode 100644 index 00000000..df7567f0 --- /dev/null +++ b/tests/unit_tests/intset.c @@ -0,0 +1,164 @@ +/* main.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> + */ + +#include <tests/unit_tests/intset.h> +#include <intset.h> + + + + +static void _test_intset_new_gcallback (void); +static void _test_intset_add_gcallback (void); +static void _test_intset_intersect_gcallback (void); +static void _test_intset_disjoint_gcallback (void); +static int _vala_strcmp0 (const char * str1, const char * str2); + + + + +GType test_values_get_type (void) { + static GType test_values_type_id = 0; + if (G_UNLIKELY (test_values_type_id == 0)) { + static const GEnumValue values[] = {{TEST_VALUES_A, "TEST_VALUES_A", "a"}, {TEST_VALUES_B, "TEST_VALUES_B", "b"}, {TEST_VALUES_C, "TEST_VALUES_C", "c"}, {TEST_VALUES_D, "TEST_VALUES_D", "d"}, {TEST_VALUES_E, "TEST_VALUES_E", "e"}, {0, NULL, NULL}}; + test_values_type_id = g_enum_register_static ("TestValues", values); + } + return test_values_type_id; +} + + +void test_intset_new (void) { + ContextProviderIntSet* intset; + intset = context_provider_intset_new (); + g_assert (_vala_strcmp0 (context_provider_intset_dump (intset), "") == 0); + (intset == NULL) ? NULL : (intset = (context_provider_intset_destroy (intset), NULL)); +} + + +void test_intset_add (void) { + ContextProviderIntSet* intset; + intset = context_provider_intset_new (); + context_provider_intset_add (intset, (guint) TEST_VALUES_A); + context_provider_intset_add (intset, (guint) TEST_VALUES_B); + context_provider_intset_add (intset, (guint) TEST_VALUES_C); + context_provider_intset_add (intset, (guint) TEST_VALUES_D); + context_provider_intset_add (intset, (guint) TEST_VALUES_E); + g_assert (context_provider_intset_is_member (intset, (guint) TEST_VALUES_A)); + g_assert (context_provider_intset_is_member (intset, (guint) TEST_VALUES_B)); + g_assert (context_provider_intset_is_member (intset, (guint) TEST_VALUES_C)); + g_assert (context_provider_intset_is_member (intset, (guint) TEST_VALUES_D)); + g_assert (context_provider_intset_is_member (intset, (guint) TEST_VALUES_E)); + (intset == NULL) ? NULL : (intset = (context_provider_intset_destroy (intset), NULL)); +} + + +void test_intset_intersect (void) { + ContextProviderIntSet* i1; + ContextProviderIntSet* i2; + ContextProviderIntSet* i3; + i1 = context_provider_intset_new (); + i2 = context_provider_intset_new (); + context_provider_intset_add (i1, (guint) TEST_VALUES_A); + context_provider_intset_add (i1, (guint) TEST_VALUES_B); + context_provider_intset_add (i1, (guint) TEST_VALUES_C); + context_provider_intset_add (i2, (guint) TEST_VALUES_C); + context_provider_intset_add (i2, (guint) TEST_VALUES_D); + context_provider_intset_add (i2, (guint) TEST_VALUES_E); + i3 = context_provider_intset_intersection (i1, i2); + g_assert (context_provider_intset_is_member (i3, (guint) TEST_VALUES_C)); + g_assert (!context_provider_intset_is_member (i3, (guint) TEST_VALUES_A)); + g_assert (!context_provider_intset_is_member (i3, (guint) TEST_VALUES_B)); + g_assert (!context_provider_intset_is_member (i3, (guint) TEST_VALUES_D)); + g_assert (!context_provider_intset_is_member (i3, (guint) TEST_VALUES_E)); + (i1 == NULL) ? NULL : (i1 = (context_provider_intset_destroy (i1), NULL)); + (i2 == NULL) ? NULL : (i2 = (context_provider_intset_destroy (i2), NULL)); + (i3 == NULL) ? NULL : (i3 = (context_provider_intset_destroy (i3), NULL)); +} + + +void test_intset_disjoint (void) { + ContextProviderIntSet* i1; + ContextProviderIntSet* i2; + i1 = context_provider_intset_new (); + i2 = context_provider_intset_new (); + context_provider_intset_add (i1, (guint) TEST_VALUES_A); + context_provider_intset_add (i1, (guint) TEST_VALUES_B); + context_provider_intset_add (i1, (guint) TEST_VALUES_C); + context_provider_intset_add (i2, (guint) TEST_VALUES_C); + context_provider_intset_add (i2, (guint) TEST_VALUES_D); + context_provider_intset_add (i2, (guint) TEST_VALUES_E); + g_assert (!context_provider_intset_is_disjoint (i1, i2)); + context_provider_intset_remove (i1, (guint) TEST_VALUES_C); + g_assert (context_provider_intset_is_disjoint (i1, i2)); + (i1 == NULL) ? NULL : (i1 = (context_provider_intset_destroy (i1), NULL)); + (i2 == NULL) ? NULL : (i2 = (context_provider_intset_destroy (i2), NULL)); +} + + +static void _test_intset_new_gcallback (void) { + test_intset_new (); +} + + +static void _test_intset_add_gcallback (void) { + test_intset_add (); +} + + +static void _test_intset_intersect_gcallback (void) { + test_intset_intersect (); +} + + +static void _test_intset_disjoint_gcallback (void) { + test_intset_disjoint (); +} + + +void _main (char** args, int args_length1) { + g_test_init (&args_length1, &args, NULL); + g_test_add_func ("/contextkit/intset/new", _test_intset_new_gcallback); + g_test_add_func ("/contextkit/intset/add", _test_intset_add_gcallback); + g_test_add_func ("/contextkit/intset/intersect", _test_intset_intersect_gcallback); + g_test_add_func ("/contextkit/intset/disjoint", _test_intset_disjoint_gcallback); + g_test_run (); +} + + +int main (int argc, char ** argv) { + g_type_init (); + _main (argv, argc); + return 0; +} + + +static int _vala_strcmp0 (const char * str1, const char * str2) { + if (str1 == NULL) { + return -(str1 != str2); + } + if (str2 == NULL) { + return str1 != str2; + } + return strcmp (str1, str2); +} + + + + |