]> gitweb.hhaalo.de Git - mv_none_space.git/commitdiff
add test for remove spaces
authorBastian Dehn <hhaalo@arcor.de>
Tue, 16 Jul 2024 10:01:56 +0000 (12:01 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Tue, 16 Jul 2024 10:01:56 +0000 (12:01 +0200)
CMakeLists.txt
src/rename.c
src/rename.h
tests/CMakeLists.txt
tests/rename_tests.c

index a8767e98df425519957b7fb78cb38a3a1adf7615..8395857b14cd75121f4dc7719b2e6ddb1851b53d 100644 (file)
@@ -1,6 +1,9 @@
 CMAKE_MINIMUM_REQUIRED(VERSION 3.25.1)
 
+SET(CMAKE_C_FLAGS "-g -fsanitize=address")
+MESSAGE(STATUS "CMAKE_C_FLAGS: ${CMAKE_C_FLAGS}")
+
 PROJECT(mv_none_space)
 
-add_subdirectory(src)
-add_subdirectory(tests)
\ No newline at end of file
+ADD_SUBDIRECTORY(src)
+ADD_SUBDIRECTORY(tests)
\ No newline at end of file
index 424074f03a54f2b393bf8ff8d3aacc6bfaa81b5c..9db5fc7b57942f97fecdc22e0df71684f5259483 100644 (file)
@@ -1 +1,18 @@
-#include "rename.h"
\ No newline at end of file
+#include <stdio.h>
+#include <string.h>
+#include "rename.h"
+
+void rename_str(char* src, char* dst)
+{
+       int len = strlen(src);
+       for (int i = 0; i < len; i++) {
+               switch(src[i]) {
+               case ' ':
+                       dst[i] = '_';
+                       break;
+               default:
+                       dst[i] = src[i];
+                       break;
+               }
+       }
+}
\ No newline at end of file
index 47ab8fb51479f76443bd0465274fa28d19df9aab..6cc818797be4077709a0471bc4e9bdee466bf90c 100644 (file)
@@ -1,4 +1,8 @@
 #ifndef RENAME_H
 #define RENAME_H
 
+#define STR_MAX_LENGTH 255
+
+void rename_str(char* src, char* dst);
+
 #endif
\ No newline at end of file
index 92eb7b3669397ca681248928e9e6038ac6a5d537..47e115296328f9b9c9e93da5c0e776ec6cbff79f 100644 (file)
@@ -4,9 +4,11 @@ FIND_LIBRARY(cmocka NAMES cmocka REQUIRED)
 
 INCLUDE(CTest)
 
-ADD_EXECUTABLE(rename_tests rename_tests.c)
+ADD_EXECUTABLE(rename_tests
+       rename_tests.c
+       ../src/rename.c)
 TARGET_LINK_LIBRARIES(rename_tests ${cmocka})
 
 ADD_TEST(NAME rename_tests COMMAND rename_tests)
 
-ADD_CUSTOM_TARGET(run_tests ALL ctest)
\ No newline at end of file
+ADD_CUSTOM_TARGET(run_tests ALL ctest --verbose)
\ No newline at end of file
index 29b0ed653769827fb5b2b626c1ea1124077bb410..da9aff1867a4971595e6dfa91db10cdc94c6d3e0 100644 (file)
@@ -3,16 +3,28 @@
 #include <stdint.h>
 #include <setjmp.h>
 #include <cmocka.h>
+#include <stdlib.h>
+#include <string.h>
+#include "../src/rename.h"
 
-void sanity_check()
+void rename_spaces()
 {
-       assert_true(1);
+       char* input = "Dies ist ein Test Satz\0";
+       char* output = malloc(sizeof(char) * STR_MAX_LENGTH);
+       memset(output, 0, STR_MAX_LENGTH);
+
+       rename_str(input, output);
+
+       assert_string_equal(output, "Dies_ist_ein_Test_Satz");
+
+       free(output);
+       output = NULL;
 }
 
 int main()
 {
        const struct CMUnitTest tests[] = {
-               cmocka_unit_test(sanity_check)
+               cmocka_unit_test(rename_spaces)
        };
 
        return cmocka_run_group_tests(tests, NULL, NULL);