aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2017-06-22 11:34:38 +0100
committerPeter Maydell <peter.maydell@linaro.org>2017-06-22 11:34:39 +0100
commit84e3d0725b06bdf8c6985788caa7776d6b7353ce (patch)
treee4b273590132a034fe693debb52e7037bb7730f2 /tests
parentdb7a99cdc1d0f4d8cbf7c41ce9e570dce04f0a11 (diff)
parent269c20b2bbd2aa8531e0cdc741fb166f290d7a2b (diff)
downloadqemu-84e3d0725b06bdf8c6985788caa7776d6b7353ce.zip
qemu-84e3d0725b06bdf8c6985788caa7776d6b7353ce.tar.gz
qemu-84e3d0725b06bdf8c6985788caa7776d6b7353ce.tar.bz2
Merge remote-tracking branch 'remotes/armbru/tags/pull-qapi-2017-06-09-v2' into staging
QAPI patches for 2017-06-09 # gpg: Signature made Tue 20 Jun 2017 13:31:39 BST # gpg: using RSA key 0x3870B400EB918653 # gpg: Good signature from "Markus Armbruster <armbru@redhat.com>" # gpg: aka "Markus Armbruster <armbru@pond.sub.org>" # Primary key fingerprint: 354B C8B3 D7EB 2A6B 6867 4E5F 3870 B400 EB91 8653 * remotes/armbru/tags/pull-qapi-2017-06-09-v2: (41 commits) tests/qdict: check more get_try_int() cases console: use get_uint() for "head" property i386/cpu: use get_uint() for "min-level"/"min-xlevel" properties numa: use get_uint() for "size" property pnv-core: use get_uint() for "core-pir" property pvpanic: use get_uint() for "ioport" property auxbus: use get_uint() for "addr" property arm: use get_uint() for "mp-affinity" property xen: use get_uint() for "max-ram-below-4g" property pc: use get_uint() for "hpet-intcap" property pc: use get_uint() for "apic-id" property pc: use get_uint() for "iobase" property acpi: use get_uint() for "pci-hole*" properties acpi: use get_uint() for various acpi properties acpi: use get_uint() for "acpi-pcihp-io*" properties platform-bus: use get_uint() for "addr" property bcm2835_fb: use {get, set}_uint() for "vcram-size" and "vcram-base" aspeed: use {set, get}_uint() for "ram-size" property pcihp: use get_uint() for "bsel" property pc-dimm: make "size" property uint64 ... Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/.gitignore3
-rw-r--r--tests/Makefile.include13
-rw-r--r--tests/check-qdict.c41
-rw-r--r--tests/check-qfloat.c53
-rw-r--r--tests/check-qint.c87
-rw-r--r--tests/check-qjson.c135
-rw-r--r--tests/check-qlist.c40
-rw-r--r--tests/check-qnum.c170
-rw-r--r--tests/check-qstring.c9
-rw-r--r--tests/qapi-schema/comments.out2
-rw-r--r--tests/qapi-schema/doc-good.out2
-rw-r--r--tests/qapi-schema/empty.out2
-rw-r--r--tests/qapi-schema/event-case.out2
-rw-r--r--tests/qapi-schema/ident-with-escape.out2
-rw-r--r--tests/qapi-schema/include-relpath.out2
-rw-r--r--tests/qapi-schema/include-repetition.out2
-rw-r--r--tests/qapi-schema/include-simple.out2
-rw-r--r--tests/qapi-schema/indented-expr.out2
-rw-r--r--tests/qapi-schema/qapi-schema-test.json2
-rw-r--r--tests/qapi-schema/qapi-schema-test.out10
-rw-r--r--tests/test-keyval.c4
-rw-r--r--tests/test-qmp-commands.c8
-rw-r--r--tests/test-qmp-event.c9
-rw-r--r--tests/test-qobject-input-visitor.c112
-rw-r--r--tests/test-qobject-output-visitor.c93
-rw-r--r--tests/test-x86-cpuid-compat.c18
26 files changed, 457 insertions, 368 deletions
diff --git a/tests/.gitignore b/tests/.gitignore
index 40c2e3e..8e01b00 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -1,7 +1,6 @@
atomic_add-bench
check-qdict
-check-qfloat
-check-qint
+check-qnum
check-qjson
check-qlist
check-qnull
diff --git a/tests/Makefile.include b/tests/Makefile.include
index 77da9b7..ae889ca 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -10,10 +10,8 @@ check-unit-y = tests/check-qdict$(EXESUF)
gcov-files-check-qdict-y = qobject/qdict.c
check-unit-y += tests/test-char$(EXESUF)
gcov-files-check-qdict-y = chardev/char.c
-check-unit-y += tests/check-qfloat$(EXESUF)
-gcov-files-check-qfloat-y = qobject/qfloat.c
-check-unit-y += tests/check-qint$(EXESUF)
-gcov-files-check-qint-y = qobject/qint.c
+check-unit-y += tests/check-qnum$(EXESUF)
+gcov-files-check-qnum-y = qobject/qnum.c
check-unit-y += tests/check-qstring$(EXESUF)
gcov-files-check-qstring-y = qobject/qstring.c
check-unit-y += tests/check-qlist$(EXESUF)
@@ -508,8 +506,8 @@ GENERATED_FILES += tests/test-qapi-types.h tests/test-qapi-visit.h \
tests/test-qmp-commands.h tests/test-qapi-event.h \
tests/test-qmp-introspect.h
-test-obj-y = tests/check-qint.o tests/check-qstring.o tests/check-qdict.o \
- tests/check-qlist.o tests/check-qfloat.o tests/check-qnull.o \
+test-obj-y = tests/check-qnum.o tests/check-qstring.o tests/check-qdict.o \
+ tests/check-qlist.o tests/check-qnull.o \
tests/check-qjson.o \
tests/test-coroutine.o tests/test-string-output-visitor.o \
tests/test-string-input-visitor.o tests/test-qobject-output-visitor.o \
@@ -537,11 +535,10 @@ test-crypto-obj-y = $(crypto-obj-y) $(test-qom-obj-y)
test-io-obj-y = $(io-obj-y) $(test-crypto-obj-y)
test-block-obj-y = $(block-obj-y) $(test-io-obj-y) tests/iothread.o
-tests/check-qint$(EXESUF): tests/check-qint.o $(test-util-obj-y)
+tests/check-qnum$(EXESUF): tests/check-qnum.o $(test-util-obj-y)
tests/check-qstring$(EXESUF): tests/check-qstring.o $(test-util-obj-y)
tests/check-qdict$(EXESUF): tests/check-qdict.o $(test-util-obj-y)
tests/check-qlist$(EXESUF): tests/check-qlist.o $(test-util-obj-y)
-tests/check-qfloat$(EXESUF): tests/check-qfloat.o $(test-util-obj-y)
tests/check-qnull$(EXESUF): tests/check-qnull.o $(test-util-obj-y)
tests/check-qjson$(EXESUF): tests/check-qjson.o $(test-util-obj-y)
tests/check-qom-interface$(EXESUF): tests/check-qom-interface.o $(test-qom-obj-y)
diff --git a/tests/check-qdict.c b/tests/check-qdict.c
index be8d81f..3540577 100644
--- a/tests/check-qdict.c
+++ b/tests/check-qdict.c
@@ -11,7 +11,6 @@
*/
#include "qemu/osdep.h"
-#include "qapi/qmp/qint.h"
#include "qapi/qmp/qdict.h"
#include "qapi/qmp/qstring.h"
#include "qapi/error.h"
@@ -33,13 +32,12 @@ static void qdict_new_test(void)
g_assert(qdict->base.refcnt == 1);
g_assert(qobject_type(QOBJECT(qdict)) == QTYPE_QDICT);
- // destroy doesn't exit yet
- g_free(qdict);
+ QDECREF(qdict);
}
static void qdict_put_obj_test(void)
{
- QInt *qi;
+ QNum *qn;
QDict *qdict;
QDictEntry *ent;
const int num = 42;
@@ -51,14 +49,10 @@ static void qdict_put_obj_test(void)
g_assert(qdict_size(qdict) == 1);
ent = QLIST_FIRST(&qdict->table[12345 % QDICT_BUCKET_MAX]);
- qi = qobject_to_qint(ent->value);
- g_assert(qint_get_int(qi) == num);
-
- // destroy doesn't exit yet
- QDECREF(qi);
- g_free(ent->key);
- g_free(ent);
- g_free(qdict);
+ qn = qobject_to_qnum(ent->value);
+ g_assert_cmpint(qnum_get_int(qn), ==, num);
+
+ QDECREF(qdict);
}
static void qdict_destroy_simple_test(void)
@@ -74,7 +68,7 @@ static void qdict_destroy_simple_test(void)
static void qdict_get_test(void)
{
- QInt *qi;
+ QNum *qn;
QObject *obj;
const int value = -42;
const char *key = "test";
@@ -85,8 +79,8 @@ static void qdict_get_test(void)
obj = qdict_get(tests_dict, key);
g_assert(obj != NULL);
- qi = qobject_to_qint(obj);
- g_assert(qint_get_int(qi) == value);
+ qn = qobject_to_qnum(obj);
+ g_assert_cmpint(qnum_get_int(qn), ==, value);
QDECREF(tests_dict);
}
@@ -114,10 +108,17 @@ static void qdict_get_try_int_test(void)
QDict *tests_dict = qdict_new();
qdict_put_int(tests_dict, key, value);
+ qdict_put_str(tests_dict, "string", "test");
ret = qdict_get_try_int(tests_dict, key, 0);
g_assert(ret == value);
+ ret = qdict_get_try_int(tests_dict, "missing", -42);
+ g_assert_cmpuint(ret, ==, -42);
+
+ ret = qdict_get_try_int(tests_dict, "string", -42);
+ g_assert_cmpuint(ret, ==, -42);
+
QDECREF(tests_dict);
}
@@ -329,7 +330,7 @@ static void qdict_array_split_test(void)
{
QDict *test_dict = qdict_new();
QDict *dict1, *dict2;
- QInt *int1;
+ QNum *int1;
QList *test_list;
/*
@@ -380,7 +381,7 @@ static void qdict_array_split_test(void)
dict1 = qobject_to_qdict(qlist_pop(test_list));
dict2 = qobject_to_qdict(qlist_pop(test_list));
- int1 = qobject_to_qint(qlist_pop(test_list));
+ int1 = qobject_to_qnum(qlist_pop(test_list));
g_assert(dict1);
g_assert(dict2);
@@ -402,7 +403,7 @@ static void qdict_array_split_test(void)
QDECREF(dict2);
- g_assert(qint_get_int(int1) == 66);
+ g_assert_cmpint(qnum_get_int(int1), ==, 66);
QDECREF(int1);
@@ -447,14 +448,14 @@ static void qdict_array_split_test(void)
qdict_array_split(test_dict, &test_list);
- int1 = qobject_to_qint(qlist_pop(test_list));
+ int1 = qobject_to_qnum(qlist_pop(test_list));
g_assert(int1);
g_assert(qlist_empty(test_list));
QDECREF(test_list);
- g_assert(qint_get_int(int1) == 42);
+ g_assert_cmpint(qnum_get_int(int1), ==, 42);
QDECREF(int1);
diff --git a/tests/check-qfloat.c b/tests/check-qfloat.c
deleted file mode 100644
index 1da2cda..0000000
--- a/tests/check-qfloat.c
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * QFloat unit-tests.
- *
- * Copyright IBM, Corp. 2009
- *
- * Authors:
- * Anthony Liguori <aliguori@us.ibm.com>
- *
- * 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/qfloat.h"
-#include "qemu-common.h"
-
-/*
- * Public Interface test-cases
- *
- * (with some violations to access 'private' data)
- */
-
-static void qfloat_from_double_test(void)
-{
- QFloat *qf;
- const double value = -42.23423;
-
- qf = qfloat_from_double(value);
- g_assert(qf != NULL);
- g_assert(qf->value == value);
- g_assert(qf->base.refcnt == 1);
- g_assert(qobject_type(QOBJECT(qf)) == QTYPE_QFLOAT);
-
- // destroy doesn't exit yet
- g_free(qf);
-}
-
-static void qfloat_destroy_test(void)
-{
- QFloat *qf = qfloat_from_double(0.0);
- QDECREF(qf);
-}
-
-int main(int argc, char **argv)
-{
- g_test_init(&argc, &argv, NULL);
-
- g_test_add_func("/public/from_double", qfloat_from_double_test);
- g_test_add_func("/public/destroy", qfloat_destroy_test);
-
- return g_test_run();
-}
diff --git a/tests/check-qint.c b/tests/check-qint.c
deleted file mode 100644
index b6e4555..0000000
--- a/tests/check-qint.c
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * QInt unit-tests.
- *
- * Copyright (C) 2009 Red Hat Inc.
- *
- * Authors:
- * Luiz Capitulino <lcapitulino@redhat.com>
- *
- * 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/qint.h"
-#include "qemu-common.h"
-
-/*
- * Public Interface test-cases
- *
- * (with some violations to access 'private' data)
- */
-
-static void qint_from_int_test(void)
-{
- QInt *qi;
- const int value = -42;
-
- qi = qint_from_int(value);
- g_assert(qi != NULL);
- g_assert(qi->value == value);
- g_assert(qi->base.refcnt == 1);
- g_assert(qobject_type(QOBJECT(qi)) == QTYPE_QINT);
-
- // destroy doesn't exit yet
- g_free(qi);
-}
-
-static void qint_destroy_test(void)
-{
- QInt *qi = qint_from_int(0);
- QDECREF(qi);
-}
-
-static void qint_from_int64_test(void)
-{
- QInt *qi;
- const int64_t value = 0x1234567890abcdefLL;
-
- qi = qint_from_int(value);
- g_assert((int64_t) qi->value == value);
-
- QDECREF(qi);
-}
-
-static void qint_get_int_test(void)
-{
- QInt *qi;
- const int value = 123456;
-
- qi = qint_from_int(value);
- g_assert(qint_get_int(qi) == value);
-
- QDECREF(qi);
-}
-
-static void qobject_to_qint_test(void)
-{
- QInt *qi;
-
- qi = qint_from_int(0);
- g_assert(qobject_to_qint(QOBJECT(qi)) == qi);
-
- QDECREF(qi);
-}
-
-int main(int argc, char **argv)
-{
- g_test_init(&argc, &argv, NULL);
-
- g_test_add_func("/public/from_int", qint_from_int_test);
- g_test_add_func("/public/destroy", qint_destroy_test);
- g_test_add_func("/public/from_int64", qint_from_int64_test);
- g_test_add_func("/public/get_int", qint_get_int_test);
- g_test_add_func("/public/to_qint", qobject_to_qint_test);
-
- return g_test_run();
-}
diff --git a/tests/check-qjson.c b/tests/check-qjson.c
index 963dd46..53f2275 100644
--- a/tests/check-qjson.c
+++ b/tests/check-qjson.c
@@ -886,24 +886,69 @@ static void simple_number(void)
};
for (i = 0; test_cases[i].encoded; i++) {
- QInt *qint;
+ QNum *qnum;
+ int64_t val;
- qint = qobject_to_qint(qobject_from_json(test_cases[i].encoded,
+ qnum = qobject_to_qnum(qobject_from_json(test_cases[i].encoded,
&error_abort));
- g_assert(qint);
- g_assert(qint_get_int(qint) == test_cases[i].decoded);
+ g_assert(qnum);
+ g_assert(qnum_get_try_int(qnum, &val));
+ g_assert_cmpint(val, ==, test_cases[i].decoded);
if (test_cases[i].skip == 0) {
QString *str;
- str = qobject_to_json(QOBJECT(qint));
+ str = qobject_to_json(QOBJECT(qnum));
g_assert(strcmp(qstring_get_str(str), test_cases[i].encoded) == 0);
QDECREF(str);
}
- QDECREF(qint);
+ QDECREF(qnum);
}
}
+static void large_number(void)
+{
+ const char *maxu64 = "18446744073709551615"; /* 2^64-1 */
+ const char *gtu64 = "18446744073709551616"; /* 2^64 */
+ const char *lti64 = "-9223372036854775809"; /* -2^63 - 1 */
+ QNum *qnum;
+ QString *str;
+ uint64_t val;
+ int64_t ival;
+
+ qnum = qobject_to_qnum(qobject_from_json(maxu64, &error_abort));
+ g_assert(qnum);
+ g_assert_cmpuint(qnum_get_uint(qnum), ==, 18446744073709551615U);
+ g_assert(!qnum_get_try_int(qnum, &ival));
+
+ str = qobject_to_json(QOBJECT(qnum));
+ g_assert_cmpstr(qstring_get_str(str), ==, maxu64);
+ QDECREF(str);
+ QDECREF(qnum);
+
+ qnum = qobject_to_qnum(qobject_from_json(gtu64, &error_abort));
+ g_assert(qnum);
+ g_assert_cmpfloat(qnum_get_double(qnum), ==, 18446744073709552e3);
+ g_assert(!qnum_get_try_uint(qnum, &val));
+ g_assert(!qnum_get_try_int(qnum, &ival));
+
+ str = qobject_to_json(QOBJECT(qnum));
+ g_assert_cmpstr(qstring_get_str(str), ==, gtu64);
+ QDECREF(str);
+ QDECREF(qnum);
+
+ qnum = qobject_to_qnum(qobject_from_json(lti64, &error_abort));
+ g_assert(qnum);
+ g_assert_cmpfloat(qnum_get_double(qnum), ==, -92233720368547758e2);
+ g_assert(!qnum_get_try_uint(qnum, &val));
+ g_assert(!qnum_get_try_int(qnum, &ival));
+
+ str = qobject_to_json(QOBJECT(qnum));
+ g_assert_cmpstr(qstring_get_str(str), ==, "-9223372036854775808");
+ QDECREF(str);
+ QDECREF(qnum);
+}
+
static void float_number(void)
{
int i;
@@ -921,12 +966,12 @@ static void float_number(void)
for (i = 0; test_cases[i].encoded; i++) {
QObject *obj;
- QFloat *qfloat;
+ QNum *qnum;
obj = qobject_from_json(test_cases[i].encoded, &error_abort);
- qfloat = qobject_to_qfloat(obj);
- g_assert(qfloat);
- g_assert(qfloat_get_double(qfloat) == test_cases[i].decoded);
+ qnum = qobject_to_qnum(obj);
+ g_assert(qnum);
+ g_assert(qnum_get_double(qnum) == test_cases[i].decoded);
if (test_cases[i].skip == 0) {
QString *str;
@@ -936,29 +981,31 @@ static void float_number(void)
QDECREF(str);
}
- QDECREF(qfloat);
+ QDECREF(qnum);
}
}
static void vararg_number(void)
{
- QInt *qint;
- QFloat *qfloat;
+ QNum *qnum;
int value = 0x2342;
long long value_ll = 0x2342342343LL;
double valuef = 2.323423423;
+ int64_t val;
- qint = qobject_to_qint(qobject_from_jsonf("%d", value));
- g_assert(qint_get_int(qint) == value);
- QDECREF(qint);
+ qnum = qobject_to_qnum(qobject_from_jsonf("%d", value));
+ g_assert(qnum_get_try_int(qnum, &val));
+ g_assert_cmpint(val, ==, value);
+ QDECREF(qnum);
- qint = qobject_to_qint(qobject_from_jsonf("%lld", value_ll));
- g_assert(qint_get_int(qint) == value_ll);
- QDECREF(qint);
+ qnum = qobject_to_qnum(qobject_from_jsonf("%lld", value_ll));
+ g_assert(qnum_get_try_int(qnum, &val));
+ g_assert_cmpint(val, ==, value_ll);
+ QDECREF(qnum);
- qfloat = qobject_to_qfloat(qobject_from_jsonf("%f", valuef));
- g_assert(qfloat_get_double(qfloat) == valuef);
- QDECREF(qfloat);
+ qnum = qobject_to_qnum(qobject_from_jsonf("%f", valuef));
+ g_assert(qnum_get_double(qnum) == valuef);
+ QDECREF(qnum);
}
static void keyword_literal(void)
@@ -1019,7 +1066,7 @@ struct LiteralQObject
{
int type;
union {
- int64_t qint;
+ int64_t qnum;
const char *qstr;
LiteralQDictEntry *qdict;
LiteralQObject *qlist;
@@ -1032,7 +1079,7 @@ struct LiteralQDictEntry
LiteralQObject value;
};
-#define QLIT_QINT(val) (LiteralQObject){.type = QTYPE_QINT, .value.qint = (val)}
+#define QLIT_QNUM(val) (LiteralQObject){.type = QTYPE_QNUM, .value.qnum = (val)}
#define QLIT_QSTR(val) (LiteralQObject){.type = QTYPE_QSTRING, .value.qstr = (val)}
#define QLIT_QDICT(val) (LiteralQObject){.type = QTYPE_QDICT, .value.qdict = (val)}
#define QLIT_QLIST(val) (LiteralQObject){.type = QTYPE_QLIST, .value.qlist = (val)}
@@ -1064,13 +1111,16 @@ static void compare_helper(QObject *obj, void *opaque)
static int compare_litqobj_to_qobj(LiteralQObject *lhs, QObject *rhs)
{
+ int64_t val;
+
if (!rhs || lhs->type != qobject_type(rhs)) {
return 0;
}
switch (lhs->type) {
- case QTYPE_QINT:
- return lhs->value.qint == qint_get_int(qobject_to_qint(rhs));
+ case QTYPE_QNUM:
+ g_assert(qnum_get_try_int(qobject_to_qnum(rhs), &val));
+ return lhs->value.qnum == val;
case QTYPE_QSTRING:
return (strcmp(lhs->value.qstr, qstring_get_str(qobject_to_qstring(rhs))) == 0);
case QTYPE_QDICT: {
@@ -1114,7 +1164,7 @@ static void simple_dict(void)
{
.encoded = "{\"foo\": 42, \"bar\": \"hello world\"}",
.decoded = QLIT_QDICT(((LiteralQDictEntry[]){
- { "foo", QLIT_QINT(42) },
+ { "foo", QLIT_QNUM(42) },
{ "bar", QLIT_QSTR("hello world") },
{ }
})),
@@ -1126,7 +1176,7 @@ static void simple_dict(void)
}, {
.encoded = "{\"foo\": 43}",
.decoded = QLIT_QDICT(((LiteralQDictEntry[]){
- { "foo", QLIT_QINT(43) },
+ { "foo", QLIT_QNUM(43) },
{ }
})),
},
@@ -1212,15 +1262,15 @@ static void simple_list(void)
{
.encoded = "[43,42]",
.decoded = QLIT_QLIST(((LiteralQObject[]){
- QLIT_QINT(43),
- QLIT_QINT(42),
+ QLIT_QNUM(43),
+ QLIT_QNUM(42),
{ }
})),
},
{
.encoded = "[43]",
.decoded = QLIT_QLIST(((LiteralQObject[]){
- QLIT_QINT(43),
+ QLIT_QNUM(43),
{ }
})),
},
@@ -1269,35 +1319,35 @@ static void simple_whitespace(void)
{
.encoded = " [ 43 , 42 ]",
.decoded = QLIT_QLIST(((LiteralQObject[]){
- QLIT_QINT(43),
- QLIT_QINT(42),
+ QLIT_QNUM(43),
+ QLIT_QNUM(42),
{ }
})),
},
{
.encoded = " [ 43 , { 'h' : 'b' }, [ ], 42 ]",
.decoded = QLIT_QLIST(((LiteralQObject[]){
- QLIT_QINT(43),
+ QLIT_QNUM(43),
QLIT_QDICT(((LiteralQDictEntry[]){
{ "h", QLIT_QSTR("b") },
{ }})),
QLIT_QLIST(((LiteralQObject[]){
{ }})),
- QLIT_QINT(42),
+ QLIT_QNUM(42),
{ }
})),
},
{
.encoded = " [ 43 , { 'h' : 'b' , 'a' : 32 }, [ ], 42 ]",
.decoded = QLIT_QLIST(((LiteralQObject[]){
- QLIT_QINT(43),
+ QLIT_QNUM(43),
QLIT_QDICT(((LiteralQDictEntry[]){
{ "h", QLIT_QSTR("b") },
- { "a", QLIT_QINT(32) },
+ { "a", QLIT_QNUM(32) },
{ }})),
QLIT_QLIST(((LiteralQObject[]){
{ }})),
- QLIT_QINT(42),
+ QLIT_QNUM(42),
{ }
})),
},
@@ -1327,11 +1377,11 @@ static void simple_varargs(void)
QObject *embedded_obj;
QObject *obj;
LiteralQObject decoded = QLIT_QLIST(((LiteralQObject[]){
- QLIT_QINT(1),
- QLIT_QINT(2),
+ QLIT_QNUM(1),
+ QLIT_QNUM(2),
QLIT_QLIST(((LiteralQObject[]){
- QLIT_QINT(32),
- QLIT_QINT(42),
+ QLIT_QNUM(32),
+ QLIT_QNUM(42),
{}})),
{}}));
@@ -1468,6 +1518,7 @@ int main(int argc, char **argv)
g_test_add_func("/literals/string/vararg", vararg_string);
g_test_add_func("/literals/number/simple", simple_number);
+ g_test_add_func("/literals/number/large", large_number);
g_test_add_func("/literals/number/float", float_number);
g_test_add_func("/literals/number/vararg", vararg_number);
diff --git a/tests/check-qlist.c b/tests/check-qlist.c
index 4983867c..894e991 100644
--- a/tests/check-qlist.c
+++ b/tests/check-qlist.c
@@ -11,7 +11,8 @@
*/
#include "qemu/osdep.h"
-#include "qapi/qmp/qint.h"
+#include "qapi/error.h"
+#include "qapi/qmp/qnum.h"
#include "qapi/qmp/qlist.h"
/*
@@ -29,17 +30,16 @@ static void qlist_new_test(void)
g_assert(qlist->base.refcnt == 1);
g_assert(qobject_type(QOBJECT(qlist)) == QTYPE_QLIST);
- // destroy doesn't exist yet
- g_free(qlist);
+ QDECREF(qlist);
}
static void qlist_append_test(void)
{
- QInt *qi;
+ QNum *qi;
QList *qlist;
QListEntry *entry;
- qi = qint_from_int(42);
+ qi = qnum_from_int(42);
qlist = qlist_new();
qlist_append(qlist, qi);
@@ -48,10 +48,7 @@ static void qlist_append_test(void)
g_assert(entry != NULL);
g_assert(entry->value == QOBJECT(qi));
- // destroy doesn't exist yet
- QDECREF(qi);
- g_free(entry);
- g_free(qlist);
+ QDECREF(qlist);
}
static void qobject_to_qlist_test(void)
@@ -62,20 +59,6 @@ static void qobject_to_qlist_test(void)
g_assert(qobject_to_qlist(QOBJECT(qlist)) == qlist);
- // destroy doesn't exist yet
- g_free(qlist);
-}
-
-static void qlist_destroy_test(void)
-{
- int i;
- QList *qlist;
-
- qlist = qlist_new();
-
- for (i = 0; i < 42; i++)
- qlist_append_int(qlist, i);
-
QDECREF(qlist);
}
@@ -84,13 +67,17 @@ static const int iter_max = 42;
static void iter_func(QObject *obj, void *opaque)
{
- QInt *qi;
+ QNum *qi;
+ int64_t val;
g_assert(opaque == NULL);
- qi = qobject_to_qint(obj);
+ qi = qobject_to_qnum(obj);
g_assert(qi != NULL);
- g_assert((qint_get_int(qi) >= 0) && (qint_get_int(qi) <= iter_max));
+
+ g_assert(qnum_get_try_int(qi, &val));
+ g_assert_cmpint(val, >=, 0);
+ g_assert_cmpint(val, <=, iter_max);
iter_called++;
}
@@ -120,7 +107,6 @@ int main(int argc, char **argv)
g_test_add_func("/public/new", qlist_new_test);
g_test_add_func("/public/append", qlist_append_test);
g_test_add_func("/public/to_qlist", qobject_to_qlist_test);
- g_test_add_func("/public/destroy", qlist_destroy_test);
g_test_add_func("/public/iter", qlist_iter_test);
return g_test_run();
diff --git a/tests/check-qnum.c b/tests/check-qnum.c
new file mode 100644
index 0000000..d702d5d
--- /dev/null
+++ b/tests/check-qnum.c
@@ -0,0 +1,170 @@
+/*
+ * QNum unit-tests.
+ *
+ * Copyright (C) 2009 Red Hat Inc.
+ * Copyright IBM, Corp. 2009
+ *
+ * Authors:
+ * Luiz Capitulino <lcapitulino@redhat.com>
+ * Anthony Liguori <aliguori@us.ibm.com>
+ *
+ * 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/qnum.h"
+#include "qapi/error.h"
+#include "qemu-common.h"
+
+/*
+ * Public Interface test-cases
+ *
+ * (with some violations to access 'private' data)
+ */
+
+static void qnum_from_int_test(void)
+{
+ QNum *qn;
+ const int value = -42;
+
+ qn = qnum_from_int(value);
+ g_assert(qn != NULL);
+ g_assert_cmpint(qn->kind, ==, QNUM_I64);
+ g_assert_cmpint(qn->u.i64, ==, value);
+ g_assert_cmpint(qn->base.refcnt, ==, 1);
+ g_assert_cmpint(qobject_type(QOBJECT(qn)), ==, QTYPE_QNUM);
+
+ QDECREF(qn);
+}
+
+static void qnum_from_uint_test(void)
+{
+ QNum *qn;
+ const uint64_t value = UINT64_MAX;
+
+ qn = qnum_from_uint(value);
+ g_assert(qn != NULL);
+ g_assert_cmpint(qn->kind, ==, QNUM_U64);
+ g_assert(qn->u.u64 == value);
+ g_assert(qn->base.refcnt == 1);
+ g_assert(qobject_type(QOBJECT(qn)) == QTYPE_QNUM);
+
+ QDECREF(qn);
+}
+
+static void qnum_from_double_test(void)
+{
+ QNum *qn;
+ const double value = -42.23423;
+
+ qn = qnum_from_double(value);
+ g_assert(qn != NULL);
+ g_assert_cmpint(qn->kind, ==, QNUM_DOUBLE);
+ g_assert_cmpfloat(qn->u.dbl, ==, value);
+ g_assert_cmpint(qn->base.refcnt, ==, 1);
+ g_assert_cmpint(qobject_type(QOBJECT(qn)), ==, QTYPE_QNUM);
+
+ QDECREF(qn);
+}
+
+static void qnum_from_int64_test(void)
+{
+ QNum *qn;
+ const int64_t value = 0x1234567890abcdefLL;
+
+ qn = qnum_from_int(value);
+ g_assert_cmpint((int64_t) qn->u.i64, ==, value);
+
+ QDECREF(qn);
+}
+
+static void qnum_get_int_test(void)
+{
+ QNum *qn;
+ const int value = 123456;
+
+ qn = qnum_from_int(value);
+ g_assert_cmpint(qnum_get_int(qn), ==, value);
+
+ QDECREF(qn);
+}
+
+static void qnum_get_uint_test(void)
+{
+ QNum *qn;
+ const int value = 123456;
+ uint64_t val;
+ int64_t ival;
+
+ qn = qnum_from_uint(value);
+ g_assert(qnum_get_try_uint(qn, &val));
+ g_assert_cmpuint(val, ==, value);
+ QDECREF(qn);
+
+ qn = qnum_from_int(value);
+ g_assert(qnum_get_try_uint(qn, &val));
+ g_assert_cmpuint(val, ==, value);
+ QDECREF(qn);
+
+ /* invalid cases */
+ qn = qnum_from_int(-1);
+ g_assert(!qnum_get_try_uint(qn, &val));
+ QDECREF(qn);
+
+ qn = qnum_from_uint(-1ULL);
+ g_assert(!qnum_get_try_int(qn, &ival));
+ QDECREF(qn);
+
+ qn = qnum_from_double(0.42);
+ g_assert(!qnum_get_try_uint(qn, &val));
+ QDECREF(qn);
+}
+
+static void qobject_to_qnum_test(void)
+{
+ QNum *qn;
+
+ qn = qnum_from_int(0);
+ g_assert(qobject_to_qnum(QOBJECT(qn)) == qn);
+ QDECREF(qn);
+
+ qn = qnum_from_double(0);
+ g_assert(qobject_to_qnum(QOBJECT(qn)) == qn);
+ QDECREF(qn);
+}
+
+static void qnum_to_string_test(void)
+{
+ QNum *qn;
+ char *tmp;
+
+ qn = qnum_from_int(123456);
+ tmp = qnum_to_string(qn);
+ g_assert_cmpstr(tmp, ==, "123456");
+ g_free(tmp);
+ QDECREF(qn);
+
+ qn = qnum_from_double(0.42);
+ tmp = qnum_to_string(qn);
+ g_assert_cmpstr(tmp, ==, "0.42");
+ g_free(tmp);
+ QDECREF(qn);
+}
+
+int main(int argc, char **argv)
+{
+ g_test_init(&argc, &argv, NULL);
+
+ g_test_add_func("/qnum/from_int", qnum_from_int_test);
+ g_test_add_func("/qnum/from_uint", qnum_from_uint_test);
+ g_test_add_func("/qnum/from_double", qnum_from_double_test);
+ g_test_add_func("/qnum/from_int64", qnum_from_int64_test);
+ g_test_add_func("/qnum/get_int", qnum_get_int_test);
+ g_test_add_func("/qnum/get_uint", qnum_get_uint_test);
+ g_test_add_func("/qnum/to_qnum", qobject_to_qnum_test);
+ g_test_add_func("/qnum/to_string", qnum_to_string_test);
+
+ return g_test_run();
+}
diff --git a/tests/check-qstring.c b/tests/check-qstring.c
index 239e9d9..112ec08 100644
--- a/tests/check-qstring.c
+++ b/tests/check-qstring.c
@@ -31,14 +31,6 @@ static void qstring_from_str_test(void)
g_assert(strcmp(str, qstring->string) == 0);
g_assert(qobject_type(QOBJECT(qstring)) == QTYPE_QSTRING);
- // destroy doesn't exit yet
- g_free(qstring->string);
- g_free(qstring);
-}
-
-static void qstring_destroy_test(void)
-{
- QString *qstring = qstring_from_str("destroy test");
QDECREF(qstring);
}
@@ -97,7 +89,6 @@ int main(int argc, char **argv)
g_test_init(&argc, &argv, NULL);
g_test_add_func("/public/from_str", qstring_from_str_test);
- g_test_add_func("/public/destroy", qstring_destroy_test);
g_test_add_func("/public/get_str", qstring_get_str_test);
g_test_add_func("/public/append_chr", qstring_append_chr_test);
g_test_add_func("/public/from_substr", qstring_from_substr_test);
diff --git a/tests/qapi-schema/comments.out b/tests/qapi-schema/comments.out
index 5d7c13c..17e6525 100644
--- a/tests/qapi-schema/comments.out
+++ b/tests/qapi-schema/comments.out
@@ -1,4 +1,4 @@
-enum QType ['none', 'qnull', 'qint', 'qstring', 'qdict', 'qlist', 'qfloat', 'qbool']
+enum QType ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', 'qbool']
prefix QTYPE
enum Status ['good', 'bad', 'ugly']
object q_empty
diff --git a/tests/qapi-schema/doc-good.out b/tests/qapi-schema/doc-good.out
index 70c1252..63ca25a 100644
--- a/tests/qapi-schema/doc-good.out
+++ b/tests/qapi-schema/doc-good.out
@@ -6,7 +6,7 @@ object Object
tag base1
case one: Variant1
case two: Variant2
-enum QType ['none', 'qnull', 'qint', 'qstring', 'qdict', 'qlist', 'qfloat', 'qbool']
+enum QType ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', 'qbool']
prefix QTYPE
object SugaredUnion
member type: SugaredUnionKind optional=False
diff --git a/tests/qapi-schema/empty.out b/tests/qapi-schema/empty.out
index 8a5b034..40b886d 100644
--- a/tests/qapi-schema/empty.out
+++ b/tests/qapi-schema/empty.out
@@ -1,3 +1,3 @@
-enum QType ['none', 'qnull', 'qint', 'qstring', 'qdict', 'qlist', 'qfloat', 'qbool']
+enum QType ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', 'qbool']
prefix QTYPE
object q_empty
diff --git a/tests/qapi-schema/event-case.out b/tests/qapi-schema/event-case.out
index 5a0f2bf..313c0fe 100644
--- a/tests/qapi-schema/event-case.out
+++ b/tests/qapi-schema/event-case.out
@@ -1,4 +1,4 @@
-enum QType ['none', 'qnull', 'qint', 'qstring', 'qdict', 'qlist', 'qfloat', 'qbool']
+enum QType ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', 'qbool']
prefix QTYPE
event oops None
boxed=False
diff --git a/tests/qapi-schema/ident-with-escape.out b/tests/qapi-schema/ident-with-escape.out
index 1d2722c..b5637cb 100644
--- a/tests/qapi-schema/ident-with-escape.out
+++ b/tests/qapi-schema/ident-with-escape.out
@@ -1,4 +1,4 @@
-enum QType ['none', 'qnull', 'qint', 'qstring', 'qdict', 'qlist', 'qfloat', 'qbool']
+enum QType ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', 'qbool']
prefix QTYPE
command fooA q_obj_fooA-arg -> None
gen=True success_response=True boxed=False
diff --git a/tests/qapi-schema/include-relpath.out b/tests/qapi-schema/include-relpath.out
index 5d7c13c..17e6525 100644
--- a/tests/qapi-schema/include-relpath.out
+++ b/tests/qapi-schema/include-relpath.out
@@ -1,4 +1,4 @@
-enum QType ['none', 'qnull', 'qint', 'qstring', 'qdict', 'qlist', 'qfloat', 'qbool']
+enum QType ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', 'qbool']
prefix QTYPE
enum Status ['good', 'bad', 'ugly']
object q_empty
diff --git a/tests/qapi-schema/include-repetition.out b/tests/qapi-schema/include-repetition.out
index 5d7c13c..17e6525 100644
--- a/tests/qapi-schema/include-repetition.out
+++ b/tests/qapi-schema/include-repetition.out
@@ -1,4 +1,4 @@
-enum QType ['none', 'qnull', 'qint', 'qstring', 'qdict', 'qlist', 'qfloat', 'qbool']
+enum QType ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', 'qbool']
prefix QTYPE
enum Status ['good', 'bad', 'ugly']
object q_empty
diff --git a/tests/qapi-schema/include-simple.out b/tests/qapi-schema/include-simple.out
index 5d7c13c..17e6525 100644
--- a/tests/qapi-schema/include-simple.out
+++ b/tests/qapi-schema/include-simple.out
@@ -1,4 +1,4 @@
-enum QType ['none', 'qnull', 'qint', 'qstring', 'qdict', 'qlist', 'qfloat', 'qbool']
+enum QType ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', 'qbool']
prefix QTYPE
enum Status ['good', 'bad', 'ugly']
object q_empty
diff --git a/tests/qapi-schema/indented-expr.out b/tests/qapi-schema/indented-expr.out
index e8171c9..586795f 100644
--- a/tests/qapi-schema/indented-expr.out
+++ b/tests/qapi-schema/indented-expr.out
@@ -1,4 +1,4 @@
-enum QType ['none', 'qnull', 'qint', 'qstring', 'qdict', 'qlist', 'qfloat', 'qbool']
+enum QType ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', 'qbool']
prefix QTYPE
command eins None -> None
gen=True success_response=True boxed=False
diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qapi-schema-test.json
index 17649c6..91ffb26 100644
--- a/tests/qapi-schema/qapi-schema-test.json
+++ b/tests/qapi-schema/qapi-schema-test.json
@@ -103,8 +103,6 @@
{ 'alternate': 'AltEnumNum', 'data': { 'e': 'EnumOne', 'n': 'number' } }
{ 'alternate': 'AltNumEnum', 'data': { 'n': 'number', 'e': 'EnumOne' } }
{ 'alternate': 'AltEnumInt', 'data': { 'e': 'EnumOne', 'i': 'int' } }
-{ 'alternate': 'AltIntNum', 'data': { 'i': 'int', 'n': 'number' } }
-{ 'alternate': 'AltNumInt', 'data': { 'n': 'number', 'i': 'int' } }
# for testing use of 'str' within alternates
{ 'alternate': 'AltStrObj', 'data': { 's': 'str', 'o': 'TestStruct' } }
diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qapi-schema-test.out
index 9f68610..b88b8aa 100644
--- a/tests/qapi-schema/qapi-schema-test.out
+++ b/tests/qapi-schema/qapi-schema-test.out
@@ -10,18 +10,10 @@ alternate AltEnumNum
tag type
case e: EnumOne
case n: number
-alternate AltIntNum
- tag type
- case i: int
- case n: number
alternate AltNumEnum
tag type
case n: number
case e: EnumOne
-alternate AltNumInt
- tag type
- case n: number
- case i: int
alternate AltStrObj
tag type
case s: str
@@ -58,7 +50,7 @@ object NestedEnumsOne
member enum4: EnumOne optional=True
enum QEnumTwo ['value1', 'value2']
prefix QENUM_TWO
-enum QType ['none', 'qnull', 'qint', 'qstring', 'qdict', 'qlist', 'qfloat', 'qbool']
+enum QType ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', 'qbool']
prefix QTYPE
object TestStruct
member integer: int optional=False
diff --git a/tests/test-keyval.c b/tests/test-keyval.c
index c3be005..baf7e33 100644
--- a/tests/test-keyval.c
+++ b/tests/test-keyval.c
@@ -615,7 +615,7 @@ static void test_keyval_visit_alternate(void)
Visitor *v;
QDict *qdict;
AltStrObj *aso;
- AltNumInt *ani;
+ AltNumEnum *ane;
AltEnumBool *aeb;
/*
@@ -631,7 +631,7 @@ static void test_keyval_visit_alternate(void)
g_assert_cmpint(aso->type, ==, QTYPE_QSTRING);
g_assert_cmpstr(aso->u.s, ==, "1");
qapi_free_AltStrObj(aso);
- visit_type_AltNumInt(v, "b", &ani, &err);
+ visit_type_AltNumEnum(v, "b", &ane, &err);
error_free_or_abort(&err);
visit_type_AltEnumBool(v, "c", &aeb, &err);
error_free_or_abort(&err);
diff --git a/tests/test-qmp-commands.c b/tests/test-qmp-commands.c
index acdded4..904c89d 100644
--- a/tests/test-qmp-commands.c
+++ b/tests/test-qmp-commands.c
@@ -162,7 +162,8 @@ static void test_dispatch_cmd_io(void)
QDict *ud1b = qdict_new();
QDict *ret, *ret_dict, *ret_dict_dict, *ret_dict_dict_userdef;
QDict *ret_dict_dict2, *ret_dict_dict2_userdef;
- QInt *ret3;
+ QNum *ret3;
+ int64_t val;
qdict_put_int(ud1a, "integer", 42);
qdict_put_str(ud1a, "string", "hello");
@@ -194,8 +195,9 @@ static void test_dispatch_cmd_io(void)
qdict_put(req, "arguments", args3);
qdict_put_str(req, "execute", "guest-get-time");
- ret3 = qobject_to_qint(test_qmp_dispatch(req));
- assert(qint_get_int(ret3) == 66);
+ ret3 = qobject_to_qnum(test_qmp_dispatch(req));
+ g_assert(qnum_get_try_int(ret3, &val));
+ g_assert_cmpint(val, ==, 66);
QDECREF(ret3);
QDECREF(req);
diff --git a/tests/test-qmp-event.c b/tests/test-qmp-event.c
index 4c0f096..9fb3c5e 100644
--- a/tests/test-qmp-event.c
+++ b/tests/test-qmp-event.c
@@ -18,7 +18,6 @@
#include "test-qapi-visit.h"
#include "test-qapi-event.h"
#include "qapi/qmp/types.h"
-#include "qapi/qmp/qint.h"
#include "qapi/qmp/qobject.h"
#include "qapi/qmp-event.h"
@@ -41,6 +40,7 @@ void qdict_cmp_do_simple(const char *key, QObject *obj1, void *opaque)
{
QObject *obj2;
QDictCmpData d_new, *d = opaque;
+ int64_t val1, val2;
if (!d->result) {
return;
@@ -62,9 +62,10 @@ void qdict_cmp_do_simple(const char *key, QObject *obj1, void *opaque)
d->result = (qbool_get_bool(qobject_to_qbool(obj1)) ==
qbool_get_bool(qobject_to_qbool(obj2)));
return;
- case QTYPE_QINT:
- d->result = (qint_get_int(qobject_to_qint(obj1)) ==
- qint_get_int(qobject_to_qint(obj2)));
+ case QTYPE_QNUM:
+ g_assert(qnum_get_try_int(qobject_to_qnum(obj1), &val1));
+ g_assert(qnum_get_try_int(qobject_to_qnum(obj2), &val2));
+ d->result = val1 == val2;
return;
case QTYPE_QSTRING:
d->result = g_strcmp0(qstring_get_str(qobject_to_qstring(obj1)),
diff --git a/tests/test-qobject-input-visitor.c b/tests/test-qobject-input-visitor.c
index 6b997a1..34bab8a 100644
--- a/tests/test-qobject-input-visitor.c
+++ b/tests/test-qobject-input-visitor.c
@@ -107,6 +107,7 @@ static void test_visitor_in_int(TestInputVisitorData *data,
const void *unused)
{
int64_t res = 0;
+ double dbl;
int value = -42;
Visitor *v;
@@ -114,13 +115,17 @@ static void test_visitor_in_int(TestInputVisitorData *data,
visit_type_int(v, NULL, &res, &error_abort);
g_assert_cmpint(res, ==, value);
+
+ visit_type_number(v, NULL, &dbl, &error_abort);
+ g_assert_cmpfloat(dbl, ==, -42.0);
}
static void test_visitor_in_uint(TestInputVisitorData *data,
const void *unused)
{
- Error *err = NULL;
uint64_t res = 0;
+ int64_t i64;
+ double dbl;
int value = 42;
Visitor *v;
@@ -129,19 +134,25 @@ static void test_visitor_in_uint(TestInputVisitorData *data,
visit_type_uint64(v, NULL, &res, &error_abort);
g_assert_cmpuint(res, ==, (uint64_t)value);
- /* BUG: value between INT64_MIN and -1 accepted modulo 2^64 */
+ visit_type_int(v, NULL, &i64, &error_abort);
+ g_assert_cmpint(i64, ==, value);
+
+ visit_type_number(v, NULL, &dbl, &error_abort);
+ g_assert_cmpfloat(dbl, ==, value);
+ /* BUG: value between INT64_MIN and -1 accepted modulo 2^64 */
v = visitor_input_test_init(data, "%d", -value);
visit_type_uint64(v, NULL, &res, &error_abort);
g_assert_cmpuint(res, ==, (uint64_t)-value);
- /* BUG: value between INT64_MAX+1 and UINT64_MAX rejected */
-
v = visitor_input_test_init(data, "18446744073709551574");
- visit_type_uint64(v, NULL, &res, &err);
- error_free_or_abort(&err);
+ visit_type_uint64(v, NULL, &res, &error_abort);
+ g_assert_cmpuint(res, ==, 18446744073709551574U);
+
+ visit_type_number(v, NULL, &dbl, &error_abort);
+ g_assert_cmpfloat(dbl, ==, 18446744073709552000.0);
}
static void test_visitor_in_int_overflow(TestInputVisitorData *data,
@@ -151,9 +162,10 @@ static void test_visitor_in_int_overflow(TestInputVisitorData *data,
Error *err = NULL;
Visitor *v;
- /* this will overflow a Qint/int64, so should be deserialized into
- * a QFloat/double field instead, leading to an error if we pass it
- * to visit_type_int. confirm this.
+ /*
+ * This will overflow a QNUM_I64, so should be deserialized into a
+ * QNUM_DOUBLE field instead, leading to an error if we pass it to
+ * visit_type_int(). Confirm this.
*/
v = visitor_input_test_init(data, "%f", DBL_MAX);
@@ -260,6 +272,27 @@ static void test_visitor_in_number(TestInputVisitorData *data,
g_assert_cmpfloat(res, ==, value);
}
+static void test_visitor_in_large_number(TestInputVisitorData *data,
+ const void *unused)
+{
+ Error *err = NULL;
+ double res = 0;
+ int64_t i64;
+ uint64_t u64;
+ Visitor *v;
+
+ v = visitor_input_test_init(data, "-18446744073709551616"); /* -2^64 */
+
+ visit_type_number(v, NULL, &res, &error_abort);
+ g_assert_cmpfloat(res, ==, -18446744073709552e3);
+
+ visit_type_int(v, NULL, &i64, &err);
+ error_free_or_abort(&err);
+
+ visit_type_uint64(v, NULL, &u64, &err);
+ error_free_or_abort(&err);
+}
+
static void test_visitor_in_number_keyval(TestInputVisitorData *data,
const void *unused)
{
@@ -434,17 +467,19 @@ static void test_visitor_in_any(TestInputVisitorData *data,
{
QObject *res = NULL;
Visitor *v;
- QInt *qint;
+ QNum *qnum;
QBool *qbool;
QString *qstring;
QDict *qdict;
QObject *qobj;
+ int64_t val;
v = visitor_input_test_init(data, "-42");
visit_type_any(v, NULL, &res, &error_abort);
- qint = qobject_to_qint(res);
- g_assert(qint);
- g_assert_cmpint(qint_get_int(qint), ==, -42);
+ qnum = qobject_to_qnum(res);
+ g_assert(qnum);
+ g_assert(qnum_get_try_int(qnum, &val));
+ g_assert_cmpint(val, ==, -42);
qobject_decref(res);
v = visitor_input_test_init(data, "{ 'integer': -42, 'boolean': true, 'string': 'foo' }");
@@ -453,9 +488,10 @@ static void test_visitor_in_any(TestInputVisitorData *data,
g_assert(qdict && qdict_size(qdict) == 3);
qobj = qdict_get(qdict, "integer");
g_assert(qobj);
- qint = qobject_to_qint(qobj);
- g_assert(qint);
- g_assert_cmpint(qint_get_int(qint), ==, -42);
+ qnum = qobject_to_qnum(qobj);
+ g_assert(qnum);
+ g_assert(qnum_get_try_int(qnum, &val));
+ g_assert_cmpint(val, ==, -42);
qobj = qdict_get(qdict, "boolean");
g_assert(qobj);
qbool = qobject_to_qbool(qobj);
@@ -533,7 +569,7 @@ static void test_visitor_in_alternate(TestInputVisitorData *data,
v = visitor_input_test_init(data, "42");
visit_type_UserDefAlternate(v, NULL, &tmp, &error_abort);
- g_assert_cmpint(tmp->type, ==, QTYPE_QINT);
+ g_assert_cmpint(tmp->type, ==, QTYPE_QNUM);
g_assert_cmpint(tmp->u.i, ==, 42);
qapi_free_UserDefAlternate(tmp);
@@ -561,7 +597,7 @@ static void test_visitor_in_alternate(TestInputVisitorData *data,
v = visitor_input_test_init(data, "{ 'alt': 42 }");
visit_type_WrapAlternate(v, NULL, &wrap, &error_abort);
- g_assert_cmpint(wrap->alt->type, ==, QTYPE_QINT);
+ g_assert_cmpint(wrap->alt->type, ==, QTYPE_QNUM);
g_assert_cmpint(wrap->alt->u.i, ==, 42);
qapi_free_WrapAlternate(wrap);
@@ -592,8 +628,6 @@ static void test_visitor_in_alternate_number(TestInputVisitorData *data,
AltEnumNum *aen;
AltNumEnum *ans;
AltEnumInt *asi;
- AltIntNum *ain;
- AltNumInt *ani;
/* Parsing an int */
@@ -604,34 +638,22 @@ static void test_visitor_in_alternate_number(TestInputVisitorData *data,
v = visitor_input_test_init(data, "42");
visit_type_AltEnumNum(v, NULL, &aen, &error_abort);
- g_assert_cmpint(aen->type, ==, QTYPE_QFLOAT);
+ g_assert_cmpint(aen->type, ==, QTYPE_QNUM);
g_assert_cmpfloat(aen->u.n, ==, 42);
qapi_free_AltEnumNum(aen);
v = visitor_input_test_init(data, "42");
visit_type_AltNumEnum(v, NULL, &ans, &error_abort);
- g_assert_cmpint(ans->type, ==, QTYPE_QFLOAT);
+ g_assert_cmpint(ans->type, ==, QTYPE_QNUM);
g_assert_cmpfloat(ans->u.n, ==, 42);
qapi_free_AltNumEnum(ans);
v = visitor_input_test_init(data, "42");
visit_type_AltEnumInt(v, NULL, &asi, &error_abort);
- g_assert_cmpint(asi->type, ==, QTYPE_QINT);
+ g_assert_cmpint(asi->type, ==, QTYPE_QNUM);
g_assert_cmpint(asi->u.i, ==, 42);
qapi_free_AltEnumInt(asi);
- v = visitor_input_test_init(data, "42");
- visit_type_AltIntNum(v, NULL, &ain, &error_abort);
- g_assert_cmpint(ain->type, ==, QTYPE_QINT);
- g_assert_cmpint(ain->u.i, ==, 42);
- qapi_free_AltIntNum(ain);
-
- v = visitor_input_test_init(data, "42");
- visit_type_AltNumInt(v, NULL, &ani, &error_abort);
- g_assert_cmpint(ani->type, ==, QTYPE_QINT);
- g_assert_cmpint(ani->u.i, ==, 42);
- qapi_free_AltNumInt(ani);
-
/* Parsing a double */
v = visitor_input_test_init(data, "42.5");
@@ -641,13 +663,13 @@ static void test_visitor_in_alternate_number(TestInputVisitorData *data,
v = visitor_input_test_init(data, "42.5");
visit_type_AltEnumNum(v, NULL, &aen, &error_abort);
- g_assert_cmpint(aen->type, ==, QTYPE_QFLOAT);
+ g_assert_cmpint(aen->type, ==, QTYPE_QNUM);
g_assert_cmpfloat(aen->u.n, ==, 42.5);
qapi_free_AltEnumNum(aen);
v = visitor_input_test_init(data, "42.5");
visit_type_AltNumEnum(v, NULL, &ans, &error_abort);
- g_assert_cmpint(ans->type, ==, QTYPE_QFLOAT);
+ g_assert_cmpint(ans->type, ==, QTYPE_QNUM);
g_assert_cmpfloat(ans->u.n, ==, 42.5);
qapi_free_AltNumEnum(ans);
@@ -655,18 +677,6 @@ static void test_visitor_in_alternate_number(TestInputVisitorData *data,
visit_type_AltEnumInt(v, NULL, &asi, &err);
error_free_or_abort(&err);
qapi_free_AltEnumInt(asi);
-
- v = visitor_input_test_init(data, "42.5");
- visit_type_AltIntNum(v, NULL, &ain, &error_abort);
- g_assert_cmpint(ain->type, ==, QTYPE_QFLOAT);
- g_assert_cmpfloat(ain->u.n, ==, 42.5);
- qapi_free_AltIntNum(ain);
-
- v = visitor_input_test_init(data, "42.5");
- visit_type_AltNumInt(v, NULL, &ani, &error_abort);
- g_assert_cmpint(ani->type, ==, QTYPE_QFLOAT);
- g_assert_cmpfloat(ani->u.n, ==, 42.5);
- qapi_free_AltNumInt(ani);
}
static void test_native_list_integer_helper(TestInputVisitorData *data,
@@ -1092,7 +1102,7 @@ static void test_visitor_in_fail_struct_missing(TestInputVisitorData *data,
error_free_or_abort(&err);
visit_start_list(v, "list", NULL, 0, &err);
error_free_or_abort(&err);
- visit_start_alternate(v, "alternate", &alt, sizeof(*alt), false, &err);
+ visit_start_alternate(v, "alternate", &alt, sizeof(*alt), &err);
error_free_or_abort(&err);
visit_optional(v, "optional", &present);
g_assert(!present);
@@ -1279,6 +1289,8 @@ int main(int argc, char **argv)
NULL, test_visitor_in_bool_str_fail);
input_visitor_test_add("/visitor/input/number",
NULL, test_visitor_in_number);
+ input_visitor_test_add("/visitor/input/large_number",
+ NULL, test_visitor_in_large_number);
input_visitor_test_add("/visitor/input/number_keyval",
NULL, test_visitor_in_number_keyval);
input_visitor_test_add("/visitor/input/number_str_keyval",
diff --git a/tests/test-qobject-output-visitor.c b/tests/test-qobject-output-visitor.c
index 4e8fdf1..749c540 100644
--- a/tests/test-qobject-output-visitor.c
+++ b/tests/test-qobject-output-visitor.c
@@ -58,13 +58,15 @@ static void test_visitor_out_int(TestOutputVisitorData *data,
const void *unused)
{
int64_t value = -42;
- QInt *qint;
+ int64_t val;
+ QNum *qnum;
visit_type_int(data->ov, NULL, &value, &error_abort);
- qint = qobject_to_qint(visitor_get(data));
- g_assert(qint);
- g_assert_cmpint(qint_get_int(qint), ==, value);
+ qnum = qobject_to_qnum(visitor_get(data));
+ g_assert(qnum);
+ g_assert(qnum_get_try_int(qnum, &val));
+ g_assert_cmpint(val, ==, value);
}
static void test_visitor_out_bool(TestOutputVisitorData *data,
@@ -84,13 +86,13 @@ static void test_visitor_out_number(TestOutputVisitorData *data,
const void *unused)
{
double value = 3.14;
- QFloat *qfloat;
+ QNum *qnum;
visit_type_number(data->ov, NULL, &value, &error_abort);
- qfloat = qobject_to_qfloat(visitor_get(data));
- g_assert(qfloat);
- g_assert(qfloat_get_double(qfloat) == value);
+ qnum = qobject_to_qnum(visitor_get(data));
+ g_assert(qnum);
+ g_assert(qnum_get_double(qnum) == value);
}
static void test_visitor_out_string(TestOutputVisitorData *data,
@@ -329,16 +331,18 @@ static void test_visitor_out_any(TestOutputVisitorData *data,
const void *unused)
{
QObject *qobj;
- QInt *qint;
+ QNum *qnum;
QBool *qbool;
QString *qstring;
QDict *qdict;
+ int64_t val;
- qobj = QOBJECT(qint_from_int(-42));
+ qobj = QOBJECT(qnum_from_int(-42));
visit_type_any(data->ov, NULL, &qobj, &error_abort);
- qint = qobject_to_qint(visitor_get(data));
- g_assert(qint);
- g_assert_cmpint(qint_get_int(qint), ==, -42);
+ qnum = qobject_to_qnum(visitor_get(data));
+ g_assert(qnum);
+ g_assert(qnum_get_try_int(qnum, &val));
+ g_assert_cmpint(val, ==, -42);
qobject_decref(qobj);
visitor_reset(data);
@@ -351,9 +355,10 @@ static void test_visitor_out_any(TestOutputVisitorData *data,
qobject_decref(qobj);
qdict = qobject_to_qdict(visitor_get(data));
g_assert(qdict);
- qint = qobject_to_qint(qdict_get(qdict, "integer"));
- g_assert(qint);
- g_assert_cmpint(qint_get_int(qint), ==, -42);
+ qnum = qobject_to_qnum(qdict_get(qdict, "integer"));
+ g_assert(qnum);
+ g_assert(qnum_get_try_int(qnum, &val));
+ g_assert_cmpint(val, ==, -42);
qbool = qobject_to_qbool(qdict_get(qdict, "boolean"));
g_assert(qbool);
g_assert(qbool_get_bool(qbool) == true);
@@ -388,18 +393,20 @@ static void test_visitor_out_alternate(TestOutputVisitorData *data,
const void *unused)
{
UserDefAlternate *tmp;
- QInt *qint;
+ QNum *qnum;
QString *qstr;
QDict *qdict;
+ int64_t val;
tmp = g_new0(UserDefAlternate, 1);
- tmp->type = QTYPE_QINT;
+ tmp->type = QTYPE_QNUM;
tmp->u.i = 42;
visit_type_UserDefAlternate(data->ov, NULL, &tmp, &error_abort);
- qint = qobject_to_qint(visitor_get(data));
- g_assert(qint);
- g_assert_cmpint(qint_get_int(qint), ==, 42);
+ qnum = qobject_to_qnum(visitor_get(data));
+ g_assert(qnum);
+ g_assert(qnum_get_try_int(qnum, &val));
+ g_assert_cmpint(val, ==, 42);
qapi_free_UserDefAlternate(tmp);
@@ -595,26 +602,44 @@ static void check_native_list(QObject *qobj,
qlist = qlist_copy(qobject_to_qlist(qdict_get(qdict, "data")));
switch (kind) {
- case USER_DEF_NATIVE_LIST_UNION_KIND_S8:
- case USER_DEF_NATIVE_LIST_UNION_KIND_S16:
- case USER_DEF_NATIVE_LIST_UNION_KIND_S32:
- case USER_DEF_NATIVE_LIST_UNION_KIND_S64:
case USER_DEF_NATIVE_LIST_UNION_KIND_U8:
case USER_DEF_NATIVE_LIST_UNION_KIND_U16:
case USER_DEF_NATIVE_LIST_UNION_KIND_U32:
case USER_DEF_NATIVE_LIST_UNION_KIND_U64:
- /* all integer elements in JSON arrays get stored into QInts when
- * we convert to QObjects, so we can check them all in the same
- * fashion, so simply fall through here
+ for (i = 0; i < 32; i++) {
+ QObject *tmp;
+ QNum *qvalue;
+ uint64_t val;
+
+ tmp = qlist_peek(qlist);
+ g_assert(tmp);
+ qvalue = qobject_to_qnum(tmp);
+ g_assert(qnum_get_try_uint(qvalue, &val));
+ g_assert_cmpint(val, ==, i);
+ qobject_decref(qlist_pop(qlist));
+ }
+ break;
+
+ case USER_DEF_NATIVE_LIST_UNION_KIND_S8:
+ case USER_DEF_NATIVE_LIST_UNION_KIND_S16:
+ case USER_DEF_NATIVE_LIST_UNION_KIND_S32:
+ case USER_DEF_NATIVE_LIST_UNION_KIND_S64:
+ /*
+ * All integer elements in JSON arrays get stored into QNums
+ * when we convert to QObjects, so we can check them all in
+ * the same fashion, so simply fall through here.
*/
case USER_DEF_NATIVE_LIST_UNION_KIND_INTEGER:
for (i = 0; i < 32; i++) {
QObject *tmp;
- QInt *qvalue;
+ QNum *qvalue;
+ int64_t val;
+
tmp = qlist_peek(qlist);
g_assert(tmp);
- qvalue = qobject_to_qint(tmp);
- g_assert_cmpint(qint_get_int(qvalue), ==, i);
+ qvalue = qobject_to_qnum(tmp);
+ g_assert(qnum_get_try_int(qvalue, &val));
+ g_assert_cmpint(val, ==, i);
qobject_decref(qlist_pop(qlist));
}
break;
@@ -645,15 +670,15 @@ static void check_native_list(QObject *qobj,
case USER_DEF_NATIVE_LIST_UNION_KIND_NUMBER:
for (i = 0; i < 32; i++) {
QObject *tmp;
- QFloat *qvalue;
+ QNum *qvalue;
GString *double_expected = g_string_new("");
GString *double_actual = g_string_new("");
tmp = qlist_peek(qlist);
g_assert(tmp);
- qvalue = qobject_to_qfloat(tmp);
+ qvalue = qobject_to_qnum(tmp);
g_string_printf(double_expected, "%.6f", (double)i / 3);
- g_string_printf(double_actual, "%.6f", qfloat_get_double(qvalue));
+ g_string_printf(double_actual, "%.6f", qnum_get_double(qvalue));
g_assert_cmpstr(double_actual->str, ==, double_expected->str);
qobject_decref(qlist_pop(qlist));
diff --git a/tests/test-x86-cpuid-compat.c b/tests/test-x86-cpuid-compat.c
index 4166ce5..58a2dd9 100644
--- a/tests/test-x86-cpuid-compat.c
+++ b/tests/test-x86-cpuid-compat.c
@@ -1,9 +1,8 @@
#include "qemu/osdep.h"
#include "qemu-common.h"
-#include "qapi/qmp/qlist.h"
-#include "qapi/qmp/qstring.h"
+#include "qapi/error.h"
#include "qapi/qmp/qdict.h"
-#include "qapi/qmp/qint.h"
+#include "qapi/qmp/qnum.h"
#include "qapi/qmp/qbool.h"
#include "libqtest.h"
@@ -57,12 +56,14 @@ static void test_cpuid_prop(const void *data)
{
const CpuidTestArgs *args = data;
char *path;
- QInt *value;
+ QNum *value;
+ int64_t val;
qtest_start(args->cmdline);
path = get_cpu0_qom_path();
- value = qobject_to_qint(qom_get(path, args->property));
- g_assert_cmpint(qint_get_int(value), ==, args->expected_value);
+ value = qobject_to_qnum(qom_get(path, args->property));
+ g_assert(qnum_get_try_int(value, &val));
+ g_assert_cmpint(val, ==, args->expected_value);
qtest_end();
QDECREF(value);
@@ -109,12 +110,15 @@ static uint32_t get_feature_word(QList *features, uint32_t eax, uint32_t ecx,
uint32_t reax = qdict_get_int(w, "cpuid-input-eax");
bool has_ecx = qdict_haskey(w, "cpuid-input-ecx");
uint32_t recx = 0;
+ int64_t val;
if (has_ecx) {
recx = qdict_get_int(w, "cpuid-input-ecx");
}
if (eax == reax && (!has_ecx || ecx == recx) && !strcmp(rreg, reg)) {
- return qint_get_int(qobject_to_qint(qdict_get(w, "features")));
+ g_assert(qnum_get_try_int(qobject_to_qnum(qdict_get(w, "features")),
+ &val));
+ return val;
}
}
return 0;