Skip to content
Snippets Groups Projects
Commit 3a7e347c authored by Riccardo Maria Bianchi's avatar Riccardo Maria Bianchi :sunny:
Browse files

Merge branch 'add-tests' into 'main'

Enabling CTest testing and add a first 'create db file' test

See merge request !233
parents 755c5d70 630abc13
No related branches found
No related tags found
1 merge request!233Enabling CTest testing and add a first 'create db file' test
Pipeline #6601792 failed
......@@ -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
......
......@@ -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)
// 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;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment