diff options
author | Eric Blake <eblake@redhat.com> | 2016-04-28 15:45:21 -0600 |
---|---|---|
committer | Markus Armbruster <armbru@redhat.com> | 2016-05-12 09:47:54 +0200 |
commit | 7d7a337ec32c77f11ba04da412752b35e18d3c5c (patch) | |
tree | a6cf363d41caf30b3b998ba9d557de7892483eac /tests/check-qnull.c | |
parent | adfb264c9ed04bfc694921b72173be8e29e90024 (diff) |
tests: Add check-qnull
Add a new test, for checking reference counting of qnull(). As
part of the new file, move a previous reference counting change
added in commit a861564 to a more logical place.
Note that while most of the check-q*.c leave visitor stuff to
the test-qmp-*-visitor.c, in this case we actually want the
visitor tests in our new file because we are validating the
reference count of qnull_, which is an internal detail that
test-qmp-*-visitor should not be peeking into (or put another
way, qnull() is the only special case where we don't have
independent allocation of a QObject, so none of the other
visitor tests require the layering violation present in this
test).
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1461879932-9020-14-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Diffstat (limited to 'tests/check-qnull.c')
-rw-r--r-- | tests/check-qnull.c | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/tests/check-qnull.c b/tests/check-qnull.c new file mode 100644 index 0000000000..4a1c3d830e --- /dev/null +++ b/tests/check-qnull.c @@ -0,0 +1,66 @@ +/* + * 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 <glib.h> + +#include "qapi/qmp/qobject.h" +#include "qemu-common.h" +#include "qapi/qmp-output-visitor.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; + QmpOutputVisitor *qov; + + /* + * 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); + qov = qmp_output_visitor_new(); + /* FIXME: Empty visits are ugly, we should have a visit_type_null(). */ + obj = qmp_output_get_qobject(qov); + g_assert(obj == &qnull_); + qobject_decref(obj); + + qmp_output_visitor_cleanup(qov); + 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(); +} |