From 17b3c3aca1290a3f2c20a0858d4d499a17752ced Mon Sep 17 00:00:00 2001 From: Jacob Erlbeck Date: Fri, 27 Nov 2015 13:26:20 +0100 Subject: msgb/test: Add test case for error cases Include a test for msgb_trim. Sponsored-by: On-Waves ehf --- tests/msgb/msgb_test.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'tests/msgb/msgb_test.c') diff --git a/tests/msgb/msgb_test.c b/tests/msgb/msgb_test.c index e6cb33ec..8839a2ed 100644 --- a/tests/msgb/msgb_test.c +++ b/tests/msgb/msgb_test.c @@ -121,6 +121,27 @@ static void test_msgb_api() msgb_free(msg); } +static void test_msgb_api_errors() +{ + struct msgb *msg = msgb_alloc_headroom(4096, 128, "data"); + volatile int e = 0; + int rc; + + printf("Testing the msgb API error handling\n"); + + osmo_set_panic_handler(osmo_panic_raise); + + if (OSMO_PANIC_TRY(&e)) + msgb_trim(msg, -1); + OSMO_ASSERT(e != 0); + + rc = msgb_trim(msg, 4096 + 500); + OSMO_ASSERT(rc == -1); + + msgb_free(msg); + osmo_set_panic_handler(NULL); +} + static void test_msgb_copy() { struct msgb *msg = msgb_alloc_headroom(4096, 128, "data"); @@ -263,6 +284,7 @@ int main(int argc, char **argv) osmo_init_logging(&info); test_msgb_api(); + test_msgb_api_errors(); test_msgb_copy(); test_msgb_resize_area(); -- cgit v1.2.3