testCentralConfig.cc
Go to the documentation of this file.
1 
8 #include <string>
9 #include <iostream>
10 #include <list>
11 
12 #include <utl/AugerException.h>
13 #include <utl/AugerUnits.h>
14 #include <utl/ErrorLogger.h>
15 
16 #include <fwk/CentralConfig.h>
17 #include <utl/Reader.h>
18 #include <fwk/RunController.h>
19 
20 #include <cppunit/extensions/HelperMacros.h>
21 #include <tst/Verify.h>
22 
23 using namespace std;
24 using namespace utl;
25 using namespace tst;
26 using namespace fwk;
27 
28 
29 class CentralConfigTest : public CppUnit::TestFixture {
30 
31  CPPUNIT_TEST_SUITE(CentralConfigTest);
32  CPPUNIT_TEST_EXCEPTION(testCreationException, AugerException);
33  CPPUNIT_TEST(testCreation);
34  CPPUNIT_TEST(testGetSomeData);
35  CPPUNIT_TEST(testConfigLinkOverride);
36  CPPUNIT_TEST(testGetConfig);
37  CPPUNIT_TEST(testParameterOverride);
38  CPPUNIT_TEST(testLog);
39  CPPUNIT_TEST(testSeverity);
40  CPPUNIT_TEST_SUITE_END();
41 
42 public:
43  void setUp() { }
44 
45  void tearDown() { }
46 
47  void
49  {
50  // The first time you call CentralConfig you must specify a bootstrap file.
51  CentralConfig::GetInstance();
52  }
53 
54  void
56  {
57  CentralConfig* theCC = CentralConfig::GetInstance(BOOTSTRAPFILE);
58 
59  CentralConfig* theCCAgain = CentralConfig::GetInstance();
60  CPPUNIT_ASSERT(Verify<Equal>(theCC, theCCAgain));
61 
62  RunController::GetInstance().Init();
63  RunController::GetInstance().Run();
64  RunController::GetInstance().Finish();
65 
66  theCC->WriteConfig("./CentralConfig/testLogModules.xml");
67 
68  CPPUNIT_ASSERT(theCC->GetInstallPath() != "");
69  cout << theCC->GetInstallPath() << endl;
70  }
71 
72  void
74  {
75  CentralConfig* theCC = CentralConfig::GetInstance();
76  Branch topOfModule1 = theCC->GetTopBranch("Module-1");
77 
78  CPPUNIT_ASSERT(Verify<Equal>(!topOfModule1, false));
79 
80  double someData;
81  topOfModule1.GetChild("someParameters").GetChild("parameter","id=1").GetData(someData);
82  CPPUNIT_ASSERT(Verify<Equal>(someData, 6.1));
83  }
84 
85  void
87  {
88  CentralConfig* theCC = CentralConfig::GetInstance();
89  Branch topOfOverrideModule = theCC->GetTopBranch("Module-to-Override");
90  CPPUNIT_ASSERT(Verify<Equal>(topOfOverrideModule.GetName(),
91  string("module-3")));
92 
93  Branch topOfOverrideModule2 = theCC->GetTopBranch("Module-to-Override2");
94  CPPUNIT_ASSERT(Verify<Equal>(topOfOverrideModule2.GetName(),
95  string("another-override")));
96  }
97 
98  void
100  {
101  CentralConfig* theCC = CentralConfig::GetInstance();
102  string configString =
103  theCC->GetConfig();
104  // add a check here
105  // CPPUNIT_ASSERT(Verify<Equal>(configString, testString));
106  }
107 
108  void
110  {
111  // well, we can at least test that it doesn't crash
112  CentralConfig* theCC = CentralConfig::GetInstance();
113 
114  theCC->WriteConfig("./CentralConfig/testLog.xml");
115  }
116 
117  void
119  {
120  CentralConfig* const theCC = CentralConfig::GetInstance();
121 
122  const Reader* override1 = theCC->GetReader("Parameters-to-Override1");
123  CPPUNIT_ASSERT(override1);
124  const Reader* override2 = theCC->GetReader("Parameters-to-Override2");
125  CPPUNIT_ASSERT(override2);
126 
127  Branch topB = theCC->GetTopBranch("Parameters-to-Override1");
128 
129  double data1;
130  topB.GetChild("someData").GetData(data1);
131  CPPUNIT_ASSERT(Verify<CloseTo>(data1, 3.2));
132 
133  int data2;
134  AttributeMap atts;
135  atts["att"] = "override_me";
136  topB.GetChild("dataWithAtt", atts).GetData(data2);
137  CPPUNIT_ASSERT(Verify<Equal>(data2, 22));
138  topB.GetChild("dataWithAtt", "att=override_me").GetData(data2);
139  CPPUNIT_ASSERT(Verify<Equal>(data2, 22));
140 
141  double dataUnit1;
142  AttributeMap idAtt;
143  idAtt["id"] = "1";
144  topB.GetChild("dataWithUnit", idAtt).GetData(dataUnit1);
145  CPPUNIT_ASSERT(Verify<CloseTo>(dataUnit1, 100.*kilometer));
146  topB.GetChild("dataWithUnit", "id=1").GetData(dataUnit1);
147  CPPUNIT_ASSERT(Verify<CloseTo>(dataUnit1, 100.*kilometer));
148 
149  double dataUnit2;
150  idAtt["id"] = "2";
151  topB.GetChild("dataWithUnit", idAtt).GetData(dataUnit2);
152  CPPUNIT_ASSERT(Verify<CloseTo>(dataUnit2, 3.0*meter/second));
153  topB.GetChild("dataWithUnit", "id=2").GetData(dataUnit2);
154  CPPUNIT_ASSERT(Verify<CloseTo>(dataUnit2, 3.0*meter/second));
155 
156  topB = theCC->GetTopBranch("Parameters-to-Override2");
157  string data3;
158  AttributeMap atts3;
159  atts3["attribute"] = "cow";
160  topB.GetChild("branch1").
161  GetChild("branch2").
162  GetChild("branch4").
163  GetChild("branch5", atts3).GetData(data3);
164  CPPUNIT_ASSERT(Verify<Equal>(data3, string("woof! wooooof!")));
165  topB.GetChild("branch1").
166  GetChild("branch2").
167  GetChild("branch4").
168  GetChild("branch5", "attribute=cow").GetData(data3);
169  CPPUNIT_ASSERT(Verify<Equal>(data3, string("woof! wooooof!")));
170 
171  double data4;
172  topB.GetChild("branch1").GetChild("branch6").GetData(data4);
173  CPPUNIT_ASSERT(Verify<CloseTo>(data4, 3.0));\
174  }
175 
176  void
178  {
179  CPPUNIT_ASSERT(Verify<Equal>(utl::ErrorLogger::GetInstance().GetMinSeverity(),
181  }
182 
183 };
184 
const std::string & GetInstallPath() const
Definition: CentralConfig.h:99
Base class for all exceptions used in the auger offline code.
std::map< std::string, std::string > AttributeMap
Definition: Branch.h:24
std::string GetConfig()
Get configuration in a string.
const double meter
Definition: GalacticUnits.h:29
Debugging message.
Definition: ErrorLogger.h:41
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
Definition: Branch.cc:211
CPPUNIT_TEST_SUITE_REGISTRATION(testAiresShowerFile)
Utility for parsing XML files.
Definition: Reader.h:25
Class representing a document branch.
Definition: Branch.h:107
const double second
Definition: GalacticUnits.h:32
void GetData(bool &b) const
Overloads of the GetData member template function.
Definition: Branch.cc:644
std::string GetName() const
function to get the Branch name
Definition: Branch.cc:374
const utl::Reader * GetReader(const std::string &id)
Get the Reader for moduleConfigLink with given id (XML files)
constexpr double kilometer
Definition: AugerUnits.h:93
static ErrorLogger & GetInstance()
Definition: Singleton.h:128
Main configuration utility.
Definition: CentralConfig.h:51
void WriteConfig(const std::string &fileName="")
Get the link name for moduleConfigLink with given id (any)
utl::Branch GetTopBranch(const std::string &id)
Get top branch for moduleConfigLink with given id (XML files)

, generated on Tue Sep 26 2023.