Skip to content
This repository has been archived by the owner on Feb 18, 2023. It is now read-only.

Commit

Permalink
fmt: add test_fmt_str_itoa (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
sreimers authored Oct 7, 2022
1 parent d8674bc commit 4c58d74
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/fmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -1056,3 +1056,35 @@ int test_fmt_str_bool(void)

return err;
}


int test_fmt_str_itoa(void)
{
char buf[ITOA_BUFSZ];
char *s;
int err = 0;

s = str_itoa(0, buf, 10);
TEST_ASSERT(!str_casecmp(s, "0"));

s = str_itoa(42, buf, 10);
TEST_ASSERT(!str_casecmp(s, "42"));

s = str_itoa(UINT32_MAX, buf, 10);
TEST_ASSERT(!str_casecmp(s, "4294967295"));

s = str_itoa(UINT32_MAX, buf, 16);
TEST_ASSERT(!str_casecmp(s, "FFFFFFFF"));

s = str_itoa(23, buf, 2);
TEST_ASSERT(!str_casecmp(s, "10111"));

s = str_itoa(UINT32_MAX, buf, 2);
TEST_ASSERT(!str_casecmp(s, "11111111111111111111111111111111"));

out:
if (err)
DEBUG_WARNING("err itoa string: %s\n", s);

return err;
}
1 change: 1 addition & 0 deletions src/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ static const struct test tests[] = {
TEST(test_fmt_str),
TEST(test_fmt_str_bool),
TEST(test_fmt_str_error),
TEST(test_fmt_str_itoa),
TEST(test_fmt_unicode),
TEST(test_fmt_unicode_decode),
TEST(test_g711_alaw),
Expand Down
1 change: 1 addition & 0 deletions src/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ int test_fmt_snprintf(void);
int test_fmt_str(void);
int test_fmt_str_bool(void);
int test_fmt_str_error(void);
int test_fmt_str_itoa(void);
int test_fmt_unicode(void);
int test_fmt_unicode_decode(void);
int test_g711_alaw(void);
Expand Down

0 comments on commit 4c58d74

Please sign in to comment.