From 701b0918332f17e0654f8507100b5a5b12d2bb2e Mon Sep 17 00:00:00 2001 From: zv0n Date: Wed, 28 Sep 2022 23:40:21 +0200 Subject: [PATCH] Trying tests --- CMakeLists.txt | 19 +++++++++++++++++++ tests/tests.cpp | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 tests/tests.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 242f728..a78bf93 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,12 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) include_directories(/usr/local/include) link_directories(/usr/local/lib) +if(APPLE) + include_directories(/opt/homebrew/include) + link_directories(/opt/homebrew/lib) +endif() + +find_package(Catch2 3 REQUIRED) project(RenameServer) @@ -47,3 +53,16 @@ add_library(moviedb SHARED network/unix/network.cpp) target_link_libraries(moviedb curl) + +add_executable(tests + tests/tests.cpp + rename_object.cpp + functions.cpp + config/config.cpp + filesystem/unix/filesystem.cpp + jwt.cpp + ) +set_source_files_properties(tests/tests.cpp PROPERTIES COMPILE_OPTIONS "--coverage;-g;-fsanitize=address,undefined") +target_compile_options(tests PUBLIC -Wall -fprofile-arcs -ftest-coverage --coverage -g) +target_link_options(tests PUBLIC --coverage -Wall -fprofile-arcs -ftest-coverage -fsanitize=address,undefined) +target_link_libraries(tests PRIVATE restbed config++ jwt Catch2::Catch2WithMain) diff --git a/tests/tests.cpp b/tests/tests.cpp new file mode 100644 index 0000000..48a1668 --- /dev/null +++ b/tests/tests.cpp @@ -0,0 +1,37 @@ +#include + +#include "../functions.hpp" +#include + + +bool runBash( const std::string &command ) { + std::string cmd = "/bin/bash -c \"" + command + "\""; + return system( cmd.c_str() ) == 0; +} + + +TEST_CASE( "iterateFS" ) { + const std::string directory = "test_dir"; + runBash( + "mkdir " + directory + " ; cd test_dir ; for f in {01..10} ; do " + "mkdir \\\"Season \\${f}\\\" ; cd \\\"Season \\${f}\\\" ; for g in " + "{01..30} ; do touch \\\"S\\${f}E\\${g}.mkv\\\" ; done ; cd .. ; " + "done" ); + auto files = getFilesInSource("test_dir"); + REQUIRE( files.size() == 310 ); + REQUIRE(files[0].getFileType() == FileType::TYPE_DIRECTORY); + REQUIRE(files[0].getDepth() == 0); + REQUIRE_THAT(files[0].getPath(), Catch::Matchers::Equals("Season 01") || Catch::Matchers::Equals("Season 1")); + REQUIRE(files[1].getFileType() == FileType::TYPE_FILE); + REQUIRE(files[1].getDepth() == 1); + REQUIRE_THAT(files[1].getPath(), Catch::Matchers::EndsWith(".mkv")); + + REQUIRE_THROWS_WITH( getFilesInSource( "nonexistendir" ), + Catch::Matchers::ContainsSubstring( "Directory" ) && + Catch::Matchers::ContainsSubstring( "doesn't exist" ) ); + REQUIRE_THROWS_WITH( + getFilesInSource( directory + "/Season 01/S01E01.mkv" ), + Catch::Matchers::ContainsSubstring( "Directory" ) && + Catch::Matchers::ContainsSubstring( "isn't a directory" ) ); + runBash("rm -Rf " + directory ); +}