Patchwork [2/9] check-qdict: Add test for qdict_iter()

login
register
mail settings
Submitter Luiz Capitulino
Date Oct. 13, 2009, 4:56 p.m.
Message ID <1255453026-18637-3-git-send-email-lcapitulino@redhat.com>
Download mbox | patch
Permalink /patch/35874/
State New
Headers show

Comments

Luiz Capitulino - Oct. 13, 2009, 4:56 p.m.
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 check-qdict.c |   35 +++++++++++++++++++++++++++++++++++
 1 files changed, 35 insertions(+), 0 deletions(-)

Patch

diff --git a/check-qdict.c b/check-qdict.c
index c37d448..c80ff22 100644
--- a/check-qdict.c
+++ b/check-qdict.c
@@ -191,6 +191,40 @@  START_TEST(qobject_to_qdict_test)
 }
 END_TEST
 
+static int iter_called;
+static const int iter_max = 42;
+
+static void iter_func(const char *key, QObject *obj, void *opaque)
+{
+    QInt *qi;
+
+    fail_unless(key != NULL);
+    fail_unless(strstr(key, "key_") != NULL);
+    fail_unless(opaque == NULL),
+
+    qi = qobject_to_qint(obj);
+    fail_unless(qi != NULL);
+    fail_unless((qint_get_int(qi) >= 0) && (qint_get_int(qi) <= iter_max));
+
+    iter_called++;
+}
+
+START_TEST(qdict_iter_test)
+{
+    int i;
+
+    for (i = 0; i < iter_max; i++) {
+        char key[12];
+        sprintf(key, "key_%d", i);
+        qdict_put(tests_dict, key, qint_from_int(i));
+    }
+
+    iter_called = 0;
+    qdict_iter(tests_dict, iter_func, NULL);
+    fail_unless(iter_called == iter_max, "%d\n", iter_called);
+}
+END_TEST
+
 /*
  * Errors test-cases
  */
@@ -333,6 +367,7 @@  static Suite *qdict_suite(void)
     tcase_add_test(qdict_public2_tcase, qdict_haskey_test);
     tcase_add_test(qdict_public2_tcase, qdict_del_test);
     tcase_add_test(qdict_public2_tcase, qobject_to_qdict_test);
+    tcase_add_test(qdict_public2_tcase, qdict_iter_test);
 
     qdict_errors_tcase = tcase_create("Errors");
     suite_add_tcase(s, qdict_errors_tcase);