未验证 提交 d31fdefa 编写于 作者: A Alanscut 提交者: GitHub

Merge pull request #412 from Alanscut/fix_issue_327

fix issue#327
......@@ -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.");
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册