static void test_operators () { succeed_if (!gelektra_key_equal (g_key, g_bkey), "keys shouldn't be equal"); succeed_if (gelektra_key_cmp (g_key, g_bkey) != 0, "keys shouldn't be equal"); GElektraKey * key = gelektra_key_dup (g_key); succeed_if (gelektra_key_equal (g_key, key), "keys should be equal"); succeed_if (gelektra_key_cmp (g_key, key) == 0, "keys should be equal"); g_object_unref (key); }
static void test_iterating (void) { GElektraKeySet * ks; GElektraKey *key1, *key2, *tmpkey; key1 = gelektra_key_new ("user/a", GELEKTRA_KEY_END); g_object_ref (key1); key2 = gelektra_key_new ("user/c", GELEKTRA_KEY_END); g_object_ref (key2); ks = gelektra_keyset_new (3, key1, gelektra_key_new ("user/b", GELEKTRA_KEY_END), key2, GELEKTRA_KEYSET_END); guint cnt = 0; gelektra_keyset_rewind (ks); while ((tmpkey = gelektra_keyset_next (ks)) != NULL) { GElektraKey * curkey = gelektra_keyset_current (ks); succeed_if (gelektra_key_cmp (tmpkey, curkey) == 0, "iterators returned different keys"); g_object_unref (curkey); succeed_if (gelektra_keyset_getcursor (ks) == cnt, "cursor is at unexpected position"); ++cnt; g_object_unref (tmpkey); } succeed_if (cnt == 3, "some keys are missing"); tmpkey = gelektra_keyset_head (ks); succeed_if (gelektra_key_cmp (tmpkey, key1) == 0, "keyset_head returned unexpected key"); g_object_unref (tmpkey); tmpkey = gelektra_keyset_tail (ks); succeed_if (gelektra_key_cmp (tmpkey, key2) == 0, "keyset_tail returned unexpected key"); g_object_unref (tmpkey); tmpkey = gelektra_keyset_atcursor (ks, 0); succeed_if (gelektra_key_cmp (tmpkey, key1) == 0, "keyset_atcursor returned unexpected key"); g_object_unref (tmpkey); gelektra_keyset_setcursor (ks, 1); succeed_if (gelektra_keyset_getcursor (ks) == 1, "cursor is at unexpected position"); g_object_unref (key1); g_object_unref (key2); g_object_unref (ks); }
static void test_searching (void) { GElektraKeySet * ks; GElektraKey *key1, *key2; const char * name = "user/bar"; key1 = gelektra_key_new (name, GELEKTRA_KEY_END); g_object_ref (key1); ks = gelektra_keyset_new (3, gelektra_key_new ("user/foo", GELEKTRA_KEY_END), key1, gelektra_key_new ("user/foobar", GELEKTRA_KEY_END), GELEKTRA_KEYSET_END); key2 = gelektra_keyset_lookup (ks, key1, GELEKTRA_KDB_O_NONE); succeed_if (gelektra_key_cmp (key1, key2) == 0, "lookup returned different key"); g_object_unref (key2); key2 = gelektra_keyset_lookup_byname (ks, name, GELEKTRA_KDB_O_NONE); succeed_if (gelektra_key_cmp (key1, key2) == 0, "lookup returned different key"); g_object_unref (key2); g_object_unref (key1); g_object_unref (ks); }