[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH v2 07/10] tests: Add QDict clone-flatten test
From: |
Max Reitz |
Subject: |
[Qemu-block] [PATCH v2 07/10] tests: Add QDict clone-flatten test |
Date: |
Mon, 11 Jun 2018 22:52:00 +0200 |
This new test verifies that qdict_flatten() does not modify a shallow
clone of the given QDict.
Reviewed-by: Eric Blake <address@hidden>
Signed-off-by: Max Reitz <address@hidden>
---
tests/check-block-qdict.c | 33 +++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+)
diff --git a/tests/check-block-qdict.c b/tests/check-block-qdict.c
index 1d20fccbd4..478807f839 100644
--- a/tests/check-block-qdict.c
+++ b/tests/check-block-qdict.c
@@ -125,6 +125,38 @@ static void qdict_flatten_test(void)
qobject_unref(root);
}
+static void qdict_clone_flatten_test(void)
+{
+ QDict *dict1 = qdict_new();
+ QDict *dict2 = qdict_new();
+ QDict *cloned_dict1;
+
+ /*
+ * Test that we can clone and flatten
+ * { "a": { "b": 42 } }
+ * without modifying the clone.
+ */
+
+ qdict_put_int(dict2, "b", 42);
+ qdict_put(dict1, "a", dict2);
+
+ cloned_dict1 = qdict_clone_shallow(dict1);
+
+ qdict_flatten(dict1);
+
+ g_assert(qdict_size(dict1) == 1);
+ g_assert(qdict_get_int(dict1, "a.b") == 42);
+
+ g_assert(qdict_size(cloned_dict1) == 1);
+ g_assert(qdict_get_qdict(cloned_dict1, "a") == dict2);
+
+ g_assert(qdict_size(dict2) == 1);
+ g_assert(qdict_get_int(dict2, "b") == 42);
+
+ qobject_unref(dict1);
+ qobject_unref(cloned_dict1);
+}
+
static void qdict_array_split_test(void)
{
QDict *test_dict = qdict_new();
@@ -674,6 +706,7 @@ int main(int argc, char **argv)
g_test_add_func("/public/defaults", qdict_defaults_test);
g_test_add_func("/public/flatten", qdict_flatten_test);
+ g_test_add_func("/public/clone_flatten", qdict_clone_flatten_test);
g_test_add_func("/public/array_split", qdict_array_split_test);
g_test_add_func("/public/array_entries", qdict_array_entries_test);
g_test_add_func("/public/join", qdict_join_test);
--
2.17.1
- Re: [Qemu-block] [Qemu-devel] [PATCH v2 01/10] qapi: Add default-variant for flat unions, (continued)
- [Qemu-block] [PATCH v2 02/10] docs/qapi: Document optional discriminators, Max Reitz, 2018/06/11
- [Qemu-block] [PATCH v2 03/10] tests: Add QAPI optional discriminator tests, Max Reitz, 2018/06/11
- [Qemu-block] [PATCH v2 04/10] qapi: Formalize qcow2 encryption probing, Max Reitz, 2018/06/11
- [Qemu-block] [PATCH v2 05/10] qapi: Formalize qcow encryption probing, Max Reitz, 2018/06/11
- [Qemu-block] [PATCH v2 07/10] tests: Add QDict clone-flatten test,
Max Reitz <=
- [Qemu-block] [PATCH v2 06/10] qdict: Make qdict_flatten() shallow-clone-friendly, Max Reitz, 2018/06/11
- [Qemu-block] [PATCH v2 09/10] iotests: Test internal option typing, Max Reitz, 2018/06/11
- [Qemu-block] [PATCH v2 08/10] block: Try to create well typed json:{} filenames, Max Reitz, 2018/06/11
- [Qemu-block] [PATCH v2 10/10] iotests: qcow2's encrypt.format is now optional, Max Reitz, 2018/06/11
- Re: [Qemu-block] [Qemu-devel] [PATCH v2 00/10] block: Try to create well typed json:{} filenames, Markus Armbruster, 2018/06/19