chunk: Print chunks without separator if + modifier is used
This commit is contained in:
committed by
Andreas Steffen
parent
32a145fdbd
commit
f0c54e8c15
@@ -756,11 +756,12 @@ END_TEST
|
|||||||
static struct {
|
static struct {
|
||||||
chunk_t in;
|
chunk_t in;
|
||||||
char *out;
|
char *out;
|
||||||
|
char *out_plus;
|
||||||
} printf_hook_data[] = {
|
} printf_hook_data[] = {
|
||||||
{chunk_from_chars(), ""},
|
{chunk_from_chars(), "", ""},
|
||||||
{chunk_from_chars(0x00), "00"},
|
{chunk_from_chars(0x00), "00", "00"},
|
||||||
{chunk_from_chars(0x00, 0x01), "00:01"},
|
{chunk_from_chars(0x00, 0x01), "00:01", "0001"},
|
||||||
{chunk_from_chars(0x00, 0x01, 0x02), "00:01:02"},
|
{chunk_from_chars(0x00, 0x01, 0x02), "00:01:02", "000102"},
|
||||||
};
|
};
|
||||||
|
|
||||||
START_TEST(test_printf_hook_hash)
|
START_TEST(test_printf_hook_hash)
|
||||||
@@ -774,6 +775,17 @@ START_TEST(test_printf_hook_hash)
|
|||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
|
START_TEST(test_printf_hook_plus)
|
||||||
|
{
|
||||||
|
char buf[16];
|
||||||
|
int len;
|
||||||
|
|
||||||
|
len = snprintf(buf, sizeof(buf), "%+B", &printf_hook_data[_i].in);
|
||||||
|
ck_assert(len >= 0 && len < sizeof(buf));
|
||||||
|
ck_assert_str_eq(buf, printf_hook_data[_i].out_plus);
|
||||||
|
}
|
||||||
|
END_TEST
|
||||||
|
|
||||||
START_TEST(test_printf_hook)
|
START_TEST(test_printf_hook)
|
||||||
{
|
{
|
||||||
char buf[128], mem[128];
|
char buf[128], mem[128];
|
||||||
@@ -856,6 +868,7 @@ Suite *chunk_suite_create()
|
|||||||
|
|
||||||
tc = tcase_create("printf_hook");
|
tc = tcase_create("printf_hook");
|
||||||
tcase_add_loop_test(tc, test_printf_hook_hash, 0, countof(printf_hook_data));
|
tcase_add_loop_test(tc, test_printf_hook_hash, 0, countof(printf_hook_data));
|
||||||
|
tcase_add_loop_test(tc, test_printf_hook_plus, 0, countof(printf_hook_data));
|
||||||
tcase_add_loop_test(tc, test_printf_hook, 0, countof(printf_hook_data));
|
tcase_add_loop_test(tc, test_printf_hook, 0, countof(printf_hook_data));
|
||||||
suite_add_tcase(s, tc);
|
suite_add_tcase(s, tc);
|
||||||
|
|
||||||
|
|||||||
@@ -797,7 +797,7 @@ int chunk_printf_hook(printf_hook_data_t *data, printf_hook_spec_t *spec,
|
|||||||
chunk_t copy = *chunk;
|
chunk_t copy = *chunk;
|
||||||
int written = 0;
|
int written = 0;
|
||||||
|
|
||||||
if (!spec->hash)
|
if (!spec->hash && !spec->plus)
|
||||||
{
|
{
|
||||||
u_int chunk_len = chunk->len;
|
u_int chunk_len = chunk->len;
|
||||||
const void *new_args[] = {&chunk->ptr, &chunk_len};
|
const void *new_args[] = {&chunk->ptr, &chunk_len};
|
||||||
@@ -810,7 +810,7 @@ int chunk_printf_hook(printf_hook_data_t *data, printf_hook_spec_t *spec,
|
|||||||
{
|
{
|
||||||
first = FALSE;
|
first = FALSE;
|
||||||
}
|
}
|
||||||
else
|
else if (!spec->plus)
|
||||||
{
|
{
|
||||||
written += print_in_hook(data, ":");
|
written += print_in_hook(data, ":");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -368,6 +368,7 @@ u_int64_t chunk_mac(chunk_t chunk, u_char *key);
|
|||||||
* Arguments are:
|
* Arguments are:
|
||||||
* chunk_t *chunk
|
* chunk_t *chunk
|
||||||
* Use #-modifier to print a compact version
|
* Use #-modifier to print a compact version
|
||||||
|
* Use +-modifier to print a compact version without separator
|
||||||
*/
|
*/
|
||||||
int chunk_printf_hook(printf_hook_data_t *data, printf_hook_spec_t *spec,
|
int chunk_printf_hook(printf_hook_data_t *data, printf_hook_spec_t *spec,
|
||||||
const void *const *args);
|
const void *const *args);
|
||||||
|
|||||||
Reference in New Issue
Block a user