qemu/tests/unit/check-qlit.c
Daniel P. Berrangé 407bc4bf90 qapi: Move include/qapi/qmp/ to include/qobject/
The general expectation is that header files should follow the same
file/path naming scheme as the corresponding source file. There are
various historical exceptions to this practice in QEMU, with one of
the most notable being the include/qapi/qmp/ directory. Most of the
headers there correspond to source files in qobject/.

This patch corrects most of that inconsistency by creating
include/qobject/ and moving the headers for qobject/ there.

This also fixes MAINTAINERS for include/qapi/qmp/dispatch.h:
scripts/get_maintainer.pl now reports "QAPI" instead of "No
maintainers found".

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
Acked-by: Halil Pasic <pasic@linux.ibm.com> #s390x
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-ID: <20241118151235.2665921-2-armbru@redhat.com>
[Rebased]
2025-02-10 15:33:16 +01:00

101 lines
2.5 KiB
C

/*
* QLit unit-tests.
*
* Copyright (C) 2017 Red Hat Inc.
*
* This work is licensed under the terms of the GNU GPL, version 2 or later.
* See the COPYING file in the top-level directory.
*/
#include "qemu/osdep.h"
#include "qobject/qbool.h"
#include "qobject/qdict.h"
#include "qobject/qlist.h"
#include "qobject/qlit.h"
#include "qobject/qnum.h"
#include "qobject/qstring.h"
static QLitObject qlit = QLIT_QDICT(((QLitDictEntry[]) {
{ "foo", QLIT_QNUM(42) },
{ "bar", QLIT_QSTR("hello world") },
{ "baz", QLIT_QNULL },
{ "bee", QLIT_QLIST(((QLitObject[]) {
QLIT_QNUM(43),
QLIT_QNUM(44),
QLIT_QBOOL(true),
{ },
}))},
{ },
}));
static QLitObject qlit_foo = QLIT_QDICT(((QLitDictEntry[]) {
{ "foo", QLIT_QNUM(42) },
{ },
}));
static QObject *make_qobject(void)
{
QDict *qdict = qdict_new();
QList *list = qlist_new();
qdict_put_int(qdict, "foo", 42);
qdict_put_str(qdict, "bar", "hello world");
qdict_put_null(qdict, "baz");
qlist_append_int(list, 43);
qlist_append_int(list, 44);
qlist_append_bool(list, true);
qdict_put(qdict, "bee", list);
return QOBJECT(qdict);
}
static void qlit_equal_qobject_test(void)
{
QObject *qobj = make_qobject();
g_assert(qlit_equal_qobject(&qlit, qobj));
g_assert(!qlit_equal_qobject(&qlit_foo, qobj));
qdict_put(qobject_to(QDict, qobj), "bee", qlist_new());
g_assert(!qlit_equal_qobject(&qlit, qobj));
qobject_unref(qobj);
}
static void qobject_from_qlit_test(void)
{
QObject *obj, *qobj = qobject_from_qlit(&qlit);
QDict *qdict;
QList *bee;
qdict = qobject_to(QDict, qobj);
g_assert_cmpint(qdict_get_int(qdict, "foo"), ==, 42);
g_assert_cmpstr(qdict_get_str(qdict, "bar"), ==, "hello world");
g_assert(qobject_type(qdict_get(qdict, "baz")) == QTYPE_QNULL);
bee = qdict_get_qlist(qdict, "bee");
obj = qlist_pop(bee);
g_assert_cmpint(qnum_get_int(qobject_to(QNum, obj)), ==, 43);
qobject_unref(obj);
obj = qlist_pop(bee);
g_assert_cmpint(qnum_get_int(qobject_to(QNum, obj)), ==, 44);
qobject_unref(obj);
obj = qlist_pop(bee);
g_assert(qbool_get_bool(qobject_to(QBool, obj)));
qobject_unref(obj);
qobject_unref(qobj);
}
int main(int argc, char **argv)
{
g_test_init(&argc, &argv, NULL);
g_test_add_func("/qlit/equal_qobject", qlit_equal_qobject_test);
g_test_add_func("/qlit/qobject_from_qlit", qobject_from_qlit_test);
return g_test_run();
}