@@ -40,6 +40,7 @@ class NutConfTest : public CppUnit::TestFixture
40
40
CPPUNIT_TEST ( testOptions );
41
41
CPPUNIT_TEST ( testParseCHARS );
42
42
CPPUNIT_TEST ( testParseSTRCHARS );
43
+ CPPUNIT_TEST ( testParseBoolInt );
43
44
CPPUNIT_TEST ( testParseToken );
44
45
CPPUNIT_TEST ( testParseTokenWithoutColon );
45
46
CPPUNIT_TEST ( testGenericConfigParser );
@@ -55,6 +56,7 @@ class NutConfTest : public CppUnit::TestFixture
55
56
void testOptions ();
56
57
void testParseCHARS ();
57
58
void testParseSTRCHARS ();
59
+ void testParseBoolInt ();
58
60
void testParseToken ();
59
61
void testParseTokenWithoutColon ();
60
62
@@ -140,6 +142,126 @@ void NutConfTest::testParseSTRCHARS()
140
142
}
141
143
}
142
144
145
+ void NutConfTest::testParseBoolInt ()
146
+ {
147
+ // NOTE: Can not use CPPUNIT_ASSERT_EQUAL() below, requires an assertEqual() method
148
+ BoolInt bi;
149
+ CPPUNIT_ASSERT_MESSAGE (" BoolInt should be not 'set()' initially" , !(bi.set ()));
150
+ CPPUNIT_ASSERT_ASSERTION_FAIL_MESSAGE (" Unassigned BoolInt should not be equal to an int" ,
151
+ CPPUNIT_ASSERT (bi == 0 ));
152
+ CPPUNIT_ASSERT_ASSERTION_FAIL_MESSAGE (" Unassigned BoolInt should not be equal to an int" ,
153
+ CPPUNIT_ASSERT (bi == 1 ));
154
+ CPPUNIT_ASSERT_ASSERTION_FAIL_MESSAGE (" Unassigned BoolInt should not be equal to a bool" ,
155
+ CPPUNIT_ASSERT (bi == true ));
156
+ CPPUNIT_ASSERT_ASSERTION_FAIL_MESSAGE (" Unassigned BoolInt should not be equal to a bool" ,
157
+ CPPUNIT_ASSERT (bi == false ));
158
+ CPPUNIT_ASSERT_ASSERTION_FAIL_MESSAGE (" Unassigned BoolInt should not be equal to a string" ,
159
+ CPPUNIT_ASSERT (bi == " 2" ));
160
+ CPPUNIT_ASSERT_ASSERTION_FAIL_MESSAGE (" Unassigned BoolInt should not be equal to a string" ,
161
+ CPPUNIT_ASSERT (bi == " on" ));
162
+ CPPUNIT_ASSERT_ASSERTION_FAIL_MESSAGE (" Unassigned BoolInt should not be equal to a string" ,
163
+ CPPUNIT_ASSERT (bi == " no" ));
164
+ /*
165
+ // Actually not "must throw", just returns false for any comparisons - see above
166
+ CPPUNIT_ASSERT_THROW_MESSAGE("Unassigned BoolInt comparisons must throw exceptions (string)",
167
+ if (bi == "1") {}, std::invalid_argument);
168
+ CPPUNIT_ASSERT_THROW_MESSAGE("Unassigned BoolInt comparisons must throw exceptions (int)",
169
+ if (bi == 1) {}, std::invalid_argument);
170
+ CPPUNIT_ASSERT_THROW_MESSAGE("Unassigned BoolInt comparisons must throw exceptions (bool)",
171
+ if (bi == true) {}, std::invalid_argument);
172
+ */
173
+
174
+ bi = 42 ;
175
+ CPPUNIT_ASSERT_MESSAGE (" BoolInt should be 'set()' after assignment from int" , bi.set ());
176
+ CPPUNIT_ASSERT_MESSAGE (" BoolInt should be equal to the int" , (bi == 42 ));
177
+ CPPUNIT_ASSERT_MESSAGE (" BoolInt should be equal to the string value of int" , (bi == " 42" ));
178
+ CPPUNIT_ASSERT_ASSERTION_FAIL_MESSAGE (" BoolInt should not be equal to another int" ,
179
+ CPPUNIT_ASSERT (bi == 2 ));
180
+ CPPUNIT_ASSERT_ASSERTION_FAIL_MESSAGE (" BoolInt should not be equal to a bool" ,
181
+ CPPUNIT_ASSERT (bi == true ));
182
+ CPPUNIT_ASSERT_ASSERTION_FAIL_MESSAGE (" BoolInt should not be equal to a bool" ,
183
+ CPPUNIT_ASSERT (bi == false ));
184
+
185
+ bi = true ;
186
+ CPPUNIT_ASSERT_MESSAGE (" BoolInt should be 'set()' after assignment from bool" , bi.set ());
187
+ CPPUNIT_ASSERT_MESSAGE (" BoolInt should be equal to the bool" , (bi == true ));
188
+ CPPUNIT_ASSERT_MESSAGE (" BoolInt should be equal to the int value of bool" , (bi == 1 ));
189
+ CPPUNIT_ASSERT_ASSERTION_FAIL_MESSAGE (" BoolInt should not be equal to another bool" ,
190
+ CPPUNIT_ASSERT (bi == false ));
191
+ CPPUNIT_ASSERT_ASSERTION_FAIL_MESSAGE (" BoolInt should not be equal to int value of another bool" ,
192
+ CPPUNIT_ASSERT (bi == 0 ));
193
+ CPPUNIT_ASSERT_ASSERTION_FAIL_MESSAGE (" BoolInt should not be equal to another int" ,
194
+ CPPUNIT_ASSERT (bi == 2 ));
195
+ CPPUNIT_ASSERT_ASSERTION_FAIL_MESSAGE (" BoolInt should not be equal to old int" ,
196
+ CPPUNIT_ASSERT (bi == 42 ));
197
+
198
+ bi = false ;
199
+ CPPUNIT_ASSERT_MESSAGE (" BoolInt should be 'set()' after assignment from bool" , bi.set ());
200
+ CPPUNIT_ASSERT_MESSAGE (" BoolInt should be equal to the bool" , (bi == false ));
201
+ CPPUNIT_ASSERT_MESSAGE (" BoolInt should be equal to the int value of bool" , (bi == 0 ));
202
+ CPPUNIT_ASSERT_ASSERTION_FAIL_MESSAGE (" BoolInt should not be equal to another bool" ,
203
+ CPPUNIT_ASSERT (bi == true ));
204
+ CPPUNIT_ASSERT_ASSERTION_FAIL_MESSAGE (" BoolInt should not be equal to int value of another bool" ,
205
+ CPPUNIT_ASSERT (bi == 1 ));
206
+ CPPUNIT_ASSERT_ASSERTION_FAIL_MESSAGE (" BoolInt should not be equal to another int" ,
207
+ CPPUNIT_ASSERT (bi == 2 ));
208
+ CPPUNIT_ASSERT_ASSERTION_FAIL_MESSAGE (" BoolInt should not be equal to old int" ,
209
+ CPPUNIT_ASSERT (bi == 42 ));
210
+
211
+ bi = " -1" ;
212
+ CPPUNIT_ASSERT_MESSAGE (" BoolInt should be 'set()' after assignment from string" , bi.set ());
213
+ CPPUNIT_ASSERT_MESSAGE (" BoolInt should be equal to the int" , (bi == -1 ));
214
+ CPPUNIT_ASSERT_ASSERTION_FAIL_MESSAGE (" BoolInt should not be equal to another int" ,
215
+ CPPUNIT_ASSERT (bi == 2 ));
216
+ CPPUNIT_ASSERT_ASSERTION_FAIL_MESSAGE (" BoolInt should not be equal to a bool" ,
217
+ CPPUNIT_ASSERT (bi == true ));
218
+ CPPUNIT_ASSERT_ASSERTION_FAIL_MESSAGE (" BoolInt should not be equal to a bool" ,
219
+ CPPUNIT_ASSERT (bi == false ));
220
+
221
+ bi = " off" ;
222
+ CPPUNIT_ASSERT_MESSAGE (" BoolInt should be 'set()' after assignment from string" , bi.set ());
223
+ CPPUNIT_ASSERT_MESSAGE (" BoolInt should be equal to the bool" , (bi == false ));
224
+ CPPUNIT_ASSERT_MESSAGE (" BoolInt should be equal to the int value of bool" , (bi == 0 ));
225
+ CPPUNIT_ASSERT_MESSAGE (" BoolInt should be equal to the string value of bool" , (bi == " off" ));
226
+ CPPUNIT_ASSERT_MESSAGE (" BoolInt should be equal to the string value of bool" , (bi == " false" ));
227
+ CPPUNIT_ASSERT_MESSAGE (" BoolInt should be equal to the string value of bool" , (bi == " 0" ));
228
+ CPPUNIT_ASSERT_MESSAGE (" BoolInt should be equal to the string value of bool" , (bi == " no" ));
229
+ CPPUNIT_ASSERT_ASSERTION_FAIL_MESSAGE (" BoolInt should not be equal to the string value of another bool" ,
230
+ CPPUNIT_ASSERT (bi == " yes" ));
231
+ CPPUNIT_ASSERT_ASSERTION_FAIL_MESSAGE (" BoolInt should not be equal to the string value of another bool" ,
232
+ CPPUNIT_ASSERT (bi == " true" ));
233
+ CPPUNIT_ASSERT_ASSERTION_FAIL_MESSAGE (" BoolInt should not be equal to the string value of another bool" ,
234
+ CPPUNIT_ASSERT (bi == " 1" ));
235
+ CPPUNIT_ASSERT_ASSERTION_FAIL_MESSAGE (" BoolInt should not be equal to the string value of another bool" ,
236
+ CPPUNIT_ASSERT (bi == " on" ));
237
+ CPPUNIT_ASSERT_ASSERTION_FAIL_MESSAGE (" BoolInt should not be equal to the string value of another bool" ,
238
+ CPPUNIT_ASSERT (bi == " ok" ));
239
+ CPPUNIT_ASSERT_ASSERTION_FAIL_MESSAGE (" BoolInt should not be equal to another bool" ,
240
+ CPPUNIT_ASSERT (bi == true ));
241
+ CPPUNIT_ASSERT_ASSERTION_FAIL_MESSAGE (" BoolInt should not be equal to int value of another bool" ,
242
+ CPPUNIT_ASSERT (bi == 1 ));
243
+ CPPUNIT_ASSERT_ASSERTION_FAIL_MESSAGE (" BoolInt should not be equal to another int" ,
244
+ CPPUNIT_ASSERT (bi == 2 ));
245
+ CPPUNIT_ASSERT_ASSERTION_FAIL_MESSAGE (" BoolInt should not be equal to old int" ,
246
+ CPPUNIT_ASSERT (bi == 42 ));
247
+
248
+ CPPUNIT_ASSERT_THROW_MESSAGE (" BoolInt assignment from invalid strings must throw exceptions" ,
249
+ (bi = " AbraCadabra" ), std::invalid_argument);
250
+
251
+ CPPUNIT_ASSERT_THROW_MESSAGE (" BoolInt assignment from invalid strings must throw exceptions" ,
252
+ (bi = " 1.5" ), std::invalid_argument);
253
+
254
+ CPPUNIT_ASSERT_THROW_MESSAGE (" BoolInt assignment from invalid strings must throw exceptions" ,
255
+ (bi = " -3.8" ), std::invalid_argument);
256
+
257
+ // Standard casing only
258
+ CPPUNIT_ASSERT_THROW_MESSAGE (" BoolInt assignment from invalid strings must throw exceptions" ,
259
+ (bi = " OFF" ), std::invalid_argument);
260
+
261
+ bi.clear ();
262
+ CPPUNIT_ASSERT_MESSAGE (" BoolInt should be not 'set()' after 'clear()" , !(bi.set ()));
263
+ }
264
+
143
265
void NutConfTest::testParseToken ()
144
266
{
145
267
static const char * src =
0 commit comments