diff options
author | Petri Lehtinen <petri@digip.org> | 2013-06-12 08:36:51 +0300 |
---|---|---|
committer | Petri Lehtinen <petri@digip.org> | 2013-06-12 08:36:53 +0300 |
commit | f639fbd2c329ef60ba05aabade529686871458e1 (patch) | |
tree | 5285ed5d02ad041ddbf4850d5ce3b6d4d95aa013 | |
parent | a38704df5877de5252d5aeb5a65e8ff662bed752 (diff) | |
download | jansson-f639fbd2c329ef60ba05aabade529686871458e1.zip jansson-f639fbd2c329ef60ba05aabade529686871458e1.tar.gz jansson-f639fbd2c329ef60ba05aabade529686871458e1.tar.bz2 |
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".
-rw-r--r-- | test/suites/api/test_load.c | 16 |
1 files 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() |