2014-09-05 18:21:58 +02:00
|
|
|
/*
|
2015-02-08 19:19:22 +01:00
|
|
|
* Copyright (C) 2014 Martine Lenders <mlenders@inf.fu-berlin.de>
|
2014-09-05 18:21:58 +02:00
|
|
|
*
|
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
|
|
* General Public License v2.1. See the file LICENSE in the top level
|
|
|
|
* directory for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @file tests-pktqueue.c
|
|
|
|
*/
|
|
|
|
#include <string.h>
|
|
|
|
|
2014-11-27 22:30:14 +01:00
|
|
|
#include "embUnit.h"
|
2014-09-05 18:21:58 +02:00
|
|
|
|
2015-01-13 04:26:30 +01:00
|
|
|
#include "pkt.h"
|
2014-09-05 18:21:58 +02:00
|
|
|
#include "pktqueue.h"
|
|
|
|
|
|
|
|
#include "tests-pktqueue.h"
|
|
|
|
|
|
|
|
#define Q_LEN (4)
|
|
|
|
|
|
|
|
static pktqueue_t q = PKTQUEUE_INIT;
|
|
|
|
static pktqueue_node_t qe[Q_LEN];
|
|
|
|
|
|
|
|
static void set_up(void)
|
|
|
|
{
|
|
|
|
pktqueue_init(&q);
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < Q_LEN; ++i) {
|
|
|
|
pktqueue_node_init(&(qe[i]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_pktqueue_remove_head_empty(void)
|
|
|
|
{
|
|
|
|
pktqueue_t *root = &q;
|
|
|
|
pktqueue_node_t *res;
|
|
|
|
|
|
|
|
res = pktqueue_remove_head(root);
|
|
|
|
|
|
|
|
TEST_ASSERT_NULL(res);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_pktqueue_remove_head_one(void)
|
|
|
|
{
|
|
|
|
pktqueue_t *root = &q;
|
|
|
|
pktqueue_node_t *elem = &(qe[1]), *res;
|
|
|
|
|
2015-01-13 04:26:30 +01:00
|
|
|
elem->data = (pkt_t *)62801;
|
2014-09-05 18:21:58 +02:00
|
|
|
|
|
|
|
pktqueue_add(root, elem);
|
|
|
|
|
|
|
|
res = pktqueue_remove_head(root);
|
|
|
|
|
|
|
|
TEST_ASSERT(res == elem);
|
2015-01-13 04:26:30 +01:00
|
|
|
TEST_ASSERT(((pkt_t *)62801) == res->data);
|
2014-09-05 18:21:58 +02:00
|
|
|
|
|
|
|
res = pktqueue_remove_head(root);
|
|
|
|
|
|
|
|
TEST_ASSERT_NULL(res);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_pktqueue_add_one(void)
|
|
|
|
{
|
|
|
|
pktqueue_t *root = &q;
|
|
|
|
pktqueue_node_t *elem = &(qe[1]);
|
|
|
|
|
2015-01-13 04:26:30 +01:00
|
|
|
elem->data = (pkt_t *)7317;
|
2014-09-05 18:21:58 +02:00
|
|
|
elem->priority = 713643658;
|
|
|
|
|
|
|
|
pktqueue_add(root, elem);
|
|
|
|
|
|
|
|
TEST_ASSERT(root->first == elem);
|
2015-01-13 04:26:30 +01:00
|
|
|
TEST_ASSERT(((pkt_t *)7317) == root->first->data);
|
2014-09-05 18:21:58 +02:00
|
|
|
TEST_ASSERT_EQUAL_INT(713643658, root->first->priority);
|
|
|
|
|
|
|
|
TEST_ASSERT_NULL(root->first->next);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_pktqueue_add_two_equal(void)
|
|
|
|
{
|
|
|
|
pktqueue_t *root = &q;
|
|
|
|
pktqueue_node_t *elem1 = &(qe[1]), *elem2 = &(qe[2]);
|
|
|
|
|
2015-01-13 04:26:30 +01:00
|
|
|
elem1->data = (pkt_t *)27088;
|
2014-09-05 18:21:58 +02:00
|
|
|
elem1->priority = 14202;
|
|
|
|
|
2015-01-13 04:26:30 +01:00
|
|
|
elem2->data = (pkt_t *)4356;
|
2014-09-05 18:21:58 +02:00
|
|
|
elem2->priority = 14202;
|
|
|
|
|
|
|
|
pktqueue_add(root, elem1);
|
|
|
|
pktqueue_add(root, elem2);
|
|
|
|
|
2014-11-25 21:52:28 +01:00
|
|
|
TEST_ASSERT(root->first == elem1);
|
2015-01-13 04:26:30 +01:00
|
|
|
TEST_ASSERT(((pkt_t *)27088) == root->first->data);
|
2014-09-05 18:21:58 +02:00
|
|
|
TEST_ASSERT_EQUAL_INT(14202, root->first->priority);
|
|
|
|
|
2014-11-25 21:52:28 +01:00
|
|
|
TEST_ASSERT(root->first->next == elem2);
|
2015-01-13 04:26:30 +01:00
|
|
|
TEST_ASSERT(((pkt_t *)4356) == root->first->next->data);
|
2014-09-05 18:21:58 +02:00
|
|
|
TEST_ASSERT_EQUAL_INT(14202, root->first->next->priority);
|
|
|
|
|
|
|
|
TEST_ASSERT_NULL(root->first->next->next);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_pktqueue_add_two_distinct(void)
|
|
|
|
{
|
|
|
|
pktqueue_t *root = &q;
|
|
|
|
pktqueue_node_t *elem1 = &(qe[1]), *elem2 = &(qe[2]);
|
|
|
|
|
2015-01-13 04:26:30 +01:00
|
|
|
elem1->data = (pkt_t *)46421;
|
2014-09-05 18:21:58 +02:00
|
|
|
elem1->priority = 4567;
|
|
|
|
|
2015-01-13 04:26:30 +01:00
|
|
|
elem2->data = (pkt_t *)43088;
|
2014-09-05 18:21:58 +02:00
|
|
|
elem2->priority = 1234;
|
|
|
|
|
|
|
|
pktqueue_add(root, elem1);
|
|
|
|
pktqueue_add(root, elem2);
|
|
|
|
|
|
|
|
TEST_ASSERT(root->first == elem2);
|
2015-01-13 04:26:30 +01:00
|
|
|
TEST_ASSERT(((pkt_t *)43088) == root->first->data);
|
2014-09-05 18:21:58 +02:00
|
|
|
TEST_ASSERT_EQUAL_INT(1234, root->first->priority);
|
|
|
|
|
|
|
|
TEST_ASSERT(root->first->next == elem1);
|
2015-01-13 04:26:30 +01:00
|
|
|
TEST_ASSERT(((pkt_t *)46421) == root->first->next->data);
|
2014-09-05 18:21:58 +02:00
|
|
|
TEST_ASSERT_EQUAL_INT(4567, root->first->next->priority);
|
|
|
|
|
|
|
|
TEST_ASSERT_NULL(root->first->next->next);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_pktqueue_remove_one(void)
|
|
|
|
{
|
|
|
|
pktqueue_t *root = &q;
|
|
|
|
pktqueue_node_t *elem1 = &(qe[1]), *elem2 = &(qe[2]), *elem3 = &(qe[3]);
|
|
|
|
|
|
|
|
pktqueue_add(root, elem1);
|
|
|
|
pktqueue_add(root, elem2);
|
|
|
|
pktqueue_add(root, elem3);
|
|
|
|
pktqueue_remove(root, elem2);
|
|
|
|
|
|
|
|
TEST_ASSERT(root->first == elem1);
|
|
|
|
TEST_ASSERT(root->first->next == elem3);
|
|
|
|
TEST_ASSERT_NULL(root->first->next->next);
|
|
|
|
}
|
|
|
|
|
|
|
|
Test *tests_pktqueue_tests(void)
|
|
|
|
{
|
|
|
|
EMB_UNIT_TESTFIXTURES(fixtures) {
|
|
|
|
new_TestFixture(test_pktqueue_remove_head_empty),
|
|
|
|
new_TestFixture(test_pktqueue_remove_head_one),
|
|
|
|
new_TestFixture(test_pktqueue_add_one),
|
|
|
|
new_TestFixture(test_pktqueue_add_two_equal),
|
|
|
|
new_TestFixture(test_pktqueue_add_two_distinct),
|
|
|
|
new_TestFixture(test_pktqueue_remove_one),
|
|
|
|
};
|
|
|
|
|
|
|
|
EMB_UNIT_TESTCALLER(pktqueue_tests, set_up, NULL, fixtures);
|
|
|
|
|
|
|
|
return (Test *)&pktqueue_tests;
|
|
|
|
}
|
|
|
|
|
|
|
|
void tests_pktqueue(void)
|
|
|
|
{
|
|
|
|
TESTS_RUN(tests_pktqueue_tests());
|
|
|
|
}
|
|
|
|
/** @} */
|