From 9633017998c965e106f9ff4585ec09294c924c8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Thu, 6 Sep 2018 18:12:12 +0400 Subject: tests/qom-proplist: check duplicate "bv" property registration failed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit "bv" is already a class property. Signed-off-by: Marc-André Lureau Reviewed-by: Paolo Bonzini --- tests/check-qom-proplist.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/check-qom-proplist.c b/tests/check-qom-proplist.c index 92898e1520..0f6d9c1ce3 100644 --- a/tests/check-qom-proplist.c +++ b/tests/check-qom-proplist.c @@ -125,10 +125,13 @@ static char *dummy_get_sv(Object *obj, static void dummy_init(Object *obj) { + Error *err = NULL; + object_property_add_bool(obj, "bv", dummy_get_bv, dummy_set_bv, - NULL); + &err); + error_free_or_abort(&err); } -- cgit v1.2.3 From 94ef3b309273c37717fad34acd8c8b58a21861a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Thu, 6 Sep 2018 18:13:34 +0400 Subject: tests/qom-proplist: check properties are not listed multiple times MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit And factor out a common function used by the follow class properties iterator test. Fix uninitialized "seentype" variable. Signed-off-by: Marc-André Lureau Reviewed-by: Paolo Bonzini --- tests/check-qom-proplist.c | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) (limited to 'tests') diff --git a/tests/check-qom-proplist.c b/tests/check-qom-proplist.c index 0f6d9c1ce3..2c07719607 100644 --- a/tests/check-qom-proplist.c +++ b/tests/check-qom-proplist.c @@ -520,32 +520,19 @@ static void test_dummy_getenum(void) } -static void test_dummy_iterator(void) +static void test_dummy_prop_iterator(ObjectPropertyIterator *iter) { - Object *parent = object_get_objects_root(); - DummyObject *dobj = DUMMY_OBJECT( - object_new_with_props(TYPE_DUMMY, - parent, - "dummy0", - &error_abort, - "bv", "yes", - "sv", "Hiss hiss hiss", - "av", "platypus", - NULL)); - + bool seenbv = false, seensv = false, seenav = false, seentype = false; ObjectProperty *prop; - ObjectPropertyIterator iter; - bool seenbv = false, seensv = false, seenav = false, seentype; - object_property_iter_init(&iter, OBJECT(dobj)); - while ((prop = object_property_iter_next(&iter))) { - if (g_str_equal(prop->name, "bv")) { + while ((prop = object_property_iter_next(iter))) { + if (!seenbv && g_str_equal(prop->name, "bv")) { seenbv = true; - } else if (g_str_equal(prop->name, "sv")) { + } else if (!seensv && g_str_equal(prop->name, "sv")) { seensv = true; - } else if (g_str_equal(prop->name, "av")) { + } else if (!seenav && g_str_equal(prop->name, "av")) { seenav = true; - } else if (g_str_equal(prop->name, "type")) { + } else if (!seentype && g_str_equal(prop->name, "type")) { /* This prop comes from the base Object class */ seentype = true; } else { @@ -557,7 +544,24 @@ static void test_dummy_iterator(void) g_assert(seenav); g_assert(seensv); g_assert(seentype); +} +static void test_dummy_iterator(void) +{ + Object *parent = object_get_objects_root(); + DummyObject *dobj = DUMMY_OBJECT( + object_new_with_props(TYPE_DUMMY, + parent, + "dummy0", + &error_abort, + "bv", "yes", + "sv", "Hiss hiss hiss", + "av", "platypus", + NULL)); + ObjectPropertyIterator iter; + + object_property_iter_init(&iter, OBJECT(dobj)); + test_dummy_prop_iterator(&iter); object_unparent(OBJECT(dobj)); } -- cgit v1.2.3 From e569ba9232ce91bc4ffaa566b2ac44e49d8f5ba2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Thu, 6 Sep 2018 18:14:01 +0400 Subject: tests/qom-proplist: check class properties iterator MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This test failed before "fix iterating properties over a class". Signed-off-by: Marc-André Lureau Reviewed-by: Paolo Bonzini --- tests/check-qom-proplist.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'tests') diff --git a/tests/check-qom-proplist.c b/tests/check-qom-proplist.c index 2c07719607..a8b2958e6e 100644 --- a/tests/check-qom-proplist.c +++ b/tests/check-qom-proplist.c @@ -565,6 +565,14 @@ static void test_dummy_iterator(void) object_unparent(OBJECT(dobj)); } +static void test_dummy_class_iterator(void) +{ + ObjectPropertyIterator iter; + ObjectClass *klass = object_class_by_name(TYPE_DUMMY); + + object_class_property_iter_init(&iter, klass); + test_dummy_prop_iterator(&iter); +} static void test_dummy_delchild(void) { @@ -636,6 +644,7 @@ int main(int argc, char **argv) g_test_add_func("/qom/proplist/badenum", test_dummy_badenum); g_test_add_func("/qom/proplist/getenum", test_dummy_getenum); g_test_add_func("/qom/proplist/iterator", test_dummy_iterator); + g_test_add_func("/qom/proplist/class_iterator", test_dummy_class_iterator); g_test_add_func("/qom/proplist/delchild", test_dummy_delchild); g_test_add_func("/qom/resolve/partial", test_qom_partial_path); -- cgit v1.2.3