diff --git a/tests/unittests/tests-pktbuf/tests-pktbuf.c b/tests/unittests/tests-pktbuf/tests-pktbuf.c index 64d000b26ab127c9964b7de03b4c625fba7cc3c7..8f204afa85a9d79ab20bc88d4d68ea380e1c223a 100644 --- a/tests/unittests/tests-pktbuf/tests-pktbuf.c +++ b/tests/unittests/tests-pktbuf/tests-pktbuf.c @@ -653,6 +653,52 @@ static void test_pktbuf_realloc_data__success3(void) TEST_ASSERT(gnrc_pktbuf_is_empty()); } +static void test_pktbuf_merge_data__memfull(void) +{ + gnrc_pktsnip_t *pkt = gnrc_pktbuf_add(NULL, NULL, (GNRC_PKTBUF_SIZE / 4), + GNRC_NETTYPE_TEST); + + pkt = gnrc_pktbuf_add(pkt, NULL, (GNRC_PKTBUF_SIZE / 4) + 1, + GNRC_NETTYPE_TEST); + TEST_ASSERT_EQUAL_INT(ENOMEM, gnrc_pktbuf_merge(pkt)); + gnrc_pktbuf_release(pkt); + TEST_ASSERT(gnrc_pktbuf_is_empty()); +} + +static void test_pktbuf_merge_data__success1(void) +{ + gnrc_pktsnip_t *pkt = gnrc_pktbuf_add(NULL, NULL, 0, GNRC_NETTYPE_TEST); + + TEST_ASSERT_NOT_NULL(pkt); + TEST_ASSERT_NULL(pkt->data); + + TEST_ASSERT_EQUAL_INT(0, gnrc_pktbuf_merge(pkt)); + gnrc_pktbuf_release(pkt); + TEST_ASSERT(gnrc_pktbuf_is_empty()); +} + +static void test_pktbuf_merge_data__success2(void) +{ + gnrc_pktsnip_t *pkt = gnrc_pktbuf_add(NULL, TEST_STRING4, + sizeof(TEST_STRING4), + GNRC_NETTYPE_TEST); + + pkt = gnrc_pktbuf_add(pkt, TEST_STRING8, sizeof(TEST_STRING8), GNRC_NETTYPE_TEST); + pkt = gnrc_pktbuf_add(pkt, TEST_STRING16, sizeof(TEST_STRING16), GNRC_NETTYPE_TEST); + + TEST_ASSERT_EQUAL_INT(0, gnrc_pktbuf_merge(pkt)); + TEST_ASSERT_NULL(pkt->next); + TEST_ASSERT_EQUAL_STRING(TEST_STRING16, pkt->data); + TEST_ASSERT_EQUAL_STRING(TEST_STRING8, + (char *) pkt->data + sizeof(TEST_STRING16)); + TEST_ASSERT_EQUAL_STRING(TEST_STRING4, + (char *) pkt->data + sizeof(TEST_STRING16) + + sizeof(TEST_STRING8)); + gnrc_pktbuf_release(pkt); + TEST_ASSERT(gnrc_pktbuf_is_empty()); + TEST_ASSERT(gnrc_pktbuf_is_sane()); +} + static void test_pktbuf_hold__pkt_null(void) { gnrc_pktbuf_hold(NULL, 1); @@ -895,6 +941,9 @@ Test *tests_pktbuf_tests(void) new_TestFixture(test_pktbuf_realloc_data__success), new_TestFixture(test_pktbuf_realloc_data__success2), new_TestFixture(test_pktbuf_realloc_data__success3), + new_TestFixture(test_pktbuf_merge_data__memfull), + new_TestFixture(test_pktbuf_merge_data__success1), + new_TestFixture(test_pktbuf_merge_data__success2), new_TestFixture(test_pktbuf_hold__pkt_null), new_TestFixture(test_pktbuf_hold__pkt_external), new_TestFixture(test_pktbuf_hold__success),