@@ -322,15 +322,24 @@ BOOST_AUTO_TEST_CASE(util_ReadConfigStream)
322
322
" h=1\n "
323
323
" noh=1\n "
324
324
" noi=1\n "
325
- " i=1\n " ;
325
+ " i=1\n "
326
+ " sec1.ccc=extend1\n "
327
+ " \n "
328
+ " [sec1]\n "
329
+ " ccc=extend2\n "
330
+ " h=1\n "
331
+ " [sec2]\n "
332
+ " ccc=extend3\n "
333
+ " iii=2\n " ;
326
334
327
335
TestArgsManager test_args;
328
336
329
337
test_args.ReadConfigString (str_config);
330
338
// expectation: a, b, ccc, d, fff, ggg, h, i end up in map
339
+ // so do sec1.ccc, sec1.h, sec2.ccc, sec2.iii
331
340
332
341
BOOST_CHECK (test_args.GetOverrideArgs ().empty ());
333
- BOOST_CHECK (test_args.GetConfigArgs ().size () == 8 );
342
+ BOOST_CHECK (test_args.GetConfigArgs ().size () == 12 );
334
343
335
344
BOOST_CHECK (test_args.GetConfigArgs ().count (" -a" )
336
345
&& test_args.GetConfigArgs ().count (" -b" )
@@ -341,6 +350,11 @@ BOOST_AUTO_TEST_CASE(util_ReadConfigStream)
341
350
&& test_args.GetConfigArgs ().count (" -h" )
342
351
&& test_args.GetConfigArgs ().count (" -i" )
343
352
);
353
+ BOOST_CHECK (test_args.GetConfigArgs ().count (" -sec1.ccc" )
354
+ && test_args.GetConfigArgs ().count (" -sec1.h" )
355
+ && test_args.GetConfigArgs ().count (" -sec2.ccc" )
356
+ && test_args.GetConfigArgs ().count (" -sec2.iii" )
357
+ );
344
358
345
359
BOOST_CHECK (test_args.IsArgSet (" -a" )
346
360
&& test_args.IsArgSet (" -b" )
@@ -351,6 +365,7 @@ BOOST_AUTO_TEST_CASE(util_ReadConfigStream)
351
365
&& test_args.IsArgSet (" -h" )
352
366
&& test_args.IsArgSet (" -i" )
353
367
&& !test_args.IsArgSet (" -zzz" )
368
+ && !test_args.IsArgSet (" -iii" )
354
369
);
355
370
356
371
BOOST_CHECK (test_args.GetArg (" -a" , " xxx" ) == " "
@@ -362,6 +377,7 @@ BOOST_AUTO_TEST_CASE(util_ReadConfigStream)
362
377
&& test_args.GetArg (" -h" , " xxx" ) == " 0"
363
378
&& test_args.GetArg (" -i" , " xxx" ) == " 1"
364
379
&& test_args.GetArg (" -zzz" , " xxx" ) == " xxx"
380
+ && test_args.GetArg (" -iii" , " xxx" ) == " xxx"
365
381
);
366
382
367
383
for (bool def : {false , true }) {
@@ -374,6 +390,7 @@ BOOST_AUTO_TEST_CASE(util_ReadConfigStream)
374
390
&& !test_args.GetBoolArg (" -h" , def)
375
391
&& test_args.GetBoolArg (" -i" , def)
376
392
&& test_args.GetBoolArg (" -zzz" , def) == def
393
+ && test_args.GetBoolArg (" -iii" , def) == def
377
394
);
378
395
}
379
396
@@ -405,6 +422,47 @@ BOOST_AUTO_TEST_CASE(util_ReadConfigStream)
405
422
BOOST_CHECK (test_args.IsArgNegated (" -h" )); // last setting takes precedence
406
423
BOOST_CHECK (!test_args.IsArgNegated (" -i" )); // last setting takes precedence
407
424
BOOST_CHECK (!test_args.IsArgNegated (" -zzz" ));
425
+
426
+ // Test sections work
427
+ test_args.SelectConfigNetwork (" sec1" );
428
+
429
+ // same as original
430
+ BOOST_CHECK (test_args.GetArg (" -a" , " xxx" ) == " "
431
+ && test_args.GetArg (" -b" , " xxx" ) == " 1"
432
+ && test_args.GetArg (" -d" , " xxx" ) == " e"
433
+ && test_args.GetArg (" -fff" , " xxx" ) == " 0"
434
+ && test_args.GetArg (" -ggg" , " xxx" ) == " 1"
435
+ && test_args.GetArg (" -zzz" , " xxx" ) == " xxx"
436
+ && test_args.GetArg (" -iii" , " xxx" ) == " xxx"
437
+ );
438
+ // section-specific setting
439
+ BOOST_CHECK (test_args.GetArg (" -h" , " xxx" ) == " 1" );
440
+ // section takes priority for multiple values
441
+ BOOST_CHECK (test_args.GetArg (" -ccc" , " xxx" ) == " extend1" );
442
+ // check multiple values works
443
+ const std::vector<std::string> sec1_ccc_expected = {" extend1" ," extend2" ," argument" ," multiple" };
444
+ const auto & sec1_ccc_res = test_args.GetArgs (" -ccc" );
445
+ BOOST_CHECK_EQUAL_COLLECTIONS (sec1_ccc_res.begin (), sec1_ccc_res.end (), sec1_ccc_expected.begin (), sec1_ccc_expected.end ());
446
+
447
+ test_args.SelectConfigNetwork (" sec2" );
448
+
449
+ // same as original
450
+ BOOST_CHECK (test_args.GetArg (" -a" , " xxx" ) == " "
451
+ && test_args.GetArg (" -b" , " xxx" ) == " 1"
452
+ && test_args.GetArg (" -d" , " xxx" ) == " e"
453
+ && test_args.GetArg (" -fff" , " xxx" ) == " 0"
454
+ && test_args.GetArg (" -ggg" , " xxx" ) == " 1"
455
+ && test_args.GetArg (" -zzz" , " xxx" ) == " xxx"
456
+ && test_args.GetArg (" -h" , " xxx" ) == " 0"
457
+ );
458
+ // section-specific setting
459
+ BOOST_CHECK (test_args.GetArg (" -iii" , " xxx" ) == " 2" );
460
+ // section takes priority for multiple values
461
+ BOOST_CHECK (test_args.GetArg (" -ccc" , " xxx" ) == " extend3" );
462
+ // check multiple values works
463
+ const std::vector<std::string> sec2_ccc_expected = {" extend3" ," argument" ," multiple" };
464
+ const auto & sec2_ccc_res = test_args.GetArgs (" -ccc" );
465
+ BOOST_CHECK_EQUAL_COLLECTIONS (sec2_ccc_res.begin (), sec2_ccc_res.end (), sec2_ccc_expected.begin (), sec2_ccc_expected.end ());
408
466
}
409
467
410
468
BOOST_AUTO_TEST_CASE (util_GetArg)
0 commit comments