@@ -426,6 +426,32 @@ test_snprintf(void **state)
426
426
#endif
427
427
}
428
428
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
+
429
455
int
430
456
main (void )
431
457
{
@@ -460,7 +486,8 @@ main(void)
460
486
cmocka_unit_test (test_buffer_gc_realloc ),
461
487
cmocka_unit_test (test_character_class ),
462
488
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 )
464
491
};
465
492
466
493
return cmocka_run_group_tests_name ("buffer" , tests , NULL , NULL );
0 commit comments