00001 #define BOOST_TEST_MODULE ( databaseconfiguration test)
00002
00003 #include "boost/test/auto_unit_test.hpp"
00004
00005 #include <string>
00006 #include <iostream>
00007 #include <memory>
00008 #include <cassert>
00009 #include <dirent.h>
00010
00011
00012 #include "otsdaq-core/ConfigurationInterface/ConfigurationManager.h"
00013 #include "otsdaq-core/ConfigurationInterface/ConfigurationInterface.h"
00014
00015
00016
00017 #include "otsdaq-core/PluginMakers/MakeInterfaceConfiguration.h"
00018 #include "otsdaq-core/PluginMakers/MakeInterface.h"
00019 #include "artdaq-database/StorageProviders/FileSystemDB/provider_filedb_index.h"
00020 #include "artdaq-database/JsonDocument/JSONDocument.h"
00021
00022 using namespace ots;
00023
00024 BOOST_AUTO_TEST_SUITE( databaseconfiguration_test )
00025
00026 BOOST_AUTO_TEST_CASE(readxml_writedb_configurations)
00027 {
00028
00029
00030
00031
00032 std::vector<std::string> configTables;
00033
00034
00035 setenv("CONFIGURATION_DATA_PATH",(std::string(getenv("USER_DATA")) + "/ConfigurationDataExamples").c_str(),1);
00036 std::string configDir = std::string(getenv("CONFIGURATION_DATA_PATH")) + '/';
00037
00038
00039
00040 setenv("CONFIGURATION_TYPE","File",1);
00041
00042
00043 {
00044 std::cout << __COUT_HDR_FL__ << "ConfigurationDir: " << configDir << std::endl;
00045 DIR *dp;
00046
00047 struct dirent *dirp;
00048
00049 if((dp = opendir(configDir.c_str())) == 0)
00050 {
00051 std::cout << __COUT_HDR_FL__<< "ERROR:(" << errno << "). Can't open directory: " << configDir << std::endl;
00052 exit(0);
00053 }
00054
00055 const unsigned char isDir = 0x4;
00056 while ((dirp = readdir(dp)) != 0)
00057 if(dirp->d_type == isDir && dirp->d_name[0] != '.' )
00058 {
00059 std::cout << __COUT_HDR_FL__<< dirp->d_name << std::endl;
00060 configTables.push_back(dirp->d_name);
00061 }
00062
00063 closedir(dp);
00064 }
00065
00066 ConfigurationInterface* theInterface_ = ConfigurationInterface::getInstance(true);
00067
00068 for(unsigned int i = 0; i < configTables.size(); ++i)
00069 {
00070 theInterface_ = ConfigurationInterface::getInstance(true);
00071 ConfigurationBase* base = 0;
00072 std::cout << __COUT_HDR_FL__ << std::endl;
00073 std::cout << __COUT_HDR_FL__ << std::endl;
00074 std::cout << __COUT_HDR_FL__ << (i+1) << " of " << configTables.size() << ": " << configTables[i] << std::endl;
00075
00076 theInterface_->get(base,configTables[i], 0, 0, false,
00077 ConfigurationVersion(ConfigurationVersion::DEFAULT));
00078
00079 std::cout << __COUT_HDR_FL__ << "loaded " << configTables[i]<< std::endl;
00080
00081
00082
00083
00084
00085
00086 std::cout << __COUT_HDR_FL__ << "Current version: " << base->getViewVersion() << std::endl;
00087
00088
00089
00090
00091 theInterface_ = ConfigurationInterface::getInstance(false);
00092
00093
00094
00095
00096
00097 ConfigurationVersion tmpView = base->createTemporaryView(ConfigurationVersion(ConfigurationVersion::DEFAULT));
00098 theInterface_->saveNewVersion(base,tmpView);
00099
00100 delete base;
00101
00102
00103 }
00104
00105 std::cout << __COUT_HDR_FL__ << "end of debugging Configuration!" << std::endl;
00106 return;
00107 }
00108
00109 BOOST_AUTO_TEST_CASE(readdb_writexml_configurations)
00110 {
00111
00112 std::vector<std::string> configTables;
00113
00114
00115 setenv("CONFIGURATION_DATA_PATH",(std::string(getenv("USER_DATA")) + "/ConfigurationDataExamples").c_str(),1);
00116 std::string configDir = std::string(getenv("CONFIGURATION_DATA_PATH")) + '/';
00117
00118
00119
00120 setenv("CONFIGURATION_TYPE","File",1);
00121
00122
00123 {
00124 std::cout << __COUT_HDR_FL__ << "ConfigurationDir: " << configDir << std::endl;
00125 DIR *dp;
00126
00127 struct dirent *dirp;
00128
00129 if((dp = opendir(configDir.c_str())) == 0)
00130 {
00131 std::cout << __COUT_HDR_FL__<< "ERROR:(" << errno << "). Can't open directory: " << configDir << std::endl;
00132 exit(0);
00133 }
00134
00135 const unsigned char isDir = 0x4;
00136 while ((dirp = readdir(dp)) != 0)
00137 if(dirp->d_type == isDir && dirp->d_name[0] != '.' )
00138 {
00139 std::cout << __COUT_HDR_FL__<< dirp->d_name << std::endl;
00140 configTables.push_back(dirp->d_name);
00141 }
00142
00143 closedir(dp);
00144 }
00145
00146 ConfigurationInterface* theInterface_ = ConfigurationInterface::getInstance(false);
00147
00148 for(unsigned int i = 0; i < configTables.size(); ++i)
00149 {
00150 theInterface_ = ConfigurationInterface::getInstance(false);
00151 ConfigurationBase* base = 0;
00152 std::cout << __COUT_HDR_FL__ << std::endl;
00153 std::cout << __COUT_HDR_FL__ << std::endl;
00154 std::cout << __COUT_HDR_FL__ << (i+1) << " of " << configTables.size() << ": " << configTables[i] << std::endl;
00155
00156 theInterface_->get(base,configTables[i], 0, 0, false, ConfigurationVersion(ConfigurationVersion::DEFAULT));
00157
00158 std::cout << __COUT_HDR_FL__ << "loaded " << configTables[i]<< std::endl;
00159
00160
00161
00162 std::cout << __COUT_HDR_FL__ << "Current version: " << base->getViewVersion() << std::endl;
00163
00164
00165
00166
00167
00168
00169
00170
00171 ConfigurationVersion tmpView = base->createTemporaryView(ConfigurationVersion(ConfigurationVersion::DEFAULT));
00172 theInterface_->saveNewVersion(base,tmpView);
00173
00174 delete base;
00175
00176 }
00177
00178 std::cout << __COUT_HDR_FL__ << "end of debugging Configuration!" << std::endl;
00179 return;
00180 }
00181
00182 BOOST_AUTO_TEST_SUITE_END()
00183