qemu/tests/check-qnull.c
Daniel P. Berrange b3db211f3c qapi: rename *qmp-*-visitor* to *qobject-*-visitor*
The QMP visitors have no direct dependency on QMP. It is
valid to use them anywhere that one has a QObject. Rename them
to better reflect their functionality as a generic QObject
to QAPI converter.

This is the first of three parts: rename the files.  The next two
parts will rename C identifiers.  The split is necessary to make git
rename detection work.

Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
[Split into file and identifier rename, two comments touched up]
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-10-25 16:25:48 +02:00

74 lines
1.7 KiB
C

/*
* 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"
#include "qapi/qobject-input-visitor.h"
#include "qapi/qobject-output-visitor.h"
#include "qapi/error.h"
/*
* 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;
Visitor *v;
/*
* 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();
v = qmp_input_visitor_new(obj, true);
qobject_decref(obj);
visit_type_null(v, NULL, &error_abort);
visit_free(v);
v = qmp_output_visitor_new(&obj);
visit_type_null(v, NULL, &error_abort);
visit_complete(v, &obj);
g_assert(obj == &qnull_);
qobject_decref(obj);
visit_free(v);
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();
}