diff options
author | Eric Blake <eblake@redhat.com> | 2017-04-27 16:58:17 -0500 |
---|---|---|
committer | Markus Armbruster <armbru@redhat.com> | 2017-05-09 09:13:51 +0200 |
commit | 46f5ac205a9dc5e2c24274c7df371509a286281f (patch) | |
tree | 52cd3eab32f34963a5275f6f291386d4ad8b6624 /tests/check-qdict.c | |
parent | a92c21591b5bb9543996538f14854ca6b528318b (diff) | |
download | qemu-46f5ac205a9dc5e2c24274c7df371509a286281f.zip qemu-46f5ac205a9dc5e2c24274c7df371509a286281f.tar.gz qemu-46f5ac205a9dc5e2c24274c7df371509a286281f.tar.bz2 |
qobject: Use simpler QDict/QList scalar insertion macros
We now have macros in place to make it less verbose to add a scalar
to QDict and QList, so use them.
Patch created mechanically via:
spatch --sp-file scripts/coccinelle/qobject.cocci \
--macro-file scripts/cocci-macro-file.h --dir . --in-place
then touched up manually to fix a couple of '?:' back to original
spacing, as well as avoiding a long line in monitor.c.
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20170427215821.19397-7-eblake@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Alberto Garcia <berto@igalia.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Diffstat (limited to 'tests/check-qdict.c')
-rw-r--r-- | tests/check-qdict.c | 134 |
1 files changed, 67 insertions, 67 deletions
diff --git a/tests/check-qdict.c b/tests/check-qdict.c index 3cb72fb..be8d81f 100644 --- a/tests/check-qdict.c +++ b/tests/check-qdict.c @@ -47,7 +47,7 @@ static void qdict_put_obj_test(void) qdict = qdict_new(); // key "" will have tdb hash 12345 - qdict_put(qdict, "", qint_from_int(num)); + qdict_put_int(qdict, "", num); g_assert(qdict_size(qdict) == 1); ent = QLIST_FIRST(&qdict->table[12345 % QDICT_BUCKET_MAX]); @@ -66,8 +66,8 @@ static void qdict_destroy_simple_test(void) QDict *qdict; qdict = qdict_new(); - qdict_put(qdict, "num", qint_from_int(0)); - qdict_put(qdict, "str", qstring_from_str("foo")); + qdict_put_int(qdict, "num", 0); + qdict_put_str(qdict, "str", "foo"); QDECREF(qdict); } @@ -80,7 +80,7 @@ static void qdict_get_test(void) const char *key = "test"; QDict *tests_dict = qdict_new(); - qdict_put(tests_dict, key, qint_from_int(value)); + qdict_put_int(tests_dict, key, value); obj = qdict_get(tests_dict, key); g_assert(obj != NULL); @@ -98,7 +98,7 @@ static void qdict_get_int_test(void) const char *key = "int"; QDict *tests_dict = qdict_new(); - qdict_put(tests_dict, key, qint_from_int(value)); + qdict_put_int(tests_dict, key, value); ret = qdict_get_int(tests_dict, key); g_assert(ret == value); @@ -113,7 +113,7 @@ static void qdict_get_try_int_test(void) const char *key = "int"; QDict *tests_dict = qdict_new(); - qdict_put(tests_dict, key, qint_from_int(value)); + qdict_put_int(tests_dict, key, value); ret = qdict_get_try_int(tests_dict, key, 0); g_assert(ret == value); @@ -128,7 +128,7 @@ static void qdict_get_str_test(void) const char *str = "string"; QDict *tests_dict = qdict_new(); - qdict_put(tests_dict, key, qstring_from_str(str)); + qdict_put_str(tests_dict, key, str); p = qdict_get_str(tests_dict, key); g_assert(p != NULL); @@ -144,7 +144,7 @@ static void qdict_get_try_str_test(void) const char *str = "string"; QDict *tests_dict = qdict_new(); - qdict_put(tests_dict, key, qstring_from_str(str)); + qdict_put_str(tests_dict, key, str); p = qdict_get_try_str(tests_dict, key); g_assert(p != NULL); @@ -188,7 +188,7 @@ static void qdict_haskey_test(void) const char *key = "test"; QDict *tests_dict = qdict_new(); - qdict_put(tests_dict, key, qint_from_int(0)); + qdict_put_int(tests_dict, key, 0); g_assert(qdict_haskey(tests_dict, key) == 1); QDECREF(tests_dict); @@ -199,7 +199,7 @@ static void qdict_del_test(void) const char *key = "key test"; QDict *tests_dict = qdict_new(); - qdict_put(tests_dict, key, qstring_from_str("foo")); + qdict_put_str(tests_dict, key, "foo"); g_assert(qdict_size(tests_dict) == 1); qdict_del(tests_dict, key); @@ -226,9 +226,9 @@ static void qdict_iterapi_test(void) g_assert(qdict_first(tests_dict) == NULL); - qdict_put(tests_dict, "key1", qint_from_int(1)); - qdict_put(tests_dict, "key2", qint_from_int(2)); - qdict_put(tests_dict, "key3", qint_from_int(3)); + qdict_put_int(tests_dict, "key1", 1); + qdict_put_int(tests_dict, "key2", 2); + qdict_put_int(tests_dict, "key3", 3); count = 0; for (ent = qdict_first(tests_dict); ent; ent = qdict_next(tests_dict, ent)){ @@ -294,20 +294,20 @@ static void qdict_flatten_test(void) * } */ - qdict_put(dict1, "a", qint_from_int(0)); - qdict_put(dict1, "b", qint_from_int(1)); + qdict_put_int(dict1, "a", 0); + qdict_put_int(dict1, "b", 1); - qlist_append(list1, qint_from_int(23)); - qlist_append(list1, qint_from_int(66)); + qlist_append_int(list1, 23); + qlist_append_int(list1, 66); qlist_append(list1, dict1); - qlist_append(list2, qint_from_int(42)); + qlist_append_int(list2, 42); qlist_append(list2, list1); - qdict_put(dict2, "c", qint_from_int(2)); - qdict_put(dict2, "d", qint_from_int(3)); + qdict_put_int(dict2, "c", 2); + qdict_put_int(dict2, "d", 3); qdict_put(dict3, "e", list2); qdict_put(dict3, "f", dict2); - qdict_put(dict3, "g", qint_from_int(4)); + qdict_put_int(dict3, "g", 4); qdict_flatten(dict3); @@ -369,12 +369,12 @@ static void qdict_array_split_test(void) * This example is given in the comment of qdict_array_split(). */ - qdict_put(test_dict, "1.x", qint_from_int(0)); - qdict_put(test_dict, "4.y", qint_from_int(1)); - qdict_put(test_dict, "0.a", qint_from_int(42)); - qdict_put(test_dict, "o.o", qint_from_int(7)); - qdict_put(test_dict, "0.b", qint_from_int(23)); - qdict_put(test_dict, "2", qint_from_int(66)); + qdict_put_int(test_dict, "1.x", 0); + qdict_put_int(test_dict, "4.y", 1); + qdict_put_int(test_dict, "0.a", 42); + qdict_put_int(test_dict, "o.o", 7); + qdict_put_int(test_dict, "0.b", 23); + qdict_put_int(test_dict, "2", 66); qdict_array_split(test_dict, &test_list); @@ -441,9 +441,9 @@ static void qdict_array_split_test(void) test_dict = qdict_new(); - qdict_put(test_dict, "0", qint_from_int(42)); - qdict_put(test_dict, "1", qint_from_int(23)); - qdict_put(test_dict, "1.x", qint_from_int(84)); + qdict_put_int(test_dict, "0", 42); + qdict_put_int(test_dict, "1", 23); + qdict_put_int(test_dict, "1.x", 84); qdict_array_split(test_dict, &test_list); @@ -472,38 +472,38 @@ static void qdict_array_entries_test(void) g_assert_cmpint(qdict_array_entries(dict, "foo."), ==, 0); - qdict_put(dict, "bar", qint_from_int(0)); - qdict_put(dict, "baz.0", qint_from_int(0)); + qdict_put_int(dict, "bar", 0); + qdict_put_int(dict, "baz.0", 0); g_assert_cmpint(qdict_array_entries(dict, "foo."), ==, 0); - qdict_put(dict, "foo.1", qint_from_int(0)); + qdict_put_int(dict, "foo.1", 0); g_assert_cmpint(qdict_array_entries(dict, "foo."), ==, -EINVAL); - qdict_put(dict, "foo.0", qint_from_int(0)); + qdict_put_int(dict, "foo.0", 0); g_assert_cmpint(qdict_array_entries(dict, "foo."), ==, 2); - qdict_put(dict, "foo.bar", qint_from_int(0)); + qdict_put_int(dict, "foo.bar", 0); g_assert_cmpint(qdict_array_entries(dict, "foo."), ==, -EINVAL); qdict_del(dict, "foo.bar"); - qdict_put(dict, "foo.2.a", qint_from_int(0)); - qdict_put(dict, "foo.2.b", qint_from_int(0)); - qdict_put(dict, "foo.2.c", qint_from_int(0)); + qdict_put_int(dict, "foo.2.a", 0); + qdict_put_int(dict, "foo.2.b", 0); + qdict_put_int(dict, "foo.2.c", 0); g_assert_cmpint(qdict_array_entries(dict, "foo."), ==, 3); g_assert_cmpint(qdict_array_entries(dict, ""), ==, -EINVAL); QDECREF(dict); dict = qdict_new(); - qdict_put(dict, "1", qint_from_int(0)); + qdict_put_int(dict, "1", 0); g_assert_cmpint(qdict_array_entries(dict, ""), ==, -EINVAL); - qdict_put(dict, "0", qint_from_int(0)); + qdict_put_int(dict, "0", 0); g_assert_cmpint(qdict_array_entries(dict, ""), ==, 2); - qdict_put(dict, "bar", qint_from_int(0)); + qdict_put_int(dict, "bar", 0); g_assert_cmpint(qdict_array_entries(dict, ""), ==, -EINVAL); qdict_del(dict, "bar"); - qdict_put(dict, "2.a", qint_from_int(0)); - qdict_put(dict, "2.b", qint_from_int(0)); - qdict_put(dict, "2.c", qint_from_int(0)); + qdict_put_int(dict, "2.a", 0); + qdict_put_int(dict, "2.b", 0); + qdict_put_int(dict, "2.c", 0); g_assert_cmpint(qdict_array_entries(dict, ""), ==, 3); QDECREF(dict); @@ -529,7 +529,7 @@ static void qdict_join_test(void) /* First iteration: Test movement */ /* Second iteration: Test empty source and non-empty destination */ - qdict_put(dict2, "foo", qint_from_int(42)); + qdict_put_int(dict2, "foo", 42); for (i = 0; i < 2; i++) { qdict_join(dict1, dict2, overwrite); @@ -541,7 +541,7 @@ static void qdict_join_test(void) } /* Test non-empty source and destination without conflict */ - qdict_put(dict2, "bar", qint_from_int(23)); + qdict_put_int(dict2, "bar", 23); qdict_join(dict1, dict2, overwrite); @@ -552,7 +552,7 @@ static void qdict_join_test(void) g_assert(qdict_get_int(dict1, "bar") == 23); /* Test conflict */ - qdict_put(dict2, "foo", qint_from_int(84)); + qdict_put_int(dict2, "foo", 84); qdict_join(dict1, dict2, overwrite); @@ -594,15 +594,15 @@ static void qdict_crumple_test_recursive(void) QList *rules; src = qdict_new(); - qdict_put(src, "vnc.listen.addr", qstring_from_str("127.0.0.1")); - qdict_put(src, "vnc.listen.port", qstring_from_str("5901")); - qdict_put(src, "vnc.acl.rules.0.match", qstring_from_str("fred")); - qdict_put(src, "vnc.acl.rules.0.policy", qstring_from_str("allow")); - qdict_put(src, "vnc.acl.rules.1.match", qstring_from_str("bob")); - qdict_put(src, "vnc.acl.rules.1.policy", qstring_from_str("deny")); - qdict_put(src, "vnc.acl.default", qstring_from_str("deny")); - qdict_put(src, "vnc.acl..name", qstring_from_str("acl0")); - qdict_put(src, "vnc.acl.rule..name", qstring_from_str("acl0")); + qdict_put_str(src, "vnc.listen.addr", "127.0.0.1"); + qdict_put_str(src, "vnc.listen.port", "5901"); + qdict_put_str(src, "vnc.acl.rules.0.match", "fred"); + qdict_put_str(src, "vnc.acl.rules.0.policy", "allow"); + qdict_put_str(src, "vnc.acl.rules.1.match", "bob"); + qdict_put_str(src, "vnc.acl.rules.1.policy", "deny"); + qdict_put_str(src, "vnc.acl.default", "deny"); + qdict_put_str(src, "vnc.acl..name", "acl0"); + qdict_put_str(src, "vnc.acl.rule..name", "acl0"); dst = qobject_to_qdict(qdict_crumple(src, &error_abort)); g_assert(dst); @@ -669,8 +669,8 @@ static void qdict_crumple_test_bad_inputs(void) src = qdict_new(); /* rule.0 can't be both a string and a dict */ - qdict_put(src, "rule.0", qstring_from_str("fred")); - qdict_put(src, "rule.0.policy", qstring_from_str("allow")); + qdict_put_str(src, "rule.0", "fred"); + qdict_put_str(src, "rule.0.policy", "allow"); g_assert(qdict_crumple(src, &error) == NULL); g_assert(error != NULL); @@ -680,8 +680,8 @@ static void qdict_crumple_test_bad_inputs(void) src = qdict_new(); /* rule can't be both a list and a dict */ - qdict_put(src, "rule.0", qstring_from_str("fred")); - qdict_put(src, "rule.a", qstring_from_str("allow")); + qdict_put_str(src, "rule.0", "fred"); + qdict_put_str(src, "rule.a", "allow"); g_assert(qdict_crumple(src, &error) == NULL); g_assert(error != NULL); @@ -692,7 +692,7 @@ static void qdict_crumple_test_bad_inputs(void) src = qdict_new(); /* The input should be flat, ie no dicts or lists */ qdict_put(src, "rule.a", qdict_new()); - qdict_put(src, "rule.b", qstring_from_str("allow")); + qdict_put_str(src, "rule.b", "allow"); g_assert(qdict_crumple(src, &error) == NULL); g_assert(error != NULL); @@ -702,8 +702,8 @@ static void qdict_crumple_test_bad_inputs(void) src = qdict_new(); /* List indexes must not have gaps */ - qdict_put(src, "rule.0", qstring_from_str("deny")); - qdict_put(src, "rule.3", qstring_from_str("allow")); + qdict_put_str(src, "rule.0", "deny"); + qdict_put_str(src, "rule.3", "allow"); g_assert(qdict_crumple(src, &error) == NULL); g_assert(error != NULL); @@ -713,8 +713,8 @@ static void qdict_crumple_test_bad_inputs(void) src = qdict_new(); /* List indexes must be in %zu format */ - qdict_put(src, "rule.0", qstring_from_str("deny")); - qdict_put(src, "rule.+1", qstring_from_str("allow")); + qdict_put_str(src, "rule.0", "deny"); + qdict_put_str(src, "rule.+1", "allow"); g_assert(qdict_crumple(src, &error) == NULL); g_assert(error != NULL); @@ -733,8 +733,8 @@ static void qdict_put_exists_test(void) const char *key = "exists"; QDict *tests_dict = qdict_new(); - qdict_put(tests_dict, key, qint_from_int(1)); - qdict_put(tests_dict, key, qint_from_int(2)); + qdict_put_int(tests_dict, key, 1); + qdict_put_int(tests_dict, key, 2); value = qdict_get_int(tests_dict, key); g_assert(value == 2); |