From 16ddb1e67d17b2f81b343144d108519796165fe9 Mon Sep 17 00:00:00 2001 From: Coline Date: Wed, 20 Jul 2022 15:40:01 +0200 Subject: [PATCH] feat: TU demo .c fix: TU demo fix: TU demo --- tests/unit/CMakeLists.txt | 10 ++++++---- tests/unit/demo_tu.c | 12 ++++++++++++ tests/unit/tests/{utils.c => demo.c} | 6 +++--- 3 files changed, 21 insertions(+), 7 deletions(-) create mode 100644 tests/unit/demo_tu.c rename tests/unit/tests/{utils.c => demo.c} (64%) diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt index cf5b0d5..93605b2 100644 --- a/tests/unit/CMakeLists.txt +++ b/tests/unit/CMakeLists.txt @@ -54,10 +54,12 @@ add_compile_definitions(TEST DEBUG=0 SKIP_FOR_CMOCKA) include_directories(../../src/) include_directories(../../src_common) -add_executable(test_utils tests/utils.c) +# add cmocka tests +add_executable(test_demo tests/demo.c) -add_library(utils SHARED ../../src/utils2.c) +# add src +add_library(demo SHARED ./demo_tu.c) -target_link_libraries(test_utils PUBLIC cmocka gcov utils) +target_link_libraries(test_demo PUBLIC cmocka gcov demo) -add_test(test_utils test_utils) \ No newline at end of file +add_test(test_demo test_demo) \ No newline at end of file diff --git a/tests/unit/demo_tu.c b/tests/unit/demo_tu.c new file mode 100644 index 0000000..c4f450c --- /dev/null +++ b/tests/unit/demo_tu.c @@ -0,0 +1,12 @@ +#include + +int local_strchr_demo(char *string, char ch) { + unsigned int length = strlen(string); + unsigned int i; + for (i = 0; i < length; i++) { + if (string[i] == ch) { + return i; + } + } + return -1; +} \ No newline at end of file diff --git a/tests/unit/tests/utils.c b/tests/unit/tests/demo.c similarity index 64% rename from tests/unit/tests/utils.c rename to tests/unit/tests/demo.c index b2424d7..1da227d 100644 --- a/tests/unit/tests/utils.c +++ b/tests/unit/tests/demo.c @@ -3,11 +3,11 @@ #include #include -int local_strchr(char *string, char ch); +int local_strchr_demo(char *string, char ch); static void null_test_success(void **state) { - assert_int_equal(local_strchr("salut", 'c'), -1); - assert_int_equal(local_strchr("av", 'a'), 0); + assert_int_equal(local_strchr_demo("salut", 'c'), -1); + assert_int_equal(local_strchr_demo("av", 'a'), 0); } int main(void) {