static void qerror_set_data(QError *qerr, const char *fmt, va_list *va) { QObject *obj; obj = qobject_from_jsonv(fmt, va); if (!obj) { qerror_abort(qerr, "invalid format '%s'", fmt); } if (qobject_type(obj) != QTYPE_QDICT) { qerror_abort(qerr, "error format is not a QDict '%s'", fmt); } qerr->error = qobject_to_qdict(obj); obj = qdict_get(qerr->error, "class"); if (!obj) { qerror_abort(qerr, "missing 'class' key in '%s'", fmt); } if (qobject_type(obj) != QTYPE_QSTRING) { qerror_abort(qerr, "'class' key value should be a QString"); } obj = qdict_get(qerr->error, "data"); if (!obj) { qerror_abort(qerr, "missing 'data' key in '%s'", fmt); } if (qobject_type(obj) != QTYPE_QDICT) { qerror_abort(qerr, "'data' key value should be a QDICT"); } }
QObject *qobject_from_jsonf(const char *string, ...) { QObject *obj; va_list ap; va_start(ap, string); obj = qobject_from_jsonv(string, &ap); va_end(ap); return obj; }
/* The various test_init functions are provided instead of a test setup function so that the JSON string used by the tests are kept in the test functions (and not in main()). */ static Visitor *visitor_input_test_init_internal(TestInputVisitorData *data, const char *json_string, va_list *ap) { visitor_input_teardown(data, NULL); data->obj = qobject_from_jsonv(json_string, ap); g_assert(data->obj); data->qiv = qmp_input_visitor_new(data->obj, false); g_assert(data->qiv); return data->qiv; }
void error_set(Error **errp, const char *fmt, ...) { Error *err; va_list ap; if (errp == NULL) { return; } err = g_malloc0(sizeof(*err)); va_start(ap, fmt); err->obj = qobject_to_qdict(qobject_from_jsonv(fmt, &ap)); va_end(ap); err->fmt = fmt; *errp = err; }
/* The various test_init functions are provided instead of a test setup function so that the JSON string used by the tests are kept in the test functions (and not in main()). */ static Visitor *validate_test_init_internal(TestInputVisitorData *data, const char *json_string, va_list *ap) { Visitor *v; validate_teardown(data, NULL); data->obj = qobject_from_jsonv(json_string, ap); g_assert(data->obj); data->qiv = qmp_input_visitor_new(data->obj, true); g_assert(data->qiv); v = qmp_input_get_visitor(data->qiv); g_assert(v); return v; }
/* This is provided instead of a test setup function so that the JSON string used by the tests are kept in the test functions (and not int main()) */ static Visitor *visitor_input_test_init(TestInputVisitorData *data, const char *json_string, ...) { Visitor *v; va_list ap; va_start(ap, json_string); data->obj = qobject_from_jsonv(json_string, &ap); va_end(ap); g_assert(data->obj != NULL); data->qiv = qmp_input_visitor_new(data->obj); g_assert(data->qiv != NULL); v = qmp_input_get_visitor(data->qiv); g_assert(v != NULL); return v; }
QObject *qobject_from_json(const char *string) { return qobject_from_jsonv(string, NULL); }