Skip to content

Commit

Permalink
Add long tests and _MIN/_MAX to test_snprintf
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtSin committed Oct 23, 2024
1 parent 62953e9 commit 5690c4e
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion tests/test_snprintf.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <stdio.h>
#include <string.h>
#include <limits.h>

#undef HAVE_VSNPRINTF
#undef HAVE_SNPRINTF
Expand All @@ -28,7 +29,14 @@ int main(void)
char *int_fmt[] = {"%-1.5d", "%1.5d", "%123.9d", "%5.5d",
"%10.5d", "% 10.5d", "%+22.33d", "%01.3d",
"%4d", "0x%x", "0x%04x", NULL};
int int_nums[] = {-1, 134, 91340, 341, 0203, 0x76543210, 0};
int int_nums[] = {-1, 134, 91340, 341, 0203,
0x76543210, INT_MIN, INT_MAX, 0};
char *long_fmt[] = {"%-1.5ld", "%1.5ld", "%123.9ld", "%5.5ld",
"%10.5ld", "% 10.5ld", "%+22.33ld", "%01.3ld",
"%4ld", "0x%lx", "0x%04lx", NULL};
long long_nums[] = {-1L, 134L, 91340L,
341L, 0203L, 0xFEDCBA9876543210L,
LONG_MIN, LONG_MAX, 0L};
int x, y;
int fail = 0;
int num = 0;
Expand Down Expand Up @@ -60,6 +68,19 @@ int main(void)
}
num++;
}

for (x = 0; long_fmt[x] != NULL; x++)
for (y = 0; long_nums[y] != 0; y++) {
strophe_snprintf(buf1, sizeof(buf1), long_fmt[x], long_nums[y]);
sprintf(buf2, long_fmt[x], long_nums[y]);
if (strcmp(buf1, buf2)) {
printf("xmpp_snprintf doesn't match Format: "
"%s\n\txmpp_snprintf = %s\n\tsprintf = %s\n",
long_fmt[x], buf1, buf2);
fail++;
}
num++;
}
printf("%d tests failed out of %d.\n", fail, num);
return fail != 0 ? 1 : 0;
}

0 comments on commit 5690c4e

Please sign in to comment.