[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 06/22] check-qdict: Add test for qdict_join()
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 06/22] check-qdict: Add test for qdict_join() |
Date: |
Mon, 19 May 2014 16:22:24 +0200 |
From: Max Reitz <address@hidden>
Add some test cases for qdict_join().
Signed-off-by: Max Reitz <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Reviewed-by: Benoit Canet <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
tests/check-qdict.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 87 insertions(+)
diff --git a/tests/check-qdict.c b/tests/check-qdict.c
index 2ad0f78..a9296f0 100644
--- a/tests/check-qdict.c
+++ b/tests/check-qdict.c
@@ -444,6 +444,92 @@ static void qdict_array_split_test(void)
QDECREF(test_dict);
}
+static void qdict_join_test(void)
+{
+ QDict *dict1, *dict2;
+ bool overwrite = false;
+ int i;
+
+ dict1 = qdict_new();
+ dict2 = qdict_new();
+
+
+ /* Test everything once without overwrite and once with */
+ do
+ {
+ /* Test empty dicts */
+ qdict_join(dict1, dict2, overwrite);
+
+ g_assert(qdict_size(dict1) == 0);
+ g_assert(qdict_size(dict2) == 0);
+
+
+ /* First iteration: Test movement */
+ /* Second iteration: Test empty source and non-empty destination */
+ qdict_put(dict2, "foo", qint_from_int(42));
+
+ for (i = 0; i < 2; i++) {
+ qdict_join(dict1, dict2, overwrite);
+
+ g_assert(qdict_size(dict1) == 1);
+ g_assert(qdict_size(dict2) == 0);
+
+ g_assert(qdict_get_int(dict1, "foo") == 42);
+ }
+
+
+ /* Test non-empty source and destination without conflict */
+ qdict_put(dict2, "bar", qint_from_int(23));
+
+ qdict_join(dict1, dict2, overwrite);
+
+ g_assert(qdict_size(dict1) == 2);
+ g_assert(qdict_size(dict2) == 0);
+
+ g_assert(qdict_get_int(dict1, "foo") == 42);
+ g_assert(qdict_get_int(dict1, "bar") == 23);
+
+
+ /* Test conflict */
+ qdict_put(dict2, "foo", qint_from_int(84));
+
+ qdict_join(dict1, dict2, overwrite);
+
+ g_assert(qdict_size(dict1) == 2);
+ g_assert(qdict_size(dict2) == !overwrite);
+
+ g_assert(qdict_get_int(dict1, "foo") == overwrite ? 84 : 42);
+ g_assert(qdict_get_int(dict1, "bar") == 23);
+
+ if (!overwrite) {
+ g_assert(qdict_get_int(dict2, "foo") == 84);
+ }
+
+
+ /* Check the references */
+ g_assert(qdict_get(dict1, "foo")->refcnt == 1);
+ g_assert(qdict_get(dict1, "bar")->refcnt == 1);
+
+ if (!overwrite) {
+ g_assert(qdict_get(dict2, "foo")->refcnt == 1);
+ }
+
+
+ /* Clean up */
+ qdict_del(dict1, "foo");
+ qdict_del(dict1, "bar");
+
+ if (!overwrite) {
+ qdict_del(dict2, "foo");
+ }
+ }
+ while (overwrite ^= true);
+
+
+ QDECREF(dict1);
+ QDECREF(dict2);
+}
+
/*
* Errors test-cases
*/
@@ -584,6 +670,7 @@ int main(int argc, char **argv)
g_test_add_func("/public/iterapi", qdict_iterapi_test);
g_test_add_func("/public/flatten", qdict_flatten_test);
g_test_add_func("/public/array_split", qdict_array_split_test);
+ g_test_add_func("/public/join", qdict_join_test);
g_test_add_func("/errors/put_exists", qdict_put_exists_test);
g_test_add_func("/errors/get_not_exists", qdict_get_not_exists_test);
--
1.8.3.1
- [Qemu-devel] [PULL 00/22] Block patches, Kevin Wolf, 2014/05/19
- [Qemu-devel] [PULL 02/22] Remove g_sequence_lookup from qemu-img help function, Kevin Wolf, 2014/05/19
- [Qemu-devel] [PULL 05/22] qdict: Add qdict_join(), Kevin Wolf, 2014/05/19
- [Qemu-devel] [PULL 06/22] check-qdict: Add test for qdict_join(),
Kevin Wolf <=
- [Qemu-devel] [PULL 04/22] block: add test for vhdx image created by Disk2VHD, Kevin Wolf, 2014/05/19
- [Qemu-devel] [PULL 01/22] block: Fix bdrv_is_allocated() for short backing files, Kevin Wolf, 2014/05/19
- [Qemu-devel] [PULL 03/22] block: vhdx - account for identical header sections, Kevin Wolf, 2014/05/19
- [Qemu-devel] [PULL 08/22] iotests: Add test for the JSON protocol, Kevin Wolf, 2014/05/19
- [Qemu-devel] [PULL 09/22] qemu-iotests: Fix core dump suppression in test 039, Kevin Wolf, 2014/05/19
- [Qemu-devel] [PULL 07/22] block: Allow JSON filenames, Kevin Wolf, 2014/05/19
- [Qemu-devel] [PULL 10/22] qemu-iotests: Fix blkdebug in VM drive in 030, Kevin Wolf, 2014/05/19
- [Qemu-devel] [PULL 14/22] curl: Add usage documentation, Kevin Wolf, 2014/05/19
- [Qemu-devel] [PULL 12/22] curl: Remove broken parsing of options from url, Kevin Wolf, 2014/05/19
- [Qemu-devel] [PULL 11/22] curl: Fix build when curl_multi_socket_action isn't available, Kevin Wolf, 2014/05/19