aboutsummaryrefslogtreecommitdiff
path: root/tests/unit/test-qobject-output-visitor.c
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2021-09-27 15:03:42 +0100
committerPeter Maydell <peter.maydell@linaro.org>2021-09-27 15:03:42 +0100
commitde8ed1055c2ce18c95f597eb10df360dcb534f99 (patch)
tree2554d4c016c5c7cc5bf9a8bc0dcde28b7ceef9b1 /tests/unit/test-qobject-output-visitor.c
parent9b03a1178204598055f23f24e438fdddb5935df9 (diff)
parentf333681c6e277004796b0bed808697da1280d140 (diff)
downloadqemu-de8ed1055c2ce18c95f597eb10df360dcb534f99.zip
qemu-de8ed1055c2ce18c95f597eb10df360dcb534f99.tar.gz
qemu-de8ed1055c2ce18c95f597eb10df360dcb534f99.tar.bz2
Merge remote-tracking branch 'remotes/armbru/tags/pull-qapi-2021-09-25-v2' into staging
QAPI patches patches for 2021-09-25 # gpg: Signature made Mon 27 Sep 2021 13:44:23 BST # gpg: using RSA key 354BC8B3D7EB2A6B68674E5F3870B400EB918653 # gpg: issuer "armbru@redhat.com" # gpg: Good signature from "Markus Armbruster <armbru@redhat.com>" [full] # gpg: aka "Markus Armbruster <armbru@pond.sub.org>" [full] # Primary key fingerprint: 354B C8B3 D7EB 2A6B 6867 4E5F 3870 B400 EB91 8653 * remotes/armbru/tags/pull-qapi-2021-09-25-v2: (25 commits) tests/qapi-schema: Make test-qapi.py -u work when files are absent tests/qapi-schema: Use Python OSError instead of outmoded IOError test-clone-visitor: Correct an accidental rename tests/qapi-schema: Rename flat-union-* test cases to union-* qapi: Drop simple unions tests/qapi-schema: Purge simple unions from tests tests/qapi-schema: Drop simple union __org.qemu_x-Union1 test-clone-visitor: Wean off __org.qemu_x-Union1 tests/qapi-schema: Rewrite simple union TestIfUnion to be flat tests/qapi-schema: Simple union UserDefListUnion is now unused, drop tests/qapi-schema: Wean off UserDefListUnion test-clone-visitor: Wean off UserDefListUnion test-qobject-output-visitor: Wean off UserDefListUnion test-qobject-input-visitor: Wean off UserDefListUnion tests/qapi-schema: Prepare for simple union UserDefListUnion removal qapi: Convert simple union TransactionAction to flat one qapi: Convert simple union ImageInfoSpecific to flat one qapi: Convert simple union SocketAddressLegacy to flat one qapi: Convert simple union ChardevBackend to flat one qapi: Convert simple union MemoryDeviceInfo to flat one ... Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'tests/unit/test-qobject-output-visitor.c')
-rw-r--r--tests/unit/test-qobject-output-visitor.c389
1 files changed, 92 insertions, 297 deletions
diff --git a/tests/unit/test-qobject-output-visitor.c b/tests/unit/test-qobject-output-visitor.c
index 9dc1e07..34d67a4 100644
--- a/tests/unit/test-qobject-output-visitor.c
+++ b/tests/unit/test-qobject-output-visitor.c
@@ -437,289 +437,118 @@ static void test_visitor_out_null(TestOutputVisitorData *data,
g_assert(qobject_type(nil) == QTYPE_QNULL);
}
-static void init_list_union(UserDefListUnion *cvalue)
+static void test_visitor_out_list_struct(TestOutputVisitorData *data,
+ const void *unused)
{
- int i;
- switch (cvalue->type) {
- case USER_DEF_LIST_UNION_KIND_INTEGER: {
- intList **tail = &cvalue->u.integer.data;
- for (i = 0; i < 32; i++) {
- QAPI_LIST_APPEND(tail, i);
- }
- break;
- }
- case USER_DEF_LIST_UNION_KIND_S8: {
- int8List **tail = &cvalue->u.s8.data;
- for (i = 0; i < 32; i++) {
- QAPI_LIST_APPEND(tail, i);
- }
- break;
+ const char *int_member[] = {
+ "integer", "s8", "s16", "s32", "s64", "u8", "u16", "u32", "u64" };
+ g_autoptr(ArrayStruct) arrs = g_new0(ArrayStruct, 1);
+ int i, j;
+ QDict *qdict;
+ QList *qlist;
+ QListEntry *e;
+
+ for (i = 31; i >= 0; i--) {
+ QAPI_LIST_PREPEND(arrs->integer, i);
}
- case USER_DEF_LIST_UNION_KIND_S16: {
- int16List **tail = &cvalue->u.s16.data;
- for (i = 0; i < 32; i++) {
- QAPI_LIST_APPEND(tail, i);
- }
- break;
+
+ for (i = 31; i >= 0; i--) {
+ QAPI_LIST_PREPEND(arrs->s8, i);
}
- case USER_DEF_LIST_UNION_KIND_S32: {
- int32List **tail = &cvalue->u.s32.data;
- for (i = 0; i < 32; i++) {
- QAPI_LIST_APPEND(tail, i);
- }
- break;
+
+ for (i = 31; i >= 0; i--) {
+ QAPI_LIST_PREPEND(arrs->s16, i);
}
- case USER_DEF_LIST_UNION_KIND_S64: {
- int64List **tail = &cvalue->u.s64.data;
- for (i = 0; i < 32; i++) {
- QAPI_LIST_APPEND(tail, i);
- }
- break;
+
+ for (i = 31; i >= 0; i--) {
+ QAPI_LIST_PREPEND(arrs->s32, i);
}
- case USER_DEF_LIST_UNION_KIND_U8: {
- uint8List **tail = &cvalue->u.u8.data;
- for (i = 0; i < 32; i++) {
- QAPI_LIST_APPEND(tail, i);
- }
- break;
+
+ for (i = 31; i >= 0; i--) {
+ QAPI_LIST_PREPEND(arrs->s64, i);
}
- case USER_DEF_LIST_UNION_KIND_U16: {
- uint16List **tail = &cvalue->u.u16.data;
- for (i = 0; i < 32; i++) {
- QAPI_LIST_APPEND(tail, i);
- }
- break;
+
+ for (i = 31; i >= 0; i--) {
+ QAPI_LIST_PREPEND(arrs->u8, i);
}
- case USER_DEF_LIST_UNION_KIND_U32: {
- uint32List **tail = &cvalue->u.u32.data;
- for (i = 0; i < 32; i++) {
- QAPI_LIST_APPEND(tail, i);
- }
- break;
+
+ for (i = 31; i >= 0; i--) {
+ QAPI_LIST_PREPEND(arrs->u16, i);
}
- case USER_DEF_LIST_UNION_KIND_U64: {
- uint64List **tail = &cvalue->u.u64.data;
- for (i = 0; i < 32; i++) {
- QAPI_LIST_APPEND(tail, i);
- }
- break;
+
+ for (i = 31; i >= 0; i--) {
+ QAPI_LIST_PREPEND(arrs->u32, i);
}
- case USER_DEF_LIST_UNION_KIND_BOOLEAN: {
- boolList **tail = &cvalue->u.boolean.data;
- for (i = 0; i < 32; i++) {
- QAPI_LIST_APPEND(tail, QEMU_IS_ALIGNED(i, 3));
- }
- break;
+
+ for (i = 31; i >= 0; i--) {
+ QAPI_LIST_PREPEND(arrs->u64, i);
}
- case USER_DEF_LIST_UNION_KIND_STRING: {
- strList **tail = &cvalue->u.string.data;
- for (i = 0; i < 32; i++) {
- QAPI_LIST_APPEND(tail, g_strdup_printf("%d", i));
- }
- break;
+
+ for (i = 31; i >= 0; i--) {
+ QAPI_LIST_PREPEND(arrs->number, (double)i / 3);
}
- case USER_DEF_LIST_UNION_KIND_NUMBER: {
- numberList **tail = &cvalue->u.number.data;
- for (i = 0; i < 32; i++) {
- QAPI_LIST_APPEND(tail, (double)i / 3);
- }
- break;
+
+ for (i = 31; i >= 0; i--) {
+ QAPI_LIST_PREPEND(arrs->boolean, QEMU_IS_ALIGNED(i, 3));
}
- default:
- g_assert_not_reached();
+
+ for (i = 31; i >= 0; i--) {
+ QAPI_LIST_PREPEND(arrs->string, g_strdup_printf("%d", i));
}
-}
-static void check_list_union(QObject *qobj,
- UserDefListUnionKind kind)
-{
- QDict *qdict;
- QList *qlist;
- int i;
+ visit_type_ArrayStruct(data->ov, NULL, &arrs, &error_abort);
- qdict = qobject_to(QDict, qobj);
+ qdict = qobject_to(QDict, visitor_get(data));
g_assert(qdict);
- g_assert(qdict_haskey(qdict, "data"));
- qlist = qlist_copy(qobject_to(QList, qdict_get(qdict, "data")));
-
- switch (kind) {
- case USER_DEF_LIST_UNION_KIND_U8:
- case USER_DEF_LIST_UNION_KIND_U16:
- case USER_DEF_LIST_UNION_KIND_U32:
- case USER_DEF_LIST_UNION_KIND_U64:
- for (i = 0; i < 32; i++) {
- QObject *tmp;
- QNum *qvalue;
- uint64_t val;
-
- tmp = qlist_peek(qlist);
- g_assert(tmp);
- qvalue = qobject_to(QNum, tmp);
- g_assert(qnum_get_try_uint(qvalue, &val));
- g_assert_cmpint(val, ==, i);
- qobject_unref(qlist_pop(qlist));
- }
- break;
-
- case USER_DEF_LIST_UNION_KIND_S8:
- case USER_DEF_LIST_UNION_KIND_S16:
- case USER_DEF_LIST_UNION_KIND_S32:
- case USER_DEF_LIST_UNION_KIND_S64:
- /*
- * All integer elements in JSON arrays get stored into QNums
- * when we convert to QObjects, so we can check them all in
- * the same fashion, so simply fall through here.
- */
- case USER_DEF_LIST_UNION_KIND_INTEGER:
- for (i = 0; i < 32; i++) {
- QObject *tmp;
- QNum *qvalue;
- int64_t val;
-
- tmp = qlist_peek(qlist);
- g_assert(tmp);
- qvalue = qobject_to(QNum, tmp);
- g_assert(qnum_get_try_int(qvalue, &val));
- g_assert_cmpint(val, ==, i);
- qobject_unref(qlist_pop(qlist));
- }
- break;
- case USER_DEF_LIST_UNION_KIND_BOOLEAN:
- for (i = 0; i < 32; i++) {
- QObject *tmp;
- QBool *qvalue;
- tmp = qlist_peek(qlist);
- g_assert(tmp);
- qvalue = qobject_to(QBool, tmp);
- g_assert_cmpint(qbool_get_bool(qvalue), ==, i % 3 == 0);
- qobject_unref(qlist_pop(qlist));
- }
- break;
- case USER_DEF_LIST_UNION_KIND_STRING:
- for (i = 0; i < 32; i++) {
- QObject *tmp;
- QString *qvalue;
- gchar str[8];
- tmp = qlist_peek(qlist);
- g_assert(tmp);
- qvalue = qobject_to(QString, tmp);
- sprintf(str, "%d", i);
- g_assert_cmpstr(qstring_get_str(qvalue), ==, str);
- qobject_unref(qlist_pop(qlist));
- }
- break;
- case USER_DEF_LIST_UNION_KIND_NUMBER:
- for (i = 0; i < 32; i++) {
- QObject *tmp;
- QNum *qvalue;
- GString *double_expected = g_string_new("");
- GString *double_actual = g_string_new("");
-
- tmp = qlist_peek(qlist);
- g_assert(tmp);
- qvalue = qobject_to(QNum, tmp);
- g_string_printf(double_expected, "%.6f", (double)i / 3);
- g_string_printf(double_actual, "%.6f", qnum_get_double(qvalue));
- g_assert_cmpstr(double_actual->str, ==, double_expected->str);
-
- qobject_unref(qlist_pop(qlist));
- g_string_free(double_expected, true);
- g_string_free(double_actual, true);
+
+ for (i = 0; i < G_N_ELEMENTS(int_member); i++) {
+ qlist = qdict_get_qlist(qdict, int_member[i]);
+ g_assert(qlist);
+ j = 0;
+ QLIST_FOREACH_ENTRY(qlist, e) {
+ QNum *qvalue = qobject_to(QNum, qlist_entry_obj(e));
+ g_assert(qvalue);
+ g_assert_cmpint(qnum_get_int(qvalue), ==, j);
+ j++;
}
- break;
- default:
- g_assert_not_reached();
}
- qobject_unref(qlist);
-}
-
-static void test_list_union(TestOutputVisitorData *data,
- const void *unused,
- UserDefListUnionKind kind)
-{
- UserDefListUnion *cvalue = g_new0(UserDefListUnion, 1);
- QObject *obj;
-
- cvalue->type = kind;
- init_list_union(cvalue);
-
- visit_type_UserDefListUnion(data->ov, NULL, &cvalue, &error_abort);
-
- obj = visitor_get(data);
- check_list_union(obj, cvalue->type);
- qapi_free_UserDefListUnion(cvalue);
-}
-
-static void test_visitor_out_list_union_int(TestOutputVisitorData *data,
- const void *unused)
-{
- test_list_union(data, unused, USER_DEF_LIST_UNION_KIND_INTEGER);
-}
-
-static void test_visitor_out_list_union_int8(TestOutputVisitorData *data,
- const void *unused)
-{
- test_list_union(data, unused, USER_DEF_LIST_UNION_KIND_S8);
-}
-
-static void test_visitor_out_list_union_int16(TestOutputVisitorData *data,
- const void *unused)
-{
- test_list_union(data, unused, USER_DEF_LIST_UNION_KIND_S16);
-}
-
-static void test_visitor_out_list_union_int32(TestOutputVisitorData *data,
- const void *unused)
-{
- test_list_union(data, unused, USER_DEF_LIST_UNION_KIND_S32);
-}
-
-static void test_visitor_out_list_union_int64(TestOutputVisitorData *data,
- const void *unused)
-{
- test_list_union(data, unused, USER_DEF_LIST_UNION_KIND_S64);
-}
-
-static void test_visitor_out_list_union_uint8(TestOutputVisitorData *data,
- const void *unused)
-{
- test_list_union(data, unused, USER_DEF_LIST_UNION_KIND_U8);
-}
-
-static void test_visitor_out_list_union_uint16(TestOutputVisitorData *data,
- const void *unused)
-{
- test_list_union(data, unused, USER_DEF_LIST_UNION_KIND_U16);
-}
-static void test_visitor_out_list_union_uint32(TestOutputVisitorData *data,
- const void *unused)
-{
- test_list_union(data, unused, USER_DEF_LIST_UNION_KIND_U32);
-}
-
-static void test_visitor_out_list_union_uint64(TestOutputVisitorData *data,
- const void *unused)
-{
- test_list_union(data, unused, USER_DEF_LIST_UNION_KIND_U64);
-}
+ qlist = qdict_get_qlist(qdict, "number");
+ g_assert(qlist);
+ i = 0;
+ QLIST_FOREACH_ENTRY(qlist, e) {
+ QNum *qvalue = qobject_to(QNum, qlist_entry_obj(e));
+ char expected[32], actual[32];
+
+ g_assert(qvalue);
+ sprintf(expected, "%.6f", (double)i / 3);
+ sprintf(actual, "%.6f", qnum_get_double(qvalue));
+ g_assert_cmpstr(actual, ==, expected);
+ i++;
+ }
-static void test_visitor_out_list_union_bool(TestOutputVisitorData *data,
- const void *unused)
-{
- test_list_union(data, unused, USER_DEF_LIST_UNION_KIND_BOOLEAN);
-}
+ qlist = qdict_get_qlist(qdict, "boolean");
+ g_assert(qlist);
+ i = 0;
+ QLIST_FOREACH_ENTRY(qlist, e) {
+ QBool *qvalue = qobject_to(QBool, qlist_entry_obj(e));
+ g_assert(qvalue);
+ g_assert_cmpint(qbool_get_bool(qvalue), ==, i % 3 == 0);
+ i++;
+ }
-static void test_visitor_out_list_union_str(TestOutputVisitorData *data,
- const void *unused)
-{
- test_list_union(data, unused, USER_DEF_LIST_UNION_KIND_STRING);
-}
+ qlist = qdict_get_qlist(qdict, "string");
+ g_assert(qlist);
+ i = 0;
+ QLIST_FOREACH_ENTRY(qlist, e) {
+ QString *qvalue = qobject_to(QString, qlist_entry_obj(e));
+ char expected[32];
-static void test_visitor_out_list_union_number(TestOutputVisitorData *data,
- const void *unused)
-{
- test_list_union(data, unused, USER_DEF_LIST_UNION_KIND_NUMBER);
+ g_assert(qvalue);
+ sprintf(expected, "%d", i);
+ g_assert_cmpstr(qstring_get_str(qvalue), ==, expected);
+ i++;
+ }
}
static void output_visitor_test_add(const char *testpath,
@@ -764,42 +593,8 @@ int main(int argc, char **argv)
&out_visitor_data, test_visitor_out_alternate);
output_visitor_test_add("/visitor/output/null",
&out_visitor_data, test_visitor_out_null);
- output_visitor_test_add("/visitor/output/list_union/int",
- &out_visitor_data,
- test_visitor_out_list_union_int);
- output_visitor_test_add("/visitor/output/list_union/int8",
- &out_visitor_data,
- test_visitor_out_list_union_int8);
- output_visitor_test_add("/visitor/output/list_union/int16",
- &out_visitor_data,
- test_visitor_out_list_union_int16);
- output_visitor_test_add("/visitor/output/list_union/int32",
- &out_visitor_data,
- test_visitor_out_list_union_int32);
- output_visitor_test_add("/visitor/output/list_union/int64",
- &out_visitor_data,
- test_visitor_out_list_union_int64);
- output_visitor_test_add("/visitor/output/list_union/uint8",
- &out_visitor_data,
- test_visitor_out_list_union_uint8);
- output_visitor_test_add("/visitor/output/list_union/uint16",
- &out_visitor_data,
- test_visitor_out_list_union_uint16);
- output_visitor_test_add("/visitor/output/list_union/uint32",
- &out_visitor_data,
- test_visitor_out_list_union_uint32);
- output_visitor_test_add("/visitor/output/list_union/uint64",
- &out_visitor_data,
- test_visitor_out_list_union_uint64);
- output_visitor_test_add("/visitor/output/list_union/bool",
- &out_visitor_data,
- test_visitor_out_list_union_bool);
- output_visitor_test_add("/visitor/output/list_union/string",
- &out_visitor_data,
- test_visitor_out_list_union_str);
- output_visitor_test_add("/visitor/output/list_union/number",
- &out_visitor_data,
- test_visitor_out_list_union_number);
+ output_visitor_test_add("/visitor/output/list_struct",
+ &out_visitor_data, test_visitor_out_list_struct);
g_test_run();