mirror of
https://github.com/xemu-project/xemu.git
synced 2024-11-24 03:59:52 +00:00
cb3e7f08ae
Now that we can safely call QOBJECT() on QObject * as well as its subtypes, we can have macros qobject_ref() / qobject_unref() that work everywhere instead of having to use QINCREF() / QDECREF() for QObject and qobject_incref() / qobject_decref() for its subtypes. The replacement is mechanical, except I broke a long line, and added a cast in monitor_qmp_cleanup_req_queue_locked(). Unlike qobject_decref(), qobject_unref() doesn't accept void *. Note that the new macros evaluate their argument exactly once, thus no need to shout them. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-Id: <20180419150145.24795-4-marcandre.lureau@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> [Rebased, semantic conflict resolved, commit message improved] Signed-off-by: Markus Armbruster <armbru@redhat.com>
79 lines
1.8 KiB
C
79 lines
1.8 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/qnull.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_.base.refcnt == 1);
|
|
obj = QOBJECT(qnull());
|
|
g_assert(obj);
|
|
g_assert(obj == QOBJECT(&qnull_));
|
|
g_assert(qnull_.base.refcnt == 2);
|
|
g_assert(qobject_type(obj) == QTYPE_QNULL);
|
|
qobject_unref(obj);
|
|
g_assert(qnull_.base.refcnt == 1);
|
|
}
|
|
|
|
static void qnull_visit_test(void)
|
|
{
|
|
QObject *obj;
|
|
Visitor *v;
|
|
QNull *null;
|
|
|
|
/*
|
|
* 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_.base.refcnt == 1);
|
|
obj = QOBJECT(qnull());
|
|
v = qobject_input_visitor_new(obj);
|
|
qobject_unref(obj);
|
|
visit_type_null(v, NULL, &null, &error_abort);
|
|
g_assert(obj == QOBJECT(&qnull_));
|
|
qobject_unref(null);
|
|
visit_free(v);
|
|
|
|
null = NULL;
|
|
v = qobject_output_visitor_new(&obj);
|
|
visit_type_null(v, NULL, &null, &error_abort);
|
|
visit_complete(v, &obj);
|
|
g_assert(obj == QOBJECT(&qnull_));
|
|
qobject_unref(null);
|
|
qobject_unref(obj);
|
|
visit_free(v);
|
|
|
|
g_assert(qnull_.base.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();
|
|
}
|