added tests
This commit is contained in:
parent
06310475df
commit
1b9856c192
|
@ -2,3 +2,4 @@
|
||||||
#
|
#
|
||||||
add_subdirectory(led_driver)
|
add_subdirectory(led_driver)
|
||||||
add_subdirectory(simple_test)
|
add_subdirectory(simple_test)
|
||||||
|
add_subdirectory(gy521_driver)
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
# The gy521_driver module tests
|
||||||
|
list(APPEND TEST_LIBS "${CMOCKA_LIBRARIES}")
|
||||||
|
list(APPEND TEST_LIBS gy521_driver)
|
||||||
|
|
||||||
|
list(APPEND TEST_DIRS "${CMOCKA_INCLUDE_DIRS}")
|
||||||
|
list(APPEND TEST_DIRS "${MyProject_SOURCE_DIR}/src")
|
||||||
|
|
||||||
|
add_cmocka_test(test_gy521_driver
|
||||||
|
SOURCES test_gy521_driver.c
|
||||||
|
COMPILE_OPTIONS ${DEFAULT_C_COMPILE_FLAGS}
|
||||||
|
LINK_LIBRARIES "${TEST_LIBS}")
|
||||||
|
add_cmocka_test_environment(test_gy521_driver)
|
||||||
|
target_include_directories(test_gy521_driver PUBLIC "${TEST_DIRS}")
|
|
@ -0,0 +1,50 @@
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <setjmp.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <cmocka.h>
|
||||||
|
#include "gy521_driver.h"
|
||||||
|
|
||||||
|
|
||||||
|
/* A test case that does nothing and succeeds. */
|
||||||
|
static void null_test_success(void **state) {
|
||||||
|
(void) state; /* unused */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Fake Object for TWI_TX*/
|
||||||
|
void fake_twi_tx(uint8_t slave_addr, uint8_t *data, uint8_t size)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Tests the donothing function */
|
||||||
|
static void test_gy521_init(void **state) {
|
||||||
|
|
||||||
|
_Bool result = init_gy521(0);
|
||||||
|
assert_false(result);
|
||||||
|
|
||||||
|
result = init_gy521(1);
|
||||||
|
assert_false(result);
|
||||||
|
|
||||||
|
result = init_gy521((uint8_t) TWI_GY521_ADDR1);
|
||||||
|
assert_true(result);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_gy521_module_methods(void **state) {
|
||||||
|
gy521_module *module = malloc(sizeof(gy521_module));
|
||||||
|
assert_true(module_test(*module));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
const struct CMUnitTest tests[] = {
|
||||||
|
cmocka_unit_test(null_test_success),
|
||||||
|
cmocka_unit_test(test_gy521_init),
|
||||||
|
cmocka_unit_test(test_gy521_module_methods),
|
||||||
|
};
|
||||||
|
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||||
|
}
|
Loading…
Reference in New Issue