[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 15/25] check-qdict: Test cases for new functions
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PULL 15/25] check-qdict: Test cases for new functions |
Date: |
Fri, 12 Jun 2015 18:23:24 +0200 |
This adds test cases for the following new QDict functions:
* qdict_array_entries()
* qdict_set_default_str()
* qdict_copy_default()
Signed-off-by: Kevin Wolf <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Reviewed-by: Max Reitz <address@hidden>
---
tests/check-qdict.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 67 insertions(+)
diff --git a/tests/check-qdict.c b/tests/check-qdict.c
index a9296f0..a136f2a 100644
--- a/tests/check-qdict.c
+++ b/tests/check-qdict.c
@@ -152,6 +152,28 @@ static void qdict_get_try_str_test(void)
QDECREF(tests_dict);
}
+static void qdict_defaults_test(void)
+{
+ QDict *dict, *copy;
+
+ dict = qdict_new();
+ copy = qdict_new();
+
+ qdict_set_default_str(dict, "foo", "abc");
+ qdict_set_default_str(dict, "foo", "def");
+ g_assert_cmpstr(qdict_get_str(dict, "foo"), ==, "abc");
+ qdict_set_default_str(dict, "bar", "ghi");
+
+ qdict_copy_default(copy, dict, "foo");
+ g_assert_cmpstr(qdict_get_str(copy, "foo"), ==, "abc");
+ qdict_set_default_str(copy, "bar", "xyz");
+ qdict_copy_default(copy, dict, "bar");
+ g_assert_cmpstr(qdict_get_str(copy, "bar"), ==, "xyz");
+
+ QDECREF(copy);
+ QDECREF(dict);
+}
+
static void qdict_haskey_not_test(void)
{
QDict *tests_dict = qdict_new();
@@ -444,6 +466,49 @@ static void qdict_array_split_test(void)
QDECREF(test_dict);
}
+static void qdict_array_entries_test(void)
+{
+ QDict *dict = qdict_new();
+
+ 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));
+ g_assert_cmpint(qdict_array_entries(dict, "foo."), ==, 0);
+
+ qdict_put(dict, "foo.1", qint_from_int(0));
+ g_assert_cmpint(qdict_array_entries(dict, "foo."), ==, -EINVAL);
+ qdict_put(dict, "foo.0", qint_from_int(0));
+ g_assert_cmpint(qdict_array_entries(dict, "foo."), ==, 2);
+ qdict_put(dict, "foo.bar", qint_from_int(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));
+ 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));
+ g_assert_cmpint(qdict_array_entries(dict, ""), ==, -EINVAL);
+ qdict_put(dict, "0", qint_from_int(0));
+ g_assert_cmpint(qdict_array_entries(dict, ""), ==, 2);
+ qdict_put(dict, "bar", qint_from_int(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));
+ g_assert_cmpint(qdict_array_entries(dict, ""), ==, 3);
+
+ QDECREF(dict);
+}
+
static void qdict_join_test(void)
{
QDict *dict1, *dict2;
@@ -663,6 +728,7 @@ int main(int argc, char **argv)
g_test_add_func("/public/get_try_int", qdict_get_try_int_test);
g_test_add_func("/public/get_str", qdict_get_str_test);
g_test_add_func("/public/get_try_str", qdict_get_try_str_test);
+ g_test_add_func("/public/defaults", qdict_defaults_test);
g_test_add_func("/public/haskey_not", qdict_haskey_not_test);
g_test_add_func("/public/haskey", qdict_haskey_test);
g_test_add_func("/public/del", qdict_del_test);
@@ -670,6 +736,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/array_entries", qdict_array_entries_test);
g_test_add_func("/public/join", qdict_join_test);
g_test_add_func("/errors/put_exists", qdict_put_exists_test);
--
1.8.3.1
- [Qemu-block] [PULL 05/25] qcow2: Add DEFAULT_L2_CACHE_CLUSTERS, (continued)
- [Qemu-block] [PULL 05/25] qcow2: Add DEFAULT_L2_CACHE_CLUSTERS, Kevin Wolf, 2015/06/12
- [Qemu-block] [PULL 06/25] vmdk: Fix index_in_cluster calculation in vmdk_co_get_block_status, Kevin Wolf, 2015/06/12
- [Qemu-block] [PULL 08/25] raw-posix: Fix .bdrv_co_get_block_status() for unaligned image size, Kevin Wolf, 2015/06/12
- [Qemu-block] [PULL 09/25] block: record new size in bdrv_dirty_bitmap_truncate, Kevin Wolf, 2015/06/12
- [Qemu-block] [PULL 07/25] vmdk: Use vmdk_find_index_in_cluster everywhere, Kevin Wolf, 2015/06/12
- [Qemu-block] [PULL 10/25] block: Change bitmap truncate conditional to assertion, Kevin Wolf, 2015/06/12
- [Qemu-block] [PULL 11/25] block: driver should override flags in bdrv_open(), Kevin Wolf, 2015/06/12
- [Qemu-block] [PULL 12/25] iotests: Add tests for overriding BDRV_O_PROTOCOL, Kevin Wolf, 2015/06/12
- [Qemu-block] [PULL 13/25] qdict: Add qdict_array_entries(), Kevin Wolf, 2015/06/12
- [Qemu-block] [PULL 14/25] qdict: Add qdict_{set,copy}_default(), Kevin Wolf, 2015/06/12
- [Qemu-block] [PULL 15/25] check-qdict: Test cases for new functions,
Kevin Wolf <=
- [Qemu-block] [PULL 16/25] quorum: Use bdrv_open_image(), Kevin Wolf, 2015/06/12
- [Qemu-block] [PULL 19/25] block: Use QemuOpts in bdrv_open_common(), Kevin Wolf, 2015/06/12
- [Qemu-block] [PULL 18/25] block: Use macro for cache option names, Kevin Wolf, 2015/06/12
- [Qemu-block] [PULL 21/25] block: Drain requests before swapping nodes in bdrv_swap(), Kevin Wolf, 2015/06/12
- [Qemu-block] [PULL 17/25] vmdk: Use bdrv_open_image(), Kevin Wolf, 2015/06/12
- [Qemu-block] [PULL 22/25] queue.h: Add QLIST_FIX_HEAD_PTR(), Kevin Wolf, 2015/06/12
- [Qemu-block] [PULL 20/25] block: Move flag inheritance to bdrv_open_inherit(), Kevin Wolf, 2015/06/12
- [Qemu-block] [PULL 23/25] block: Add list of children to BlockDriverState, Kevin Wolf, 2015/06/12
- [Qemu-block] [PULL 24/25] block: Add BlockDriverState.inherits_from, Kevin Wolf, 2015/06/12
- [Qemu-block] [PULL 25/25] block: Fix reopen flag inheritance, Kevin Wolf, 2015/06/12