@@ -190,6 +190,11 @@ struct TestArgsManager : public ArgsManager
190
190
std::map<std::string, std::string>& GetMapArgs () { return mapArgs; }
191
191
const std::map<std::string, std::vector<std::string> >& GetMapMultiArgs () { return mapMultiArgs; }
192
192
const std::unordered_set<std::string>& GetNegatedArgs () { return m_negated_args; }
193
+ void ReadConfigString (const std::string str_config)
194
+ {
195
+ std::istringstream stream (str_config);
196
+ ReadConfigStream (stream);
197
+ }
193
198
};
194
199
195
200
BOOST_AUTO_TEST_CASE (util_ParseParameters)
@@ -265,6 +270,108 @@ BOOST_AUTO_TEST_CASE(util_GetBoolArgEdgeCases)
265
270
BOOST_CHECK (testArgs.GetBoolArg (" -bar" , false ) == true );
266
271
}
267
272
273
+ BOOST_AUTO_TEST_CASE (util_ReadConfigStream)
274
+ {
275
+ const char *str_config =
276
+ " a=\n "
277
+ " b=1\n "
278
+ " ccc=argument\n "
279
+ " ccc=multiple\n "
280
+ " d=e\n "
281
+ " nofff=1\n "
282
+ " noggg=0\n "
283
+ " h=1\n "
284
+ " noh=1\n "
285
+ " noi=1\n "
286
+ " i=1\n " ;
287
+
288
+ TestArgsManager test_args;
289
+
290
+ test_args.ReadConfigString (str_config);
291
+ // expectation: a, b, ccc, d, fff, ggg, h, i end up in map
292
+
293
+ BOOST_CHECK (test_args.GetMapArgs ().size () == 8 );
294
+ BOOST_CHECK (test_args.GetMapMultiArgs ().size () == 8 );
295
+
296
+ BOOST_CHECK (test_args.GetMapArgs ().count (" -a" )
297
+ && test_args.GetMapArgs ().count (" -b" )
298
+ && test_args.GetMapArgs ().count (" -ccc" )
299
+ && test_args.GetMapArgs ().count (" -d" )
300
+ && test_args.GetMapArgs ().count (" -fff" )
301
+ && test_args.GetMapArgs ().count (" -ggg" )
302
+ && test_args.GetMapArgs ().count (" -h" )
303
+ && test_args.GetMapArgs ().count (" -i" )
304
+ );
305
+
306
+ BOOST_CHECK (test_args.IsArgSet (" -a" )
307
+ && test_args.IsArgSet (" -b" )
308
+ && test_args.IsArgSet (" -ccc" )
309
+ && test_args.IsArgSet (" -d" )
310
+ && test_args.IsArgSet (" -fff" )
311
+ && test_args.IsArgSet (" -ggg" )
312
+ && test_args.IsArgSet (" -h" )
313
+ && test_args.IsArgSet (" -i" )
314
+ && !test_args.IsArgSet (" -zzz" )
315
+ );
316
+
317
+ BOOST_CHECK (test_args.GetArg (" -a" , " xxx" ) == " "
318
+ && test_args.GetArg (" -b" , " xxx" ) == " 1"
319
+ && test_args.GetArg (" -ccc" , " xxx" ) == " argument"
320
+ && test_args.GetArg (" -d" , " xxx" ) == " e"
321
+ && test_args.GetArg (" -fff" , " xxx" ) == " 0"
322
+ && test_args.GetArg (" -ggg" , " xxx" ) == " 1"
323
+ && test_args.GetArg (" -h" , " xxx" ) == " 1" // 1st value takes precedence
324
+ && test_args.GetArg (" -i" , " xxx" ) == " 0" // 1st value takes precedence
325
+ && test_args.GetArg (" -zzz" , " xxx" ) == " xxx"
326
+ );
327
+
328
+ for (bool def : {false , true }) {
329
+ BOOST_CHECK (test_args.GetBoolArg (" -a" , def)
330
+ && test_args.GetBoolArg (" -b" , def)
331
+ && !test_args.GetBoolArg (" -ccc" , def)
332
+ && !test_args.GetBoolArg (" -d" , def)
333
+ && !test_args.GetBoolArg (" -fff" , def)
334
+ && test_args.GetBoolArg (" -ggg" , def)
335
+ && test_args.GetBoolArg (" -h" , def)
336
+ && !test_args.GetBoolArg (" -i" , def)
337
+ && test_args.GetBoolArg (" -zzz" , def) == def
338
+ );
339
+ }
340
+
341
+ BOOST_CHECK (test_args.GetArgs (" -a" ).size () == 1
342
+ && test_args.GetArgs (" -a" ).front () == " " );
343
+ BOOST_CHECK (test_args.GetArgs (" -b" ).size () == 1
344
+ && test_args.GetArgs (" -b" ).front () == " 1" );
345
+ BOOST_CHECK (test_args.GetArgs (" -ccc" ).size () == 2
346
+ && test_args.GetArgs (" -ccc" ).front () == " argument"
347
+ && test_args.GetArgs (" -ccc" ).back () == " multiple" );
348
+ BOOST_CHECK (test_args.GetArgs (" -fff" ).size () == 1
349
+ && test_args.GetArgs (" -fff" ).front () == " 0" );
350
+ BOOST_CHECK (test_args.GetArgs (" -nofff" ).size () == 0 );
351
+ BOOST_CHECK (test_args.GetArgs (" -ggg" ).size () == 1
352
+ && test_args.GetArgs (" -ggg" ).front () == " 1" );
353
+ BOOST_CHECK (test_args.GetArgs (" -noggg" ).size () == 0 );
354
+ BOOST_CHECK (test_args.GetArgs (" -h" ).size () == 2
355
+ && test_args.GetArgs (" -h" ).front () == " 1"
356
+ && test_args.GetArgs (" -h" ).back () == " 0" );
357
+ BOOST_CHECK (test_args.GetArgs (" -noh" ).size () == 0 );
358
+ BOOST_CHECK (test_args.GetArgs (" -i" ).size () == 2
359
+ && test_args.GetArgs (" -i" ).front () == " 0"
360
+ && test_args.GetArgs (" -i" ).back () == " 1" );
361
+ BOOST_CHECK (test_args.GetArgs (" -noi" ).size () == 0 );
362
+ BOOST_CHECK (test_args.GetArgs (" -zzz" ).size () == 0 );
363
+
364
+ BOOST_CHECK (!test_args.IsArgNegated (" -a" ));
365
+ BOOST_CHECK (!test_args.IsArgNegated (" -b" ));
366
+ BOOST_CHECK (!test_args.IsArgNegated (" -ccc" ));
367
+ BOOST_CHECK (!test_args.IsArgNegated (" -d" ));
368
+ BOOST_CHECK (test_args.IsArgNegated (" -fff" ));
369
+ BOOST_CHECK (test_args.IsArgNegated (" -ggg" )); // IsArgNegated==true when noggg=0
370
+ BOOST_CHECK (test_args.IsArgNegated (" -h" )); // last setting takes precedence
371
+ BOOST_CHECK (!test_args.IsArgNegated (" -i" )); // last setting takes precedence
372
+ BOOST_CHECK (!test_args.IsArgNegated (" -zzz" ));
373
+ }
374
+
268
375
BOOST_AUTO_TEST_CASE (util_GetArg)
269
376
{
270
377
TestArgsManager testArgs;
0 commit comments