void qapi_copy_SocketAddress(SocketAddress **p_dest, SocketAddress *src) { QmpOutputVisitor *qov; QmpInputVisitor *qiv; Visitor *ov, *iv; QObject *obj; *p_dest = NULL; qov = qmp_output_visitor_new(); ov = qmp_output_get_visitor(qov); visit_type_SocketAddress(ov, NULL, &src, &error_abort); obj = qmp_output_get_qobject(qov); qmp_output_visitor_cleanup(qov); if (!obj) { return; } qiv = qmp_input_visitor_new(obj); iv = qmp_input_get_visitor(qiv); visit_type_SocketAddress(iv, NULL, p_dest, &error_abort); qmp_input_visitor_cleanup(qiv); qobject_decref(obj); }
static void visitor_output_teardown(TestOutputVisitorData *data, const void *unused) { qmp_output_visitor_cleanup(data->qov); data->qov = NULL; data->ov = NULL; }
static void qnull_visit_test(void) { QObject *obj; QmpOutputVisitor *qov; QmpInputVisitor *qiv; /* * Most tests of interactions between QObject and visitors are in * test-qmp-*-visitor; but these tests live here because they * depend on layering violations to check qnull_ refcnt. */ g_assert(qnull_.refcnt == 1); obj = qnull(); qiv = qmp_input_visitor_new(obj, true); qobject_decref(obj); visit_type_null(qmp_input_get_visitor(qiv), NULL, &error_abort); qmp_input_visitor_cleanup(qiv); qov = qmp_output_visitor_new(); visit_type_null(qmp_output_get_visitor(qov), NULL, &error_abort); obj = qmp_output_get_qobject(qov); g_assert(obj == &qnull_); qobject_decref(obj); qmp_output_visitor_cleanup(qov); g_assert(qnull_.refcnt == 1); }
/* test enum values nested in schema-defined structs */ static void test_nested_enums(void) { QmpOutputVisitor *mo; QmpInputVisitor *mi; Visitor *v; NestedEnumsOne *nested_enums, *nested_enums_cpy = NULL; Error *err = NULL; QObject *obj; QString *str; nested_enums = g_malloc0(sizeof(NestedEnumsOne)); nested_enums->enum1 = ENUM_ONE_VALUE1; nested_enums->enum2 = ENUM_ONE_VALUE2; nested_enums->enum3 = ENUM_ONE_VALUE3; nested_enums->enum4 = ENUM_ONE_VALUE3; nested_enums->has_enum2 = false; nested_enums->has_enum4 = true; /* C type -> QObject */ mo = qmp_output_visitor_new(); v = qmp_output_get_visitor(mo); visit_type_NestedEnumsOne(v, &nested_enums, NULL, &err); if (err) { g_error("%s", error_get_pretty(err)); } obj = qmp_output_get_qobject(mo); g_assert(obj); str = qobject_to_json_pretty(obj); g_print("%s\n", qstring_get_str(str)); QDECREF(str); /* QObject -> C type */ mi = qmp_input_visitor_new(obj); v = qmp_input_get_visitor(mi); visit_type_NestedEnumsOne(v, &nested_enums_cpy, NULL, &err); if (err) { g_error("%s", error_get_pretty(err)); } g_assert(nested_enums_cpy); g_assert(nested_enums_cpy->enum1 == nested_enums->enum1); g_assert(nested_enums_cpy->enum3 == nested_enums->enum3); g_assert(nested_enums_cpy->enum4 == nested_enums->enum4); g_assert(nested_enums_cpy->has_enum2 == false); g_assert(nested_enums_cpy->has_enum4 == true); qmp_output_visitor_cleanup(mo); qmp_input_visitor_cleanup(mi); qapi_free_NestedEnumsOne(nested_enums); qapi_free_NestedEnumsOne(nested_enums_cpy); }
QObject *object_property_get_qobject(struct uc_struct *uc, Object *obj, const char *name, Error **errp) { QObject *ret = NULL; Error *local_err = NULL; QmpOutputVisitor *mo; mo = qmp_output_visitor_new(); object_property_get(uc, obj, qmp_output_get_visitor(mo), name, &local_err); if (!local_err) { ret = qmp_output_get_qobject(mo); } error_propagate(errp, local_err); qmp_output_visitor_cleanup(mo); return ret; }
static void qmp_marshal_output_query_version(VersionInfo * ret_in, QObject **ret_out, Error **errp) { QapiDeallocVisitor *md = qapi_dealloc_visitor_new(); QmpOutputVisitor *mo = qmp_output_visitor_new(); Visitor *v; v = qmp_output_get_visitor(mo); visit_type_VersionInfo(v, &ret_in, "unused", errp); if (!error_is_set(errp)) { *ret_out = qmp_output_get_qobject(mo); } qmp_output_visitor_cleanup(mo); v = qapi_dealloc_get_visitor(md); visit_type_VersionInfo(v, &ret_in, "unused", errp); qapi_dealloc_visitor_cleanup(md); }
/* test core visitor methods */ static void test_visitor_core(void) { QmpOutputVisitor *mo; QmpInputVisitor *mi; Visitor *v; TestStruct ts = { 42, 82 }; TestStruct *pts = &ts; TestStructList *lts = NULL; Error *err = NULL; QObject *obj; QList *qlist; QDict *qdict; QString *str; int64_t value = 0; mo = qmp_output_visitor_new(); v = qmp_output_get_visitor(mo); visit_type_TestStruct(v, &pts, NULL, &err); obj = qmp_output_get_qobject(mo); str = qobject_to_json(obj); printf("%s\n", qstring_get_str(str)); QDECREF(str); obj = QOBJECT(qint_from_int(0x42)); mi = qmp_input_visitor_new(obj); v = qmp_input_get_visitor(mi); visit_type_int(v, &value, NULL, &err); if (err) { g_error("%s", error_get_pretty(err)); } g_assert(value == 0x42); qobject_decref(obj); obj = qobject_from_json("{'x': 42, 'y': 84}"); mi = qmp_input_visitor_new(obj); v = qmp_input_get_visitor(mi); pts = NULL; visit_type_TestStruct(v, &pts, NULL, &err); if (err) { g_error("%s", error_get_pretty(err)); } g_assert(pts != NULL); g_assert(pts->x == 42); g_assert(pts->y == 84); qobject_decref(obj); g_free(pts); /* test list input visitor */ obj = qobject_from_json("[{'x': 42, 'y': 84}, {'x': 12, 'y': 24}]"); mi = qmp_input_visitor_new(obj); v = qmp_input_get_visitor(mi); visit_type_TestStructList(v, <s, NULL, &err); if (err) { g_error("%s", error_get_pretty(err)); } g_assert(lts != NULL); g_assert(lts->value->x == 42); g_assert(lts->value->y == 84); g_assert(lts->next != NULL); g_assert(lts->next->value->x == 12); g_assert(lts->next->value->y == 24); g_assert(lts->next->next == NULL); qobject_decref(obj); /* test list output visitor */ mo = qmp_output_visitor_new(); v = qmp_output_get_visitor(mo); visit_type_TestStructList(v, <s, NULL, &err); if (err) { g_error("%s", error_get_pretty(err)); } obj = qmp_output_get_qobject(mo); g_print("obj: %s\n", qstring_get_str(qobject_to_json(obj))); qlist = qobject_to_qlist(obj); assert(qlist); obj = qlist_pop(qlist); qdict = qobject_to_qdict(obj); assert(qdict); assert(qdict_get_int(qdict, "x") == 42); assert(qdict_get_int(qdict, "y") == 84); qobject_decref(obj); obj = qlist_pop(qlist); qdict = qobject_to_qdict(obj); assert(qdict); assert(qdict_get_int(qdict, "x") == 12); assert(qdict_get_int(qdict, "y") == 24); qobject_decref(obj); qmp_output_visitor_cleanup(mo); QDECREF(qlist); }