Skip to content

Commit

Permalink
hexdump: fix format and add test
Browse files Browse the repository at this point in the history
  • Loading branch information
alfredh committed Sep 2, 2023
1 parent c5ad6ca commit 2524f20
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/fmt/hexdump.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void hexdump(FILE *f, const void *p, size_t len)

for (i=0; i < len; i += 16) {

(void)re_fprintf(f, "%08x ", i);
(void)re_fprintf(f, "%08zx ", i);

for (j=0; j<16; j++) {
const size_t pos = i+j;
Expand Down
13 changes: 13 additions & 0 deletions test/fmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -1123,3 +1123,16 @@ int test_fmt_str_wchar(void)
mem_deref(s2);
return err;
}


int test_fmt_hexdump(void)
{
const char buf[] =
"0lnmdj2ihickdspjkm2ffd0jcpbk5l1n"
"8abcjt5m950gxvkuvippcvt60me9z5zh"
;

hexdump(stdout, buf, str_len(buf));

return 0;
}
9 changes: 5 additions & 4 deletions test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,16 @@ static const struct test tests[] = {
TEST(test_dtmf),
TEST(test_fir),
TEST(test_fmt_gmtime),
TEST(test_fmt_hexdump),
TEST(test_fmt_human_time),
TEST(test_fmt_timestamp),
TEST(test_fmt_param),
TEST(test_fmt_pl),
TEST(test_fmt_pl_u32),
TEST(test_fmt_pl_u64),
TEST(test_fmt_pl_float),
TEST(test_fmt_pl_i32),
TEST(test_fmt_pl_i64),
TEST(test_fmt_pl_u32),
TEST(test_fmt_pl_u64),
TEST(test_fmt_pl_x3264),
TEST(test_fmt_pl_float),
TEST(test_fmt_print),
TEST(test_fmt_regex),
TEST(test_fmt_snprintf),
Expand All @@ -93,6 +93,7 @@ static const struct test tests[] = {
TEST(test_fmt_str_error),
TEST(test_fmt_str_itoa),
TEST(test_fmt_str_wchar),
TEST(test_fmt_timestamp),
TEST(test_fmt_unicode),
TEST(test_fmt_unicode_decode),
TEST(test_g711_alaw),
Expand Down
5 changes: 3 additions & 2 deletions test/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,16 +177,16 @@ int test_dsp(void);
int test_dtmf(void);
int test_fir(void);
int test_fmt_gmtime(void);
int test_fmt_timestamp(void);
int test_fmt_hexdump(void);
int test_fmt_human_time(void);
int test_fmt_param(void);
int test_fmt_pl(void);
int test_fmt_pl_float(void);
int test_fmt_pl_i32(void);
int test_fmt_pl_i64(void);
int test_fmt_pl_u32(void);
int test_fmt_pl_u64(void);
int test_fmt_pl_x3264(void);
int test_fmt_pl_float(void);
int test_fmt_print(void);
int test_fmt_regex(void);
int test_fmt_snprintf(void);
Expand All @@ -195,6 +195,7 @@ int test_fmt_str_bool(void);
int test_fmt_str_error(void);
int test_fmt_str_itoa(void);
int test_fmt_str_wchar(void);
int test_fmt_timestamp(void);
int test_fmt_unicode(void);
int test_fmt_unicode_decode(void);
int test_g711_alaw(void);
Expand Down

0 comments on commit 2524f20

Please sign in to comment.