1*da668aa1SThomas Huth /* 2*da668aa1SThomas Huth * QObject Output Visitor unit-tests. 3*da668aa1SThomas Huth * 4*da668aa1SThomas Huth * Copyright (C) 2011-2016 Red Hat Inc. 5*da668aa1SThomas Huth * 6*da668aa1SThomas Huth * Authors: 7*da668aa1SThomas Huth * Luiz Capitulino <lcapitulino@redhat.com> 8*da668aa1SThomas Huth * 9*da668aa1SThomas Huth * This work is licensed under the terms of the GNU GPL, version 2 or later. 10*da668aa1SThomas Huth * See the COPYING file in the top-level directory. 11*da668aa1SThomas Huth */ 12*da668aa1SThomas Huth 13*da668aa1SThomas Huth #include "qemu/osdep.h" 14*da668aa1SThomas Huth 15*da668aa1SThomas Huth #include "qemu-common.h" 16*da668aa1SThomas Huth #include "qapi/error.h" 17*da668aa1SThomas Huth #include "qapi/qobject-output-visitor.h" 18*da668aa1SThomas Huth #include "test-qapi-visit.h" 19*da668aa1SThomas Huth #include "qapi/qmp/qbool.h" 20*da668aa1SThomas Huth #include "qapi/qmp/qdict.h" 21*da668aa1SThomas Huth #include "qapi/qmp/qlist.h" 22*da668aa1SThomas Huth #include "qapi/qmp/qnull.h" 23*da668aa1SThomas Huth #include "qapi/qmp/qnum.h" 24*da668aa1SThomas Huth #include "qapi/qmp/qstring.h" 25*da668aa1SThomas Huth 26*da668aa1SThomas Huth typedef struct TestOutputVisitorData { 27*da668aa1SThomas Huth Visitor *ov; 28*da668aa1SThomas Huth QObject *obj; 29*da668aa1SThomas Huth } TestOutputVisitorData; 30*da668aa1SThomas Huth 31*da668aa1SThomas Huth static void visitor_output_setup(TestOutputVisitorData *data, 32*da668aa1SThomas Huth const void *unused) 33*da668aa1SThomas Huth { 34*da668aa1SThomas Huth data->ov = qobject_output_visitor_new(&data->obj); 35*da668aa1SThomas Huth g_assert(data->ov); 36*da668aa1SThomas Huth } 37*da668aa1SThomas Huth 38*da668aa1SThomas Huth static void visitor_output_teardown(TestOutputVisitorData *data, 39*da668aa1SThomas Huth const void *unused) 40*da668aa1SThomas Huth { 41*da668aa1SThomas Huth visit_free(data->ov); 42*da668aa1SThomas Huth data->ov = NULL; 43*da668aa1SThomas Huth qobject_unref(data->obj); 44*da668aa1SThomas Huth data->obj = NULL; 45*da668aa1SThomas Huth } 46*da668aa1SThomas Huth 47*da668aa1SThomas Huth static QObject *visitor_get(TestOutputVisitorData *data) 48*da668aa1SThomas Huth { 49*da668aa1SThomas Huth visit_complete(data->ov, &data->obj); 50*da668aa1SThomas Huth g_assert(data->obj); 51*da668aa1SThomas Huth return data->obj; 52*da668aa1SThomas Huth } 53*da668aa1SThomas Huth 54*da668aa1SThomas Huth static void visitor_reset(TestOutputVisitorData *data) 55*da668aa1SThomas Huth { 56*da668aa1SThomas Huth visitor_output_teardown(data, NULL); 57*da668aa1SThomas Huth visitor_output_setup(data, NULL); 58*da668aa1SThomas Huth } 59*da668aa1SThomas Huth 60*da668aa1SThomas Huth static void test_visitor_out_int(TestOutputVisitorData *data, 61*da668aa1SThomas Huth const void *unused) 62*da668aa1SThomas Huth { 63*da668aa1SThomas Huth int64_t value = -42; 64*da668aa1SThomas Huth int64_t val; 65*da668aa1SThomas Huth QNum *qnum; 66*da668aa1SThomas Huth 67*da668aa1SThomas Huth visit_type_int(data->ov, NULL, &value, &error_abort); 68*da668aa1SThomas Huth 69*da668aa1SThomas Huth qnum = qobject_to(QNum, visitor_get(data)); 70*da668aa1SThomas Huth g_assert(qnum); 71*da668aa1SThomas Huth g_assert(qnum_get_try_int(qnum, &val)); 72*da668aa1SThomas Huth g_assert_cmpint(val, ==, value); 73*da668aa1SThomas Huth } 74*da668aa1SThomas Huth 75*da668aa1SThomas Huth static void test_visitor_out_bool(TestOutputVisitorData *data, 76*da668aa1SThomas Huth const void *unused) 77*da668aa1SThomas Huth { 78*da668aa1SThomas Huth bool value = true; 79*da668aa1SThomas Huth QBool *qbool; 80*da668aa1SThomas Huth 81*da668aa1SThomas Huth visit_type_bool(data->ov, NULL, &value, &error_abort); 82*da668aa1SThomas Huth 83*da668aa1SThomas Huth qbool = qobject_to(QBool, visitor_get(data)); 84*da668aa1SThomas Huth g_assert(qbool); 85*da668aa1SThomas Huth g_assert(qbool_get_bool(qbool) == value); 86*da668aa1SThomas Huth } 87*da668aa1SThomas Huth 88*da668aa1SThomas Huth static void test_visitor_out_number(TestOutputVisitorData *data, 89*da668aa1SThomas Huth const void *unused) 90*da668aa1SThomas Huth { 91*da668aa1SThomas Huth double value = 3.14; 92*da668aa1SThomas Huth QNum *qnum; 93*da668aa1SThomas Huth 94*da668aa1SThomas Huth visit_type_number(data->ov, NULL, &value, &error_abort); 95*da668aa1SThomas Huth 96*da668aa1SThomas Huth qnum = qobject_to(QNum, visitor_get(data)); 97*da668aa1SThomas Huth g_assert(qnum); 98*da668aa1SThomas Huth g_assert(qnum_get_double(qnum) == value); 99*da668aa1SThomas Huth } 100*da668aa1SThomas Huth 101*da668aa1SThomas Huth static void test_visitor_out_string(TestOutputVisitorData *data, 102*da668aa1SThomas Huth const void *unused) 103*da668aa1SThomas Huth { 104*da668aa1SThomas Huth char *string = (char *) "Q E M U"; 105*da668aa1SThomas Huth QString *qstr; 106*da668aa1SThomas Huth 107*da668aa1SThomas Huth visit_type_str(data->ov, NULL, &string, &error_abort); 108*da668aa1SThomas Huth 109*da668aa1SThomas Huth qstr = qobject_to(QString, visitor_get(data)); 110*da668aa1SThomas Huth g_assert(qstr); 111*da668aa1SThomas Huth g_assert_cmpstr(qstring_get_str(qstr), ==, string); 112*da668aa1SThomas Huth } 113*da668aa1SThomas Huth 114*da668aa1SThomas Huth static void test_visitor_out_no_string(TestOutputVisitorData *data, 115*da668aa1SThomas Huth const void *unused) 116*da668aa1SThomas Huth { 117*da668aa1SThomas Huth char *string = NULL; 118*da668aa1SThomas Huth QString *qstr; 119*da668aa1SThomas Huth 120*da668aa1SThomas Huth /* A null string should return "" */ 121*da668aa1SThomas Huth visit_type_str(data->ov, NULL, &string, &error_abort); 122*da668aa1SThomas Huth 123*da668aa1SThomas Huth qstr = qobject_to(QString, visitor_get(data)); 124*da668aa1SThomas Huth g_assert(qstr); 125*da668aa1SThomas Huth g_assert_cmpstr(qstring_get_str(qstr), ==, ""); 126*da668aa1SThomas Huth } 127*da668aa1SThomas Huth 128*da668aa1SThomas Huth static void test_visitor_out_enum(TestOutputVisitorData *data, 129*da668aa1SThomas Huth const void *unused) 130*da668aa1SThomas Huth { 131*da668aa1SThomas Huth EnumOne i; 132*da668aa1SThomas Huth QString *qstr; 133*da668aa1SThomas Huth 134*da668aa1SThomas Huth for (i = 0; i < ENUM_ONE__MAX; i++) { 135*da668aa1SThomas Huth visit_type_EnumOne(data->ov, "unused", &i, &error_abort); 136*da668aa1SThomas Huth 137*da668aa1SThomas Huth qstr = qobject_to(QString, visitor_get(data)); 138*da668aa1SThomas Huth g_assert(qstr); 139*da668aa1SThomas Huth g_assert_cmpstr(qstring_get_str(qstr), ==, EnumOne_str(i)); 140*da668aa1SThomas Huth visitor_reset(data); 141*da668aa1SThomas Huth } 142*da668aa1SThomas Huth } 143*da668aa1SThomas Huth 144*da668aa1SThomas Huth static void test_visitor_out_struct(TestOutputVisitorData *data, 145*da668aa1SThomas Huth const void *unused) 146*da668aa1SThomas Huth { 147*da668aa1SThomas Huth TestStruct test_struct = { .integer = 42, 148*da668aa1SThomas Huth .boolean = false, 149*da668aa1SThomas Huth .string = (char *) "foo"}; 150*da668aa1SThomas Huth TestStruct *p = &test_struct; 151*da668aa1SThomas Huth QDict *qdict; 152*da668aa1SThomas Huth 153*da668aa1SThomas Huth visit_type_TestStruct(data->ov, NULL, &p, &error_abort); 154*da668aa1SThomas Huth 155*da668aa1SThomas Huth qdict = qobject_to(QDict, visitor_get(data)); 156*da668aa1SThomas Huth g_assert(qdict); 157*da668aa1SThomas Huth g_assert_cmpint(qdict_size(qdict), ==, 3); 158*da668aa1SThomas Huth g_assert_cmpint(qdict_get_int(qdict, "integer"), ==, 42); 159*da668aa1SThomas Huth g_assert_cmpint(qdict_get_bool(qdict, "boolean"), ==, false); 160*da668aa1SThomas Huth g_assert_cmpstr(qdict_get_str(qdict, "string"), ==, "foo"); 161*da668aa1SThomas Huth } 162*da668aa1SThomas Huth 163*da668aa1SThomas Huth static void test_visitor_out_struct_nested(TestOutputVisitorData *data, 164*da668aa1SThomas Huth const void *unused) 165*da668aa1SThomas Huth { 166*da668aa1SThomas Huth int64_t value = 42; 167*da668aa1SThomas Huth UserDefTwo *ud2; 168*da668aa1SThomas Huth QDict *qdict, *dict1, *dict2, *dict3, *userdef; 169*da668aa1SThomas Huth const char *string = "user def string"; 170*da668aa1SThomas Huth const char *strings[] = { "forty two", "forty three", "forty four", 171*da668aa1SThomas Huth "forty five" }; 172*da668aa1SThomas Huth 173*da668aa1SThomas Huth ud2 = g_malloc0(sizeof(*ud2)); 174*da668aa1SThomas Huth ud2->string0 = g_strdup(strings[0]); 175*da668aa1SThomas Huth 176*da668aa1SThomas Huth ud2->dict1 = g_malloc0(sizeof(*ud2->dict1)); 177*da668aa1SThomas Huth ud2->dict1->string1 = g_strdup(strings[1]); 178*da668aa1SThomas Huth 179*da668aa1SThomas Huth ud2->dict1->dict2 = g_malloc0(sizeof(*ud2->dict1->dict2)); 180*da668aa1SThomas Huth ud2->dict1->dict2->userdef = g_new0(UserDefOne, 1); 181*da668aa1SThomas Huth ud2->dict1->dict2->userdef->string = g_strdup(string); 182*da668aa1SThomas Huth ud2->dict1->dict2->userdef->integer = value; 183*da668aa1SThomas Huth ud2->dict1->dict2->string = g_strdup(strings[2]); 184*da668aa1SThomas Huth 185*da668aa1SThomas Huth ud2->dict1->dict3 = g_malloc0(sizeof(*ud2->dict1->dict3)); 186*da668aa1SThomas Huth ud2->dict1->has_dict3 = true; 187*da668aa1SThomas Huth ud2->dict1->dict3->userdef = g_new0(UserDefOne, 1); 188*da668aa1SThomas Huth ud2->dict1->dict3->userdef->string = g_strdup(string); 189*da668aa1SThomas Huth ud2->dict1->dict3->userdef->integer = value; 190*da668aa1SThomas Huth ud2->dict1->dict3->string = g_strdup(strings[3]); 191*da668aa1SThomas Huth 192*da668aa1SThomas Huth visit_type_UserDefTwo(data->ov, "unused", &ud2, &error_abort); 193*da668aa1SThomas Huth 194*da668aa1SThomas Huth qdict = qobject_to(QDict, visitor_get(data)); 195*da668aa1SThomas Huth g_assert(qdict); 196*da668aa1SThomas Huth g_assert_cmpint(qdict_size(qdict), ==, 2); 197*da668aa1SThomas Huth g_assert_cmpstr(qdict_get_str(qdict, "string0"), ==, strings[0]); 198*da668aa1SThomas Huth 199*da668aa1SThomas Huth dict1 = qdict_get_qdict(qdict, "dict1"); 200*da668aa1SThomas Huth g_assert_cmpint(qdict_size(dict1), ==, 3); 201*da668aa1SThomas Huth g_assert_cmpstr(qdict_get_str(dict1, "string1"), ==, strings[1]); 202*da668aa1SThomas Huth 203*da668aa1SThomas Huth dict2 = qdict_get_qdict(dict1, "dict2"); 204*da668aa1SThomas Huth g_assert_cmpint(qdict_size(dict2), ==, 2); 205*da668aa1SThomas Huth g_assert_cmpstr(qdict_get_str(dict2, "string"), ==, strings[2]); 206*da668aa1SThomas Huth userdef = qdict_get_qdict(dict2, "userdef"); 207*da668aa1SThomas Huth g_assert_cmpint(qdict_size(userdef), ==, 2); 208*da668aa1SThomas Huth g_assert_cmpint(qdict_get_int(userdef, "integer"), ==, value); 209*da668aa1SThomas Huth g_assert_cmpstr(qdict_get_str(userdef, "string"), ==, string); 210*da668aa1SThomas Huth 211*da668aa1SThomas Huth dict3 = qdict_get_qdict(dict1, "dict3"); 212*da668aa1SThomas Huth g_assert_cmpint(qdict_size(dict3), ==, 2); 213*da668aa1SThomas Huth g_assert_cmpstr(qdict_get_str(dict3, "string"), ==, strings[3]); 214*da668aa1SThomas Huth userdef = qdict_get_qdict(dict3, "userdef"); 215*da668aa1SThomas Huth g_assert_cmpint(qdict_size(userdef), ==, 2); 216*da668aa1SThomas Huth g_assert_cmpint(qdict_get_int(userdef, "integer"), ==, value); 217*da668aa1SThomas Huth g_assert_cmpstr(qdict_get_str(userdef, "string"), ==, string); 218*da668aa1SThomas Huth 219*da668aa1SThomas Huth qapi_free_UserDefTwo(ud2); 220*da668aa1SThomas Huth } 221*da668aa1SThomas Huth 222*da668aa1SThomas Huth static void test_visitor_out_list(TestOutputVisitorData *data, 223*da668aa1SThomas Huth const void *unused) 224*da668aa1SThomas Huth { 225*da668aa1SThomas Huth const char *value_str = "list value"; 226*da668aa1SThomas Huth TestStruct *value; 227*da668aa1SThomas Huth TestStructList *head = NULL; 228*da668aa1SThomas Huth const int max_items = 10; 229*da668aa1SThomas Huth bool value_bool = true; 230*da668aa1SThomas Huth int value_int = 10; 231*da668aa1SThomas Huth QListEntry *entry; 232*da668aa1SThomas Huth QList *qlist; 233*da668aa1SThomas Huth int i; 234*da668aa1SThomas Huth 235*da668aa1SThomas Huth /* Build the list in reverse order... */ 236*da668aa1SThomas Huth for (i = 0; i < max_items; i++) { 237*da668aa1SThomas Huth value = g_malloc0(sizeof(*value)); 238*da668aa1SThomas Huth value->integer = value_int + (max_items - i - 1); 239*da668aa1SThomas Huth value->boolean = value_bool; 240*da668aa1SThomas Huth value->string = g_strdup(value_str); 241*da668aa1SThomas Huth 242*da668aa1SThomas Huth QAPI_LIST_PREPEND(head, value); 243*da668aa1SThomas Huth } 244*da668aa1SThomas Huth 245*da668aa1SThomas Huth visit_type_TestStructList(data->ov, NULL, &head, &error_abort); 246*da668aa1SThomas Huth 247*da668aa1SThomas Huth qlist = qobject_to(QList, visitor_get(data)); 248*da668aa1SThomas Huth g_assert(qlist); 249*da668aa1SThomas Huth g_assert(!qlist_empty(qlist)); 250*da668aa1SThomas Huth 251*da668aa1SThomas Huth /* ...and ensure that the visitor sees it in order */ 252*da668aa1SThomas Huth i = 0; 253*da668aa1SThomas Huth QLIST_FOREACH_ENTRY(qlist, entry) { 254*da668aa1SThomas Huth QDict *qdict; 255*da668aa1SThomas Huth 256*da668aa1SThomas Huth qdict = qobject_to(QDict, entry->value); 257*da668aa1SThomas Huth g_assert(qdict); 258*da668aa1SThomas Huth g_assert_cmpint(qdict_size(qdict), ==, 3); 259*da668aa1SThomas Huth g_assert_cmpint(qdict_get_int(qdict, "integer"), ==, value_int + i); 260*da668aa1SThomas Huth g_assert_cmpint(qdict_get_bool(qdict, "boolean"), ==, value_bool); 261*da668aa1SThomas Huth g_assert_cmpstr(qdict_get_str(qdict, "string"), ==, value_str); 262*da668aa1SThomas Huth i++; 263*da668aa1SThomas Huth } 264*da668aa1SThomas Huth g_assert_cmpint(i, ==, max_items); 265*da668aa1SThomas Huth 266*da668aa1SThomas Huth qapi_free_TestStructList(head); 267*da668aa1SThomas Huth } 268*da668aa1SThomas Huth 269*da668aa1SThomas Huth static void test_visitor_out_list_qapi_free(TestOutputVisitorData *data, 270*da668aa1SThomas Huth const void *unused) 271*da668aa1SThomas Huth { 272*da668aa1SThomas Huth UserDefTwo *value; 273*da668aa1SThomas Huth UserDefTwoList *head = NULL; 274*da668aa1SThomas Huth const char string[] = "foo bar"; 275*da668aa1SThomas Huth int i, max_count = 1024; 276*da668aa1SThomas Huth 277*da668aa1SThomas Huth for (i = 0; i < max_count; i++) { 278*da668aa1SThomas Huth value = g_malloc0(sizeof(*value)); 279*da668aa1SThomas Huth 280*da668aa1SThomas Huth value->string0 = g_strdup(string); 281*da668aa1SThomas Huth value->dict1 = g_new0(UserDefTwoDict, 1); 282*da668aa1SThomas Huth value->dict1->string1 = g_strdup(string); 283*da668aa1SThomas Huth value->dict1->dict2 = g_new0(UserDefTwoDictDict, 1); 284*da668aa1SThomas Huth value->dict1->dict2->userdef = g_new0(UserDefOne, 1); 285*da668aa1SThomas Huth value->dict1->dict2->userdef->string = g_strdup(string); 286*da668aa1SThomas Huth value->dict1->dict2->userdef->integer = 42; 287*da668aa1SThomas Huth value->dict1->dict2->string = g_strdup(string); 288*da668aa1SThomas Huth value->dict1->has_dict3 = false; 289*da668aa1SThomas Huth 290*da668aa1SThomas Huth QAPI_LIST_PREPEND(head, value); 291*da668aa1SThomas Huth } 292*da668aa1SThomas Huth 293*da668aa1SThomas Huth qapi_free_UserDefTwoList(head); 294*da668aa1SThomas Huth } 295*da668aa1SThomas Huth 296*da668aa1SThomas Huth static void test_visitor_out_any(TestOutputVisitorData *data, 297*da668aa1SThomas Huth const void *unused) 298*da668aa1SThomas Huth { 299*da668aa1SThomas Huth QObject *qobj; 300*da668aa1SThomas Huth QNum *qnum; 301*da668aa1SThomas Huth QBool *qbool; 302*da668aa1SThomas Huth QString *qstring; 303*da668aa1SThomas Huth QDict *qdict; 304*da668aa1SThomas Huth int64_t val; 305*da668aa1SThomas Huth 306*da668aa1SThomas Huth qobj = QOBJECT(qnum_from_int(-42)); 307*da668aa1SThomas Huth visit_type_any(data->ov, NULL, &qobj, &error_abort); 308*da668aa1SThomas Huth qnum = qobject_to(QNum, visitor_get(data)); 309*da668aa1SThomas Huth g_assert(qnum); 310*da668aa1SThomas Huth g_assert(qnum_get_try_int(qnum, &val)); 311*da668aa1SThomas Huth g_assert_cmpint(val, ==, -42); 312*da668aa1SThomas Huth qobject_unref(qobj); 313*da668aa1SThomas Huth 314*da668aa1SThomas Huth visitor_reset(data); 315*da668aa1SThomas Huth qdict = qdict_new(); 316*da668aa1SThomas Huth qdict_put_int(qdict, "integer", -42); 317*da668aa1SThomas Huth qdict_put_bool(qdict, "boolean", true); 318*da668aa1SThomas Huth qdict_put_str(qdict, "string", "foo"); 319*da668aa1SThomas Huth qobj = QOBJECT(qdict); 320*da668aa1SThomas Huth visit_type_any(data->ov, NULL, &qobj, &error_abort); 321*da668aa1SThomas Huth qobject_unref(qobj); 322*da668aa1SThomas Huth qdict = qobject_to(QDict, visitor_get(data)); 323*da668aa1SThomas Huth g_assert(qdict); 324*da668aa1SThomas Huth qnum = qobject_to(QNum, qdict_get(qdict, "integer")); 325*da668aa1SThomas Huth g_assert(qnum); 326*da668aa1SThomas Huth g_assert(qnum_get_try_int(qnum, &val)); 327*da668aa1SThomas Huth g_assert_cmpint(val, ==, -42); 328*da668aa1SThomas Huth qbool = qobject_to(QBool, qdict_get(qdict, "boolean")); 329*da668aa1SThomas Huth g_assert(qbool); 330*da668aa1SThomas Huth g_assert(qbool_get_bool(qbool) == true); 331*da668aa1SThomas Huth qstring = qobject_to(QString, qdict_get(qdict, "string")); 332*da668aa1SThomas Huth g_assert(qstring); 333*da668aa1SThomas Huth g_assert_cmpstr(qstring_get_str(qstring), ==, "foo"); 334*da668aa1SThomas Huth } 335*da668aa1SThomas Huth 336*da668aa1SThomas Huth static void test_visitor_out_union_flat(TestOutputVisitorData *data, 337*da668aa1SThomas Huth const void *unused) 338*da668aa1SThomas Huth { 339*da668aa1SThomas Huth QDict *qdict; 340*da668aa1SThomas Huth 341*da668aa1SThomas Huth UserDefFlatUnion *tmp = g_malloc0(sizeof(UserDefFlatUnion)); 342*da668aa1SThomas Huth tmp->enum1 = ENUM_ONE_VALUE1; 343*da668aa1SThomas Huth tmp->string = g_strdup("str"); 344*da668aa1SThomas Huth tmp->integer = 41; 345*da668aa1SThomas Huth tmp->u.value1.boolean = true; 346*da668aa1SThomas Huth 347*da668aa1SThomas Huth visit_type_UserDefFlatUnion(data->ov, NULL, &tmp, &error_abort); 348*da668aa1SThomas Huth qdict = qobject_to(QDict, visitor_get(data)); 349*da668aa1SThomas Huth g_assert(qdict); 350*da668aa1SThomas Huth g_assert_cmpstr(qdict_get_str(qdict, "enum1"), ==, "value1"); 351*da668aa1SThomas Huth g_assert_cmpstr(qdict_get_str(qdict, "string"), ==, "str"); 352*da668aa1SThomas Huth g_assert_cmpint(qdict_get_int(qdict, "integer"), ==, 41); 353*da668aa1SThomas Huth g_assert_cmpint(qdict_get_bool(qdict, "boolean"), ==, true); 354*da668aa1SThomas Huth 355*da668aa1SThomas Huth qapi_free_UserDefFlatUnion(tmp); 356*da668aa1SThomas Huth } 357*da668aa1SThomas Huth 358*da668aa1SThomas Huth static void test_visitor_out_alternate(TestOutputVisitorData *data, 359*da668aa1SThomas Huth const void *unused) 360*da668aa1SThomas Huth { 361*da668aa1SThomas Huth UserDefAlternate *tmp; 362*da668aa1SThomas Huth QNum *qnum; 363*da668aa1SThomas Huth QString *qstr; 364*da668aa1SThomas Huth QDict *qdict; 365*da668aa1SThomas Huth int64_t val; 366*da668aa1SThomas Huth 367*da668aa1SThomas Huth tmp = g_new0(UserDefAlternate, 1); 368*da668aa1SThomas Huth tmp->type = QTYPE_QNUM; 369*da668aa1SThomas Huth tmp->u.i = 42; 370*da668aa1SThomas Huth 371*da668aa1SThomas Huth visit_type_UserDefAlternate(data->ov, NULL, &tmp, &error_abort); 372*da668aa1SThomas Huth qnum = qobject_to(QNum, visitor_get(data)); 373*da668aa1SThomas Huth g_assert(qnum); 374*da668aa1SThomas Huth g_assert(qnum_get_try_int(qnum, &val)); 375*da668aa1SThomas Huth g_assert_cmpint(val, ==, 42); 376*da668aa1SThomas Huth 377*da668aa1SThomas Huth qapi_free_UserDefAlternate(tmp); 378*da668aa1SThomas Huth 379*da668aa1SThomas Huth visitor_reset(data); 380*da668aa1SThomas Huth tmp = g_new0(UserDefAlternate, 1); 381*da668aa1SThomas Huth tmp->type = QTYPE_QSTRING; 382*da668aa1SThomas Huth tmp->u.e = ENUM_ONE_VALUE1; 383*da668aa1SThomas Huth 384*da668aa1SThomas Huth visit_type_UserDefAlternate(data->ov, NULL, &tmp, &error_abort); 385*da668aa1SThomas Huth qstr = qobject_to(QString, visitor_get(data)); 386*da668aa1SThomas Huth g_assert(qstr); 387*da668aa1SThomas Huth g_assert_cmpstr(qstring_get_str(qstr), ==, "value1"); 388*da668aa1SThomas Huth 389*da668aa1SThomas Huth qapi_free_UserDefAlternate(tmp); 390*da668aa1SThomas Huth 391*da668aa1SThomas Huth visitor_reset(data); 392*da668aa1SThomas Huth tmp = g_new0(UserDefAlternate, 1); 393*da668aa1SThomas Huth tmp->type = QTYPE_QNULL; 394*da668aa1SThomas Huth tmp->u.n = qnull(); 395*da668aa1SThomas Huth 396*da668aa1SThomas Huth visit_type_UserDefAlternate(data->ov, NULL, &tmp, &error_abort); 397*da668aa1SThomas Huth g_assert_cmpint(qobject_type(visitor_get(data)), ==, QTYPE_QNULL); 398*da668aa1SThomas Huth 399*da668aa1SThomas Huth qapi_free_UserDefAlternate(tmp); 400*da668aa1SThomas Huth 401*da668aa1SThomas Huth visitor_reset(data); 402*da668aa1SThomas Huth tmp = g_new0(UserDefAlternate, 1); 403*da668aa1SThomas Huth tmp->type = QTYPE_QDICT; 404*da668aa1SThomas Huth tmp->u.udfu.integer = 1; 405*da668aa1SThomas Huth tmp->u.udfu.string = g_strdup("str"); 406*da668aa1SThomas Huth tmp->u.udfu.enum1 = ENUM_ONE_VALUE1; 407*da668aa1SThomas Huth tmp->u.udfu.u.value1.boolean = true; 408*da668aa1SThomas Huth 409*da668aa1SThomas Huth visit_type_UserDefAlternate(data->ov, NULL, &tmp, &error_abort); 410*da668aa1SThomas Huth qdict = qobject_to(QDict, visitor_get(data)); 411*da668aa1SThomas Huth g_assert(qdict); 412*da668aa1SThomas Huth g_assert_cmpint(qdict_size(qdict), ==, 4); 413*da668aa1SThomas Huth g_assert_cmpint(qdict_get_int(qdict, "integer"), ==, 1); 414*da668aa1SThomas Huth g_assert_cmpstr(qdict_get_str(qdict, "string"), ==, "str"); 415*da668aa1SThomas Huth g_assert_cmpstr(qdict_get_str(qdict, "enum1"), ==, "value1"); 416*da668aa1SThomas Huth g_assert_cmpint(qdict_get_bool(qdict, "boolean"), ==, true); 417*da668aa1SThomas Huth 418*da668aa1SThomas Huth qapi_free_UserDefAlternate(tmp); 419*da668aa1SThomas Huth } 420*da668aa1SThomas Huth 421*da668aa1SThomas Huth static void test_visitor_out_null(TestOutputVisitorData *data, 422*da668aa1SThomas Huth const void *unused) 423*da668aa1SThomas Huth { 424*da668aa1SThomas Huth QNull *null = NULL; 425*da668aa1SThomas Huth QDict *qdict; 426*da668aa1SThomas Huth QObject *nil; 427*da668aa1SThomas Huth 428*da668aa1SThomas Huth visit_start_struct(data->ov, NULL, NULL, 0, &error_abort); 429*da668aa1SThomas Huth visit_type_null(data->ov, "a", &null, &error_abort); 430*da668aa1SThomas Huth visit_check_struct(data->ov, &error_abort); 431*da668aa1SThomas Huth visit_end_struct(data->ov, NULL); 432*da668aa1SThomas Huth qdict = qobject_to(QDict, visitor_get(data)); 433*da668aa1SThomas Huth g_assert(qdict); 434*da668aa1SThomas Huth g_assert_cmpint(qdict_size(qdict), ==, 1); 435*da668aa1SThomas Huth nil = qdict_get(qdict, "a"); 436*da668aa1SThomas Huth g_assert(nil); 437*da668aa1SThomas Huth g_assert(qobject_type(nil) == QTYPE_QNULL); 438*da668aa1SThomas Huth } 439*da668aa1SThomas Huth 440*da668aa1SThomas Huth static void init_list_union(UserDefListUnion *cvalue) 441*da668aa1SThomas Huth { 442*da668aa1SThomas Huth int i; 443*da668aa1SThomas Huth switch (cvalue->type) { 444*da668aa1SThomas Huth case USER_DEF_LIST_UNION_KIND_INTEGER: { 445*da668aa1SThomas Huth intList **tail = &cvalue->u.integer.data; 446*da668aa1SThomas Huth for (i = 0; i < 32; i++) { 447*da668aa1SThomas Huth QAPI_LIST_APPEND(tail, i); 448*da668aa1SThomas Huth } 449*da668aa1SThomas Huth break; 450*da668aa1SThomas Huth } 451*da668aa1SThomas Huth case USER_DEF_LIST_UNION_KIND_S8: { 452*da668aa1SThomas Huth int8List **tail = &cvalue->u.s8.data; 453*da668aa1SThomas Huth for (i = 0; i < 32; i++) { 454*da668aa1SThomas Huth QAPI_LIST_APPEND(tail, i); 455*da668aa1SThomas Huth } 456*da668aa1SThomas Huth break; 457*da668aa1SThomas Huth } 458*da668aa1SThomas Huth case USER_DEF_LIST_UNION_KIND_S16: { 459*da668aa1SThomas Huth int16List **tail = &cvalue->u.s16.data; 460*da668aa1SThomas Huth for (i = 0; i < 32; i++) { 461*da668aa1SThomas Huth QAPI_LIST_APPEND(tail, i); 462*da668aa1SThomas Huth } 463*da668aa1SThomas Huth break; 464*da668aa1SThomas Huth } 465*da668aa1SThomas Huth case USER_DEF_LIST_UNION_KIND_S32: { 466*da668aa1SThomas Huth int32List **tail = &cvalue->u.s32.data; 467*da668aa1SThomas Huth for (i = 0; i < 32; i++) { 468*da668aa1SThomas Huth QAPI_LIST_APPEND(tail, i); 469*da668aa1SThomas Huth } 470*da668aa1SThomas Huth break; 471*da668aa1SThomas Huth } 472*da668aa1SThomas Huth case USER_DEF_LIST_UNION_KIND_S64: { 473*da668aa1SThomas Huth int64List **tail = &cvalue->u.s64.data; 474*da668aa1SThomas Huth for (i = 0; i < 32; i++) { 475*da668aa1SThomas Huth QAPI_LIST_APPEND(tail, i); 476*da668aa1SThomas Huth } 477*da668aa1SThomas Huth break; 478*da668aa1SThomas Huth } 479*da668aa1SThomas Huth case USER_DEF_LIST_UNION_KIND_U8: { 480*da668aa1SThomas Huth uint8List **tail = &cvalue->u.u8.data; 481*da668aa1SThomas Huth for (i = 0; i < 32; i++) { 482*da668aa1SThomas Huth QAPI_LIST_APPEND(tail, i); 483*da668aa1SThomas Huth } 484*da668aa1SThomas Huth break; 485*da668aa1SThomas Huth } 486*da668aa1SThomas Huth case USER_DEF_LIST_UNION_KIND_U16: { 487*da668aa1SThomas Huth uint16List **tail = &cvalue->u.u16.data; 488*da668aa1SThomas Huth for (i = 0; i < 32; i++) { 489*da668aa1SThomas Huth QAPI_LIST_APPEND(tail, i); 490*da668aa1SThomas Huth } 491*da668aa1SThomas Huth break; 492*da668aa1SThomas Huth } 493*da668aa1SThomas Huth case USER_DEF_LIST_UNION_KIND_U32: { 494*da668aa1SThomas Huth uint32List **tail = &cvalue->u.u32.data; 495*da668aa1SThomas Huth for (i = 0; i < 32; i++) { 496*da668aa1SThomas Huth QAPI_LIST_APPEND(tail, i); 497*da668aa1SThomas Huth } 498*da668aa1SThomas Huth break; 499*da668aa1SThomas Huth } 500*da668aa1SThomas Huth case USER_DEF_LIST_UNION_KIND_U64: { 501*da668aa1SThomas Huth uint64List **tail = &cvalue->u.u64.data; 502*da668aa1SThomas Huth for (i = 0; i < 32; i++) { 503*da668aa1SThomas Huth QAPI_LIST_APPEND(tail, i); 504*da668aa1SThomas Huth } 505*da668aa1SThomas Huth break; 506*da668aa1SThomas Huth } 507*da668aa1SThomas Huth case USER_DEF_LIST_UNION_KIND_BOOLEAN: { 508*da668aa1SThomas Huth boolList **tail = &cvalue->u.boolean.data; 509*da668aa1SThomas Huth for (i = 0; i < 32; i++) { 510*da668aa1SThomas Huth QAPI_LIST_APPEND(tail, QEMU_IS_ALIGNED(i, 3)); 511*da668aa1SThomas Huth } 512*da668aa1SThomas Huth break; 513*da668aa1SThomas Huth } 514*da668aa1SThomas Huth case USER_DEF_LIST_UNION_KIND_STRING: { 515*da668aa1SThomas Huth strList **tail = &cvalue->u.string.data; 516*da668aa1SThomas Huth for (i = 0; i < 32; i++) { 517*da668aa1SThomas Huth QAPI_LIST_APPEND(tail, g_strdup_printf("%d", i)); 518*da668aa1SThomas Huth } 519*da668aa1SThomas Huth break; 520*da668aa1SThomas Huth } 521*da668aa1SThomas Huth case USER_DEF_LIST_UNION_KIND_NUMBER: { 522*da668aa1SThomas Huth numberList **tail = &cvalue->u.number.data; 523*da668aa1SThomas Huth for (i = 0; i < 32; i++) { 524*da668aa1SThomas Huth QAPI_LIST_APPEND(tail, (double)i / 3); 525*da668aa1SThomas Huth } 526*da668aa1SThomas Huth break; 527*da668aa1SThomas Huth } 528*da668aa1SThomas Huth default: 529*da668aa1SThomas Huth g_assert_not_reached(); 530*da668aa1SThomas Huth } 531*da668aa1SThomas Huth } 532*da668aa1SThomas Huth 533*da668aa1SThomas Huth static void check_list_union(QObject *qobj, 534*da668aa1SThomas Huth UserDefListUnionKind kind) 535*da668aa1SThomas Huth { 536*da668aa1SThomas Huth QDict *qdict; 537*da668aa1SThomas Huth QList *qlist; 538*da668aa1SThomas Huth int i; 539*da668aa1SThomas Huth 540*da668aa1SThomas Huth qdict = qobject_to(QDict, qobj); 541*da668aa1SThomas Huth g_assert(qdict); 542*da668aa1SThomas Huth g_assert(qdict_haskey(qdict, "data")); 543*da668aa1SThomas Huth qlist = qlist_copy(qobject_to(QList, qdict_get(qdict, "data"))); 544*da668aa1SThomas Huth 545*da668aa1SThomas Huth switch (kind) { 546*da668aa1SThomas Huth case USER_DEF_LIST_UNION_KIND_U8: 547*da668aa1SThomas Huth case USER_DEF_LIST_UNION_KIND_U16: 548*da668aa1SThomas Huth case USER_DEF_LIST_UNION_KIND_U32: 549*da668aa1SThomas Huth case USER_DEF_LIST_UNION_KIND_U64: 550*da668aa1SThomas Huth for (i = 0; i < 32; i++) { 551*da668aa1SThomas Huth QObject *tmp; 552*da668aa1SThomas Huth QNum *qvalue; 553*da668aa1SThomas Huth uint64_t val; 554*da668aa1SThomas Huth 555*da668aa1SThomas Huth tmp = qlist_peek(qlist); 556*da668aa1SThomas Huth g_assert(tmp); 557*da668aa1SThomas Huth qvalue = qobject_to(QNum, tmp); 558*da668aa1SThomas Huth g_assert(qnum_get_try_uint(qvalue, &val)); 559*da668aa1SThomas Huth g_assert_cmpint(val, ==, i); 560*da668aa1SThomas Huth qobject_unref(qlist_pop(qlist)); 561*da668aa1SThomas Huth } 562*da668aa1SThomas Huth break; 563*da668aa1SThomas Huth 564*da668aa1SThomas Huth case USER_DEF_LIST_UNION_KIND_S8: 565*da668aa1SThomas Huth case USER_DEF_LIST_UNION_KIND_S16: 566*da668aa1SThomas Huth case USER_DEF_LIST_UNION_KIND_S32: 567*da668aa1SThomas Huth case USER_DEF_LIST_UNION_KIND_S64: 568*da668aa1SThomas Huth /* 569*da668aa1SThomas Huth * All integer elements in JSON arrays get stored into QNums 570*da668aa1SThomas Huth * when we convert to QObjects, so we can check them all in 571*da668aa1SThomas Huth * the same fashion, so simply fall through here. 572*da668aa1SThomas Huth */ 573*da668aa1SThomas Huth case USER_DEF_LIST_UNION_KIND_INTEGER: 574*da668aa1SThomas Huth for (i = 0; i < 32; i++) { 575*da668aa1SThomas Huth QObject *tmp; 576*da668aa1SThomas Huth QNum *qvalue; 577*da668aa1SThomas Huth int64_t val; 578*da668aa1SThomas Huth 579*da668aa1SThomas Huth tmp = qlist_peek(qlist); 580*da668aa1SThomas Huth g_assert(tmp); 581*da668aa1SThomas Huth qvalue = qobject_to(QNum, tmp); 582*da668aa1SThomas Huth g_assert(qnum_get_try_int(qvalue, &val)); 583*da668aa1SThomas Huth g_assert_cmpint(val, ==, i); 584*da668aa1SThomas Huth qobject_unref(qlist_pop(qlist)); 585*da668aa1SThomas Huth } 586*da668aa1SThomas Huth break; 587*da668aa1SThomas Huth case USER_DEF_LIST_UNION_KIND_BOOLEAN: 588*da668aa1SThomas Huth for (i = 0; i < 32; i++) { 589*da668aa1SThomas Huth QObject *tmp; 590*da668aa1SThomas Huth QBool *qvalue; 591*da668aa1SThomas Huth tmp = qlist_peek(qlist); 592*da668aa1SThomas Huth g_assert(tmp); 593*da668aa1SThomas Huth qvalue = qobject_to(QBool, tmp); 594*da668aa1SThomas Huth g_assert_cmpint(qbool_get_bool(qvalue), ==, i % 3 == 0); 595*da668aa1SThomas Huth qobject_unref(qlist_pop(qlist)); 596*da668aa1SThomas Huth } 597*da668aa1SThomas Huth break; 598*da668aa1SThomas Huth case USER_DEF_LIST_UNION_KIND_STRING: 599*da668aa1SThomas Huth for (i = 0; i < 32; i++) { 600*da668aa1SThomas Huth QObject *tmp; 601*da668aa1SThomas Huth QString *qvalue; 602*da668aa1SThomas Huth gchar str[8]; 603*da668aa1SThomas Huth tmp = qlist_peek(qlist); 604*da668aa1SThomas Huth g_assert(tmp); 605*da668aa1SThomas Huth qvalue = qobject_to(QString, tmp); 606*da668aa1SThomas Huth sprintf(str, "%d", i); 607*da668aa1SThomas Huth g_assert_cmpstr(qstring_get_str(qvalue), ==, str); 608*da668aa1SThomas Huth qobject_unref(qlist_pop(qlist)); 609*da668aa1SThomas Huth } 610*da668aa1SThomas Huth break; 611*da668aa1SThomas Huth case USER_DEF_LIST_UNION_KIND_NUMBER: 612*da668aa1SThomas Huth for (i = 0; i < 32; i++) { 613*da668aa1SThomas Huth QObject *tmp; 614*da668aa1SThomas Huth QNum *qvalue; 615*da668aa1SThomas Huth GString *double_expected = g_string_new(""); 616*da668aa1SThomas Huth GString *double_actual = g_string_new(""); 617*da668aa1SThomas Huth 618*da668aa1SThomas Huth tmp = qlist_peek(qlist); 619*da668aa1SThomas Huth g_assert(tmp); 620*da668aa1SThomas Huth qvalue = qobject_to(QNum, tmp); 621*da668aa1SThomas Huth g_string_printf(double_expected, "%.6f", (double)i / 3); 622*da668aa1SThomas Huth g_string_printf(double_actual, "%.6f", qnum_get_double(qvalue)); 623*da668aa1SThomas Huth g_assert_cmpstr(double_actual->str, ==, double_expected->str); 624*da668aa1SThomas Huth 625*da668aa1SThomas Huth qobject_unref(qlist_pop(qlist)); 626*da668aa1SThomas Huth g_string_free(double_expected, true); 627*da668aa1SThomas Huth g_string_free(double_actual, true); 628*da668aa1SThomas Huth } 629*da668aa1SThomas Huth break; 630*da668aa1SThomas Huth default: 631*da668aa1SThomas Huth g_assert_not_reached(); 632*da668aa1SThomas Huth } 633*da668aa1SThomas Huth qobject_unref(qlist); 634*da668aa1SThomas Huth } 635*da668aa1SThomas Huth 636*da668aa1SThomas Huth static void test_list_union(TestOutputVisitorData *data, 637*da668aa1SThomas Huth const void *unused, 638*da668aa1SThomas Huth UserDefListUnionKind kind) 639*da668aa1SThomas Huth { 640*da668aa1SThomas Huth UserDefListUnion *cvalue = g_new0(UserDefListUnion, 1); 641*da668aa1SThomas Huth QObject *obj; 642*da668aa1SThomas Huth 643*da668aa1SThomas Huth cvalue->type = kind; 644*da668aa1SThomas Huth init_list_union(cvalue); 645*da668aa1SThomas Huth 646*da668aa1SThomas Huth visit_type_UserDefListUnion(data->ov, NULL, &cvalue, &error_abort); 647*da668aa1SThomas Huth 648*da668aa1SThomas Huth obj = visitor_get(data); 649*da668aa1SThomas Huth check_list_union(obj, cvalue->type); 650*da668aa1SThomas Huth qapi_free_UserDefListUnion(cvalue); 651*da668aa1SThomas Huth } 652*da668aa1SThomas Huth 653*da668aa1SThomas Huth static void test_visitor_out_list_union_int(TestOutputVisitorData *data, 654*da668aa1SThomas Huth const void *unused) 655*da668aa1SThomas Huth { 656*da668aa1SThomas Huth test_list_union(data, unused, USER_DEF_LIST_UNION_KIND_INTEGER); 657*da668aa1SThomas Huth } 658*da668aa1SThomas Huth 659*da668aa1SThomas Huth static void test_visitor_out_list_union_int8(TestOutputVisitorData *data, 660*da668aa1SThomas Huth const void *unused) 661*da668aa1SThomas Huth { 662*da668aa1SThomas Huth test_list_union(data, unused, USER_DEF_LIST_UNION_KIND_S8); 663*da668aa1SThomas Huth } 664*da668aa1SThomas Huth 665*da668aa1SThomas Huth static void test_visitor_out_list_union_int16(TestOutputVisitorData *data, 666*da668aa1SThomas Huth const void *unused) 667*da668aa1SThomas Huth { 668*da668aa1SThomas Huth test_list_union(data, unused, USER_DEF_LIST_UNION_KIND_S16); 669*da668aa1SThomas Huth } 670*da668aa1SThomas Huth 671*da668aa1SThomas Huth static void test_visitor_out_list_union_int32(TestOutputVisitorData *data, 672*da668aa1SThomas Huth const void *unused) 673*da668aa1SThomas Huth { 674*da668aa1SThomas Huth test_list_union(data, unused, USER_DEF_LIST_UNION_KIND_S32); 675*da668aa1SThomas Huth } 676*da668aa1SThomas Huth 677*da668aa1SThomas Huth static void test_visitor_out_list_union_int64(TestOutputVisitorData *data, 678*da668aa1SThomas Huth const void *unused) 679*da668aa1SThomas Huth { 680*da668aa1SThomas Huth test_list_union(data, unused, USER_DEF_LIST_UNION_KIND_S64); 681*da668aa1SThomas Huth } 682*da668aa1SThomas Huth 683*da668aa1SThomas Huth static void test_visitor_out_list_union_uint8(TestOutputVisitorData *data, 684*da668aa1SThomas Huth const void *unused) 685*da668aa1SThomas Huth { 686*da668aa1SThomas Huth test_list_union(data, unused, USER_DEF_LIST_UNION_KIND_U8); 687*da668aa1SThomas Huth } 688*da668aa1SThomas Huth 689*da668aa1SThomas Huth static void test_visitor_out_list_union_uint16(TestOutputVisitorData *data, 690*da668aa1SThomas Huth const void *unused) 691*da668aa1SThomas Huth { 692*da668aa1SThomas Huth test_list_union(data, unused, USER_DEF_LIST_UNION_KIND_U16); 693*da668aa1SThomas Huth } 694*da668aa1SThomas Huth 695*da668aa1SThomas Huth static void test_visitor_out_list_union_uint32(TestOutputVisitorData *data, 696*da668aa1SThomas Huth const void *unused) 697*da668aa1SThomas Huth { 698*da668aa1SThomas Huth test_list_union(data, unused, USER_DEF_LIST_UNION_KIND_U32); 699*da668aa1SThomas Huth } 700*da668aa1SThomas Huth 701*da668aa1SThomas Huth static void test_visitor_out_list_union_uint64(TestOutputVisitorData *data, 702*da668aa1SThomas Huth const void *unused) 703*da668aa1SThomas Huth { 704*da668aa1SThomas Huth test_list_union(data, unused, USER_DEF_LIST_UNION_KIND_U64); 705*da668aa1SThomas Huth } 706*da668aa1SThomas Huth 707*da668aa1SThomas Huth static void test_visitor_out_list_union_bool(TestOutputVisitorData *data, 708*da668aa1SThomas Huth const void *unused) 709*da668aa1SThomas Huth { 710*da668aa1SThomas Huth test_list_union(data, unused, USER_DEF_LIST_UNION_KIND_BOOLEAN); 711*da668aa1SThomas Huth } 712*da668aa1SThomas Huth 713*da668aa1SThomas Huth static void test_visitor_out_list_union_str(TestOutputVisitorData *data, 714*da668aa1SThomas Huth const void *unused) 715*da668aa1SThomas Huth { 716*da668aa1SThomas Huth test_list_union(data, unused, USER_DEF_LIST_UNION_KIND_STRING); 717*da668aa1SThomas Huth } 718*da668aa1SThomas Huth 719*da668aa1SThomas Huth static void test_visitor_out_list_union_number(TestOutputVisitorData *data, 720*da668aa1SThomas Huth const void *unused) 721*da668aa1SThomas Huth { 722*da668aa1SThomas Huth test_list_union(data, unused, USER_DEF_LIST_UNION_KIND_NUMBER); 723*da668aa1SThomas Huth } 724*da668aa1SThomas Huth 725*da668aa1SThomas Huth static void output_visitor_test_add(const char *testpath, 726*da668aa1SThomas Huth TestOutputVisitorData *data, 727*da668aa1SThomas Huth void (*test_func)(TestOutputVisitorData *data, const void *user_data)) 728*da668aa1SThomas Huth { 729*da668aa1SThomas Huth g_test_add(testpath, TestOutputVisitorData, data, visitor_output_setup, 730*da668aa1SThomas Huth test_func, visitor_output_teardown); 731*da668aa1SThomas Huth } 732*da668aa1SThomas Huth 733*da668aa1SThomas Huth int main(int argc, char **argv) 734*da668aa1SThomas Huth { 735*da668aa1SThomas Huth TestOutputVisitorData out_visitor_data; 736*da668aa1SThomas Huth 737*da668aa1SThomas Huth g_test_init(&argc, &argv, NULL); 738*da668aa1SThomas Huth 739*da668aa1SThomas Huth output_visitor_test_add("/visitor/output/int", 740*da668aa1SThomas Huth &out_visitor_data, test_visitor_out_int); 741*da668aa1SThomas Huth output_visitor_test_add("/visitor/output/bool", 742*da668aa1SThomas Huth &out_visitor_data, test_visitor_out_bool); 743*da668aa1SThomas Huth output_visitor_test_add("/visitor/output/number", 744*da668aa1SThomas Huth &out_visitor_data, test_visitor_out_number); 745*da668aa1SThomas Huth output_visitor_test_add("/visitor/output/string", 746*da668aa1SThomas Huth &out_visitor_data, test_visitor_out_string); 747*da668aa1SThomas Huth output_visitor_test_add("/visitor/output/no-string", 748*da668aa1SThomas Huth &out_visitor_data, test_visitor_out_no_string); 749*da668aa1SThomas Huth output_visitor_test_add("/visitor/output/enum", 750*da668aa1SThomas Huth &out_visitor_data, test_visitor_out_enum); 751*da668aa1SThomas Huth output_visitor_test_add("/visitor/output/struct", 752*da668aa1SThomas Huth &out_visitor_data, test_visitor_out_struct); 753*da668aa1SThomas Huth output_visitor_test_add("/visitor/output/struct-nested", 754*da668aa1SThomas Huth &out_visitor_data, test_visitor_out_struct_nested); 755*da668aa1SThomas Huth output_visitor_test_add("/visitor/output/list", 756*da668aa1SThomas Huth &out_visitor_data, test_visitor_out_list); 757*da668aa1SThomas Huth output_visitor_test_add("/visitor/output/any", 758*da668aa1SThomas Huth &out_visitor_data, test_visitor_out_any); 759*da668aa1SThomas Huth output_visitor_test_add("/visitor/output/list-qapi-free", 760*da668aa1SThomas Huth &out_visitor_data, test_visitor_out_list_qapi_free); 761*da668aa1SThomas Huth output_visitor_test_add("/visitor/output/union-flat", 762*da668aa1SThomas Huth &out_visitor_data, test_visitor_out_union_flat); 763*da668aa1SThomas Huth output_visitor_test_add("/visitor/output/alternate", 764*da668aa1SThomas Huth &out_visitor_data, test_visitor_out_alternate); 765*da668aa1SThomas Huth output_visitor_test_add("/visitor/output/null", 766*da668aa1SThomas Huth &out_visitor_data, test_visitor_out_null); 767*da668aa1SThomas Huth output_visitor_test_add("/visitor/output/list_union/int", 768*da668aa1SThomas Huth &out_visitor_data, 769*da668aa1SThomas Huth test_visitor_out_list_union_int); 770*da668aa1SThomas Huth output_visitor_test_add("/visitor/output/list_union/int8", 771*da668aa1SThomas Huth &out_visitor_data, 772*da668aa1SThomas Huth test_visitor_out_list_union_int8); 773*da668aa1SThomas Huth output_visitor_test_add("/visitor/output/list_union/int16", 774*da668aa1SThomas Huth &out_visitor_data, 775*da668aa1SThomas Huth test_visitor_out_list_union_int16); 776*da668aa1SThomas Huth output_visitor_test_add("/visitor/output/list_union/int32", 777*da668aa1SThomas Huth &out_visitor_data, 778*da668aa1SThomas Huth test_visitor_out_list_union_int32); 779*da668aa1SThomas Huth output_visitor_test_add("/visitor/output/list_union/int64", 780*da668aa1SThomas Huth &out_visitor_data, 781*da668aa1SThomas Huth test_visitor_out_list_union_int64); 782*da668aa1SThomas Huth output_visitor_test_add("/visitor/output/list_union/uint8", 783*da668aa1SThomas Huth &out_visitor_data, 784*da668aa1SThomas Huth test_visitor_out_list_union_uint8); 785*da668aa1SThomas Huth output_visitor_test_add("/visitor/output/list_union/uint16", 786*da668aa1SThomas Huth &out_visitor_data, 787*da668aa1SThomas Huth test_visitor_out_list_union_uint16); 788*da668aa1SThomas Huth output_visitor_test_add("/visitor/output/list_union/uint32", 789*da668aa1SThomas Huth &out_visitor_data, 790*da668aa1SThomas Huth test_visitor_out_list_union_uint32); 791*da668aa1SThomas Huth output_visitor_test_add("/visitor/output/list_union/uint64", 792*da668aa1SThomas Huth &out_visitor_data, 793*da668aa1SThomas Huth test_visitor_out_list_union_uint64); 794*da668aa1SThomas Huth output_visitor_test_add("/visitor/output/list_union/bool", 795*da668aa1SThomas Huth &out_visitor_data, 796*da668aa1SThomas Huth test_visitor_out_list_union_bool); 797*da668aa1SThomas Huth output_visitor_test_add("/visitor/output/list_union/string", 798*da668aa1SThomas Huth &out_visitor_data, 799*da668aa1SThomas Huth test_visitor_out_list_union_str); 800*da668aa1SThomas Huth output_visitor_test_add("/visitor/output/list_union/number", 801*da668aa1SThomas Huth &out_visitor_data, 802*da668aa1SThomas Huth test_visitor_out_list_union_number); 803*da668aa1SThomas Huth 804*da668aa1SThomas Huth g_test_run(); 805*da668aa1SThomas Huth 806*da668aa1SThomas Huth return 0; 807*da668aa1SThomas Huth } 808