Skip to content

Commit

Permalink
Add test for is_safe_filename
Browse files Browse the repository at this point in the history
  • Loading branch information
lmoureaux authored and jwrober committed Jan 1, 2024
1 parent 0a6ba6d commit 57f76ed
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
5 changes: 5 additions & 0 deletions utility/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
5 changes: 5 additions & 0 deletions utility/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
27 changes: 27 additions & 0 deletions utility/tests/test_paths.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "shared.h"

#include <QtTest>

/**
* 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"

0 comments on commit 57f76ed

Please sign in to comment.