From 842de50a5e8e6a11f97639daec9798d69fb87ae1 Mon Sep 17 00:00:00 2001 From: Tim Teulings Date: Sun, 29 Sep 2024 13:52:19 +0200 Subject: [PATCH] feat: #1606 Better support for FileFormatVersion Added tests --- Tests/CMakeLists.txt | 4 +++ Tests/meson.build | 12 +++++++++ Tests/src/FileFormatVersion.cpp | 48 +++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 Tests/src/FileFormatVersion.cpp diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index 30bbf2103..be12e9d29 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -34,6 +34,10 @@ osmscout_test_project(NAME ColorParse SOURCES src/ColorParse.cpp) #---- CoordinateEncoding osmscout_test_project(NAME CoordinateEncoding SOURCES src/CoordinateEncoding.cpp COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/data/testregion") +#---- FileFormatVersion +osmscout_test_project(NAME FileFormatVersion SOURCES src/FileFormatVersion.cpp) +set_tests_properties(FileFormatVersion PROPERTIES ENVIRONMENT "TESTS_TOP_DIR=${CMAKE_CURRENT_SOURCE_DIR}") + #---- Latch osmscout_test_project(NAME Latch SOURCES src/Latch.cpp) diff --git a/Tests/meson.build b/Tests/meson.build index 624cf42af..c5cef2598 100644 --- a/Tests/meson.build +++ b/Tests/meson.build @@ -172,6 +172,18 @@ File = executable('File', test('Check File utilities', File) +FileFormatVersion = executable('FileFormatVersion', + 'src/FileFormatVersion.cpp', + include_directories: [testIncDir, osmscoutIncDir], + dependencies: [mathDep, openmpDep], + link_with: [osmscout], + install: true, + install_dir: testInstallDir) + +test('Check FileFormatVersion APIs', + FileFormatVersion, + env: ['TESTS_TOP_DIR='+meson.current_source_dir()]) + FileScannerWriter = executable('FileScannerWriter', 'src/FileScannerWriter.cpp', include_directories: [testIncDir, osmscoutIncDir], diff --git a/Tests/src/FileFormatVersion.cpp b/Tests/src/FileFormatVersion.cpp new file mode 100644 index 000000000..e9d8ce608 --- /dev/null +++ b/Tests/src/FileFormatVersion.cpp @@ -0,0 +1,48 @@ + +#include + +#include +#include + +#include + +static std::string GetTestDatabaseDirectory() +{ + char* testsTopDirEnv=::getenv("TESTS_TOP_DIR"); + + if (testsTopDirEnv==nullptr) { + throw osmscout::UninitializedException("Expected environment variable 'TESTS_TOP_DIR' not set"); + } + + std::string testsTopDir=testsTopDirEnv; + + if (testsTopDir.empty()) { + throw osmscout::UninitializedException("Environment variable 'TESTS_TOP_DIR' is empty"); + } + + if (!osmscout::IsDirectory(testsTopDir)) { + throw osmscout::UninitializedException("Environment variable 'TESTS_TOP_DIR' does not point to directory"); + } + + return std::filesystem::path(testsTopDir).append("data").append("testregion").native(); +} + +TEST_CASE("TypeConfig::GetFileFormatVersion(dir) throws exception on missing db") { + CHECK_THROWS_AS(osmscout::TypeConfig::GetDatabaseFileFormatVersion("does_not_exist"),osmscout::IOException); +} + +TEST_CASE("Database::GetFileFormatVersion(dir) throws exception on missing db") { + CHECK_THROWS_AS(osmscout::Database::GetDatabaseFileFormatVersion("does_not_exist"),osmscout::IOException); +} + +TEST_CASE("TypeConfig::GetFileFormatVersion(dir) returns current version for test database") { + REQUIRE(osmscout::TypeConfig::GetDatabaseFileFormatVersion(GetTestDatabaseDirectory()) == osmscout::FILE_FORMAT_VERSION); +} + +TEST_CASE("Database::GetFileFormatVersion(dir) returns current version for test database") { + REQUIRE(osmscout::Database::GetDatabaseFileFormatVersion(GetTestDatabaseDirectory()) == osmscout::FILE_FORMAT_VERSION); +} + +TEST_CASE("Database::GetLibraryFileFormatVersion() returns current version") { + REQUIRE(osmscout::Database::GetLibraryFileFormatVersion() == osmscout::FILE_FORMAT_VERSION); +}