diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/check-qdict.c | 37 | ||||
-rw-r--r-- | tests/check-qjson.c | 113 | ||||
-rw-r--r-- | tests/libqtest.c | 4 | ||||
-rw-r--r-- | tests/test-qmp-event.c | 14 | ||||
-rw-r--r-- | tests/test-qobject-output-visitor.c | 133 |
5 files changed, 95 insertions, 206 deletions
diff --git a/tests/check-qdict.c b/tests/check-qdict.c index 07b1c798d8..81162ee572 100644 --- a/tests/check-qdict.c +++ b/tests/check-qdict.c @@ -591,7 +591,6 @@ static void qdict_join_test(void) static void qdict_crumple_test_recursive(void) { QDict *src, *dst, *rule, *vnc, *acl, *listen; - QObject *child, *res; QList *rules; src = qdict_new(); @@ -605,40 +604,37 @@ static void qdict_crumple_test_recursive(void) qdict_put(src, "vnc.acl..name", qstring_from_str("acl0")); qdict_put(src, "vnc.acl.rule..name", qstring_from_str("acl0")); - res = qdict_crumple(src, &error_abort); - - g_assert_cmpint(qobject_type(res), ==, QTYPE_QDICT); - - dst = qobject_to_qdict(res); - + dst = qobject_to_qdict(qdict_crumple(src, &error_abort)); + g_assert(dst); g_assert_cmpint(qdict_size(dst), ==, 1); - child = qdict_get(dst, "vnc"); - g_assert_cmpint(qobject_type(child), ==, QTYPE_QDICT); - vnc = qobject_to_qdict(child); + vnc = qdict_get_qdict(dst, "vnc"); + g_assert(vnc); + g_assert_cmpint(qdict_size(vnc), ==, 3); - child = qdict_get(vnc, "listen"); - g_assert_cmpint(qobject_type(child), ==, QTYPE_QDICT); - listen = qobject_to_qdict(child); + listen = qdict_get_qdict(vnc, "listen"); + g_assert(listen); + g_assert_cmpint(qdict_size(listen), ==, 2); g_assert_cmpstr("127.0.0.1", ==, qdict_get_str(listen, "addr")); g_assert_cmpstr("5901", ==, qdict_get_str(listen, "port")); - child = qdict_get(vnc, "acl"); - g_assert_cmpint(qobject_type(child), ==, QTYPE_QDICT); - acl = qobject_to_qdict(child); + acl = qdict_get_qdict(vnc, "acl"); + g_assert(acl); + g_assert_cmpint(qdict_size(acl), ==, 3); - child = qdict_get(acl, "rules"); - g_assert_cmpint(qobject_type(child), ==, QTYPE_QLIST); - rules = qobject_to_qlist(child); + rules = qdict_get_qlist(acl, "rules"); + g_assert(rules); g_assert_cmpint(qlist_size(rules), ==, 2); rule = qobject_to_qdict(qlist_pop(rules)); + g_assert(rule); g_assert_cmpint(qdict_size(rule), ==, 2); g_assert_cmpstr("fred", ==, qdict_get_str(rule, "match")); g_assert_cmpstr("allow", ==, qdict_get_str(rule, "policy")); QDECREF(rule); rule = qobject_to_qdict(qlist_pop(rules)); + g_assert(rule); g_assert_cmpint(qdict_size(rule), ==, 2); g_assert_cmpstr("bob", ==, qdict_get_str(rule, "match")); g_assert_cmpstr("deny", ==, qdict_get_str(rule, "policy")); @@ -646,9 +642,6 @@ static void qdict_crumple_test_recursive(void) /* With recursive crumpling, we should see all names unescaped */ g_assert_cmpstr("acl0", ==, qdict_get_str(vnc, "acl.name")); - child = qdict_get(vnc, "acl"); - g_assert_cmpint(qobject_type(child), ==, QTYPE_QDICT); - acl = qdict_get_qdict(vnc, "acl"); g_assert_cmpstr("acl0", ==, qdict_get_str(acl, "rule.name")); QDECREF(src); diff --git a/tests/check-qjson.c b/tests/check-qjson.c index 0b21a22e10..e6d6935653 100644 --- a/tests/check-qjson.c +++ b/tests/check-qjson.c @@ -54,11 +54,8 @@ static void escaped_string(void) QString *str; obj = qobject_from_json(test_cases[i].encoded); - - g_assert(obj != NULL); - g_assert(qobject_type(obj) == QTYPE_QSTRING); - str = qobject_to_qstring(obj); + g_assert(str); g_assert_cmpstr(qstring_get_str(str), ==, test_cases[i].decoded); if (test_cases[i].skip == 0) { @@ -89,11 +86,8 @@ static void simple_string(void) QString *str; obj = qobject_from_json(test_cases[i].encoded); - - g_assert(obj != NULL); - g_assert(qobject_type(obj) == QTYPE_QSTRING); - str = qobject_to_qstring(obj); + g_assert(str); g_assert(strcmp(qstring_get_str(str), test_cases[i].decoded) == 0); str = qobject_to_json(obj); @@ -123,11 +117,8 @@ static void single_quote_string(void) QString *str; obj = qobject_from_json(test_cases[i].encoded); - - g_assert(obj != NULL); - g_assert(qobject_type(obj) == QTYPE_QSTRING); - str = qobject_to_qstring(obj); + g_assert(str); g_assert(strcmp(qstring_get_str(str), test_cases[i].decoded) == 0); QDECREF(str); @@ -820,9 +811,8 @@ static void utf8_string(void) obj = qobject_from_json(json_in); if (utf8_out) { - g_assert(obj); - g_assert(qobject_type(obj) == QTYPE_QSTRING); str = qobject_to_qstring(obj); + g_assert(str); g_assert_cmpstr(qstring_get_str(str), ==, utf8_out); } else { g_assert(!obj); @@ -847,9 +837,8 @@ static void utf8_string(void) */ if (0 && json_out != json_in) { obj = qobject_from_json(json_out); - g_assert(obj); - g_assert(qobject_type(obj) == QTYPE_QSTRING); str = qobject_to_qstring(obj); + g_assert(str); g_assert_cmpstr(qstring_get_str(str), ==, utf8_out); } } @@ -867,15 +856,11 @@ static void vararg_string(void) }; for (i = 0; test_cases[i].decoded; i++) { - QObject *obj; QString *str; - obj = qobject_from_jsonf("%s", test_cases[i].decoded); - - g_assert(obj != NULL); - g_assert(qobject_type(obj) == QTYPE_QSTRING); - - str = qobject_to_qstring(obj); + str = qobject_to_qstring(qobject_from_jsonf("%s", + test_cases[i].decoded)); + g_assert(str); g_assert(strcmp(qstring_get_str(str), test_cases[i].decoded) == 0); QDECREF(str); @@ -899,19 +884,15 @@ static void simple_number(void) }; for (i = 0; test_cases[i].encoded; i++) { - QObject *obj; QInt *qint; - obj = qobject_from_json(test_cases[i].encoded); - g_assert(obj != NULL); - g_assert(qobject_type(obj) == QTYPE_QINT); - - qint = qobject_to_qint(obj); + qint = qobject_to_qint(qobject_from_json(test_cases[i].encoded)); + g_assert(qint); g_assert(qint_get_int(qint) == test_cases[i].decoded); if (test_cases[i].skip == 0) { QString *str; - str = qobject_to_json(obj); + str = qobject_to_json(QOBJECT(qint)); g_assert(strcmp(qstring_get_str(str), test_cases[i].encoded) == 0); QDECREF(str); } @@ -940,10 +921,8 @@ static void float_number(void) QFloat *qfloat; obj = qobject_from_json(test_cases[i].encoded); - g_assert(obj != NULL); - g_assert(qobject_type(obj) == QTYPE_QFLOAT); - qfloat = qobject_to_qfloat(obj); + g_assert(qfloat); g_assert(qfloat_get_double(qfloat) == test_cases[i].decoded); if (test_cases[i].skip == 0) { @@ -960,38 +939,22 @@ static void float_number(void) static void vararg_number(void) { - QObject *obj; QInt *qint; QFloat *qfloat; int value = 0x2342; long long value_ll = 0x2342342343LL; double valuef = 2.323423423; - obj = qobject_from_jsonf("%d", value); - g_assert(obj != NULL); - g_assert(qobject_type(obj) == QTYPE_QINT); - - qint = qobject_to_qint(obj); + qint = qobject_to_qint(qobject_from_jsonf("%d", value)); g_assert(qint_get_int(qint) == value); - QDECREF(qint); - obj = qobject_from_jsonf("%lld", value_ll); - g_assert(obj != NULL); - g_assert(qobject_type(obj) == QTYPE_QINT); - - qint = qobject_to_qint(obj); + qint = qobject_to_qint(qobject_from_jsonf("%lld", value_ll)); g_assert(qint_get_int(qint) == value_ll); - QDECREF(qint); - obj = qobject_from_jsonf("%f", valuef); - g_assert(obj != NULL); - g_assert(qobject_type(obj) == QTYPE_QFLOAT); - - qfloat = qobject_to_qfloat(obj); + qfloat = qobject_to_qfloat(qobject_from_jsonf("%f", valuef)); g_assert(qfloat_get_double(qfloat) == valuef); - QDECREF(qfloat); } @@ -1003,10 +966,8 @@ static void keyword_literal(void) QString *str; obj = qobject_from_json("true"); - g_assert(obj != NULL); - g_assert(qobject_type(obj) == QTYPE_QBOOL); - qbool = qobject_to_qbool(obj); + g_assert(qbool); g_assert(qbool_get_bool(qbool) == true); str = qobject_to_json(obj); @@ -1016,10 +977,8 @@ static void keyword_literal(void) QDECREF(qbool); obj = qobject_from_json("false"); - g_assert(obj != NULL); - g_assert(qobject_type(obj) == QTYPE_QBOOL); - qbool = qobject_to_qbool(obj); + g_assert(qbool); g_assert(qbool_get_bool(qbool) == false); str = qobject_to_json(obj); @@ -1028,23 +987,15 @@ static void keyword_literal(void) QDECREF(qbool); - obj = qobject_from_jsonf("%i", false); - g_assert(obj != NULL); - g_assert(qobject_type(obj) == QTYPE_QBOOL); - - qbool = qobject_to_qbool(obj); + qbool = qobject_to_qbool(qobject_from_jsonf("%i", false)); + g_assert(qbool); g_assert(qbool_get_bool(qbool) == false); - QDECREF(qbool); /* Test that non-zero values other than 1 get collapsed to true */ - obj = qobject_from_jsonf("%i", 2); - g_assert(obj != NULL); - g_assert(qobject_type(obj) == QTYPE_QBOOL); - - qbool = qobject_to_qbool(obj); + qbool = qobject_to_qbool(qobject_from_jsonf("%i", 2)); + g_assert(qbool); g_assert(qbool_get_bool(qbool) == true); - QDECREF(qbool); obj = qobject_from_json("null"); @@ -1110,7 +1061,7 @@ static void compare_helper(QObject *obj, void *opaque) static int compare_litqobj_to_qobj(LiteralQObject *lhs, QObject *rhs) { - if (lhs->type != qobject_type(rhs)) { + if (!rhs || lhs->type != qobject_type(rhs)) { return 0; } @@ -1184,18 +1135,12 @@ static void simple_dict(void) QString *str; obj = qobject_from_json(test_cases[i].encoded); - g_assert(obj != NULL); - g_assert(qobject_type(obj) == QTYPE_QDICT); - g_assert(compare_litqobj_to_qobj(&test_cases[i].decoded, obj) == 1); str = qobject_to_json(obj); qobject_decref(obj); obj = qobject_from_json(qstring_get_str(str)); - g_assert(obj != NULL); - g_assert(qobject_type(obj) == QTYPE_QDICT); - g_assert(compare_litqobj_to_qobj(&test_cases[i].decoded, obj) == 1); qobject_decref(obj); QDECREF(str); @@ -1299,18 +1244,12 @@ static void simple_list(void) QString *str; obj = qobject_from_json(test_cases[i].encoded); - g_assert(obj != NULL); - g_assert(qobject_type(obj) == QTYPE_QLIST); - g_assert(compare_litqobj_to_qobj(&test_cases[i].decoded, obj) == 1); str = qobject_to_json(obj); qobject_decref(obj); obj = qobject_from_json(qstring_get_str(str)); - g_assert(obj != NULL); - g_assert(qobject_type(obj) == QTYPE_QLIST); - g_assert(compare_litqobj_to_qobj(&test_cases[i].decoded, obj) == 1); qobject_decref(obj); QDECREF(str); @@ -1367,18 +1306,12 @@ static void simple_whitespace(void) QString *str; obj = qobject_from_json(test_cases[i].encoded); - g_assert(obj != NULL); - g_assert(qobject_type(obj) == QTYPE_QLIST); - g_assert(compare_litqobj_to_qobj(&test_cases[i].decoded, obj) == 1); str = qobject_to_json(obj); qobject_decref(obj); obj = qobject_from_json(qstring_get_str(str)); - g_assert(obj != NULL); - g_assert(qobject_type(obj) == QTYPE_QLIST); - g_assert(compare_litqobj_to_qobj(&test_cases[i].decoded, obj) == 1); qobject_decref(obj); @@ -1403,8 +1336,6 @@ static void simple_varargs(void) g_assert(embedded_obj != NULL); obj = qobject_from_jsonf("[%d, 2, %p]", 1, embedded_obj); - g_assert(obj != NULL); - g_assert(compare_litqobj_to_qobj(&decoded, obj) == 1); qobject_decref(obj); diff --git a/tests/libqtest.c b/tests/libqtest.c index d8fba6647a..e54354de8a 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -379,9 +379,9 @@ static void qmp_response(JSONMessageParser *parser, GQueue *tokens) exit(1); } - g_assert(qobject_type(obj) == QTYPE_QDICT); g_assert(!qmp->response); - qmp->response = (QDict *)obj; + qmp->response = qobject_to_qdict(obj); + g_assert(qmp->response); } QDict *qmp_fd_receive(int fd) diff --git a/tests/test-qmp-event.c b/tests/test-qmp-event.c index 633dc87402..7bb621b027 100644 --- a/tests/test-qmp-event.c +++ b/tests/test-qmp-event.c @@ -95,24 +95,18 @@ static bool qdict_cmp_simple(QDict *a, QDict *b) correctness. */ static void event_test_emit(test_QAPIEvent event, QDict *d, Error **errp) { - QObject *obj; QDict *t; int64_t s, ms; /* Verify that we have timestamp, then remove it to compare other fields */ - obj = qdict_get(d, "timestamp"); - g_assert(obj); - t = qobject_to_qdict(obj); + t = qdict_get_qdict(d, "timestamp"); g_assert(t); - obj = qdict_get(t, "seconds"); - g_assert(obj && qobject_type(obj) == QTYPE_QINT); - s = qint_get_int(qobject_to_qint(obj)); - obj = qdict_get(t, "microseconds"); - g_assert(obj && qobject_type(obj) == QTYPE_QINT); - ms = qint_get_int(qobject_to_qint(obj)); + s = qdict_get_try_int(t, "seconds", -2); + ms = qdict_get_try_int(t, "microseconds", -2); if (s == -1) { g_assert(ms == -1); } else { + g_assert(s >= 0); g_assert(ms >= 0 && ms <= 999999); } g_assert(qdict_size(t) == 2); diff --git a/tests/test-qobject-output-visitor.c b/tests/test-qobject-output-visitor.c index 4e2d79c5d1..500b452d98 100644 --- a/tests/test-qobject-output-visitor.c +++ b/tests/test-qobject-output-visitor.c @@ -58,81 +58,80 @@ static void test_visitor_out_int(TestOutputVisitorData *data, const void *unused) { int64_t value = -42; - QObject *obj; + QInt *qint; visit_type_int(data->ov, NULL, &value, &error_abort); - obj = visitor_get(data); - g_assert(qobject_type(obj) == QTYPE_QINT); - g_assert_cmpint(qint_get_int(qobject_to_qint(obj)), ==, value); + qint = qobject_to_qint(visitor_get(data)); + g_assert(qint); + g_assert_cmpint(qint_get_int(qint), ==, value); } static void test_visitor_out_bool(TestOutputVisitorData *data, const void *unused) { bool value = true; - QObject *obj; + QBool *qbool; visit_type_bool(data->ov, NULL, &value, &error_abort); - obj = visitor_get(data); - g_assert(qobject_type(obj) == QTYPE_QBOOL); - g_assert(qbool_get_bool(qobject_to_qbool(obj)) == value); + qbool = qobject_to_qbool(visitor_get(data)); + g_assert(qbool); + g_assert(qbool_get_bool(qbool) == value); } static void test_visitor_out_number(TestOutputVisitorData *data, const void *unused) { double value = 3.14; - QObject *obj; + QFloat *qfloat; visit_type_number(data->ov, NULL, &value, &error_abort); - obj = visitor_get(data); - g_assert(qobject_type(obj) == QTYPE_QFLOAT); - g_assert(qfloat_get_double(qobject_to_qfloat(obj)) == value); + qfloat = qobject_to_qfloat(visitor_get(data)); + g_assert(qfloat); + g_assert(qfloat_get_double(qfloat) == value); } static void test_visitor_out_string(TestOutputVisitorData *data, const void *unused) { char *string = (char *) "Q E M U"; - QObject *obj; + QString *qstr; visit_type_str(data->ov, NULL, &string, &error_abort); - obj = visitor_get(data); - g_assert(qobject_type(obj) == QTYPE_QSTRING); - g_assert_cmpstr(qstring_get_str(qobject_to_qstring(obj)), ==, string); + qstr = qobject_to_qstring(visitor_get(data)); + g_assert(qstr); + g_assert_cmpstr(qstring_get_str(qstr), ==, string); } static void test_visitor_out_no_string(TestOutputVisitorData *data, const void *unused) { char *string = NULL; - QObject *obj; + QString *qstr; /* A null string should return "" */ visit_type_str(data->ov, NULL, &string, &error_abort); - obj = visitor_get(data); - g_assert(qobject_type(obj) == QTYPE_QSTRING); - g_assert_cmpstr(qstring_get_str(qobject_to_qstring(obj)), ==, ""); + qstr = qobject_to_qstring(visitor_get(data)); + g_assert(qstr); + g_assert_cmpstr(qstring_get_str(qstr), ==, ""); } static void test_visitor_out_enum(TestOutputVisitorData *data, const void *unused) { - QObject *obj; EnumOne i; + QString *qstr; for (i = 0; i < ENUM_ONE__MAX; i++) { visit_type_EnumOne(data->ov, "unused", &i, &error_abort); - obj = visitor_get(data); - g_assert(qobject_type(obj) == QTYPE_QSTRING); - g_assert_cmpstr(qstring_get_str(qobject_to_qstring(obj)), ==, - EnumOne_lookup[i]); + qstr = qobject_to_qstring(visitor_get(data)); + g_assert(qstr); + g_assert_cmpstr(qstring_get_str(qstr), ==, EnumOne_lookup[i]); visitor_reset(data); } } @@ -160,15 +159,12 @@ static void test_visitor_out_struct(TestOutputVisitorData *data, .boolean = false, .string = (char *) "foo"}; TestStruct *p = &test_struct; - QObject *obj; QDict *qdict; visit_type_TestStruct(data->ov, NULL, &p, &error_abort); - obj = visitor_get(data); - g_assert(qobject_type(obj) == QTYPE_QDICT); - - qdict = qobject_to_qdict(obj); + qdict = qobject_to_qdict(visitor_get(data)); + g_assert(qdict); g_assert_cmpint(qdict_size(qdict), ==, 3); g_assert_cmpint(qdict_get_int(qdict, "integer"), ==, 42); g_assert_cmpint(qdict_get_bool(qdict, "boolean"), ==, false); @@ -180,7 +176,6 @@ static void test_visitor_out_struct_nested(TestOutputVisitorData *data, { int64_t value = 42; UserDefTwo *ud2; - QObject *obj; QDict *qdict, *dict1, *dict2, *dict3, *userdef; const char *string = "user def string"; const char *strings[] = { "forty two", "forty three", "forty four", @@ -207,10 +202,8 @@ static void test_visitor_out_struct_nested(TestOutputVisitorData *data, visit_type_UserDefTwo(data->ov, "unused", &ud2, &error_abort); - obj = visitor_get(data); - g_assert(qobject_type(obj) == QTYPE_QDICT); - - qdict = qobject_to_qdict(obj); + qdict = qobject_to_qdict(visitor_get(data)); + g_assert(qdict); g_assert_cmpint(qdict_size(qdict), ==, 2); g_assert_cmpstr(qdict_get_str(qdict, "string0"), ==, strings[0]); @@ -267,7 +260,6 @@ static void test_visitor_out_list(TestOutputVisitorData *data, bool value_bool = true; int value_int = 10; QListEntry *entry; - QObject *obj; QList *qlist; int i; @@ -285,10 +277,8 @@ static void test_visitor_out_list(TestOutputVisitorData *data, visit_type_TestStructList(data->ov, NULL, &head, &error_abort); - obj = visitor_get(data); - g_assert(qobject_type(obj) == QTYPE_QLIST); - - qlist = qobject_to_qlist(obj); + qlist = qobject_to_qlist(visitor_get(data)); + g_assert(qlist); g_assert(!qlist_empty(qlist)); /* ...and ensure that the visitor sees it in order */ @@ -296,8 +286,8 @@ static void test_visitor_out_list(TestOutputVisitorData *data, QLIST_FOREACH_ENTRY(qlist, entry) { QDict *qdict; - g_assert(qobject_type(entry->value) == QTYPE_QDICT); qdict = qobject_to_qdict(entry->value); + g_assert(qdict); g_assert_cmpint(qdict_size(qdict), ==, 3); g_assert_cmpint(qdict_get_int(qdict, "integer"), ==, value_int + i); g_assert_cmpint(qdict_get_bool(qdict, "boolean"), ==, value_bool); @@ -345,13 +335,12 @@ static void test_visitor_out_any(TestOutputVisitorData *data, QBool *qbool; QString *qstring; QDict *qdict; - QObject *obj; qobj = QOBJECT(qint_from_int(-42)); visit_type_any(data->ov, NULL, &qobj, &error_abort); - obj = visitor_get(data); - g_assert(qobject_type(obj) == QTYPE_QINT); - g_assert_cmpint(qint_get_int(qobject_to_qint(obj)), ==, -42); + qint = qobject_to_qint(visitor_get(data)); + g_assert(qint); + g_assert_cmpint(qint_get_int(qint), ==, -42); qobject_decref(qobj); visitor_reset(data); @@ -362,22 +351,15 @@ static void test_visitor_out_any(TestOutputVisitorData *data, qobj = QOBJECT(qdict); visit_type_any(data->ov, NULL, &qobj, &error_abort); qobject_decref(qobj); - obj = visitor_get(data); - qdict = qobject_to_qdict(obj); + qdict = qobject_to_qdict(visitor_get(data)); g_assert(qdict); - qobj = qdict_get(qdict, "integer"); - g_assert(qobj); - qint = qobject_to_qint(qobj); + qint = qobject_to_qint(qdict_get(qdict, "integer")); g_assert(qint); g_assert_cmpint(qint_get_int(qint), ==, -42); - qobj = qdict_get(qdict, "boolean"); - g_assert(qobj); - qbool = qobject_to_qbool(qobj); + qbool = qobject_to_qbool(qdict_get(qdict, "boolean")); g_assert(qbool); g_assert(qbool_get_bool(qbool) == true); - qobj = qdict_get(qdict, "string"); - g_assert(qobj); - qstring = qobject_to_qstring(qobj); + qstring = qobject_to_qstring(qdict_get(qdict, "string")); g_assert(qstring); g_assert_cmpstr(qstring_get_str(qstring), ==, "foo"); } @@ -385,7 +367,6 @@ static void test_visitor_out_any(TestOutputVisitorData *data, static void test_visitor_out_union_flat(TestOutputVisitorData *data, const void *unused) { - QObject *arg; QDict *qdict; UserDefFlatUnion *tmp = g_malloc0(sizeof(UserDefFlatUnion)); @@ -395,11 +376,8 @@ static void test_visitor_out_union_flat(TestOutputVisitorData *data, tmp->u.value1.boolean = true; visit_type_UserDefFlatUnion(data->ov, NULL, &tmp, &error_abort); - arg = visitor_get(data); - - g_assert(qobject_type(arg) == QTYPE_QDICT); - qdict = qobject_to_qdict(arg); - + qdict = qobject_to_qdict(visitor_get(data)); + g_assert(qdict); g_assert_cmpstr(qdict_get_str(qdict, "enum1"), ==, "value1"); g_assert_cmpstr(qdict_get_str(qdict, "string"), ==, "str"); g_assert_cmpint(qdict_get_int(qdict, "integer"), ==, 41); @@ -411,8 +389,9 @@ static void test_visitor_out_union_flat(TestOutputVisitorData *data, static void test_visitor_out_alternate(TestOutputVisitorData *data, const void *unused) { - QObject *arg; UserDefAlternate *tmp; + QInt *qint; + QString *qstr; QDict *qdict; tmp = g_new0(UserDefAlternate, 1); @@ -420,10 +399,9 @@ static void test_visitor_out_alternate(TestOutputVisitorData *data, tmp->u.i = 42; visit_type_UserDefAlternate(data->ov, NULL, &tmp, &error_abort); - arg = visitor_get(data); - - g_assert(qobject_type(arg) == QTYPE_QINT); - g_assert_cmpint(qint_get_int(qobject_to_qint(arg)), ==, 42); + qint = qobject_to_qint(visitor_get(data)); + g_assert(qint); + g_assert_cmpint(qint_get_int(qint), ==, 42); qapi_free_UserDefAlternate(tmp); @@ -433,10 +411,9 @@ static void test_visitor_out_alternate(TestOutputVisitorData *data, tmp->u.s = g_strdup("hello"); visit_type_UserDefAlternate(data->ov, NULL, &tmp, &error_abort); - arg = visitor_get(data); - - g_assert(qobject_type(arg) == QTYPE_QSTRING); - g_assert_cmpstr(qstring_get_str(qobject_to_qstring(arg)), ==, "hello"); + qstr = qobject_to_qstring(visitor_get(data)); + g_assert(qstr); + g_assert_cmpstr(qstring_get_str(qstr), ==, "hello"); qapi_free_UserDefAlternate(tmp); @@ -449,10 +426,8 @@ static void test_visitor_out_alternate(TestOutputVisitorData *data, tmp->u.udfu.u.value1.boolean = true; visit_type_UserDefAlternate(data->ov, NULL, &tmp, &error_abort); - arg = visitor_get(data); - - g_assert_cmpint(qobject_type(arg), ==, QTYPE_QDICT); - qdict = qobject_to_qdict(arg); + qdict = qobject_to_qdict(visitor_get(data)); + g_assert(qdict); g_assert_cmpint(qdict_size(qdict), ==, 4); g_assert_cmpint(qdict_get_int(qdict, "integer"), ==, 1); g_assert_cmpstr(qdict_get_str(qdict, "string"), ==, "str"); @@ -465,7 +440,6 @@ static void test_visitor_out_alternate(TestOutputVisitorData *data, static void test_visitor_out_null(TestOutputVisitorData *data, const void *unused) { - QObject *arg; QDict *qdict; QObject *nil; @@ -473,9 +447,8 @@ static void test_visitor_out_null(TestOutputVisitorData *data, visit_type_null(data->ov, "a", &error_abort); visit_check_struct(data->ov, &error_abort); visit_end_struct(data->ov, NULL); - arg = visitor_get(data); - g_assert(qobject_type(arg) == QTYPE_QDICT); - qdict = qobject_to_qdict(arg); + qdict = qobject_to_qdict(visitor_get(data)); + g_assert(qdict); g_assert_cmpint(qdict_size(qdict), ==, 1); nil = qdict_get(qdict, "a"); g_assert(nil); @@ -618,8 +591,6 @@ static void check_native_list(QObject *qobj, QList *qlist; int i; - g_assert(qobj); - g_assert(qobject_type(qobj) == QTYPE_QDICT); qdict = qobject_to_qdict(qobj); g_assert(qdict); g_assert(qdict_haskey(qdict, "data")); |