From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org
Subject: [PULL 13/33] test-visitor-serialization: Clean up test_primitives()
Date: Sat, 19 Dec 2020 11:55:12 +0100 [thread overview]
Message-ID: <20201219105532.1734134-14-armbru@redhat.com> (raw)
In-Reply-To: <20201219105532.1734134-1-armbru@redhat.com>
test_primitives() uses union member intmax_t max to compare the
integer members. Unspecified behavior. Has worked fine for many
years, though. Clean it up.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20201210161452.2813491-11-armbru@redhat.com>
---
tests/test-visitor-serialization.c | 44 +++++++++++++++++++++++++-----
1 file changed, 37 insertions(+), 7 deletions(-)
diff --git a/tests/test-visitor-serialization.c b/tests/test-visitor-serialization.c
index cf19924068..dfe120a50d 100644
--- a/tests/test-visitor-serialization.c
+++ b/tests/test-visitor-serialization.c
@@ -55,7 +55,6 @@ typedef struct PrimitiveType {
int16_t s16;
int32_t s32;
int64_t s64;
- intmax_t max;
} value;
enum PrimitiveTypeKind type;
const char *description;
@@ -307,15 +306,46 @@ static void test_primitives(gconstpointer opaque)
&error_abort);
g_assert(pt_copy != NULL);
- if (pt->type == PTYPE_STRING) {
+ switch (pt->type) {
+ case PTYPE_STRING:
g_assert_cmpstr(pt->value.string, ==, pt_copy->value.string);
g_free((char *)pt_copy->value.string);
- } else if (pt->type == PTYPE_NUMBER) {
+ break;
+ case PTYPE_BOOLEAN:
+ g_assert_cmpint(pt->value.boolean, ==, pt->value.boolean);
+ break;
+ case PTYPE_NUMBER:
g_assert_cmpfloat(pt->value.number, ==, pt_copy->value.number);
- } else if (pt->type == PTYPE_BOOLEAN) {
- g_assert_cmpint(!!pt->value.max, ==, !!pt->value.max);
- } else {
- g_assert_cmpint(pt->value.max, ==, pt_copy->value.max);
+ break;
+ case PTYPE_INTEGER:
+ g_assert_cmpint(pt->value.integer, ==, pt_copy->value.integer);
+ break;
+ case PTYPE_U8:
+ g_assert_cmpuint(pt->value.u8, ==, pt_copy->value.u8);
+ break;
+ case PTYPE_U16:
+ g_assert_cmpuint(pt->value.u16, ==, pt_copy->value.u16);
+ break;
+ case PTYPE_U32:
+ g_assert_cmpuint(pt->value.u32, ==, pt_copy->value.u32);
+ break;
+ case PTYPE_U64:
+ g_assert_cmpuint(pt->value.u64, ==, pt_copy->value.u64);
+ break;
+ case PTYPE_S8:
+ g_assert_cmpint(pt->value.s8, ==, pt_copy->value.s8);
+ break;
+ case PTYPE_S16:
+ g_assert_cmpint(pt->value.s16, ==, pt_copy->value.s16);
+ break;
+ case PTYPE_S32:
+ g_assert_cmpint(pt->value.s32, ==, pt_copy->value.s32);
+ break;
+ case PTYPE_S64:
+ g_assert_cmpint(pt->value.s64, ==, pt_copy->value.s64);
+ break;
+ case PTYPE_EOL:
+ g_assert_not_reached();
}
ops->cleanup(serialize_data);
--
2.26.2
next prev parent reply other threads:[~2020-12-19 11:05 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-19 10:54 [PULL 00/33] QAPI patches patches for 2020-12-19 Markus Armbruster
2020-12-19 10:55 ` [PULL 01/33] rocker: Revamp fp_port_get_info Markus Armbruster
2020-12-19 10:55 ` [PULL 02/33] migration: Refactor migrate_cap_add Markus Armbruster
2020-12-19 10:55 ` [PULL 03/33] qapi: Use QAPI_LIST_PREPEND() where possible Markus Armbruster
2020-12-19 10:55 ` [PULL 04/33] tests/check-qjson: Don't skip funny QNumber to JSON conversions Markus Armbruster
2020-12-19 10:55 ` [PULL 05/33] tests/check-qjson: Examine QNum more thoroughly Markus Armbruster
2020-12-19 10:55 ` [PULL 06/33] tests/check-qjson: Cover number 2^63 Markus Armbruster
2020-12-19 10:55 ` [PULL 07/33] tests/check-qjson: Replace redundant large_number() Markus Armbruster
2020-12-19 10:55 ` [PULL 08/33] tests/check-qnum: Cover qnum_to_string() for "unround" argument Markus Armbruster
2020-12-19 10:55 ` [PULL 09/33] qobject: Fix qnum_to_string() to use sufficient precision Markus Armbruster
2020-12-19 10:55 ` [PULL 10/33] test-string-output-visitor: Cover "unround" number Markus Armbruster
2020-12-19 10:55 ` [PULL 11/33] string-output-visitor: Fix to use sufficient precision Markus Armbruster
2020-12-19 10:55 ` [PULL 12/33] test-visitor-serialization: Drop insufficient precision workaround Markus Armbruster
2020-12-19 10:55 ` Markus Armbruster [this message]
2020-12-19 10:55 ` [PULL 14/33] hmp: Simplify how qmp_human_monitor_command() gets output Markus Armbruster
2020-12-19 10:55 ` [PULL 15/33] monitor: Use GString instead of QString for output buffer Markus Armbruster
2020-12-19 10:55 ` [PULL 16/33] qobject: Make qobject_to_json_pretty() take a pretty argument Markus Armbruster
2020-12-19 10:55 ` [PULL 17/33] qobject: Use GString instead of QString to accumulate JSON Markus Armbruster
2020-12-19 10:55 ` [PULL 18/33] qobject: Change qobject_to_json()'s value to GString Markus Armbruster
2020-12-19 10:55 ` [PULL 19/33] Revert "qstring: add qstring_free()" Markus Armbruster
2020-12-19 10:55 ` [PULL 20/33] hw/rdma: Replace QList by GQueue Markus Armbruster
2020-12-19 10:55 ` [PULL 21/33] qobject: Move internals to qobject-internal.h Markus Armbruster
2020-12-19 10:55 ` [PULL 22/33] qmp: Fix tracing of non-string command IDs Markus Armbruster
2020-12-19 10:55 ` [PULL 23/33] block: Avoid qobject_get_try_str() Markus Armbruster
2020-12-19 10:55 ` [PULL 24/33] Revert "qobject: let object_property_get_str() use new API" Markus Armbruster
2020-12-19 10:55 ` [PULL 25/33] qobject: Drop qobject_get_try_str() Markus Armbruster
2020-12-19 10:55 ` [PULL 26/33] qobject: Drop qstring_get_try_str() Markus Armbruster
2020-12-19 10:55 ` [PULL 27/33] qobject: Factor quoted_str() out of to_json() Markus Armbruster
2020-12-19 10:55 ` [PULL 28/33] qobject: Factor JSON writer out of qobject_to_json() Markus Armbruster
2020-12-19 10:55 ` [PULL 29/33] migration: Replace migration's JSON writer by the general one Markus Armbruster
2020-12-19 10:55 ` [PULL 30/33] json: Use GString instead of QString to accumulate strings Markus Armbruster
2020-12-19 10:55 ` [PULL 31/33] keyval: Use GString to accumulate value strings Markus Armbruster
2020-12-19 10:55 ` [PULL 32/33] block: Use GString instead of QString to build filenames Markus Armbruster
2020-12-19 10:55 ` [PULL 33/33] qobject: Make QString immutable Markus Armbruster
2020-12-19 11:24 ` [PULL 00/33] QAPI patches patches for 2020-12-19 no-reply
2021-01-01 16:56 ` Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201219105532.1734134-14-armbru@redhat.com \
--to=armbru@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).