diff options
author | Thomas Huth | 2021-03-10 07:33:14 +0100 |
---|---|---|
committer | Thomas Huth | 2021-03-12 15:46:30 +0100 |
commit | da668aa15b99150a8595c491aee00d5d2426aaf9 (patch) | |
tree | 0463b0a303e807bdab46460f6c702be611bd7179 /tests/unit/check-qnull.c | |
parent | Merge remote-tracking branch 'remotes/legoater/tags/pull-aspeed-20210309' int... (diff) | |
download | qemu-da668aa15b99150a8595c491aee00d5d2426aaf9.tar.gz qemu-da668aa15b99150a8595c491aee00d5d2426aaf9.tar.xz qemu-da668aa15b99150a8595c491aee00d5d2426aaf9.zip |
tests: Move unit tests into a separate directory
The main tests directory still looks very crowded, and it's not
clear which files are part of a unit tests and which belong to
a different test subsystem. Let's clean up the mess and move the
unit tests to a separate directory.
Message-Id: <20210310063314.1049838-1-thuth@redhat.com>
Acked-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
Diffstat (limited to 'tests/unit/check-qnull.c')
-rw-r--r-- | tests/unit/check-qnull.c | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/tests/unit/check-qnull.c b/tests/unit/check-qnull.c new file mode 100644 index 0000000000..ebf21db83c --- /dev/null +++ b/tests/unit/check-qnull.c @@ -0,0 +1,78 @@ +/* + * 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(); +} |