mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-18 12:52:44 +01:00
Implement core unittests
This commit is contained in:
parent
b06eaeeefd
commit
1b042e75c4
12
tests/unittests/doc.txt
Normal file
12
tests/unittests/doc.txt
Normal file
@ -0,0 +1,12 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Freie Universität Berlin
|
||||
*
|
||||
* This file subject to the terms and conditions of the GNU Lesser General
|
||||
* Public License. See the file LICENSE in the top level directory for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup unittests Unittests
|
||||
* @brief Application for unittests of RIOT.
|
||||
*/
|
81
tests/unittests/tests-core-atomic.c
Normal file
81
tests/unittests/tests-core-atomic.c
Normal file
@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Martin Lenders
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser General
|
||||
* Public License. See the file LICENSE in the top level directory for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
#include "embUnit/embUnit.h"
|
||||
|
||||
#include "atomic.h"
|
||||
|
||||
#include "tests-core.h"
|
||||
|
||||
static void test_atomic_set_return_null_null(void)
|
||||
{
|
||||
unsigned int res = 0;
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(0, atomic_set_return(&res, 0));
|
||||
TEST_ASSERT_EQUAL_INT(0, res);
|
||||
}
|
||||
|
||||
static void test_atomic_set_return_one_null(void)
|
||||
{
|
||||
unsigned int res = 1;
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(1, atomic_set_return(&res, 0));
|
||||
TEST_ASSERT_EQUAL_INT(0, res);
|
||||
}
|
||||
|
||||
static void test_atomic_set_return_null_one(void)
|
||||
{
|
||||
unsigned int res = 0;
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(0, atomic_set_return(&res, 1));
|
||||
TEST_ASSERT_EQUAL_INT(1, res);
|
||||
}
|
||||
|
||||
static void test_atomic_set_return_limit_null(void)
|
||||
{
|
||||
unsigned int res = UINT_MAX;
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(UINT_MAX, atomic_set_return(&res, 0));
|
||||
TEST_ASSERT_EQUAL_INT(0, res);
|
||||
}
|
||||
|
||||
static void test_atomic_set_return_null_limit(void)
|
||||
{
|
||||
unsigned int res = 0;
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(0, atomic_set_return(&res, UINT_MAX));
|
||||
TEST_ASSERT_EQUAL_INT(UINT_MAX, res);
|
||||
}
|
||||
|
||||
static void test_atomic_set_return_null_random(void)
|
||||
{
|
||||
unsigned int res = 0;
|
||||
unsigned int r = 45; /* XXX: decided by fair dice-roll ;-) */
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(0, atomic_set_return(&res, r));
|
||||
TEST_ASSERT_EQUAL_INT(r, res);
|
||||
}
|
||||
|
||||
Test *tests_core_atomic_tests(void)
|
||||
{
|
||||
EMB_UNIT_TESTFIXTURES(fixtures) {
|
||||
new_TestFixture(test_atomic_set_return_null_null),
|
||||
new_TestFixture(test_atomic_set_return_one_null),
|
||||
new_TestFixture(test_atomic_set_return_null_one),
|
||||
new_TestFixture(test_atomic_set_return_limit_null),
|
||||
new_TestFixture(test_atomic_set_return_null_limit),
|
||||
new_TestFixture(test_atomic_set_return_null_random),
|
||||
};
|
||||
|
||||
EMB_UNIT_TESTCALLER(core_atomic_tests, NULL, NULL,
|
||||
fixtures);
|
||||
|
||||
return (Test *)&core_atomic_tests;
|
||||
}
|
230
tests/unittests/tests-core-bitarithm.c
Normal file
230
tests/unittests/tests-core-bitarithm.c
Normal file
@ -0,0 +1,230 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Martin Lenders
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser General
|
||||
* Public License. See the file LICENSE in the top level directory for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
#include "embUnit/embUnit.h"
|
||||
|
||||
#include "bitarithm.h"
|
||||
|
||||
#include "tests-core.h"
|
||||
|
||||
static void test_SETBIT_null_null(void)
|
||||
{
|
||||
int res = 0x00;
|
||||
|
||||
SETBIT(res, 0x00);
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(0x00, res);
|
||||
}
|
||||
|
||||
static void test_SETBIT_null_limit(void)
|
||||
{
|
||||
unsigned int res = 0x00;
|
||||
|
||||
SETBIT(res, UINT_MAX);
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(UINT_MAX, res);
|
||||
}
|
||||
|
||||
static void test_SETBIT_limit_null(void)
|
||||
{
|
||||
unsigned int res = UINT_MAX;
|
||||
|
||||
SETBIT(res, 0x00);
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(UINT_MAX, res);
|
||||
}
|
||||
|
||||
static void test_SETBIT_limit_limit(void)
|
||||
{
|
||||
unsigned int res = UINT_MAX;
|
||||
|
||||
SETBIT(res, UINT_MAX);
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(UINT_MAX, res);
|
||||
}
|
||||
|
||||
static void test_SETBIT_null_one(void)
|
||||
{
|
||||
unsigned int res = 0x00;
|
||||
|
||||
SETBIT(res, 0x01);
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(0x01, res);
|
||||
}
|
||||
|
||||
static void test_SETBIT_one_null(void)
|
||||
{
|
||||
unsigned int res = 0x01;
|
||||
|
||||
SETBIT(res, 0x00);
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(0x01, res);
|
||||
}
|
||||
|
||||
static void test_SETBIT_one_random(void)
|
||||
{
|
||||
unsigned int res = 0x01;
|
||||
|
||||
SETBIT(res, 0x06); /* randomized by fair dice roll ;-) */
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(0x07, res);
|
||||
}
|
||||
|
||||
static void test_CLRBIT_null_null(void)
|
||||
{
|
||||
int res = 0x00;
|
||||
|
||||
CLRBIT(res, 0x00);
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(0x00, res);
|
||||
}
|
||||
|
||||
static void test_CLRBIT_null_limit(void)
|
||||
{
|
||||
unsigned int res = 0x00;
|
||||
|
||||
CLRBIT(res, UINT_MAX);
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(0x00, res);
|
||||
}
|
||||
|
||||
static void test_CLRBIT_limit_null(void)
|
||||
{
|
||||
unsigned int res = UINT_MAX;
|
||||
|
||||
CLRBIT(res, 0x00);
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(UINT_MAX, res);
|
||||
}
|
||||
|
||||
static void test_CLRBIT_limit_limit(void)
|
||||
{
|
||||
unsigned int res = UINT_MAX;
|
||||
|
||||
CLRBIT(res, UINT_MAX);
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(0x00, res);
|
||||
}
|
||||
|
||||
static void test_CLRBIT_null_one(void)
|
||||
{
|
||||
unsigned int res = 0x00;
|
||||
|
||||
CLRBIT(res, 0x01);
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(0x00, res);
|
||||
}
|
||||
|
||||
static void test_CLRBIT_one_null(void)
|
||||
{
|
||||
unsigned int res = 0x01;
|
||||
|
||||
CLRBIT(res, 0x00);
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(0x01, res);
|
||||
}
|
||||
|
||||
static void test_CLRBIT_one_random(void)
|
||||
{
|
||||
unsigned int res = 0x01;
|
||||
|
||||
CLRBIT(res, 0x05); /* randomized by fair dice roll ;-) */
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(0x00, res);
|
||||
}
|
||||
|
||||
static void test_number_of_highest_bit_one(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL_INT(0, number_of_highest_bit(1));
|
||||
}
|
||||
|
||||
static void test_number_of_highest_bit_limit(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL_INT(sizeof(unsigned) * 8 - 1,
|
||||
number_of_highest_bit(UINT_MAX));
|
||||
}
|
||||
|
||||
static void test_number_of_highest_bit_random(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL_INT(2, number_of_highest_bit(4)); /* randomized by fair
|
||||
dice roll ;-) */
|
||||
}
|
||||
|
||||
static void test_number_of_lowest_bit_one(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL_INT(0, number_of_lowest_bit(1));
|
||||
}
|
||||
|
||||
static void test_number_of_lowest_bit_limit(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL_INT(0, number_of_lowest_bit(UINT_MAX));
|
||||
}
|
||||
|
||||
static void test_number_of_lowest_bit_random(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL_INT(3, number_of_lowest_bit(8)); /* randomized by fair
|
||||
dice roll ;-) */
|
||||
}
|
||||
|
||||
static void test_number_of_bits_set_null(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL_INT(0, number_of_bits_set(0));
|
||||
}
|
||||
|
||||
static void test_number_of_bits_set_one(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL_INT(1, number_of_bits_set(1));
|
||||
}
|
||||
|
||||
static void test_number_of_bits_set_limit(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL_INT(sizeof(unsigned) * 8,
|
||||
number_of_bits_set(UINT_MAX));
|
||||
}
|
||||
|
||||
static void test_number_of_bits_set_random(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL_INT(3, number_of_bits_set(7)); /* randomized by fair
|
||||
dice roll ;-) */
|
||||
}
|
||||
|
||||
Test *tests_core_bitarithm_tests(void)
|
||||
{
|
||||
EMB_UNIT_TESTFIXTURES(fixtures) {
|
||||
new_TestFixture(test_SETBIT_null_null),
|
||||
new_TestFixture(test_SETBIT_null_limit),
|
||||
new_TestFixture(test_SETBIT_limit_null),
|
||||
new_TestFixture(test_SETBIT_limit_limit),
|
||||
new_TestFixture(test_SETBIT_null_one),
|
||||
new_TestFixture(test_SETBIT_one_null),
|
||||
new_TestFixture(test_SETBIT_one_random),
|
||||
new_TestFixture(test_CLRBIT_null_null),
|
||||
new_TestFixture(test_CLRBIT_null_limit),
|
||||
new_TestFixture(test_CLRBIT_limit_null),
|
||||
new_TestFixture(test_CLRBIT_limit_limit),
|
||||
new_TestFixture(test_CLRBIT_null_one),
|
||||
new_TestFixture(test_CLRBIT_one_null),
|
||||
new_TestFixture(test_CLRBIT_one_random),
|
||||
new_TestFixture(test_number_of_highest_bit_one),
|
||||
new_TestFixture(test_number_of_highest_bit_limit),
|
||||
new_TestFixture(test_number_of_highest_bit_random),
|
||||
new_TestFixture(test_number_of_lowest_bit_one),
|
||||
new_TestFixture(test_number_of_lowest_bit_limit),
|
||||
new_TestFixture(test_number_of_lowest_bit_random),
|
||||
new_TestFixture(test_number_of_bits_set_null),
|
||||
new_TestFixture(test_number_of_bits_set_one),
|
||||
new_TestFixture(test_number_of_bits_set_limit),
|
||||
new_TestFixture(test_number_of_bits_set_random),
|
||||
};
|
||||
|
||||
EMB_UNIT_TESTCALLER(core_bitarithm_tests, NULL, NULL, fixtures);
|
||||
|
||||
return (Test *)&core_bitarithm_tests;
|
||||
}
|
60
tests/unittests/tests-core-cib.c
Normal file
60
tests/unittests/tests-core-cib.c
Normal file
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Martin Lenders
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser General
|
||||
* Public License. See the file LICENSE in the top level directory for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
#include "embUnit/embUnit.h"
|
||||
|
||||
#include "cib.h"
|
||||
|
||||
#include "tests-core.h"
|
||||
|
||||
#define TEST_CIB_SIZE 2
|
||||
|
||||
cib_t cib;
|
||||
|
||||
static void set_up(void)
|
||||
{
|
||||
cib_init(&cib, 2);
|
||||
}
|
||||
|
||||
static void test_cib_put(void)
|
||||
{
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(0, cib_put(&cib));
|
||||
TEST_ASSERT_EQUAL_INT(1, cib_put(&cib));
|
||||
TEST_ASSERT_EQUAL_INT(-1, cib_put(&cib));
|
||||
}
|
||||
|
||||
static void test_cib_get(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL_INT(-1, cib_get(&cib));
|
||||
TEST_ASSERT_EQUAL_INT(0, cib_put(&cib));
|
||||
TEST_ASSERT_EQUAL_INT(0, cib_get(&cib));
|
||||
TEST_ASSERT_EQUAL_INT(-1, cib_get(&cib));
|
||||
}
|
||||
|
||||
static void test_cib_avail(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL_INT(0, cib_avail(&cib));
|
||||
TEST_ASSERT_EQUAL_INT(0, cib_put(&cib));
|
||||
TEST_ASSERT_EQUAL_INT(1, cib_avail(&cib));
|
||||
TEST_ASSERT_EQUAL_INT(1, cib_put(&cib));
|
||||
TEST_ASSERT_EQUAL_INT(2, cib_avail(&cib));
|
||||
}
|
||||
|
||||
Test *tests_core_cib_tests(void)
|
||||
{
|
||||
EMB_UNIT_TESTFIXTURES(fixtures) {
|
||||
new_TestFixture(test_cib_put),
|
||||
new_TestFixture(test_cib_get),
|
||||
new_TestFixture(test_cib_avail),
|
||||
};
|
||||
|
||||
EMB_UNIT_TESTCALLER(core_cib_tests, set_up, NULL, fixtures);
|
||||
|
||||
return (Test *)&core_cib_tests;
|
||||
}
|
108
tests/unittests/tests-core-clist.c
Normal file
108
tests/unittests/tests-core-clist.c
Normal file
@ -0,0 +1,108 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Martin Lenders
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser General
|
||||
* Public License. See the file LICENSE in the top level directory for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "embUnit/embUnit.h"
|
||||
|
||||
#include "clist.h"
|
||||
|
||||
#include "tests-core.h"
|
||||
|
||||
#define TEST_CLIST_LEN (8)
|
||||
|
||||
clist_node_t tests_clist_buf[TEST_CLIST_LEN];
|
||||
|
||||
static void set_up(void)
|
||||
{
|
||||
memset(tests_clist_buf, 0, sizeof(tests_clist_buf));
|
||||
}
|
||||
|
||||
static void test_clist_add_one(void)
|
||||
{
|
||||
clist_node_t *list = NULL, *elem = &(tests_clist_buf[0]);
|
||||
|
||||
elem->data = 4435;
|
||||
|
||||
clist_add(&list, elem);
|
||||
|
||||
TEST_ASSERT_NOT_NULL(list);
|
||||
TEST_ASSERT_EQUAL_INT(4435, list->data);
|
||||
TEST_ASSERT(list->next == list);
|
||||
}
|
||||
|
||||
static void test_clist_add_two(void)
|
||||
{
|
||||
clist_node_t *list = &(tests_clist_buf[0]), *elem = &(tests_clist_buf[1]);
|
||||
|
||||
test_clist_add_one();
|
||||
|
||||
elem->data = 56345;
|
||||
|
||||
clist_add(&list, elem);
|
||||
|
||||
TEST_ASSERT_NOT_NULL(list);
|
||||
TEST_ASSERT(list->next == elem);
|
||||
TEST_ASSERT_EQUAL_INT(56345, list->next->data);
|
||||
TEST_ASSERT(list->next->next == list);
|
||||
}
|
||||
|
||||
static void test_clist_remove_one(void)
|
||||
{
|
||||
clist_node_t *list = &(tests_clist_buf[0]), *elem = &(tests_clist_buf[1]);
|
||||
|
||||
test_clist_add_two();
|
||||
|
||||
clist_remove(&list, elem);
|
||||
|
||||
TEST_ASSERT_NOT_NULL(list);
|
||||
TEST_ASSERT(list->next == list);
|
||||
}
|
||||
|
||||
static void test_clist_remove_two(void)
|
||||
{
|
||||
clist_node_t *list = &(tests_clist_buf[0]), *elem = &(tests_clist_buf[1]);
|
||||
|
||||
test_clist_add_two();
|
||||
|
||||
clist_remove(&list, elem);
|
||||
clist_remove(&list, list);
|
||||
|
||||
TEST_ASSERT_NULL(list);
|
||||
}
|
||||
|
||||
static void test_clist_advance(void)
|
||||
{
|
||||
clist_node_t *list = &(tests_clist_buf[0]);
|
||||
|
||||
test_clist_add_two();
|
||||
|
||||
clist_advance(&list);
|
||||
|
||||
TEST_ASSERT(list == &(tests_clist_buf[1]));
|
||||
|
||||
clist_advance(&list);
|
||||
|
||||
TEST_ASSERT(list == &(tests_clist_buf[0]));
|
||||
}
|
||||
|
||||
Test *tests_core_clist_tests(void)
|
||||
{
|
||||
EMB_UNIT_TESTFIXTURES(fixtures) {
|
||||
new_TestFixture(test_clist_add_one),
|
||||
new_TestFixture(test_clist_add_two),
|
||||
new_TestFixture(test_clist_remove_one),
|
||||
new_TestFixture(test_clist_remove_two),
|
||||
new_TestFixture(test_clist_advance),
|
||||
};
|
||||
|
||||
EMB_UNIT_TESTCALLER(core_clist_tests, set_up, NULL,
|
||||
fixtures);
|
||||
|
||||
return (Test *)&core_clist_tests;
|
||||
}
|
61
tests/unittests/tests-core-lifo.c
Normal file
61
tests/unittests/tests-core-lifo.c
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Martin Lenders
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser General
|
||||
* Public License. See the file LICENSE in the top level directory for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
#include "embUnit/embUnit.h"
|
||||
|
||||
#include "lifo.h"
|
||||
|
||||
#include "tests-core.h"
|
||||
|
||||
#define TEST_LIFO_LEN 2
|
||||
|
||||
int lifo[TEST_LIFO_LEN];
|
||||
|
||||
static void set_up(void)
|
||||
{
|
||||
lifo_init(lifo, TEST_LIFO_LEN);
|
||||
}
|
||||
|
||||
static void test_lifo_empty(void)
|
||||
{
|
||||
TEST_ASSERT(lifo_empty(lifo));
|
||||
}
|
||||
|
||||
static void test_lifo_insert(void)
|
||||
{
|
||||
lifo_insert(lifo, 0);
|
||||
TEST_ASSERT(!lifo_empty(lifo));
|
||||
}
|
||||
|
||||
static void test_lifo_get_one(void)
|
||||
{
|
||||
lifo_insert(lifo, 0);
|
||||
TEST_ASSERT_EQUAL_INT(0, lifo_get(lifo));
|
||||
}
|
||||
|
||||
static void test_lifo_get_two(void)
|
||||
{
|
||||
lifo_insert(lifo, 0);
|
||||
lifo_insert(lifo, 1);
|
||||
TEST_ASSERT_EQUAL_INT(1, lifo_get(lifo));
|
||||
TEST_ASSERT_EQUAL_INT(0, lifo_get(lifo));
|
||||
}
|
||||
|
||||
Test *tests_core_lifo_tests(void)
|
||||
{
|
||||
EMB_UNIT_TESTFIXTURES(fixtures) {
|
||||
new_TestFixture(test_lifo_empty),
|
||||
new_TestFixture(test_lifo_insert),
|
||||
new_TestFixture(test_lifo_get_one),
|
||||
new_TestFixture(test_lifo_get_two),
|
||||
};
|
||||
|
||||
EMB_UNIT_TESTCALLER(core_lifo_tests, set_up, NULL, fixtures);
|
||||
|
||||
return (Test *)&core_lifo_tests;
|
||||
}
|
271
tests/unittests/tests-core-queue.c
Normal file
271
tests/unittests/tests-core-queue.c
Normal file
@ -0,0 +1,271 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Martin Lenders
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser General
|
||||
* Public License. See the file LICENSE in the top level directory for more
|
||||
* details.
|
||||
*/
|
||||
#include <string.h>
|
||||
|
||||
#include "embUnit/embUnit.h"
|
||||
|
||||
#include "queue.h"
|
||||
|
||||
#include "tests-core.h"
|
||||
|
||||
#define Q_LEN (4)
|
||||
|
||||
static queue_node_t q[Q_LEN];
|
||||
|
||||
static void set_up(void)
|
||||
{
|
||||
memset(q, 0, sizeof(q));
|
||||
}
|
||||
|
||||
static void test_queue_remove_head_empty(void)
|
||||
{
|
||||
queue_node_t *root = &(q[0]), *res;
|
||||
|
||||
res = queue_remove_head(root);
|
||||
|
||||
TEST_ASSERT_NULL(res);
|
||||
}
|
||||
|
||||
static void test_queue_remove_head_one(void)
|
||||
{
|
||||
queue_node_t *root = &(q[0]), *elem = &(q[1]), *res;
|
||||
|
||||
elem->data = 62801;
|
||||
|
||||
queue_add_head(root, elem);
|
||||
|
||||
res = queue_remove_head(root);
|
||||
|
||||
TEST_ASSERT(res == elem);
|
||||
TEST_ASSERT_EQUAL_INT(62801, res->data);
|
||||
|
||||
res = queue_remove_head(root);
|
||||
|
||||
TEST_ASSERT_NULL(res);
|
||||
}
|
||||
|
||||
static void test_queue_add_head_one(void)
|
||||
{
|
||||
queue_node_t *root = &(q[0]), *elem = &(q[1]);
|
||||
|
||||
elem->data = 44011;
|
||||
|
||||
queue_add_head(root, elem);
|
||||
|
||||
TEST_ASSERT(root->next == elem);
|
||||
TEST_ASSERT_EQUAL_INT(44011, root->next->data);
|
||||
|
||||
TEST_ASSERT_NULL(root->next->next);
|
||||
}
|
||||
|
||||
static void test_queue_add_head_two(void)
|
||||
{
|
||||
queue_node_t *root = &(q[0]), *elem1 = &(q[1]), *elem2 = &(q[2]);
|
||||
|
||||
elem1->data = 25303;
|
||||
elem2->data = 64960;
|
||||
|
||||
queue_add_head(root, elem1);
|
||||
queue_add_head(root, elem2);
|
||||
|
||||
TEST_ASSERT(root->next == elem2);
|
||||
TEST_ASSERT_EQUAL_INT(64960, root->next->data);
|
||||
|
||||
TEST_ASSERT(root->next->next == elem1);
|
||||
TEST_ASSERT_EQUAL_INT(25303, root->next->next->data);
|
||||
|
||||
TEST_ASSERT_NULL(root->next->next->next);
|
||||
}
|
||||
|
||||
static void test_queue_add_tail_one(void)
|
||||
{
|
||||
queue_node_t *root = &(q[0]), *elem = &(q[1]);
|
||||
|
||||
elem->data = 33893;
|
||||
|
||||
queue_add_tail(root, elem);
|
||||
|
||||
TEST_ASSERT(root->next == elem);
|
||||
TEST_ASSERT_EQUAL_INT(33893, root->next->data);
|
||||
|
||||
TEST_ASSERT_NULL(root->next->next);
|
||||
}
|
||||
|
||||
static void test_queue_add_tail_two(void)
|
||||
{
|
||||
queue_node_t *root = &(q[0]), *elem1 = &(q[1]), *elem2 = &(q[2]);
|
||||
|
||||
elem1->data = 9084;
|
||||
elem2->data = 57068;
|
||||
|
||||
queue_add_tail(root, elem1);
|
||||
queue_add_tail(root, elem2);
|
||||
|
||||
TEST_ASSERT(root->next == elem1);
|
||||
TEST_ASSERT_EQUAL_INT(9084, root->next->data);
|
||||
|
||||
TEST_ASSERT(root->next->next == elem2);
|
||||
TEST_ASSERT_EQUAL_INT(57068, root->next->next->data);
|
||||
|
||||
TEST_ASSERT_NULL(root->next->next->next);
|
||||
}
|
||||
|
||||
static void test_queue_priority_add_one(void)
|
||||
{
|
||||
queue_node_t *root = &(q[0]), *elem = &(q[1]);
|
||||
|
||||
elem->data = 7317;
|
||||
elem->priority = 713643658;
|
||||
|
||||
queue_priority_add(root, elem);
|
||||
|
||||
TEST_ASSERT(root->next == elem);
|
||||
TEST_ASSERT_EQUAL_INT(7317, root->next->data);
|
||||
TEST_ASSERT_EQUAL_INT(713643658, root->next->priority);
|
||||
|
||||
TEST_ASSERT_NULL(root->next->next);
|
||||
}
|
||||
|
||||
static void test_queue_priority_add_two_equal(void)
|
||||
{
|
||||
queue_node_t *root = &(q[0]), *elem1 = &(q[1]), *elem2 = &(q[2]);
|
||||
|
||||
elem1->data = 27088;
|
||||
elem1->priority = 14202;
|
||||
|
||||
elem2->data = 4356;
|
||||
elem2->priority = 14202;
|
||||
|
||||
queue_priority_add(root, elem1);
|
||||
queue_priority_add(root, elem2);
|
||||
|
||||
TEST_ASSERT(root->next == elem1);
|
||||
TEST_ASSERT_EQUAL_INT(27088, root->next->data);
|
||||
TEST_ASSERT_EQUAL_INT(14202, root->next->priority);
|
||||
|
||||
TEST_ASSERT(root->next->next == elem2);
|
||||
TEST_ASSERT_EQUAL_INT(4356, root->next->next->data);
|
||||
TEST_ASSERT_EQUAL_INT(14202, root->next->next->priority);
|
||||
|
||||
TEST_ASSERT_NULL(root->next->next->next);
|
||||
}
|
||||
|
||||
static void test_queue_priority_add_two_distinct(void)
|
||||
{
|
||||
queue_node_t *root = &(q[0]), *elem1 = &(q[1]), *elem2 = &(q[2]);
|
||||
|
||||
elem1->data = 46421;
|
||||
elem1->priority = 4567;
|
||||
|
||||
elem2->data = 43088;
|
||||
elem2->priority = 1234;
|
||||
|
||||
queue_priority_add(root, elem1);
|
||||
queue_priority_add(root, elem2);
|
||||
|
||||
TEST_ASSERT(root->next == elem2);
|
||||
TEST_ASSERT_EQUAL_INT(43088, root->next->data);
|
||||
TEST_ASSERT_EQUAL_INT(1234, root->next->priority);
|
||||
|
||||
TEST_ASSERT(root->next->next == elem1);
|
||||
TEST_ASSERT_EQUAL_INT(46421, root->next->next->data);
|
||||
TEST_ASSERT_EQUAL_INT(4567, root->next->next->priority);
|
||||
|
||||
TEST_ASSERT_NULL(root->next->next->next);
|
||||
}
|
||||
|
||||
static int generic_compare(queue_node_t *a, queue_node_t *b)
|
||||
{
|
||||
return (b->priority) - (a->priority);
|
||||
}
|
||||
|
||||
static void test_queue_priority_add_generic_two_equal(void)
|
||||
{
|
||||
queue_node_t *root = &(q[0]), *elem1 = &(q[1]), *elem2 = &(q[2]);
|
||||
|
||||
elem1->data = 43804;
|
||||
elem1->priority = 34572;
|
||||
|
||||
elem2->data = 64016;
|
||||
elem2->priority = 34572;
|
||||
|
||||
queue_priority_add_generic(root, elem1, generic_compare);
|
||||
queue_priority_add_generic(root, elem2, generic_compare);
|
||||
|
||||
TEST_ASSERT(root->next == elem1);
|
||||
TEST_ASSERT_EQUAL_INT(43804, root->next->data);
|
||||
TEST_ASSERT_EQUAL_INT(34572, root->next->priority);
|
||||
|
||||
TEST_ASSERT(root->next->next == elem2);
|
||||
TEST_ASSERT_EQUAL_INT(64016, root->next->next->data);
|
||||
TEST_ASSERT_EQUAL_INT(34572, root->next->next->priority);
|
||||
|
||||
TEST_ASSERT_NULL(root->next->next->next);
|
||||
}
|
||||
|
||||
static void test_queue_priority_add_generic_two_distinct(void)
|
||||
{
|
||||
queue_node_t *root = &(q[0]), *elem1 = &(q[1]), *elem2 = &(q[2]);
|
||||
|
||||
elem1->data = 39152;
|
||||
elem1->priority = 45394;
|
||||
|
||||
elem2->data = 54496;
|
||||
elem2->priority = 56834;
|
||||
|
||||
queue_priority_add_generic(root, elem1, generic_compare);
|
||||
queue_priority_add_generic(root, elem2, generic_compare);
|
||||
|
||||
TEST_ASSERT(root->next == elem1);
|
||||
TEST_ASSERT_EQUAL_INT(39152, root->next->data);
|
||||
TEST_ASSERT_EQUAL_INT(45394, root->next->priority);
|
||||
|
||||
TEST_ASSERT(root->next->next == elem2);
|
||||
TEST_ASSERT_EQUAL_INT(54496, root->next->next->data);
|
||||
TEST_ASSERT_EQUAL_INT(56834, root->next->next->priority);
|
||||
|
||||
TEST_ASSERT_NULL(root->next->next->next);
|
||||
}
|
||||
|
||||
static void test_queue_remove_one(void)
|
||||
{
|
||||
queue_node_t *root = &(q[0]), *elem1 = &(q[1]), *elem2 = &(q[2]);
|
||||
queue_node_t *elem3 = &(q[3]);
|
||||
|
||||
queue_add_head(root, elem1);
|
||||
queue_add_head(root, elem2);
|
||||
queue_add_head(root, elem3);
|
||||
queue_remove(root, elem2);
|
||||
|
||||
TEST_ASSERT(root->next == elem3);
|
||||
TEST_ASSERT(root->next->next == elem1);
|
||||
TEST_ASSERT_NULL(root->next->next->next);
|
||||
}
|
||||
|
||||
Test *tests_core_queue_tests(void)
|
||||
{
|
||||
EMB_UNIT_TESTFIXTURES(fixtures) {
|
||||
new_TestFixture(test_queue_remove_head_empty),
|
||||
new_TestFixture(test_queue_remove_head_one),
|
||||
new_TestFixture(test_queue_add_head_one),
|
||||
new_TestFixture(test_queue_add_head_two),
|
||||
new_TestFixture(test_queue_add_tail_one),
|
||||
new_TestFixture(test_queue_add_tail_two),
|
||||
new_TestFixture(test_queue_priority_add_one),
|
||||
new_TestFixture(test_queue_priority_add_two_equal),
|
||||
new_TestFixture(test_queue_priority_add_two_distinct),
|
||||
new_TestFixture(test_queue_priority_add_generic_two_equal),
|
||||
new_TestFixture(test_queue_priority_add_generic_two_distinct),
|
||||
new_TestFixture(test_queue_remove_one),
|
||||
};
|
||||
|
||||
EMB_UNIT_TESTCALLER(core_queue_tests, set_up, NULL,
|
||||
fixtures);
|
||||
|
||||
return (Test *)&core_queue_tests;
|
||||
}
|
66
tests/unittests/tests-core.h
Normal file
66
tests/unittests/tests-core.h
Normal file
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Martin Lenders
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser General
|
||||
* Public License. See the file LICENSE in the top level directory for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup unittests
|
||||
* @{
|
||||
*
|
||||
* @file tests-core.h
|
||||
* @brief Unittests for the ``core`` module
|
||||
*
|
||||
* @author Freie Universität Berlin, Computer Systems & Telematics
|
||||
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
|
||||
*/
|
||||
#ifndef __TESTS_CORE_H_
|
||||
#define __TESTS_CORE_H_
|
||||
#include "embUnit/embUnit.h"
|
||||
|
||||
/**
|
||||
* @brief Generates tests atomic.h
|
||||
*
|
||||
* @return embUnit tests if successful, NULL if not.
|
||||
*/
|
||||
Test *tests_core_atomic_tests(void);
|
||||
|
||||
/**
|
||||
* @brief Generates tests for bitarithm.h
|
||||
*
|
||||
* @return embUnit tests if successful, NULL if not.
|
||||
*/
|
||||
Test *tests_core_bitarithm_tests(void);
|
||||
|
||||
/**
|
||||
* @brief Generates tests cib.h
|
||||
*
|
||||
* @return embUnit tests if successful, NULL if not.
|
||||
*/
|
||||
Test *tests_core_cib_tests(void);
|
||||
|
||||
/**
|
||||
* @brief Generates tests clist.h
|
||||
*
|
||||
* @return embUnit tests if successful, NULL if not.
|
||||
*/
|
||||
Test *tests_core_clist_tests(void);
|
||||
|
||||
/**
|
||||
* @brief Generates tests lifo.h
|
||||
*
|
||||
* @return embUnit tests if successful, NULL if not.
|
||||
*/
|
||||
Test *tests_core_lifo_tests(void);
|
||||
|
||||
/**
|
||||
* @brief Generates tests queue.h
|
||||
*
|
||||
* @return embUnit tests if successful, NULL if not.
|
||||
*/
|
||||
Test *tests_core_queue_tests(void);
|
||||
|
||||
#endif /* __TESTS_CORE_H_ */
|
||||
/** @} */
|
Loading…
Reference in New Issue
Block a user