Skip to content

Commit e4446ef

Browse files
committed
Add small unit test for buf_chomp
Change-Id: Ia0799189d45223e0b987a5a4da5be60404388f1f Signed-off-by: Arne Schwabe <[email protected]>
1 parent 8fa9064 commit e4446ef

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

tests/unit_tests/openvpn/test_buffer.c

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,32 @@ test_snprintf(void **state)
426426
#endif
427427
}
428428

429+
void
430+
test_buffer_chomp(void **state)
431+
{
432+
struct gc_arena gc = gc_new();
433+
struct buffer buf = alloc_buf_gc(1024, &gc);
434+
435+
const char test1[] = "There is a nice 1234 year old tree!\n\r";
436+
buf_write(&buf, test1, sizeof(test1));
437+
buf_chomp(&buf);
438+
/* Check that our own method agrees */
439+
assert_true(string_check_buf(&buf, CC_PRINT | CC_NULL, CC_CRLF));
440+
assert_string_equal(BSTR(&buf), "There is a nice 1234 year old tree!");
441+
442+
struct buffer buf2 = alloc_buf_gc(1024, &gc);
443+
const char test2[] = "CR_RESPONSE,MTIx\x0a\x00";
444+
buf_write(&buf2, test2, sizeof(test2));
445+
buf_chomp(&buf2);
446+
447+
buf_chomp(&buf2);
448+
/* Check that our own method agrees */
449+
assert_true(string_check_buf(&buf2, CC_PRINT | CC_NULL, CC_CRLF));
450+
assert_string_equal(BSTR(&buf2), "CR_RESPONSE,MTIx");
451+
452+
gc_free(&gc);
453+
}
454+
429455
int
430456
main(void)
431457
{
@@ -460,7 +486,8 @@ main(void)
460486
cmocka_unit_test(test_buffer_gc_realloc),
461487
cmocka_unit_test(test_character_class),
462488
cmocka_unit_test(test_character_string_mod_buf),
463-
cmocka_unit_test(test_snprintf)
489+
cmocka_unit_test(test_snprintf),
490+
cmocka_unit_test(test_buffer_chomp)
464491
};
465492

466493
return cmocka_run_group_tests_name("buffer", tests, NULL, NULL);

0 commit comments

Comments
 (0)