diff options
author | Markus Armbruster <armbru@redhat.com> | 2017-03-03 13:32:42 +0100 |
---|---|---|
committer | Markus Armbruster <armbru@redhat.com> | 2017-03-05 09:14:19 +0100 |
commit | 3d089cea0d32e2cb63604a98f4aa2028860502f0 (patch) | |
tree | ece0e14f3a15610d16b9099c8a979304ff9332fb | |
parent | 0f721d168da07b3d484c7354d16630f18f06cbf6 (diff) |
test-string-input-visitor: Improve list coverage
Lists with elements above INT64_MAX don't work (known bug). Empty
lists don't work (weird).
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <1488544368-30622-23-git-send-email-armbru@redhat.com>
-rw-r--r-- | tests/test-string-input-visitor.c | 85 |
1 files changed, 72 insertions, 13 deletions
diff --git a/tests/test-string-input-visitor.c b/tests/test-string-input-visitor.c index a32828cefb..72f8732f97 100644 --- a/tests/test-string-input-visitor.c +++ b/tests/test-string-input-visitor.c @@ -65,31 +65,90 @@ static void test_visitor_in_int(TestInputVisitorData *data, error_free_or_abort(&err); } +static void check_ilist(Visitor *v, int64_t *expected, size_t n) +{ + int64List *res = NULL; + int64List *tail; + int i; + + visit_type_int64List(v, NULL, &res, &error_abort); + tail = res; + for (i = 0; i < n; i++) { + g_assert(tail); + g_assert_cmpint(tail->value, ==, expected[i]); + tail = tail->next; + } + g_assert(!tail); + + qapi_free_int64List(res); +} + +static void check_ulist(Visitor *v, uint64_t *expected, size_t n) +{ + uint64List *res = NULL; + uint64List *tail; + int i; + + /* BUG: unsigned numbers above INT64_MAX don't work */ + for (i = 0; i < n; i++) { + if (expected[i] > INT64_MAX) { + Error *err = NULL; + visit_type_uint64List(v, NULL, &res, &err); + error_free_or_abort(&err); + return; + } + } + + visit_type_uint64List(v, NULL, &res, &error_abort); + tail = res; + for (i = 0; i < n; i++) { + g_assert(tail); + g_assert_cmpuint(tail->value, ==, expected[i]); + tail = tail->next; + } + g_assert(!tail); + + qapi_free_uint64List(res); +} + static void test_visitor_in_intList(TestInputVisitorData *data, const void *unused) { - int64_t value[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 20}; - int16List *res = NULL, *tmp; + /* Note: the visitor *sorts* ranges *unsigned* */ + int64_t expect1[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 20 }; + int64_t expect2[] = { 32767, -32768, -32767 }; + int64_t expect3[] = { INT64_MAX, INT64_MIN }; + uint64_t expect4[] = { UINT64_MAX }; Error *err = NULL; + int64List *res = NULL; Visitor *v; - int i = 0; + + /* Valid lists */ v = visitor_input_test_init(data, "1,2,0,2-4,20,5-9,1-8"); + check_ilist(v, expect1, ARRAY_SIZE(expect1)); - visit_type_int16List(v, NULL, &res, &error_abort); - tmp = res; - while (i < sizeof(value) / sizeof(value[0])) { - g_assert(tmp); - g_assert_cmpint(tmp->value, ==, value[i++]); - tmp = tmp->next; - } - g_assert(!tmp); + v = visitor_input_test_init(data, "32767,-32768--32767"); + check_ilist(v, expect2, ARRAY_SIZE(expect2)); + + v = visitor_input_test_init(data, + "-9223372036854775808,9223372036854775807"); + check_ilist(v, expect3, ARRAY_SIZE(expect3)); + + v = visitor_input_test_init(data, "18446744073709551615"); + check_ulist(v, expect4, ARRAY_SIZE(expect4)); + + /* Empty list is invalid (weird) */ + + v = visitor_input_test_init(data, ""); + visit_type_int64List(v, NULL, &res, &err); + error_free_or_abort(&err); - qapi_free_int16List(res); + /* Not a list */ v = visitor_input_test_init(data, "not an int list"); - visit_type_int16List(v, NULL, &res, &err); + visit_type_int64List(v, NULL, &res, &err); error_free_or_abort(&err); g_assert(!res); } |