tests/check-qom-proplist: Improve iterator coverage
The tests' "qemu-dummy" device has only class properties. Turn one of them into an instance property. test_dummy_class_iterator() expects one fewer property than test_dummy_iterator(). Rewrite test_dummy_prop_iterator() to take expected properties as argument. Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Message-Id: <20200505152926.18877-9-armbru@redhat.com>
This commit is contained in:
parent
7eecec7d12
commit
4894213817
@ -130,17 +130,18 @@ static void dummy_init(Object *obj)
|
||||
object_property_add_bool(obj, "bv",
|
||||
dummy_get_bv,
|
||||
dummy_set_bv,
|
||||
&err);
|
||||
NULL);
|
||||
/* duplicate: */
|
||||
object_property_add_str(obj, "sv",
|
||||
dummy_get_sv,
|
||||
dummy_set_sv,
|
||||
&err);
|
||||
error_free_or_abort(&err);
|
||||
}
|
||||
|
||||
|
||||
static void dummy_class_init(ObjectClass *cls, void *data)
|
||||
{
|
||||
object_class_property_add_bool(cls, "bv",
|
||||
dummy_get_bv,
|
||||
dummy_set_bv,
|
||||
NULL);
|
||||
object_class_property_add_str(cls, "sv",
|
||||
dummy_get_sv,
|
||||
dummy_set_sv,
|
||||
@ -520,34 +521,33 @@ static void test_dummy_getenum(void)
|
||||
}
|
||||
|
||||
|
||||
static void test_dummy_prop_iterator(ObjectPropertyIterator *iter)
|
||||
static void test_dummy_prop_iterator(ObjectPropertyIterator *iter,
|
||||
const char *expected[], int n)
|
||||
{
|
||||
bool seenbv = false, seensv = false, seenav = false, seentype = false;
|
||||
ObjectProperty *prop;
|
||||
int i;
|
||||
|
||||
while ((prop = object_property_iter_next(iter))) {
|
||||
if (!seenbv && g_str_equal(prop->name, "bv")) {
|
||||
seenbv = true;
|
||||
} else if (!seensv && g_str_equal(prop->name, "sv")) {
|
||||
seensv = true;
|
||||
} else if (!seenav && g_str_equal(prop->name, "av")) {
|
||||
seenav = true;
|
||||
} else if (!seentype && g_str_equal(prop->name, "type")) {
|
||||
/* This prop comes from the base Object class */
|
||||
seentype = true;
|
||||
} else {
|
||||
g_printerr("Found prop '%s'\n", prop->name);
|
||||
g_assert_not_reached();
|
||||
for (i = 0; i < n; i++) {
|
||||
if (!g_strcmp0(prop->name, expected[i])) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
g_assert(i < n);
|
||||
expected[i] = NULL;
|
||||
}
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
g_assert(!expected[i]);
|
||||
}
|
||||
g_assert(seenbv);
|
||||
g_assert(seenav);
|
||||
g_assert(seensv);
|
||||
g_assert(seentype);
|
||||
}
|
||||
|
||||
static void test_dummy_iterator(void)
|
||||
{
|
||||
const char *expected[] = {
|
||||
"type", /* inherited from TYPE_OBJECT */
|
||||
"sv", "av", /* class properties */
|
||||
"bv"}; /* instance property */
|
||||
Object *parent = object_get_objects_root();
|
||||
DummyObject *dobj = DUMMY_OBJECT(
|
||||
object_new_with_props(TYPE_DUMMY,
|
||||
@ -561,17 +561,18 @@ static void test_dummy_iterator(void)
|
||||
ObjectPropertyIterator iter;
|
||||
|
||||
object_property_iter_init(&iter, OBJECT(dobj));
|
||||
test_dummy_prop_iterator(&iter);
|
||||
test_dummy_prop_iterator(&iter, expected, ARRAY_SIZE(expected));
|
||||
object_unparent(OBJECT(dobj));
|
||||
}
|
||||
|
||||
static void test_dummy_class_iterator(void)
|
||||
{
|
||||
const char *expected[] = { "type", "av", "sv" };
|
||||
ObjectPropertyIterator iter;
|
||||
ObjectClass *klass = object_class_by_name(TYPE_DUMMY);
|
||||
|
||||
object_class_property_iter_init(&iter, klass);
|
||||
test_dummy_prop_iterator(&iter);
|
||||
test_dummy_prop_iterator(&iter, expected, ARRAY_SIZE(expected));
|
||||
}
|
||||
|
||||
static void test_dummy_delchild(void)
|
||||
|
Loading…
Reference in New Issue
Block a user