From f639fbd2c329ef60ba05aabade529686871458e1 Mon Sep 17 00:00:00 2001 From: Petri Lehtinen Date: Wed, 12 Jun 2013 08:36:51 +0300 Subject: [PATCH] Tweak the JSON_DECODE_INT_AS_REAL test introduced in #123 Only run the imprecision part if json_int_t is long long, otherwise the imprecision cannot be tested against json_int_t. Also, convert the double value to json_int_t before checking the imprecision, because otherwise the json_int_t is converted to double and the imprecision happens in the "wrong direction". --- test/suites/api/test_load.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/test/suites/api/test_load.c b/test/suites/api/test_load.c index 6eddb34..f5836bc 100644 --- a/test/suites/api/test_load.c +++ b/test/suites/api/test_load.c @@ -92,21 +92,25 @@ static void decode_int_as_real() json_t *json; json_error_t error; - // This number cannot be represented exactly by a double - const char *imprecise = "9007199254740993"; - json_int_t expected = 9007199254740992ll; + const char *imprecise; + json_int_t expected; json = json_loads("42", JSON_DECODE_INT_AS_REAL | JSON_DECODE_ANY, &error); if (!json || !json_is_real(json) || json_real_value(json) != 42.0) fail("json_load decode int as real failed - int"); json_decref(json); - // Tests that large numbers are handled correctly +#if JSON_INTEGER_IS_LONG_LONG + /* This number cannot be represented exactly by a double */ + imprecise = "9007199254740993"; + expected = 9007199254740992ll; + json = json_loads(imprecise, JSON_DECODE_INT_AS_REAL | JSON_DECODE_ANY, &error); - if (!json || !json_is_real(json) || expected != json_real_value(json)) - fail("json_load decode int as real failed - expected imprecision"); + if (!json || !json_is_real(json) || expected != (json_int_t)json_real_value(json)) + fail("json_load decode int as real failed - expected imprecision"); json_decref(json); +#endif } static void load_wrong_args()