1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/tests/unittests/tests-core/tests-core-cib.c

92 lines
2.3 KiB
C
Raw Normal View History

2014-03-31 14:02:47 +02:00
/*
2015-02-08 18:51:25 +01:00
* Copyright (C) 2014 Martine Lenders
2014-03-31 14:02:47 +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.
2014-03-31 14:02:47 +02:00
*/
#include "embUnit.h"
2014-03-31 14:02:47 +02:00
#include "cib.h"
#include "tests-core.h"
#define TEST_CIB_SIZE 2
2014-11-11 17:39:20 +01:00
static cib_t cib;
2014-03-31 14:02:47 +02:00
static void set_up(void)
{
2014-11-11 17:39:20 +01:00
cib_init(&cib, TEST_CIB_SIZE);
2014-03-31 14:02:47 +02:00
}
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));
}
2014-11-11 17:39:20 +01:00
static void test_cib_put_and_get(void)
{
TEST_ASSERT_EQUAL_INT(0, cib_put(&cib));
TEST_ASSERT_EQUAL_INT(0, cib_get(&cib));
TEST_ASSERT_EQUAL_INT(-1, cib_get(&cib));
TEST_ASSERT_EQUAL_INT(1, cib_put(&cib));
TEST_ASSERT_EQUAL_INT(0, cib_put(&cib));
TEST_ASSERT_EQUAL_INT(-1, cib_put(&cib));
}
static void test_empty_cib(void)
{
cib_init(&cib, 0);
TEST_ASSERT_EQUAL_INT(0, cib_avail(&cib));
TEST_ASSERT_EQUAL_INT(-1, cib_get(&cib));
TEST_ASSERT_EQUAL_INT(-1, cib_put(&cib));
}
static void test_singleton_cib(void)
{
cib_init(&cib, 1);
TEST_ASSERT_EQUAL_INT(0, cib_avail(&cib));
TEST_ASSERT_EQUAL_INT(-1, cib_get(&cib));
TEST_ASSERT_EQUAL_INT(0, cib_put(&cib));
TEST_ASSERT_EQUAL_INT(1, cib_avail(&cib));
TEST_ASSERT_EQUAL_INT(0, cib_get(&cib));
TEST_ASSERT_EQUAL_INT(0, cib_avail(&cib));
}
2014-03-31 14:02:47 +02:00
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),
2014-11-11 17:39:20 +01:00
new_TestFixture(test_cib_put_and_get),
new_TestFixture(test_empty_cib),
new_TestFixture(test_singleton_cib),
2014-03-31 14:02:47 +02:00
};
EMB_UNIT_TESTCALLER(core_cib_tests, set_up, NULL, fixtures);
return (Test *)&core_cib_tests;
}