test: Handle cJSON_PrintPreallocated return values correctly

This commit is contained in:
Max Bruckner 2016-12-06 08:47:44 +07:00
parent 84b48121bb
commit d992cd46e6

4
test.c
View File

@ -123,7 +123,7 @@ static int print_preallocated(cJSON *root)
} }
/* Print to buffer */ /* Print to buffer */
if (cJSON_PrintPreallocated(root, buf, len, 1) != 0) { if (!cJSON_PrintPreallocated(root, buf, len, 1)) {
printf("cJSON_PrintPreallocated failed!\n"); printf("cJSON_PrintPreallocated failed!\n");
if (strcmp(out, buf) != 0) { if (strcmp(out, buf) != 0) {
printf("cJSON_PrintPreallocated not the same as cJSON_Print!\n"); printf("cJSON_PrintPreallocated not the same as cJSON_Print!\n");
@ -140,7 +140,7 @@ static int print_preallocated(cJSON *root)
printf("%s\n", buf); printf("%s\n", buf);
/* force it to fail */ /* force it to fail */
if (cJSON_PrintPreallocated(root, buf_fail, len_fail, 1) == 0) { if (cJSON_PrintPreallocated(root, buf_fail, len_fail, 1)) {
printf("cJSON_PrintPreallocated failed to show error with insufficient memory!\n"); printf("cJSON_PrintPreallocated failed to show error with insufficient memory!\n");
printf("cJSON_Print result:\n%s\n", out); printf("cJSON_Print result:\n%s\n", out);
printf("cJSON_PrintPreallocated result:\n%s\n", buf_fail); printf("cJSON_PrintPreallocated result:\n%s\n", buf_fail);