mirror of
https://github.com/DaveGamble/cJSON.git
synced 2024-12-25 20:30:50 +08:00
fix issue#327
This commit is contained in:
parent
6a848fce32
commit
446ff0d6cc
@ -27,6 +27,8 @@
|
||||
static void assert_print_number(const char *expected, double input)
|
||||
{
|
||||
unsigned char printed[1024];
|
||||
unsigned char new_buffer[26];
|
||||
unsigned int i = 0;
|
||||
cJSON item[1];
|
||||
printbuffer buffer = { 0, 0, 0, 0, 0, 0, { 0, 0, 0 } };
|
||||
buffer.buffer = printed;
|
||||
@ -34,11 +36,29 @@ static void assert_print_number(const char *expected, double input)
|
||||
buffer.offset = 0;
|
||||
buffer.noalloc = true;
|
||||
buffer.hooks = global_hooks;
|
||||
buffer.buffer = new_buffer;
|
||||
|
||||
memset(item, 0, sizeof(item));
|
||||
memset(new_buffer, 0, sizeof(new_buffer));
|
||||
cJSON_SetNumberValue(item, input);
|
||||
|
||||
TEST_ASSERT_TRUE_MESSAGE(print_number(item, &buffer), "Failed to print number.");
|
||||
|
||||
/* In MinGW or visual studio(before 2015),the exponten is represented using three digits,like:"1e-009","1e+017"
|
||||
* remove extra "0" to output "1e-09" or "1e+17",which makes testcase PASS */
|
||||
for(i = 0;i <sizeof(new_buffer);i++)
|
||||
{
|
||||
if(i >3 && new_buffer[i] =='0')
|
||||
{
|
||||
if((new_buffer[i-3] =='e' && new_buffer[i-2] == '-' && new_buffer[i] =='0') ||(new_buffer[i-2] =='e' && new_buffer[i-1] =='+'))
|
||||
{
|
||||
while(new_buffer[i] !='\0')
|
||||
{
|
||||
new_buffer[i] = new_buffer[i+1];
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
TEST_ASSERT_EQUAL_STRING_MESSAGE(expected, buffer.buffer, "Printed number is not as expected.");
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user