diff --git a/utility/CMakeLists.txt b/utility/CMakeLists.txt index e7fbfe1706..8c4b29e57a 100644 --- a/utility/CMakeLists.txt +++ b/utility/CMakeLists.txt @@ -82,3 +82,8 @@ if(FREECIV_ENABLE_NLS) target_include_directories(utility PUBLIC ${Intl_INCLUDE_DIRS}) target_link_libraries(utility PUBLIC ${Intl_LIBRARIES}) endif() + +# Tests +if (BUILD_TESTING) + add_subdirectory(tests) +endif() diff --git a/utility/tests/CMakeLists.txt b/utility/tests/CMakeLists.txt new file mode 100644 index 0000000000..2a25ad5537 --- /dev/null +++ b/utility/tests/CMakeLists.txt @@ -0,0 +1,5 @@ +set(CMAKE_AUTOMOC ON) + +add_executable(test_utility_paths test_paths.cpp) +target_link_libraries(test_utility_paths PRIVATE Qt5::Test utility) +add_test(NAME test_utility_paths COMMAND test_utility_paths) diff --git a/utility/tests/test_paths.cpp b/utility/tests/test_paths.cpp new file mode 100644 index 0000000000..8c10d7c21d --- /dev/null +++ b/utility/tests/test_paths.cpp @@ -0,0 +1,27 @@ +#include "shared.h" + +#include + +/** + * Tests functions acting on paths + */ +class test_paths : public QObject { + Q_OBJECT + +private slots: + void is_safe_filename(); +}; + +/** + * Tests \ref ::is_safe_filename + */ +void test_paths::is_safe_filename() +{ + QCOMPARE(::is_safe_filename(QLatin1String("")), false); + QCOMPARE(::is_safe_filename(QLatin1String("abcABC_-._")), true); + QCOMPARE(::is_safe_filename(QLatin1String("a/b")), false); + QCOMPARE(::is_safe_filename(QLatin1String("..")), false); +} + +QTEST_MAIN(test_paths) +#include "test_paths.moc"