53 int testCommandOption();
54 int testRequiredOption();
55 int testCommandOptionNoArg();
56 int testCommandOptionWithArg();
57 int testCommandOptionWithAnyArg();
58 int testCommandOptionWithStringArg();
59 int testCommandOptionWithNumberArg();
60 int testCommandOptionWithDecimalArg();
61 int testCommandOptionRest();
62 int testCommandOptionNOf();
63 int testCommandOptionOneOf();
64 int testCommandOptionAllOf();
65 int testCommandOptionMutex();
66 int testCommandOptionDependent();
67 int testCommandOptionGroupOr();
68 int testCommandOptionGroupAnd();
84 TestUtil tester(
"CommandOption",
"Initialization", __FILE__, __LINE__ );
87 int expectedCount = 0;
91 CommandOption cmdOpt(CommandOption::noArgument, CommandOption::trailingType, 0,
"",
"",
false, testCmdOptVec);
92 tester.
assert(
true,
"CommandOption was created successfully.", __LINE__ );
94 tester.
assert( (cmdOpt.
getArgString().compare(
"ARG") == 0),
"CommandOption getArgString() should return ARG.", __LINE__ );
95 tester.
assert( (cmdOpt.
getCount() == 0),
"CommandOption count should be 0.", __LINE__ );
96 tester.
assert( (cmdOpt.
getValue().size() == 0),
"CommandOption value size should be 0.", __LINE__ );
97 tester.
assert( (cmdOpt.
getOrder() == 0),
"CommandOption order should be 0.", __LINE__ );
98 tester.
assert( (cmdOpt.
checkArguments().size() == 0),
"CommandOption checkArguments() should return nothing.", __LINE__ );
99 tester.
assert( (testCmdOptVec.size() == expectedCount),
"CommandOption was not added to the supplied vector.", __LINE__ );
103 tester.
assert(
false,
"CommandOption() threw an exception but should not have.", __LINE__ );
108 CommandOption cmdOpt(CommandOption::noArgument, CommandOption::stdType, 0,
"",
"",
false, testCmdOptVec);
110 tester.
assert(
false,
"CommandOption creation should have failed due to missing short and long options.", __LINE__ );
114 tester.
assert(
true,
"CommandOption() threw an exception as expected.", __LINE__ );
119 CommandOption cmdOpt(CommandOption::noArgument, CommandOption::stdType,
'f',
"",
"",
false, testCmdOptVec);
121 tester.
assert(
true,
"CommandOption was created successfully.", __LINE__ );
123 "CommandOption getOptionString() returned '" + cmdOpt.
getFullOptionString() +
"', expected '-f'",
126 "CommandOption getFullOptionString() returned '" + cmdOpt.
getFullOptionString() +
"', expected ' -f'",
128 tester.
assert( (testCmdOptVec.size() == expectedCount),
"CommandOption was not added to the supplied vector.", __LINE__ );
132 tester.
assert(
true,
"CommandOption() threw an exception as expected.", __LINE__ );
137 CommandOption cmdOpt(CommandOption::noArgument, CommandOption::stdType,
' ',
"",
"",
false, testCmdOptVec);
139 tester.
assert(
false,
"CommandOption creation should have failed due to invalid short option.", __LINE__ );
143 tester.
assert(
true,
"CommandOption() threw an exception as expected.", __LINE__ );
148 CommandOption cmdOpt(CommandOption::noArgument, CommandOption::stdType, 0,
"foo",
"",
false, testCmdOptVec);
150 tester.
assert(
true,
"CommandOption was created successfully.", __LINE__ );
152 "CommandOption getOptionString() returned '" + cmdOpt.
getFullOptionString() +
"', expected '--foo'",
155 "CommandOption getFullOptionString() returned '" + cmdOpt.
getFullOptionString() +
"', expected ' --foo'",
157 tester.
assert( (testCmdOptVec.size() == expectedCount),
"CommandOption was not added to the supplied vector.", __LINE__ );
161 tester.
assert(
true,
"CommandOption() threw an exception as expected.", __LINE__ );
166 CommandOption cmdOpt(CommandOption::noArgument, CommandOption::stdType, 0,
"foo bar",
"",
false, testCmdOptVec);
168 tester.
assert(
false,
"CommandOption creation should have failed due to invalid long option.", __LINE__ );
172 tester.
assert(
true,
"CommandOption() threw an exception as expected.", __LINE__ );
177 CommandOption cmdOpt(CommandOption::noArgument, CommandOption::stdType,
'f',
"foo",
"",
false, testCmdOptVec);
179 tester.
assert(
true,
"CommandOption was created successfully.", __LINE__ );
181 "CommandOption getOptionString() returned '" + cmdOpt.
getOptionString() +
"', expected '-f | --foo'",
184 "CommandOption getFullOptionString() returned '" + cmdOpt.
getFullOptionString() +
"', expected ' -f, --foo'",
186 tester.
assert( (testCmdOptVec.size() == expectedCount),
"CommandOption was not added to the supplied vector.", __LINE__ );
190 tester.
assert(
false,
"CommandOption() threw an exception but should not have.", __LINE__ );
195 CommandOption cmdOpt(CommandOption::noArgument, CommandOption::metaType, 0,
"",
"",
false, testCmdOptVec);
197 tester.
assert(
true,
"CommandOption was created successfully.", __LINE__ );
198 tester.
assert( (testCmdOptVec.size() == expectedCount),
"CommandOption was not added to the supplied vector.", __LINE__ );
202 tester.
assert(
false,
"CommandOption() threw an exception but should not have.", __LINE__ );
207 CommandOption cmdOpt(CommandOption::hasArgument, CommandOption::trailingType, 0,
"",
"",
false, testCmdOptVec);
209 tester.
assert(
true,
"CommandOption was created successfully.", __LINE__ );
210 tester.
assert( (testCmdOptVec.size() == expectedCount),
"CommandOption was not added to the supplied vector.", __LINE__ );
214 tester.
assert(
false,
"CommandOption() threw an exception but should not have.", __LINE__ );
219 CommandOption cmdOpt(CommandOption::hasArgument, CommandOption::stdType, 0,
"",
"",
false, testCmdOptVec);
221 tester.
assert(
false,
"CommandOption creation should have failed due to missing short and long options.", __LINE__ );
225 tester.
assert(
true,
"CommandOption() threw an exception as expected.", __LINE__ );
230 CommandOption cmdOpt(CommandOption::hasArgument, CommandOption::stdType,
'f',
"",
"",
false, testCmdOptVec);
232 tester.
assert(
true,
"CommandOption was created successfully.", __LINE__ );
234 "CommandOption getOptionString() returned '" + cmdOpt.
getFullOptionString() +
"', expected '-f'",
237 "CommandOption getFullOptionString() returned '" + cmdOpt.
getFullOptionString() +
"', expected ' -f ARG'",
239 tester.
assert( (testCmdOptVec.size() == expectedCount),
"CommandOption was not added to the supplied vector.", __LINE__ );
243 tester.
assert(
true,
"CommandOption() threw an exception as expected.", __LINE__ );
248 CommandOption cmdOpt(CommandOption::hasArgument, CommandOption::stdType,
' ',
"",
"",
false, testCmdOptVec);
250 tester.
assert(
false,
"CommandOption creation should have failed due to invalid short option.", __LINE__ );
254 tester.
assert(
true,
"CommandOption() threw an exception as expected.", __LINE__ );
259 CommandOption cmdOpt(CommandOption::hasArgument, CommandOption::stdType, 0,
"foo",
"",
false, testCmdOptVec);
261 tester.
assert(
true,
"CommandOption was created successfully.", __LINE__ );
263 "CommandOption getOptionString() returned '" + cmdOpt.
getFullOptionString() +
"', expected '--foo'",
266 "CommandOption getFullOptionString() returned '" + cmdOpt.
getFullOptionString() +
"', expected ' --foo=ARG'",
268 tester.
assert( (testCmdOptVec.size() == expectedCount),
"CommandOption was not added to the supplied vector.", __LINE__ );
272 tester.
assert(
true,
"CommandOption() threw an exception as expected.", __LINE__ );
277 CommandOption cmdOpt(CommandOption::hasArgument, CommandOption::stdType, 0,
"foo bar",
"",
false, testCmdOptVec);
279 tester.
assert(
false,
"CommandOption creation should have failed due to invalid long option.", __LINE__ );
283 tester.
assert(
true,
"CommandOption() threw an exception as expected.", __LINE__ );
288 CommandOption cmdOpt(CommandOption::hasArgument, CommandOption::stdType,
'f',
"foo",
"",
false, testCmdOptVec);
290 tester.
assert(
true,
"CommandOption was created successfully.", __LINE__ );
292 "CommandOption getOptionString() returned '" + cmdOpt.
getOptionString() +
"', expected '-f | --foo'",
295 "CommandOption getFullOptionString() returned '" + cmdOpt.
getFullOptionString() +
"', expected ' -f, --foo=ARG'",
297 tester.
assert( (testCmdOptVec.size() == expectedCount),
"CommandOption was not added to the supplied vector.", __LINE__ );
301 tester.
assert(
false,
"CommandOption() threw an exception but should not have.", __LINE__ );
308 CommandOption cmdOpt(CommandOption::hasArgument, CommandOption::metaType, 0,
"",
"",
false, testCmdOptVec);
310 tester.
assert(
true,
"CommandOption was created successfully.", __LINE__ );
311 tester.
assert( (testCmdOptVec.size() == expectedCount),
"CommandOption was not added to the supplied vector.", __LINE__ );
315 tester.
assert(
false,
"CommandOption() threw an exception but should not have.", __LINE__ );
326 TestUtil tester(
"RequiredOption",
"Initialization", __FILE__, __LINE__ );
332 RequiredOption cmdOpt(CommandOption::noArgument, CommandOption::trailingType, 0,
"",
"");
333 tester.
assert(
true,
"RequiredOption was created successfully.", __LINE__ );
334 tester.
assert( (cmdOpt.
getCount() == 0),
"RequiredOption count should be 0.", __LINE__ );
335 tester.
assert( (cmdOpt.
getValue().size() == 0),
"RequiredOption value size should be 0.", __LINE__ );
336 tester.
assert( (cmdOpt.
getOrder() == 0),
"RequiredOption order should be 0.", __LINE__ );
337 tester.
assert( (cmdOpt.
checkArguments().size() != 0),
"RequiredOption checkArguments() should have returned an error", __LINE__ );
342 tester.
assert(
false,
"RequiredOption() threw an exception but should not have.", __LINE__ );
355 TestUtil tester(
"CommandOptionNoArg",
"Initialization", __FILE__, __LINE__ );
362 tester.
assert(
false,
"CommandOptionNoArg creation should have failed due to missing short and long options.", __LINE__ );
366 tester.
assert(
true,
"CommandOptionNoArg() threw an exception as expected.", __LINE__ );
374 tester.
assert(
true,
"CommandOptionNoArg was created successfully.", __LINE__ );
375 tester.
assert( (cmdOpt.
getCount() == 0),
"CommandOptionNoArg count should be 0.", __LINE__ );
376 tester.
assert( (cmdOpt.
getValue().size() == 0),
"CommandOptionNoArg value size should be 0.", __LINE__ );
377 tester.
assert( (cmdOpt.
getOrder() == 0),
"CommandOptionNoArg order should be 0.", __LINE__ );
378 tester.
assert( (cmdOpt.
checkArguments().size() == 0),
"CommandOptionNoArg checkArguments() should return nothing.", __LINE__ );
383 tester.
assert(
false,
"CommandOptionNoArg() threw an exception but should not have.", __LINE__ );
396 TestUtil tester(
"CommandOptionWithArg",
"Initialization", __FILE__, __LINE__ );
403 tester.
assert(
false,
"CommandOptionWithArg creation should have failed due to missing short and long options.", __LINE__ );
407 tester.
assert(
true,
"CommandOptionWithArg() threw an exception as expected.", __LINE__ );
415 tester.
assert(
true,
"CommandOptionWithArg was created successfully.", __LINE__ );
416 tester.
assert( (cmdOpt.
getCount() == 0),
"CommandOptionWithArg count should be 0.", __LINE__ );
417 tester.
assert( (cmdOpt.
getValue().size() == 0),
"CommandOptionWithArg value size should be 0.", __LINE__ );
418 tester.
assert( (cmdOpt.
getOrder() == 0),
"CommandOptionWithArg order should be 0.", __LINE__ );
419 tester.
assert( (cmdOpt.
checkArguments().size() == 0),
"CommandOptionWithArg checkArguments() should return nothing.", __LINE__ );
424 tester.
assert(
false,
"CommandOptionWithArg() threw an exception but should not have.", __LINE__ );
437 TestUtil tester(
"CommandOptionWithAnyArg",
"Initialization", __FILE__, __LINE__ );
444 tester.
assert(
false,
"CommandOptionWithAnyArg creation should have failed due to missing short and long options.", __LINE__ );
448 tester.
assert(
true,
"CommandOptionWithAnyArg() threw an exception as expected.", __LINE__ );
456 tester.
assert(
true,
"CommandOptionWithAnyArg was created successfully.", __LINE__ );
457 tester.
assert( (cmdOpt.
getCount() == 0),
"CommandOptionWithAnyArg count should be 0.", __LINE__ );
458 tester.
assert( (cmdOpt.
getValue().size() == 0),
"CommandOptionWithAnyArg value size should be 0.", __LINE__ );
459 tester.
assert( (cmdOpt.
getOrder() == 0),
"CommandOptionWithAnyArg order should be 0.", __LINE__ );
460 tester.
assert( (cmdOpt.
checkArguments().size() == 0),
"CommandOptionWithAnyArg checkArguments() should return nothing.", __LINE__ );
465 tester.
assert(
false,
"CommandOptionWithAnyArg() threw an exception but should not have.", __LINE__ );
478 TestUtil tester(
"CommandOptionWithStringArg",
"Initialization", __FILE__, __LINE__ );
485 tester.
assert(
false,
"CommandOptionWithStringArg creation should have failed due to missing short and long options.", __LINE__ );
489 tester.
assert(
true,
"CommandOptionWithStringArg() threw an exception as expected.", __LINE__ );
497 tester.
assert(
true,
"CommandOptionWithStringArg was created successfully.", __LINE__ );
498 tester.
assert( (cmdOpt.
getCount() == 0),
"CommandOptionWithStringArg count should be 0.", __LINE__ );
499 tester.
assert( (cmdOpt.
getValue().size() == 0),
"CommandOptionWithStringArg value size should be 0.", __LINE__ );
500 tester.
assert( (cmdOpt.
getOrder() == 0),
"CommandOptionWithStringArg order should be 0.", __LINE__ );
501 tester.
assert( (cmdOpt.
checkArguments().size() == 0),
"CommandOptionWithStringArg checkArguments() should return nothing.", __LINE__ );
506 tester.
assert(
false,
"CommandOptionWithStringArg() threw an exception but should not have.", __LINE__ );
519 TestUtil tester(
"CommandOptionWithNumberArg",
"Initialization", __FILE__, __LINE__ );
526 tester.
assert(
false,
"CommandOptionWithNumberArg creation should have failed due to missing short and long options.", __LINE__ );
530 tester.
assert(
true,
"CommandOptionWithNumberArg() threw an exception as expected.", __LINE__ );
538 tester.
assert(
true,
"CommandOptionWithNumberArg was created successfully.", __LINE__ );
539 tester.
assert( (cmdOpt.
getCount() == 0),
"CommandOptionWithNumberArg count should be 0.", __LINE__ );
540 tester.
assert( (cmdOpt.
getValue().size() == 0),
"CommandOptionWithNumberArg value size should be 0.", __LINE__ );
541 tester.
assert( (cmdOpt.
getOrder() == 0),
"CommandOptionWithNumberArg order should be 0.", __LINE__ );
542 tester.
assert( (cmdOpt.
checkArguments().size() == 0),
"CommandOptionWithNumberArg checkArguments() should return nothing.", __LINE__ );
547 tester.
assert(
false,
"CommandOptionWithNumberArg() threw an exception but should not have.", __LINE__ );
560 TestUtil tester(
"CommandOptionWithDecimalArg",
"Initialization", __FILE__, __LINE__ );
567 tester.
assert(
false,
"CommandOptionWithDecimalArg creation should have failed due to missing short and long options.", __LINE__ );
571 tester.
assert(
true,
"CommandOptionWithDecimalArg() threw an exception as expected.", __LINE__ );
579 tester.
assert(
true,
"CommandOptionWithDecimalArg was created successfully.", __LINE__ );
580 tester.
assert( (cmdOpt.
getCount() == 0),
"CommandOptionWithDecimalArg count should be 0.", __LINE__ );
581 tester.
assert( (cmdOpt.
getValue().size() == 0),
"CommandOptionWithDecimalArg value size should be 0.", __LINE__ );
582 tester.
assert( (cmdOpt.
getOrder() == 0),
"CommandOptionWithDecimalArg order should be 0.", __LINE__ );
583 tester.
assert( (cmdOpt.
checkArguments().size() == 0),
"CommandOptionWithDecimalArg checkArguments() should return nothing.", __LINE__ );
588 tester.
assert(
false,
"CommandOptionWithDecimalArg() threw an exception but should not have.", __LINE__ );
601 TestUtil tester(
"CommandOptionRest",
"Initialization", __FILE__, __LINE__ );
608 tester.
assert(
true,
"CommandOptionRest was created successfully.", __LINE__ );
609 tester.
assert( (cmdOpt.
getCount() == 0),
"CommandOptionRest count should be 0.", __LINE__ );
610 tester.
assert( (cmdOpt.
getValue().size() == 0),
"CommandOptionRest value size should be 0.", __LINE__ );
611 tester.
assert( (cmdOpt.
getOrder() == 0),
"CommandOptionRest order should be 0.", __LINE__ );
612 tester.
assert( (cmdOpt.
checkArguments().size() == 0),
"CommandOptionRest checkArguments() should return nothing.", __LINE__ );
617 tester.
assert(
false,
"CommandOptionRest() threw an exception but should not have.", __LINE__ );
630 TUDEF(
"CommandOptionNOf",
"Initialization");
641 TUPASS(
"CommandOptionNOf was created successfully.");
645 TUFAIL(
"Exception in constructor");
655 TUFAIL(
"CommandOptionNOf()::addOption() succeeded but should have"
656 " failed due to an invalid option address.");
660 TUPASS(
"CommandOptionNOf::addOption() threw an exception as"
668 TUPASS(
"CommandOptionNOf()::addOption() succeeded.");
672 TUFAIL(
"CommandOptionNOf::addOption() threw an exception but should"
689 TestUtil tester(
"CommandOptionOneOf",
"Initialization", __FILE__, __LINE__ );
696 tester.
assert(
true,
"CommandOptionOneOf was created successfully.", __LINE__ );
697 tester.
assert( (cmdOpt.
getCount() == 0),
"CommandOptionOneOf count should be 0.", __LINE__ );
698 tester.
assert( (cmdOpt.
checkArguments().size() != 0),
"CommandOptionOneOf checkArguments() should have reported an error", __LINE__ );
704 tester.
assert(
false,
"CommandOptionOneOf()::addOption() succeeded but should have failed due to an valid option address.", __LINE__ );
708 tester.
assert(
true,
"CommandOptionOneOf::addOption() threw an exception as expected.", __LINE__ );
715 tester.
assert(
true,
"CommandOptionOneOf()::addOption() succeeded.", __LINE__ );
719 tester.
assert(
false,
"CommandOptionOneOf::addOption() threw an exception but should not have.", __LINE__ );
724 tester.
assert(
false,
"CommandOptionOneOf() threw an exception but should not have.", __LINE__ );
736 TestUtil tester(
"CommandOptionAllOf",
"Initialization", __FILE__, __LINE__ );
743 tester.
assert(
true,
"CommandOptionAllOf was created successfully.", __LINE__ );
744 tester.
assert( (cmdOpt.
getCount() == 0),
"CommandOptionAllOf count should be 0.", __LINE__ );
745 tester.
assert( (cmdOpt.
checkArguments().size() == 0),
"CommandOptionAllOf checkArguments() should return nothing.", __LINE__ );
751 tester.
assert(
false,
"CommandOptionAllOf()::addOption() succeeded but should have failed due to an valid option address.", __LINE__ );
755 tester.
assert(
true,
"CommandOptionAllOf::addOption() threw an exception as expected.", __LINE__ );
762 tester.
assert(
true,
"CommandOptionAllOf()::addOption() succeeded.", __LINE__ );
766 tester.
assert(
false,
"CommandOptionAllOf::addOption() threw an exception but should not have.", __LINE__ );
771 tester.
assert(
false,
"CommandOptionAllOf() threw an exception but should not have.", __LINE__ );
783 TestUtil tester(
"CommandOptionMutex",
"Initialization", __FILE__, __LINE__ );
790 tester.
assert(
true,
"CommandOptionMutex was created successfully.", __LINE__ );
791 tester.
assert( (cmdOpt.
getCount() == 0),
"CommandOptionMutex count should be 0.", __LINE__ );
792 tester.
assert( (cmdOpt.
checkArguments().size() == 0),
"CommandOptionMutex checkArguments() should return nothing.", __LINE__ );
798 tester.
assert(
false,
"CommandOptionMutex()::addOption() succeeded but should have failed due to an valid option address.", __LINE__ );
802 tester.
assert(
true,
"CommandOptionMutex::addOption() threw an exception as expected.", __LINE__ );
809 tester.
assert(
true,
"CommandOptionMutex()::addOption() succeeded.", __LINE__ );
813 tester.
assert(
false,
"CommandOptionMutex::addOption() threw an exception but should not have.", __LINE__ );
818 tester.
assert(
false,
"CommandOptionMutex() threw an exception but should not have.", __LINE__ );
830 TestUtil tester(
"CommandOptionDependent",
"Initialization", __FILE__, __LINE__ );
837 tester.
assert(
false,
"CommandOptionDependent creation should have failed due to NULL addresses.", __LINE__ );
841 tester.
assert(
true,
"CommandOptionDependent() threw an exception as expected.", __LINE__ );
853 TestUtil tester(
"CommandOptionGroupOr",
"Initialization", __FILE__, __LINE__ );
860 tester.
assert(
true,
"CommandOptionGroupOr was created successfully.", __LINE__ );
861 tester.
assert( (cmdOpt.
getCount() == 0),
"CommandOptionGroupOr count should be 0.", __LINE__ );
862 tester.
assert( (cmdOpt.
checkArguments().size() == 0),
"CommandOptionGroupOr checkArguments() should return nothing.", __LINE__ );
868 tester.
assert(
false,
"CommandOptionGroupOr()::addOption() succeeded but should have failed due to an valid option address.", __LINE__ );
872 tester.
assert(
true,
"CommandOptionGroupOr::addOption() threw an exception as expected.", __LINE__ );
879 tester.
assert(
true,
"CommandOptionGroupOr()::addOption() succeeded.", __LINE__ );
883 tester.
assert(
false,
"CommandOptionGroupOr::addOption() threw an exception but should not have.", __LINE__ );
888 tester.
assert(
false,
"CommandOptionGroupOr() threw an exception but should not have.", __LINE__ );
900 TestUtil tester(
"CommandOptionGroupAnd",
"Initialization", __FILE__, __LINE__ );
907 tester.
assert(
true,
"CommandOptionGroupAnd was created successfully.", __LINE__ );
908 tester.
assert( (cmdOpt.
getCount() == 0),
"CommandOptionGroupAnd count should be 0.", __LINE__ );
909 tester.
assert( (cmdOpt.
checkArguments().size() == 0),
"CommandOptionGroupAnd checkArguments() should return nothing.", __LINE__ );
915 tester.
assert(
false,
"CommandOptionGroupAnd()::addOption() succeeded but should have failed due to an valid option address.", __LINE__ );
919 tester.
assert(
true,
"CommandOptionGroupAnd::addOption() threw an exception as expected.", __LINE__ );
926 tester.
assert(
true,
"CommandOptionGroupAnd()::addOption() succeeded.", __LINE__ );
930 tester.
assert(
false,
"CommandOptionGroupAnd::addOption() threw an exception but should not have.", __LINE__ );
935 tester.
assert(
false,
"CommandOptionGroupAnd() threw an exception but should not have.", __LINE__ );
948 int main(
int argc,
char *argv[])
971 std::cout <<
"Total Failures for " << __FILE__ <<
": " << errorTotal << std::endl;
973 return( errorTotal );