aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@redhat.com>2017-06-07 20:35:56 +0400
committerMarkus Armbruster <armbru@redhat.com>2017-06-19 14:56:29 +0200
commitc1214ad3dcf392ca3d9354c8a811c76f0d4c45ce (patch)
tree605ec9de36274713f771d1a1c8bd42e1cee407e8 /tests
parent7c877c80308a8d0166029494e2e236c1f95336e8 (diff)
tests: add more int/number ranges checks
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-Id: <20170607163635.17635-5-marcandre.lureau@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> [test_visitor_in_uint() tightened slightly] Signed-off-by: Markus Armbruster <armbru@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/test-qobject-input-visitor.c39
1 files changed, 38 insertions, 1 deletions
diff --git a/tests/test-qobject-input-visitor.c b/tests/test-qobject-input-visitor.c
index 83d663d11d..4dc9c03970 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,6 +115,9 @@ 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,
@@ -121,6 +125,8 @@ static void test_visitor_in_uint(TestInputVisitorData *data,
{
Error *err = NULL;
uint64_t res = 0;
+ int64_t i64;
+ double dbl;
int value = 42;
Visitor *v;
@@ -129,8 +135,13 @@ 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);
@@ -142,6 +153,9 @@ static void test_visitor_in_uint(TestInputVisitorData *data,
visit_type_uint64(v, NULL, &res, &err);
error_free_or_abort(&err);
+
+ visit_type_number(v, NULL, &dbl, &error_abort);
+ g_assert_cmpfloat(dbl, ==, 18446744073709552000.0);
}
static void test_visitor_in_int_overflow(TestInputVisitorData *data,
@@ -260,6 +274,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)
{
@@ -1253,6 +1288,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",