mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
tests/unittests: add tests for new pkt operations
This commit is contained in:
parent
9e4dd8e451
commit
3be898757f
@ -35,6 +35,38 @@
|
||||
#define _INIT_ELEM_STATIC_TYPE(_type, _next) \
|
||||
{ .users = 1, .next = (_next), .data = NULL, .size = 0, .type = (_type) }
|
||||
|
||||
static void test_pkt_prev_snip__NULL_NULL(void)
|
||||
{
|
||||
TEST_ASSERT_NULL(gnrc_pkt_prev_snip(NULL, NULL));
|
||||
}
|
||||
|
||||
static void test_pkt_prev_snip__pkt_NULL(void)
|
||||
{
|
||||
gnrc_pktsnip_t pkt = _INIT_ELEM(SIZE_MAX, NULL, NULL);
|
||||
gnrc_pktsnip_t *res;
|
||||
|
||||
res = gnrc_pkt_prev_snip(&pkt, NULL);
|
||||
TEST_ASSERT((&pkt) == res);
|
||||
}
|
||||
|
||||
static void test_pkt_prev_snip__NULL_snip(void)
|
||||
{
|
||||
gnrc_pktsnip_t snip = _INIT_ELEM(SIZE_MAX, NULL, NULL);
|
||||
|
||||
TEST_ASSERT_NULL(gnrc_pkt_prev_snip(NULL, &snip));
|
||||
}
|
||||
|
||||
static void test_pkt_prev_snip__pkt_snip(void)
|
||||
{
|
||||
gnrc_pktsnip_t snip1 = _INIT_ELEM(SIZE_MAX, NULL, NULL);
|
||||
gnrc_pktsnip_t snip2 = _INIT_ELEM(SIZE_MAX, NULL, &snip1);
|
||||
gnrc_pktsnip_t pkt = _INIT_ELEM(SIZE_MAX, NULL, &snip2);
|
||||
gnrc_pktsnip_t *res;
|
||||
|
||||
res = gnrc_pkt_prev_snip(&pkt, &snip1);
|
||||
TEST_ASSERT((&snip2) == res);
|
||||
}
|
||||
|
||||
static void test_pkt_len__NULL(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL_INT(0, gnrc_pkt_len(NULL));
|
||||
@ -93,6 +125,80 @@ static void test_pkt_len__3_elem(void)
|
||||
TEST_ASSERT_EQUAL_INT(sizeof(TEST_STRING8), gnrc_pkt_len(&snip1));
|
||||
}
|
||||
|
||||
static void test_pkt_append(void)
|
||||
{
|
||||
gnrc_pktsnip_t snip1 = _INIT_ELEM(SIZE_MAX, NULL, NULL);
|
||||
gnrc_pktsnip_t snip2 = _INIT_ELEM(SIZE_MAX, NULL, NULL);
|
||||
gnrc_pktsnip_t pkt = _INIT_ELEM(SIZE_MAX, NULL, NULL);
|
||||
gnrc_pktsnip_t *res = &pkt;
|
||||
|
||||
res = gnrc_pkt_append(res, &snip1);
|
||||
TEST_ASSERT((&pkt) == res);
|
||||
TEST_ASSERT((&snip1) == res->next);
|
||||
TEST_ASSERT_NULL(res->next->next);
|
||||
res = gnrc_pkt_append(res, &snip2);
|
||||
TEST_ASSERT((&pkt) == res);
|
||||
TEST_ASSERT((&snip1) == res->next);
|
||||
TEST_ASSERT((&snip2) == res->next->next);
|
||||
}
|
||||
|
||||
static void test_pkt_prepend(void)
|
||||
{
|
||||
gnrc_pktsnip_t snip1 = _INIT_ELEM(SIZE_MAX, NULL, NULL);
|
||||
gnrc_pktsnip_t snip2 = _INIT_ELEM(SIZE_MAX, NULL, NULL);
|
||||
gnrc_pktsnip_t pkt = _INIT_ELEM(SIZE_MAX, NULL, NULL);
|
||||
gnrc_pktsnip_t *res = &pkt;
|
||||
|
||||
res = gnrc_pkt_prepend(res, &snip1);
|
||||
TEST_ASSERT((&snip1) == res);
|
||||
TEST_ASSERT((&pkt) == res->next);
|
||||
TEST_ASSERT_NULL(res->next->next);
|
||||
res = gnrc_pkt_prepend(res, &snip2);
|
||||
TEST_ASSERT((&snip2) == res);
|
||||
TEST_ASSERT((&snip1) == res->next);
|
||||
TEST_ASSERT((&pkt) == res->next->next);
|
||||
}
|
||||
|
||||
static void test_pkt_delete__NULL(void)
|
||||
{
|
||||
gnrc_pktsnip_t snip1 = _INIT_ELEM(SIZE_MAX, NULL, NULL);
|
||||
gnrc_pktsnip_t snip2 = _INIT_ELEM(SIZE_MAX, NULL, NULL);
|
||||
gnrc_pktsnip_t pkt = _INIT_ELEM(SIZE_MAX, NULL, NULL);
|
||||
gnrc_pktsnip_t *res = &pkt;
|
||||
|
||||
res = gnrc_pkt_prepend(res, &snip1);
|
||||
res = gnrc_pkt_prepend(res, &snip2);
|
||||
TEST_ASSERT((&snip2) == res);
|
||||
TEST_ASSERT((&snip1) == res->next);
|
||||
TEST_ASSERT((&pkt) == res->next->next);
|
||||
res = gnrc_pkt_delete(res, NULL);
|
||||
/* pkt did not change */
|
||||
TEST_ASSERT((&snip2) == res);
|
||||
TEST_ASSERT((&snip1) == res->next);
|
||||
TEST_ASSERT((&pkt) == res->next->next);
|
||||
}
|
||||
|
||||
static void test_pkt_delete(void)
|
||||
{
|
||||
gnrc_pktsnip_t snip1 = _INIT_ELEM(SIZE_MAX, NULL, NULL);
|
||||
gnrc_pktsnip_t snip2 = _INIT_ELEM(SIZE_MAX, NULL, NULL);
|
||||
gnrc_pktsnip_t pkt = _INIT_ELEM(SIZE_MAX, NULL, NULL);
|
||||
gnrc_pktsnip_t *res = &pkt;
|
||||
|
||||
res = gnrc_pkt_prepend(res, &snip1);
|
||||
res = gnrc_pkt_prepend(res, &snip2);
|
||||
TEST_ASSERT((&snip2) == res);
|
||||
TEST_ASSERT((&snip1) == res->next);
|
||||
TEST_ASSERT((&pkt) == res->next->next);
|
||||
res = gnrc_pkt_delete(res, &snip1);
|
||||
TEST_ASSERT((&snip2) == res);
|
||||
TEST_ASSERT((&pkt) == res->next);
|
||||
res = gnrc_pkt_delete(res, &snip2);
|
||||
TEST_ASSERT((&pkt) == res);
|
||||
res = gnrc_pkt_delete(res, &pkt);
|
||||
TEST_ASSERT_NULL(res);
|
||||
}
|
||||
|
||||
static void test_pkt_len_upto__NULL(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL_INT(0, gnrc_pkt_len_upto(NULL, GNRC_NETTYPE_TEST));
|
||||
@ -198,6 +304,10 @@ static void test_pkt_equals_iolist(void)
|
||||
Test *tests_pkt_tests(void)
|
||||
{
|
||||
EMB_UNIT_TESTFIXTURES(fixtures) {
|
||||
new_TestFixture(test_pkt_prev_snip__NULL_NULL),
|
||||
new_TestFixture(test_pkt_prev_snip__pkt_NULL),
|
||||
new_TestFixture(test_pkt_prev_snip__NULL_snip),
|
||||
new_TestFixture(test_pkt_prev_snip__pkt_snip),
|
||||
new_TestFixture(test_pkt_len__NULL),
|
||||
new_TestFixture(test_pkt_len__1_elem__size_MAX),
|
||||
new_TestFixture(test_pkt_len__1_elem__size_0),
|
||||
@ -205,6 +315,10 @@ Test *tests_pkt_tests(void)
|
||||
new_TestFixture(test_pkt_len__2_elem),
|
||||
new_TestFixture(test_pkt_len__2_elem__overflow),
|
||||
new_TestFixture(test_pkt_len__3_elem),
|
||||
new_TestFixture(test_pkt_append),
|
||||
new_TestFixture(test_pkt_prepend),
|
||||
new_TestFixture(test_pkt_delete__NULL),
|
||||
new_TestFixture(test_pkt_delete),
|
||||
new_TestFixture(test_pkt_len_upto__NULL),
|
||||
new_TestFixture(test_pkt_len_upto__not_in_list),
|
||||
new_TestFixture(test_pkt_len_upto__in_list),
|
||||
|
Loading…
Reference in New Issue
Block a user