[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 10/10] test-visitor-serialization: Clean up test_primitives()
From: |
Markus Armbruster |
Subject: |
[PATCH 10/10] test-visitor-serialization: Clean up test_primitives() |
Date: |
Thu, 10 Dec 2020 17:14:52 +0100 |
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>
---
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 19b72571bb..7eab18b7c6 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
- [PATCH 00/10] Fix floating-point -> text conversion precision, Markus Armbruster, 2020/12/10
- [PATCH 09/10] test-visitor-serialization: Drop insufficient precision workaround, Markus Armbruster, 2020/12/10
- [PATCH 05/10] tests/check-qnum: Cover qnum_to_string() for "unround" argument, Markus Armbruster, 2020/12/10
- [PATCH 03/10] tests/check-qjson: Cover number 2^63, Markus Armbruster, 2020/12/10
- [PATCH 07/10] test-string-output-visitor: Cover "unround" number, Markus Armbruster, 2020/12/10
- [PATCH 02/10] tests/check-qjson: Examine QNum more thoroughly, Markus Armbruster, 2020/12/10
- [PATCH 01/10] tests/check-qjson: Don't skip funny QNumber to JSON conversions, Markus Armbruster, 2020/12/10
- [PATCH 04/10] tests/check-qjson: Replace redundant large_number(), Markus Armbruster, 2020/12/10
- [PATCH 10/10] test-visitor-serialization: Clean up test_primitives(),
Markus Armbruster <=
- [PATCH 08/10] string-output-visitor: Fix to use sufficient precision, Markus Armbruster, 2020/12/10
- [PATCH 06/10] qobject: Fix qnum_to_string() to use sufficient precision, Markus Armbruster, 2020/12/10
- Re: [PATCH 00/10] Fix floating-point -> text conversion precision, no-reply, 2020/12/10