Skip to content

Commit

Permalink
feat: #1606 Better support for FileFormatVersion
Browse files Browse the repository at this point in the history
Added tests
  • Loading branch information
Framstag committed Sep 29, 2024
1 parent 8c55d7b commit 842de50
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
12 changes: 12 additions & 0 deletions Tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
48 changes: 48 additions & 0 deletions Tests/src/FileFormatVersion.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

#include <filesystem>

#include <osmscout/db/Database.h>
#include <osmscout/TypeConfig.h>

#include <TestMain.h>

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);
}

0 comments on commit 842de50

Please sign in to comment.