aboutsummaryrefslogtreecommitdiff
path: root/tests/check-qdict.c
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@redhat.com>2018-04-19 17:01:43 +0200
committerMarkus Armbruster <armbru@redhat.com>2018-05-04 08:27:53 +0200
commitcb3e7f08aeaab0ab13e629ce8496dca150a449ba (patch)
tree189830b93bea625aac19f86f26dc4b04cd99f5a3 /tests/check-qdict.c
parent3d3eacaeccaab718ea0e2ddaa578bfae9e311c59 (diff)
qobject: Replace qobject_incref/QINCREF qobject_decref/QDECREF
Now that we can safely call QOBJECT() on QObject * as well as its subtypes, we can have macros qobject_ref() / qobject_unref() that work everywhere instead of having to use QINCREF() / QDECREF() for QObject and qobject_incref() / qobject_decref() for its subtypes. The replacement is mechanical, except I broke a long line, and added a cast in monitor_qmp_cleanup_req_queue_locked(). Unlike qobject_decref(), qobject_unref() doesn't accept void *. Note that the new macros evaluate their argument exactly once, thus no need to shout them. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-Id: <20180419150145.24795-4-marcandre.lureau@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> [Rebased, semantic conflict resolved, commit message improved] Signed-off-by: Markus Armbruster <armbru@redhat.com>
Diffstat (limited to 'tests/check-qdict.c')
-rw-r--r--tests/check-qdict.c100
1 files changed, 50 insertions, 50 deletions
diff --git a/tests/check-qdict.c b/tests/check-qdict.c
index 07bb8f4564..eba5d3528e 100644
--- a/tests/check-qdict.c
+++ b/tests/check-qdict.c
@@ -34,7 +34,7 @@ static void qdict_new_test(void)
g_assert(qdict->base.refcnt == 1);
g_assert(qobject_type(QOBJECT(qdict)) == QTYPE_QDICT);
- QDECREF(qdict);
+ qobject_unref(qdict);
}
static void qdict_put_obj_test(void)
@@ -54,7 +54,7 @@ static void qdict_put_obj_test(void)
qn = qobject_to(QNum, ent->value);
g_assert_cmpint(qnum_get_int(qn), ==, num);
- QDECREF(qdict);
+ qobject_unref(qdict);
}
static void qdict_destroy_simple_test(void)
@@ -65,7 +65,7 @@ static void qdict_destroy_simple_test(void)
qdict_put_int(qdict, "num", 0);
qdict_put_str(qdict, "str", "foo");
- QDECREF(qdict);
+ qobject_unref(qdict);
}
static void qdict_get_test(void)
@@ -84,7 +84,7 @@ static void qdict_get_test(void)
qn = qobject_to(QNum, obj);
g_assert_cmpint(qnum_get_int(qn), ==, value);
- QDECREF(tests_dict);
+ qobject_unref(tests_dict);
}
static void qdict_get_int_test(void)
@@ -99,7 +99,7 @@ static void qdict_get_int_test(void)
ret = qdict_get_int(tests_dict, key);
g_assert(ret == value);
- QDECREF(tests_dict);
+ qobject_unref(tests_dict);
}
static void qdict_get_try_int_test(void)
@@ -121,7 +121,7 @@ static void qdict_get_try_int_test(void)
ret = qdict_get_try_int(tests_dict, "string", -42);
g_assert_cmpuint(ret, ==, -42);
- QDECREF(tests_dict);
+ qobject_unref(tests_dict);
}
static void qdict_get_str_test(void)
@@ -137,7 +137,7 @@ static void qdict_get_str_test(void)
g_assert(p != NULL);
g_assert(strcmp(p, str) == 0);
- QDECREF(tests_dict);
+ qobject_unref(tests_dict);
}
static void qdict_get_try_str_test(void)
@@ -153,7 +153,7 @@ static void qdict_get_try_str_test(void)
g_assert(p != NULL);
g_assert(strcmp(p, str) == 0);
- QDECREF(tests_dict);
+ qobject_unref(tests_dict);
}
static void qdict_defaults_test(void)
@@ -174,8 +174,8 @@ static void qdict_defaults_test(void)
qdict_copy_default(copy, dict, "bar");
g_assert_cmpstr(qdict_get_str(copy, "bar"), ==, "xyz");
- QDECREF(copy);
- QDECREF(dict);
+ qobject_unref(copy);
+ qobject_unref(dict);
}
static void qdict_haskey_not_test(void)
@@ -183,7 +183,7 @@ static void qdict_haskey_not_test(void)
QDict *tests_dict = qdict_new();
g_assert(qdict_haskey(tests_dict, "test") == 0);
- QDECREF(tests_dict);
+ qobject_unref(tests_dict);
}
static void qdict_haskey_test(void)
@@ -194,7 +194,7 @@ static void qdict_haskey_test(void)
qdict_put_int(tests_dict, key, 0);
g_assert(qdict_haskey(tests_dict, key) == 1);
- QDECREF(tests_dict);
+ qobject_unref(tests_dict);
}
static void qdict_del_test(void)
@@ -210,7 +210,7 @@ static void qdict_del_test(void)
g_assert(qdict_size(tests_dict) == 0);
g_assert(qdict_haskey(tests_dict, key) == 0);
- QDECREF(tests_dict);
+ qobject_unref(tests_dict);
}
static void qobject_to_qdict_test(void)
@@ -218,7 +218,7 @@ static void qobject_to_qdict_test(void)
QDict *tests_dict = qdict_new();
g_assert(qobject_to(QDict, QOBJECT(tests_dict)) == tests_dict);
- QDECREF(tests_dict);
+ qobject_unref(tests_dict);
}
static void qdict_iterapi_test(void)
@@ -250,7 +250,7 @@ static void qdict_iterapi_test(void)
g_assert(count == qdict_size(tests_dict));
- QDECREF(tests_dict);
+ qobject_unref(tests_dict);
}
static void qdict_flatten_test(void)
@@ -325,7 +325,7 @@ static void qdict_flatten_test(void)
g_assert(qdict_size(dict3) == 8);
- QDECREF(dict3);
+ qobject_unref(dict3);
}
static void qdict_array_split_test(void)
@@ -390,31 +390,31 @@ static void qdict_array_split_test(void)
g_assert(int1);
g_assert(qlist_empty(test_list));
- QDECREF(test_list);
+ qobject_unref(test_list);
g_assert(qdict_get_int(dict1, "a") == 42);
g_assert(qdict_get_int(dict1, "b") == 23);
g_assert(qdict_size(dict1) == 2);
- QDECREF(dict1);
+ qobject_unref(dict1);
g_assert(qdict_get_int(dict2, "x") == 0);
g_assert(qdict_size(dict2) == 1);
- QDECREF(dict2);
+ qobject_unref(dict2);
g_assert_cmpint(qnum_get_int(int1), ==, 66);
- QDECREF(int1);
+ qobject_unref(int1);
g_assert(qdict_get_int(test_dict, "4.y") == 1);
g_assert(qdict_get_int(test_dict, "o.o") == 7);
g_assert(qdict_size(test_dict) == 2);
- QDECREF(test_dict);
+ qobject_unref(test_dict);
/*
* Test the split of
@@ -455,18 +455,18 @@ static void qdict_array_split_test(void)
g_assert(int1);
g_assert(qlist_empty(test_list));
- QDECREF(test_list);
+ qobject_unref(test_list);
g_assert_cmpint(qnum_get_int(int1), ==, 42);
- QDECREF(int1);
+ qobject_unref(int1);
g_assert(qdict_get_int(test_dict, "1") == 23);
g_assert(qdict_get_int(test_dict, "1.x") == 84);
g_assert(qdict_size(test_dict) == 2);
- QDECREF(test_dict);
+ qobject_unref(test_dict);
}
static void qdict_array_entries_test(void)
@@ -493,7 +493,7 @@ static void qdict_array_entries_test(void)
g_assert_cmpint(qdict_array_entries(dict, "foo."), ==, 3);
g_assert_cmpint(qdict_array_entries(dict, ""), ==, -EINVAL);
- QDECREF(dict);
+ qobject_unref(dict);
dict = qdict_new();
qdict_put_int(dict, "1", 0);
@@ -509,7 +509,7 @@ static void qdict_array_entries_test(void)
qdict_put_int(dict, "2.c", 0);
g_assert_cmpint(qdict_array_entries(dict, ""), ==, 3);
- QDECREF(dict);
+ qobject_unref(dict);
}
static void qdict_join_test(void)
@@ -587,8 +587,8 @@ static void qdict_join_test(void)
}
while (overwrite ^= true);
- QDECREF(dict1);
- QDECREF(dict2);
+ qobject_unref(dict1);
+ qobject_unref(dict2);
}
static void qdict_crumple_test_recursive(void)
@@ -634,21 +634,21 @@ static void qdict_crumple_test_recursive(void)
g_assert_cmpint(qdict_size(rule), ==, 2);
g_assert_cmpstr("fred", ==, qdict_get_str(rule, "match"));
g_assert_cmpstr("allow", ==, qdict_get_str(rule, "policy"));
- QDECREF(rule);
+ qobject_unref(rule);
rule = qobject_to(QDict, qlist_pop(rules));
g_assert(rule);
g_assert_cmpint(qdict_size(rule), ==, 2);
g_assert_cmpstr("bob", ==, qdict_get_str(rule, "match"));
g_assert_cmpstr("deny", ==, qdict_get_str(rule, "policy"));
- QDECREF(rule);
+ qobject_unref(rule);
/* With recursive crumpling, we should see all names unescaped */
g_assert_cmpstr("acl0", ==, qdict_get_str(vnc, "acl.name"));
g_assert_cmpstr("acl0", ==, qdict_get_str(acl, "rule.name"));
- QDECREF(src);
- QDECREF(dst);
+ qobject_unref(src);
+ qobject_unref(dst);
}
static void qdict_crumple_test_empty(void)
@@ -661,8 +661,8 @@ static void qdict_crumple_test_empty(void)
g_assert_cmpint(qdict_size(dst), ==, 0);
- QDECREF(src);
- QDECREF(dst);
+ qobject_unref(src);
+ qobject_unref(dst);
}
static int qdict_count_entries(QDict *dict)
@@ -704,7 +704,7 @@ static void qdict_rename_keys_test(void)
g_assert(qobject_type(qdict_get(copy, "nothing")) == QTYPE_QNULL);
g_assert_cmpint(qdict_count_entries(copy), ==, 5);
- QDECREF(copy);
+ qobject_unref(copy);
/* Simple rename of all entries */
renames = (QDictRenames[]) {
@@ -731,7 +731,7 @@ static void qdict_rename_keys_test(void)
g_assert(qobject_type(qdict_get(copy, "null")) == QTYPE_QNULL);
g_assert_cmpint(qdict_count_entries(copy), ==, 5);
- QDECREF(copy);
+ qobject_unref(copy);
/* Renames are processed top to bottom */
renames = (QDictRenames[]) {
@@ -754,7 +754,7 @@ static void qdict_rename_keys_test(void)
g_assert(!qdict_haskey(copy, "tmp"));
g_assert_cmpint(qdict_count_entries(copy), ==, 5);
- QDECREF(copy);
+ qobject_unref(copy);
/* Conflicting rename */
renames = (QDictRenames[]) {
@@ -775,7 +775,7 @@ static void qdict_rename_keys_test(void)
g_assert(qobject_type(qdict_get(copy, "nothing")) == QTYPE_QNULL);
g_assert_cmpint(qdict_count_entries(copy), ==, 5);
- QDECREF(copy);
+ qobject_unref(copy);
/* Renames in an empty dict */
renames = (QDictRenames[]) {
@@ -783,13 +783,13 @@ static void qdict_rename_keys_test(void)
{ NULL , NULL }
};
- QDECREF(dict);
+ qobject_unref(dict);
dict = qdict_new();
qdict_rename_keys(dict, renames, &error_abort);
g_assert(qdict_first(dict) == NULL);
- QDECREF(dict);
+ qobject_unref(dict);
}
static void qdict_crumple_test_bad_inputs(void)
@@ -806,7 +806,7 @@ static void qdict_crumple_test_bad_inputs(void)
g_assert(error != NULL);
error_free(error);
error = NULL;
- QDECREF(src);
+ qobject_unref(src);
src = qdict_new();
/* rule can't be both a list and a dict */
@@ -817,7 +817,7 @@ static void qdict_crumple_test_bad_inputs(void)
g_assert(error != NULL);
error_free(error);
error = NULL;
- QDECREF(src);
+ qobject_unref(src);
src = qdict_new();
/* The input should be flat, ie no dicts or lists */
@@ -828,7 +828,7 @@ static void qdict_crumple_test_bad_inputs(void)
g_assert(error != NULL);
error_free(error);
error = NULL;
- QDECREF(src);
+ qobject_unref(src);
src = qdict_new();
/* List indexes must not have gaps */
@@ -839,7 +839,7 @@ static void qdict_crumple_test_bad_inputs(void)
g_assert(error != NULL);
error_free(error);
error = NULL;
- QDECREF(src);
+ qobject_unref(src);
src = qdict_new();
/* List indexes must be in %zu format */
@@ -850,7 +850,7 @@ static void qdict_crumple_test_bad_inputs(void)
g_assert(error != NULL);
error_free(error);
error = NULL;
- QDECREF(src);
+ qobject_unref(src);
}
/*
@@ -871,7 +871,7 @@ static void qdict_put_exists_test(void)
g_assert(qdict_size(tests_dict) == 1);
- QDECREF(tests_dict);
+ qobject_unref(tests_dict);
}
static void qdict_get_not_exists_test(void)
@@ -879,7 +879,7 @@ static void qdict_get_not_exists_test(void)
QDict *tests_dict = qdict_new();
g_assert(qdict_get(tests_dict, "foo") == NULL);
- QDECREF(tests_dict);
+ qobject_unref(tests_dict);
}
/*
@@ -951,7 +951,7 @@ static void qdict_stress_test(void)
g_assert(strcmp(str1, str2) == 0);
- QDECREF(value);
+ qobject_unref(value);
}
// Delete everything
@@ -962,14 +962,14 @@ static void qdict_stress_test(void)
break;
qdict_del(qdict, key);
- QDECREF(value);
+ qobject_unref(value);
g_assert(qdict_haskey(qdict, key) == 0);
}
fclose(test_file);
g_assert(qdict_size(qdict) == 0);
- QDECREF(qdict);
+ qobject_unref(qdict);
}
int main(int argc, char **argv)