aboutsummaryrefslogtreecommitdiff
path: root/tests/check-qlist.c
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2020-04-15 10:30:46 +0200
committerMarkus Armbruster <armbru@redhat.com>2020-04-30 06:51:15 +0200
commit2f2ec111795119b2e020bc0cbf4b5f42878574b2 (patch)
treeb4e60346dc8c6f5ea8e59013e85853dd1d960af6 /tests/check-qlist.c
parent1cd7741ef18e4333b17d64aaed3cd48e3e182a57 (diff)
qobject: Eliminate qlist_iter(), use QLIST_FOREACH_ENTRY() instead
qlist_iter() has just three uses outside tests/. Replace by QLIST_FOREACH_ENTRY() for more concise code and less type punning. Signed-off-by: Markus Armbruster <armbru@redhat.com> Message-Id: <20200415083048.14339-4-armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com>
Diffstat (limited to 'tests/check-qlist.c')
-rw-r--r--tests/check-qlist.c37
1 files changed, 14 insertions, 23 deletions
diff --git a/tests/check-qlist.c b/tests/check-qlist.c
index ece83e293d..3cd0ccbf19 100644
--- a/tests/check-qlist.c
+++ b/tests/check-qlist.c
@@ -61,40 +61,31 @@ static void qobject_to_qlist_test(void)
qobject_unref(qlist);
}
-static int iter_called;
-static const int iter_max = 42;
-
-static void iter_func(QObject *obj, void *opaque)
-{
- QNum *qi;
- int64_t val;
-
- g_assert(opaque == NULL);
-
- qi = qobject_to(QNum, obj);
- g_assert(qi != NULL);
-
- g_assert(qnum_get_try_int(qi, &val));
- g_assert_cmpint(val, >=, 0);
- g_assert_cmpint(val, <=, iter_max);
-
- iter_called++;
-}
-
static void qlist_iter_test(void)
{
+ const int iter_max = 42;
int i;
QList *qlist;
+ QListEntry *entry;
+ QNum *qi;
+ int64_t val;
qlist = qlist_new();
for (i = 0; i < iter_max; i++)
qlist_append_int(qlist, i);
- iter_called = 0;
- qlist_iter(qlist, iter_func, NULL);
+ i = 0;
+ QLIST_FOREACH_ENTRY(qlist, entry) {
+ qi = qobject_to(QNum, qlist_entry_obj(entry));
+ g_assert(qi != NULL);
+
+ g_assert(qnum_get_try_int(qi, &val));
+ g_assert_cmpint(val, ==, i);
+ i++;
+ }
- g_assert(iter_called == iter_max);
+ g_assert(i == iter_max);
qobject_unref(qlist);
}