testParameterStorage.cc
Go to the documentation of this file.
1 
8 #include <iostream>
9 #include <string>
10 
11 #include <tst/Verify.h>
12 
13 #include <utl/ParameterStorage.h>
14 
15 #include <cppunit/extensions/HelperMacros.h>
16 
17 using namespace std;
18 using namespace utl;
19 using namespace tst;
20 
24 class testParameterStorage : public CppUnit::TestFixture {
25 
26  CPPUNIT_TEST_SUITE(testParameterStorage);
27 //CPPUNIT_TEST(testEqualAndCopyCtor);
28  CPPUNIT_TEST(testHasSetGet);
29  CPPUNIT_TEST_SUITE_END();
30 
31  // this is the enum to define the list of allowed parameters, should usually be put in a separate .h file
32  // if the user numbers the enum by hand, it is possible to remove deprecated parameters afterwards
33  enum Dimension { eHeight = 0,
34  /* eTest = 1, */
35  eWidth = 2,
36  eLength = 3};
37 
38 private:
40 
41 public:
42 
43  void
45  {
46  }
47 
48  void
50  {
51  }
52 
53 /*
54  void
55  testEqualAndCopyCtor()
56  {
57  ParameterStorage copyParameterStorage<Dimension, double>(ourParameterStorage);
58  CPPUNIT_ASSERT(copyParameterStorage == ourParameterStorage);
59  CPPUNIT_ASSERT(!(copyParameterStorage != ourParameterStorage));
60  }
61 */
62 
63  void
65  {
66 
67  // verify that parameter eHeight has not been set
68  CPPUNIT_ASSERT(Verify<Equal>(ourParameterStorage.HasParameter(eHeight), false));
69 
70  // verify that getting undefined parameter eHeight produces an exception --- how to send result to test framework?
71  try {
72  ourParameterStorage.GetParameter(eHeight);
73  }
74  catch (NonExistentComponentException& ex) {
75  cerr << "Auger exception: " << ex.GetExceptionName()
76  << "\nMessage: " << ex.GetMessage() << endl;
77  }
78 
79 // CPPUNIT_TEST_EXCEPTION( ourParameterStorage.GetParameter(eHeight) , NonExistentComponentException);
80 
81  // set parameter eHeight without lock
82  ourParameterStorage.SetParameter(eHeight, 123.4, false);
83 
84  // verify that parameter eHeight has now been set
85  CPPUNIT_ASSERT(Verify<Equal>(ourParameterStorage.HasParameter(eHeight), true));
86 
87  // verify that parameter eHeight can be read out correctly
88  CPPUNIT_ASSERT(Verify<CloseTo>(ourParameterStorage.GetParameter(eHeight), 123.4));
89 
90  // verify that locking status of parameter eHeight can be read out correctly
91  CPPUNIT_ASSERT(Verify<Equal>(ourParameterStorage.GetParameterLockStatus(eHeight), false));
92 
93  // re-set parameter eHeight without lock
94  ourParameterStorage.SetParameter(eHeight, 246.8, false);
95 
96  // verify that re-setting of parameter eHeight worked correctly
97  CPPUNIT_ASSERT(Verify<CloseTo>(ourParameterStorage.GetParameter(eHeight), 246.8));
98 
99  // verify that setting covariance of eHeight, eWidth without parameter eWidth being set leads to an exception
100  try {
101  ourParameterStorage.SetParameterCovariance(eHeight, eWidth, 0.11, false);
102  }
103  catch (InvalidConfigurationException& ex) {
104  cerr << "Auger exception: " << ex.GetExceptionName()
105  << "\nMessage: " << ex.GetMessage() << endl;
106  }
107 
108  // verify that deleting of parameter eHeight works correctly
109  ourParameterStorage.DeleteParameter(eHeight);
110 
111  // verify that parameter eHeight has not been set
112  CPPUNIT_ASSERT(Verify<Equal>(ourParameterStorage.HasParameter(eHeight), false));
113 
114  // check that deleting unset parameter eLength does not hurt
115  ourParameterStorage.DeleteParameter(eLength);
116 
117  // re-set parameter eHeight with lock
118  ourParameterStorage.SetParameter(eHeight, 369.12, true);
119 
120  // verify that setting of parameter eHeight worked correctly
121  CPPUNIT_ASSERT(Verify<CloseTo>(ourParameterStorage.GetParameter(eHeight), 369.12));
122 
123  // verify that parameter eHeight is now locked
124  CPPUNIT_ASSERT(Verify<Equal>(ourParameterStorage.GetParameterLockStatus(eHeight), true));
125 
126  // verify that deleting locked parameter eHeight produces an exception
127  try {
128  ourParameterStorage.DeleteParameter(eHeight);
129  }
130  catch (InvalidConfigurationException& ex) {
131  cerr << "Auger exception: " << ex.GetExceptionName()
132  << "\nMessage: " << ex.GetMessage() << endl;
133  }
134 
135  // verify that parameter covariance between eHeight and eWidth has not been set
136 // reactivate this once proper exceptions are thrown inside ParameterStorage
137 // CPPUNIT_ASSERT(Verify<Equal>(ourParameterStorage.HasParameterCovariance(eHeight, eWidth), false));
138 // CPPUNIT_ASSERT(Verify<Equal>(ourParameterStorage.HasParameterCovariance(eWidth, eHeight), false));
139 
140  // verify that getting undefined parameter covariance between eHeight and eWeight produces an exception --- how to send result to test framework?
141  try {
142  ourParameterStorage.GetParameterCovariance(eHeight, eWidth);
143  }
144  catch (NonExistentComponentException& ex) {
145  cerr << "Auger exception: " << ex.GetExceptionName()
146  << "\nMessage: " << ex.GetMessage() << endl;
147  }
148 
149  // set parameter eWidth without lock
150  ourParameterStorage.SetParameter(eWidth, 0.25, false);
151 
152  // set parameter covariance of eHeight, eWidth without lock
153  ourParameterStorage.SetParameterCovariance(eHeight, eWidth, 0.33, false);
154 
155  // verify that parameter covariance between eHeight and eWidth has now been set
156  CPPUNIT_ASSERT(Verify<Equal>(ourParameterStorage.HasParameterCovariance(eHeight, eWidth), true));
157  CPPUNIT_ASSERT(Verify<Equal>(ourParameterStorage.HasParameterCovariance(eWidth, eHeight), true));
158 
159  // verify that parameter covariance between eHeight and eWidth can be read out correctly
160  CPPUNIT_ASSERT(Verify<CloseTo>(ourParameterStorage.GetParameterCovariance(eHeight, eWidth), 0.33));
161  CPPUNIT_ASSERT(Verify<CloseTo>(ourParameterStorage.GetParameterCovariance(eWidth, eHeight), 0.33));
162 
163  // verify that locking status of parameter-covariance between eHeight and eWidth can be read out correctly
164  CPPUNIT_ASSERT(Verify<Equal>(ourParameterStorage.GetParameterCovarianceLockStatus(eHeight, eWidth), false));
165  CPPUNIT_ASSERT(Verify<Equal>(ourParameterStorage.GetParameterCovarianceLockStatus(eWidth, eHeight), false));
166 
167  // verify that re-setting parameter-covariance between eHeight and eWidth works, keep lock open
168  ourParameterStorage.SetParameterCovariance(eHeight, eWidth, 0.66, false);
169 
170  // verify that parameter covariance between eHeight and eWidth can be read out correctly
171  CPPUNIT_ASSERT(Verify<CloseTo>(ourParameterStorage.GetParameterCovariance(eHeight, eWidth), 0.66));
172  CPPUNIT_ASSERT(Verify<CloseTo>(ourParameterStorage.GetParameterCovariance(eWidth, eHeight), 0.66));
173 
174  // verify that deleting parameter covariance between eHeight and eWidth works
175  ourParameterStorage.DeleteParameterCovariance(eHeight, eWidth);
176 
177  // verify that also the parameter covariances are gone
178  CPPUNIT_ASSERT(Verify<Equal>(ourParameterStorage.HasParameterCovariance(eHeight, eWidth), false));
179  CPPUNIT_ASSERT(Verify<Equal>(ourParameterStorage.HasParameterCovariance(eWidth, eHeight), false));
180 
181  // once again set parameter-covariance between eHeight and eWidth works, keep lock open
182  ourParameterStorage.SetParameterCovariance(eHeight, eWidth, 0.66, false);
183 
184  // delete parameter eWidth to check if associated parameter covariance is deleted as well
185  ourParameterStorage.DeleteParameter(eWidth);
186 
187  // verify that also the parameter covariances are gone
188 // reactivate this once proper exceptions are thrown inside ParameterStorage
189 // CPPUNIT_ASSERT(Verify<Equal>(ourParameterStorage.HasParameterCovariance(eHeight, eWidth), false));
190 // CPPUNIT_ASSERT(Verify<Equal>(ourParameterStorage.HasParameterCovariance(eWidth, eHeight), false));
191 
192  // set again parameter eWidth, this time with lock
193  ourParameterStorage.SetParameter(eWidth, 0.25, true);
194 
195  // set again parameter covariance of eHeight, eWidth with locking and check that it can be read out and is there
196  ourParameterStorage.SetParameterCovariance(eHeight, eWidth, 0.77, true);
197  CPPUNIT_ASSERT(Verify<CloseTo>(ourParameterStorage.GetParameterCovariance(eHeight, eWidth), 0.77));
198 
199  // verify that locking status of parameter-covariance between eHeight and eWidth is now true
200  CPPUNIT_ASSERT(Verify<Equal>(ourParameterStorage.GetParameterCovarianceLockStatus(eHeight, eWidth), true));
201  CPPUNIT_ASSERT(Verify<Equal>(ourParameterStorage.GetParameterCovarianceLockStatus(eWidth, eHeight), true));
202 
203  // try to delete parameter covariance of eHeight and eWidth in spite of locked status and verify that exception is raised
204  try {
205  ourParameterStorage.DeleteParameterCovariance(eHeight, eWidth);
206  }
207  catch (InvalidConfigurationException& ex) {
208  cerr << "Auger exception: " << ex.GetExceptionName()
209  << "\nMessage: " << ex.GetMessage() << endl;
210  }
211 
212  }
213 
214 };
215 
217 
218 // Configure (x)emacs for this file ...
219 // Local Variables:
220 // mode: c++
221 // End:
ParameterStorage< Dimension, double > ourParameterStorage
Base class for exceptions arising because configuration data are not valid.
Base class for exceptions trying to access non-existing components.
CPPUNIT_TEST_SUITE_REGISTRATION(testAiresShowerFile)
const std::string & GetMessage() const
Retrieve the message from the exception.

, generated on Tue Sep 26 2023.