diff --git a/CMakeLists.txt b/CMakeLists.txt index 0f5fae860f14bc27c8998673eeb6bd279b45c5ac..2300d7f6633ad4dd98791ea24fc1c481010363c7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,6 +38,14 @@ include( SetupJSON ) # Find the dependencies that the project always picks up from its environment. find_package( SQLite3 3.7.17 ) + +# === Enable testing functionality +# NOTE: this must be in the root CMakeLists.txt file +# even if the tests are defined in CMake files +# located in sub-directories. +enable_testing() + + # === Main targets built by this project === # switches to let users build specific packages on request diff --git a/GeoModelIO/GeoModelDBManager/CMakeLists.txt b/GeoModelIO/GeoModelDBManager/CMakeLists.txt index 5bc09043fef3853c4d51212b5279a8d48ee79b4f..7eb42f1af7a018644585e7a19c7d59f74234d598 100644 --- a/GeoModelIO/GeoModelDBManager/CMakeLists.txt +++ b/GeoModelIO/GeoModelDBManager/CMakeLists.txt @@ -37,3 +37,8 @@ install(TARGETS GeoModelDBManager install( FILES ${HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/GeoModelDBManager COMPONENT Development ) + +add_executable(test_create_db_file tests/test_create_db_file.cpp) +target_link_libraries( test_create_db_file GeoModelIO::GeoModelDBManager) +add_test(NAME TestCreateDBFile + COMMAND test_create_db_file) diff --git a/GeoModelIO/GeoModelDBManager/tests/test_create_db_file.cpp b/GeoModelIO/GeoModelDBManager/tests/test_create_db_file.cpp new file mode 100644 index 0000000000000000000000000000000000000000..970e18de7a8f9a009549d12bfb04cd3b692517be --- /dev/null +++ b/GeoModelIO/GeoModelDBManager/tests/test_create_db_file.cpp @@ -0,0 +1,53 @@ +// Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration + +/* + * this test simply creates a GeoModel .db file + * through the use of GeoModelDBManager, + * then it deletes it. + * + * author: Riccardo Maria BIANCHI <riccardo.maria.bianchi@cern.ch> + * 2023, Dec 11 + * + */ + + +// GeoModel includes +#include "GeoModelDBManager/GMDBManager.h" +// c++ includes +#include <fstream> + + +int main(int argc, char *argv[]) +{ + //------------------------------------------------------------------------------------// + // Open a geometry file + //------------------------------------------------------------------------------------// + std::string path = "geometry.db"; + + // check if DB file exists. If not, return. + // FIXME: TODO: this check should go in the 'GMDBManager' constructor. + std::ifstream infile(path.c_str()); + if ( infile.good() ) { + std::cout << "\n\tERROR!! A '" << path << "' file exists already!! Please, remove, move, or rename it before running this program. Exiting..."; + exit(EXIT_FAILURE); + } + infile.close(); + + // open the DB connection + GMDBManager db(path); + + // check the DB connection + if (db.checkIsDBOpen()) { + std::cout << "OK! Database is open!" << std::endl; + } else { + std::cout << "Database ERROR!! Exiting..." << std::endl; + exit(EXIT_FAILURE); + } + + std::cout << "Now, we remove the test .db file...\n"; + std::remove(path.c_str()); // delete file + std::cout << "OK, test .db file removed.\n"; + + + return 0; +}