Пример #1
0
/* test generated deallocation on an object whose construction was prematurely
 * terminated due to an error */
static void test_dealloc_partial(void)
{
    static const char text[] = "don't leak me";

    UserDefTwo *ud2 = NULL;
    Error *err = NULL;

    /* create partial object */
    {
        QDict *ud2_dict;
        QmpInputVisitor *qiv;

        ud2_dict = qdict_new();
        qdict_put_obj(ud2_dict, "string0", QOBJECT(qstring_from_str(text)));

        qiv = qmp_input_visitor_new(QOBJECT(ud2_dict));
        visit_type_UserDefTwo(qmp_input_get_visitor(qiv), &ud2, NULL, &err);
        qmp_input_visitor_cleanup(qiv);
        QDECREF(ud2_dict);
    }

    /* verify partial success */
    assert(ud2 != NULL);
    assert(ud2->string0 != NULL);
    assert(strcmp(ud2->string0, text) == 0);
    assert(ud2->dict1 == NULL);

    /* confirm & release construction error */
    assert(err != NULL);
    error_free(err);

    /* tear down partial object */
    qapi_free_UserDefTwo(ud2);
}
Пример #2
0
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);
}
Пример #3
0
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);
}
Пример #4
0
int qmp_marshal_input_cpu(Monitor *mon, const QDict *qdict, QObject **ret)
{
    Error *local_err = NULL;
    Error **errp = &local_err;
    QDict *args = (QDict *)qdict;
    QmpInputVisitor *mi;
    QapiDeallocVisitor *md;
    Visitor *v;
    int64_t index;

    mi = qmp_input_visitor_new(QOBJECT(args));
    v = qmp_input_get_visitor(mi);
    visit_type_int(v, &index, "index", errp);
    qmp_input_visitor_cleanup(mi);

    if (error_is_set(errp)) {
        goto out;
    }
    qmp_cpu(index, errp);

out:
    md = qapi_dealloc_visitor_new();
    v = qapi_dealloc_get_visitor(md);
    visit_type_int(v, &index, "index", errp);
    qapi_dealloc_visitor_cleanup(md);

    if (local_err) {
        qerror_report_err(local_err);
        error_free(local_err);
        return -1;
    }
    return 0;
}
Пример #5
0
void object_property_set_qobject(struct uc_struct *uc, Object *obj, QObject *value,
                                 const char *name, Error **errp)
{
    QmpInputVisitor *mi;
    mi = qmp_input_visitor_new(value);
    object_property_set(uc, obj, qmp_input_get_visitor(mi), name, errp);    // qq

    qmp_input_visitor_cleanup(mi);
}
static void visitor_input_teardown(TestInputVisitorData *data,
                                   const void *unused)
{
    qobject_decref(data->obj);
    data->obj = NULL;

    if (data->qiv) {
        qmp_input_visitor_cleanup(data->qiv);
        data->qiv = NULL;
    }
}
Пример #7
0
/* 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);
}