Skip to content

Commit

Permalink
Added output directory
Browse files Browse the repository at this point in the history
Signed-off-by: leonard.kosta <[email protected]>
  • Loading branch information
kostaleonard committed Jan 12, 2024
1 parent cc783b3 commit 9129461
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ target_link_libraries(main endian)
include_directories(${CMOCKA_INCLUDE_DIR})
find_package(cmocka REQUIRED)
add_executable(tests tests/main.c)
add_library(test_file_paths tests/file_paths.c)
target_link_libraries(tests test_file_paths)
add_library(test_linked_list tests/test_linked_list.c)
target_link_libraries(test_linked_list linked_list)
target_link_libraries(tests test_linked_list)
Expand Down
19 changes: 18 additions & 1 deletion tests/file_paths.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,28 @@ int get_fixture_directory(char *dirname) {
if (0 != return_code) {
goto end;
}
return_code = snprintf(
printf("Executable directory: %s\n", executable_directory); //TODO remove
snprintf(
dirname,
MAX_PATH,
"%s/../tests/fixtures/",
executable_directory);
end:
return return_code;
}

int get_output_directory(char *dirname) {
// TODO MAX_PATH is only on Windows?
char executable_directory[MAX_PATH] = {0};
int return_code = get_executable_directory(executable_directory);
if (0 != return_code) {
goto end;
}
snprintf(
dirname,
MAX_PATH,
"%s/../tests/output/",
executable_directory);
end:
return return_code;
}
14 changes: 14 additions & 0 deletions tests/file_paths.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,23 @@
/**
* @brief Fills dirname with the path to the fixture directory.
*
* The fixture directory is located at tests/fixtures. This function assumes
* that the executable is located in the build directory.
*
* @param dirname A character array of length MAX_PATH to fill with the path.
* @return 0 on success, 1 on failure.
*/
int get_fixture_directory(char *dirname);

/**
* @brief Fills dirname with the path to the output directory.
*
* The output directory is located at tests/output. This function assumes
* that the executable is located in the build directory.
*
* @param dirname A character array of length MAX_PATH to fill with the path.
* @return 0 on success, 1 on failure.
*/
int get_output_directory(char *dirname);

#endif // TESTS_FILE_PATHS_H_
10 changes: 7 additions & 3 deletions tests/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <stdio.h>
#include <setjmp.h>
#include <cmocka.h>
#include <windows.h> // TODO remove
#include "tests/file_paths.h"
#include "tests/test_linked_list.h"
#include "tests/test_block.h"
Expand Down Expand Up @@ -45,11 +46,14 @@ int create_empty_output_directory(char *dirname) {
}

int main(int argc, char **argv) {
// TODO use path to executable?
int return_value = create_empty_output_directory(TEST_OUTPUT_DIR);
// TODO Unix does not have MAX_PATH
char output_directory[MAX_PATH] = {0};
int return_value = get_output_directory(output_directory);
if (0 != return_value) {
goto end;
}
printf("Output directory: %s\n", output_directory);
create_empty_output_directory(output_directory);
const struct CMUnitTest tests[] = {
// test_linked_list.h
cmocka_unit_test(test_linked_list_create_gives_linked_list),
Expand Down Expand Up @@ -146,7 +150,7 @@ int main(int argc, char **argv) {
cmocka_unit_test(test_htobe64_correctly_encodes_data),
cmocka_unit_test(test_betoh64_correctly_decodes_data),
};
//return_value = cmocka_run_group_tests(tests, NULL, NULL);
return_value = cmocka_run_group_tests(tests, NULL, NULL);
end:
return return_value;
}

0 comments on commit 9129461

Please sign in to comment.