mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
tests/unittests: add tests for libc module
This commit is contained in:
parent
8870158609
commit
3fc4d9d98c
1
tests/unittests/tests-libc/Makefile
Normal file
1
tests/unittests/tests-libc/Makefile
Normal file
@ -0,0 +1 @@
|
||||
include $(RIOTBASE)/Makefile.base
|
46
tests/unittests/tests-libc/tests-libc.c
Normal file
46
tests/unittests/tests-libc/tests-libc.c
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (C) 2019 ML!PA Consulting GmbH
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include "string_utils.h"
|
||||
|
||||
#include "tests-libc.h"
|
||||
|
||||
static void test_libc_strscpy(void)
|
||||
{
|
||||
char buffer[8];
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(strscpy(buffer, "Hello", sizeof(buffer)), 5);
|
||||
TEST_ASSERT_EQUAL_INT(strcmp(buffer, "Hello"), 0);
|
||||
TEST_ASSERT_EQUAL_INT(strscpy(buffer, "012345678", sizeof(buffer)), -E2BIG);
|
||||
TEST_ASSERT_EQUAL_INT(strcmp(buffer, "0123456"), 0);
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
TEST_ASSERT_EQUAL_INT(strscpy(buffer, "01234567", sizeof(buffer)), -E2BIG);
|
||||
TEST_ASSERT_EQUAL_INT(strcmp(buffer, "0123456"), 0);
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
TEST_ASSERT_EQUAL_INT(strscpy(buffer, "0123456", sizeof(buffer)), 7);
|
||||
TEST_ASSERT_EQUAL_INT(strcmp(buffer, "0123456"), 0);
|
||||
TEST_ASSERT_EQUAL_INT(strscpy(buffer, "empty", 0), -E2BIG);
|
||||
}
|
||||
|
||||
Test *tests_libc_tests(void)
|
||||
{
|
||||
EMB_UNIT_TESTFIXTURES(fixtures) {
|
||||
new_TestFixture(test_libc_strscpy),
|
||||
};
|
||||
|
||||
EMB_UNIT_TESTCALLER(libc_tests, NULL, NULL, fixtures);
|
||||
|
||||
return (Test *)&libc_tests;
|
||||
}
|
||||
|
||||
void tests_libc(void)
|
||||
{
|
||||
TESTS_RUN(tests_libc_tests());
|
||||
}
|
44
tests/unittests/tests-libc/tests-libc.h
Normal file
44
tests/unittests/tests-libc/tests-libc.h
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (C) 2022 ML!PA Consulting GmbH
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup unittests
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Unittests for the ``libc`` module
|
||||
*
|
||||
* @author Benjamin Valentin <benjamin.valentin@ml-pa.com>
|
||||
*/
|
||||
#ifndef TESTS_LIBC_H
|
||||
#define TESTS_LIBC_H
|
||||
|
||||
#include "embUnit.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief The entry point of this test suite.
|
||||
*/
|
||||
void tests_libc(void);
|
||||
|
||||
/**
|
||||
* @brief Generates tests for libc
|
||||
*
|
||||
* @return embUnit tests if successful, NULL if not.
|
||||
*/
|
||||
Test *tests_libc_tests(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* TESTS_LIBC_H */
|
||||
/** @} */
|
Loading…
Reference in New Issue
Block a user