2016-04-29 05:45:21 +08:00
|
|
|
/*
|
|
|
|
* QNull unit-tests.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2016 Red Hat Inc.
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
|
|
|
|
* See the COPYING.LIB file in the top-level directory.
|
|
|
|
*/
|
|
|
|
#include "qemu/osdep.h"
|
|
|
|
|
|
|
|
#include "qapi/qmp/qobject.h"
|
|
|
|
#include "qemu-common.h"
|
2016-04-29 05:45:23 +08:00
|
|
|
#include "qapi/qmp-input-visitor.h"
|
2016-04-29 05:45:21 +08:00
|
|
|
#include "qapi/qmp-output-visitor.h"
|
2016-04-29 05:45:23 +08:00
|
|
|
#include "qapi/error.h"
|
2016-04-29 05:45:21 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Public Interface test-cases
|
|
|
|
*
|
|
|
|
* (with some violations to access 'private' data)
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void qnull_ref_test(void)
|
|
|
|
{
|
|
|
|
QObject *obj;
|
|
|
|
|
|
|
|
g_assert(qnull_.refcnt == 1);
|
|
|
|
obj = qnull();
|
|
|
|
g_assert(obj);
|
|
|
|
g_assert(obj == &qnull_);
|
|
|
|
g_assert(qnull_.refcnt == 2);
|
|
|
|
g_assert(qobject_type(obj) == QTYPE_QNULL);
|
|
|
|
qobject_decref(obj);
|
|
|
|
g_assert(qnull_.refcnt == 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void qnull_visit_test(void)
|
|
|
|
{
|
|
|
|
QObject *obj;
|
|
|
|
QmpOutputVisitor *qov;
|
qmp-input-visitor: Favor new visit_free() function
Now that we have a polymorphic visit_free(), we no longer need
qmp_input_visitor_cleanup(); which in turn means we no longer
need to return a subtype from qmp_input_visitor_new() nor a
public upcast function.
Generated code changes to qmp-marshal.c look like:
|@@ -52,11 +52,10 @@ void qmp_marshal_add_fd(QDict *args, QOb
| {
| Error *err = NULL;
| AddfdInfo *retval;
|- QmpInputVisitor *qiv = qmp_input_visitor_new(QOBJECT(args), true);
| Visitor *v;
| q_obj_add_fd_arg arg = {0};
|
|- v = qmp_input_get_visitor(qiv);
|+ v = qmp_input_visitor_new(QOBJECT(args), true);
| visit_start_struct(v, NULL, NULL, 0, &err);
| if (err) {
| goto out;
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1465490926-28625-8-git-send-email-eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-06-10 00:48:38 +08:00
|
|
|
Visitor *v;
|
2016-04-29 05:45:21 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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);
|
2016-04-29 05:45:23 +08:00
|
|
|
obj = qnull();
|
qmp-input-visitor: Favor new visit_free() function
Now that we have a polymorphic visit_free(), we no longer need
qmp_input_visitor_cleanup(); which in turn means we no longer
need to return a subtype from qmp_input_visitor_new() nor a
public upcast function.
Generated code changes to qmp-marshal.c look like:
|@@ -52,11 +52,10 @@ void qmp_marshal_add_fd(QDict *args, QOb
| {
| Error *err = NULL;
| AddfdInfo *retval;
|- QmpInputVisitor *qiv = qmp_input_visitor_new(QOBJECT(args), true);
| Visitor *v;
| q_obj_add_fd_arg arg = {0};
|
|- v = qmp_input_get_visitor(qiv);
|+ v = qmp_input_visitor_new(QOBJECT(args), true);
| visit_start_struct(v, NULL, NULL, 0, &err);
| if (err) {
| goto out;
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1465490926-28625-8-git-send-email-eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-06-10 00:48:38 +08:00
|
|
|
v = qmp_input_visitor_new(obj, true);
|
2016-04-29 05:45:23 +08:00
|
|
|
qobject_decref(obj);
|
qmp-input-visitor: Favor new visit_free() function
Now that we have a polymorphic visit_free(), we no longer need
qmp_input_visitor_cleanup(); which in turn means we no longer
need to return a subtype from qmp_input_visitor_new() nor a
public upcast function.
Generated code changes to qmp-marshal.c look like:
|@@ -52,11 +52,10 @@ void qmp_marshal_add_fd(QDict *args, QOb
| {
| Error *err = NULL;
| AddfdInfo *retval;
|- QmpInputVisitor *qiv = qmp_input_visitor_new(QOBJECT(args), true);
| Visitor *v;
| q_obj_add_fd_arg arg = {0};
|
|- v = qmp_input_get_visitor(qiv);
|+ v = qmp_input_visitor_new(QOBJECT(args), true);
| visit_start_struct(v, NULL, NULL, 0, &err);
| if (err) {
| goto out;
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1465490926-28625-8-git-send-email-eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-06-10 00:48:38 +08:00
|
|
|
visit_type_null(v, NULL, &error_abort);
|
|
|
|
visit_free(v);
|
2016-04-29 05:45:23 +08:00
|
|
|
|
2016-04-29 05:45:21 +08:00
|
|
|
qov = qmp_output_visitor_new();
|
2016-04-29 05:45:23 +08:00
|
|
|
visit_type_null(qmp_output_get_visitor(qov), NULL, &error_abort);
|
2016-04-29 05:45:21 +08:00
|
|
|
obj = qmp_output_get_qobject(qov);
|
|
|
|
g_assert(obj == &qnull_);
|
|
|
|
qobject_decref(obj);
|
2016-06-10 00:48:40 +08:00
|
|
|
visit_free(qmp_output_get_visitor(qov));
|
2016-04-29 05:45:23 +08:00
|
|
|
|
2016-04-29 05:45:21 +08:00
|
|
|
g_assert(qnull_.refcnt == 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
g_test_init(&argc, &argv, NULL);
|
|
|
|
|
|
|
|
g_test_add_func("/public/qnull_ref", qnull_ref_test);
|
|
|
|
g_test_add_func("/public/qnull_visit", qnull_visit_test);
|
|
|
|
|
|
|
|
return g_test_run();
|
|
|
|
}
|