Fix tests for all combinations of int/longlong and double/float

This commit is contained in:
No Default Name
2022-04-28 22:05:41 +02:00
parent 5cdc8d4c27
commit 882361c428
8 changed files with 83 additions and 6 deletions

View File

@@ -43,7 +43,7 @@ static void assert_is_number(cJSON *number_item)
assert_has_no_string(number_item);
}
static void assert_parse_number(const char *string, cJSON_int integer, double real)
static void assert_parse_number(const char *string, cJSON_int integer, cJSON_float real)
{
parse_buffer buffer = { 0, 0, 0, 0, { 0, 0, 0 } };
buffer.content = (const unsigned char*)string;
@@ -56,7 +56,11 @@ static void assert_parse_number(const char *string, cJSON_int integer, double re
#else
TEST_ASSERT_EQUAL_INT(integer, item->valueint);
#endif
#ifdef CJSON_FLOAT_USE_FLOAT
TEST_ASSERT_EQUAL_FLOAT(real, item->valuedouble);
#else
TEST_ASSERT_EQUAL_DOUBLE(real, item->valuedouble);
#endif
}
static void parse_number_should_parse_zero(void)
@@ -96,11 +100,15 @@ static void parse_number_should_parse_positive_reals(void)
assert_parse_number("10e-10", 0, 10e-10);
assert_parse_number("10E-10", 0, 10e-10);
#ifdef CJSON_INT_USE_LONGLONG
#ifndef CJSON_FLOAT_USE_FLOAT
assert_parse_number("10e10", 100000000000LL, 10e10);
#endif
#endif
assert_parse_number("10e20", CJSON_INT_MAX, 10e20);
#ifndef CJSON_FLOAT_USE_FLOAT
assert_parse_number("123e+127", CJSON_INT_MAX, 123e127);
assert_parse_number("123e-128", 0, 123e-128);
#endif
}
static void parse_number_should_parse_negative_reals(void)
@@ -109,11 +117,15 @@ static void parse_number_should_parse_negative_reals(void)
assert_parse_number("-10e-10", 0, -10e-10);
assert_parse_number("-10E-10", 0, -10e-10);
#ifdef CJSON_INT_USE_LONGLONG
#ifndef CJSON_FLOAT_USE_FLOAT
assert_parse_number("-10e10", -100000000000LL, -10e10);
#endif
#endif
assert_parse_number("-10e20", CJSON_INT_MIN, -10e20);
#ifndef CJSON_FLOAT_USE_FLOAT
assert_parse_number("-123e+127", CJSON_INT_MIN, -123e127);
assert_parse_number("-123e-128", 0, -123e-128);
#endif
}
int CJSON_CDECL main(void)