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
-#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
#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
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
#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);