CommandOption_T.cpp
Go to the documentation of this file.
1 //==============================================================================
2 //
3 // This file is part of GNSSTk, the ARL:UT GNSS Toolkit.
4 //
5 // The GNSSTk is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published
7 // by the Free Software Foundation; either version 3.0 of the License, or
8 // any later version.
9 //
10 // The GNSSTk is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with GNSSTk; if not, write to the Free Software Foundation,
17 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18 //
19 // This software was developed by Applied Research Laboratories at the
20 // University of Texas at Austin.
21 // Copyright 2004-2022, The Board of Regents of The University of Texas System
22 //
23 //==============================================================================
24 
25 //==============================================================================
26 //
27 // This software was developed by Applied Research Laboratories at the
28 // University of Texas at Austin, under contract to an agency or agencies
29 // within the U.S. Department of Defense. The U.S. Government retains all
30 // rights to use, duplicate, distribute, disclose, or release this software.
31 //
32 // Pursuant to DoD Directive 523024
33 //
34 // DISTRIBUTION STATEMENT A: This software has been approved for public
35 // release, distribution is unlimited.
36 //
37 //==============================================================================
38 
39 #include "CommandOption.hpp"
40 #include "TestUtil.hpp"
41 #include <iostream>
42 
43 using namespace std;
44 using namespace gnsstk;
45 
46 /*************************************************************************
47  * This class tests the creation of the various types of CommandOptions.
48  */
50 {
51 public:
52 
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();
69 
70  CommandOption_T() : verboseLevel(0) { init(); }
71  ~CommandOption_T() { }
72 
73  void init() { }
74 
75  int verboseLevel;
76 
77 }; // class CommandOption_T
78 
79 
80 /*************************************************************************
81  */
83 {
84  TestUtil tester( "CommandOption", "Initialization", __FILE__, __LINE__ );
85 
86  CommandOptionVec testCmdOptVec;
87  int expectedCount = 0;
88 
89  try // No arg, trailing, no flags
90  {
91  CommandOption cmdOpt(CommandOption::noArgument, CommandOption::trailingType, 0, "", "", false, testCmdOptVec);
92  tester.assert( true, "CommandOption was created successfully.", __LINE__ );
93  ++expectedCount;
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__ );
100  }
101  catch ( ... )
102  {
103  tester.assert( false, "CommandOption() threw an exception but should not have.", __LINE__ );
104  }
105 
106  try // No arg, standard, no flags
107  {
108  CommandOption cmdOpt(CommandOption::noArgument, CommandOption::stdType, 0, "", "", false, testCmdOptVec);
109  ++expectedCount;
110  tester.assert( false, "CommandOption creation should have failed due to missing short and long options.", __LINE__ );
111  }
112  catch ( ... )
113  {
114  tester.assert( true, "CommandOption() threw an exception as expected.", __LINE__ );
115  }
116 
117  try // No arg, standard, short flag (valid)
118  {
119  CommandOption cmdOpt(CommandOption::noArgument, CommandOption::stdType, 'f', "", "", false, testCmdOptVec);
120  ++expectedCount;
121  tester.assert( true, "CommandOption was created successfully.", __LINE__ );
122  tester.assert( (cmdOpt.getOptionString().compare("-f") == 0),
123  "CommandOption getOptionString() returned '" + cmdOpt.getFullOptionString() + "', expected '-f'",
124  __LINE__ );
125  tester.assert( (cmdOpt.getFullOptionString().compare(" -f") == 0),
126  "CommandOption getFullOptionString() returned '" + cmdOpt.getFullOptionString() + "', expected ' -f'",
127  __LINE__ );
128  tester.assert( (testCmdOptVec.size() == expectedCount), "CommandOption was not added to the supplied vector.", __LINE__ );
129  }
130  catch ( ... )
131  {
132  tester.assert( true, "CommandOption() threw an exception as expected.", __LINE__ );
133  }
134 
135  try // No arg, standard, short flag (bogus)
136  {
137  CommandOption cmdOpt(CommandOption::noArgument, CommandOption::stdType, ' ', "", "", false, testCmdOptVec);
138  ++expectedCount;
139  tester.assert( false, "CommandOption creation should have failed due to invalid short option.", __LINE__ );
140  }
141  catch ( ... )
142  {
143  tester.assert( true, "CommandOption() threw an exception as expected.", __LINE__ );
144  }
145 
146  try // No arg, standard, long flag (valid)
147  {
148  CommandOption cmdOpt(CommandOption::noArgument, CommandOption::stdType, 0, "foo", "", false, testCmdOptVec);
149  ++expectedCount;
150  tester.assert( true, "CommandOption was created successfully.", __LINE__ );
151  tester.assert( (cmdOpt.getOptionString().compare("--foo") == 0),
152  "CommandOption getOptionString() returned '" + cmdOpt.getFullOptionString() + "', expected '--foo'",
153  __LINE__ );
154  tester.assert( (cmdOpt.getFullOptionString().compare(" --foo") == 0),
155  "CommandOption getFullOptionString() returned '" + cmdOpt.getFullOptionString() + "', expected ' --foo'",
156  __LINE__ );
157  tester.assert( (testCmdOptVec.size() == expectedCount), "CommandOption was not added to the supplied vector.", __LINE__ );
158  }
159  catch ( ... )
160  {
161  tester.assert( true, "CommandOption() threw an exception as expected.", __LINE__ );
162  }
163 
164  try // No arg, standard, long flag (bogus)
165  {
166  CommandOption cmdOpt(CommandOption::noArgument, CommandOption::stdType, 0, "foo bar", "", false, testCmdOptVec);
167  ++expectedCount;
168  tester.assert( false, "CommandOption creation should have failed due to invalid long option.", __LINE__ );
169  }
170  catch ( ... )
171  {
172  tester.assert( true, "CommandOption() threw an exception as expected.", __LINE__ );
173  }
174 
175  try // No arg, standard, both flags (valid)
176  {
177  CommandOption cmdOpt(CommandOption::noArgument, CommandOption::stdType, 'f', "foo", "", false, testCmdOptVec);
178  ++expectedCount;
179  tester.assert( true, "CommandOption was created successfully.", __LINE__ );
180  tester.assert( (cmdOpt.getOptionString().compare("-f | --foo") == 0),
181  "CommandOption getOptionString() returned '" + cmdOpt.getOptionString() + "', expected '-f | --foo'",
182  __LINE__ );
183  tester.assert( (cmdOpt.getFullOptionString().compare(" -f, --foo") == 0),
184  "CommandOption getFullOptionString() returned '" + cmdOpt.getFullOptionString() + "', expected ' -f, --foo'",
185  __LINE__ );
186  tester.assert( (testCmdOptVec.size() == expectedCount), "CommandOption was not added to the supplied vector.", __LINE__ );
187  }
188  catch ( ... )
189  {
190  tester.assert( false, "CommandOption() threw an exception but should not have.", __LINE__ );
191  }
192 
193  try // No arg, meta, no flags
194  {
195  CommandOption cmdOpt(CommandOption::noArgument, CommandOption::metaType, 0, "", "", false, testCmdOptVec);
196  ++expectedCount;
197  tester.assert( true, "CommandOption was created successfully.", __LINE__ );
198  tester.assert( (testCmdOptVec.size() == expectedCount), "CommandOption was not added to the supplied vector.", __LINE__ );
199  }
200  catch ( ... )
201  {
202  tester.assert( false, "CommandOption() threw an exception but should not have.", __LINE__ );
203  }
204 
205  try // Arg, trailing, no flags
206  {
207  CommandOption cmdOpt(CommandOption::hasArgument, CommandOption::trailingType, 0, "", "", false, testCmdOptVec);
208  ++expectedCount;
209  tester.assert( true, "CommandOption was created successfully.", __LINE__ );
210  tester.assert( (testCmdOptVec.size() == expectedCount), "CommandOption was not added to the supplied vector.", __LINE__ );
211  }
212  catch ( ... )
213  {
214  tester.assert( false, "CommandOption() threw an exception but should not have.", __LINE__ );
215  }
216 
217  try // Arg, standard, no flags
218  {
219  CommandOption cmdOpt(CommandOption::hasArgument, CommandOption::stdType, 0, "", "", false, testCmdOptVec);
220  ++expectedCount;
221  tester.assert( false, "CommandOption creation should have failed due to missing short and long options.", __LINE__ );
222  }
223  catch ( ... )
224  {
225  tester.assert( true, "CommandOption() threw an exception as expected.", __LINE__ );
226  }
227 
228  try // Arg, standard, short flag (valid)
229  {
230  CommandOption cmdOpt(CommandOption::hasArgument, CommandOption::stdType, 'f', "", "", false, testCmdOptVec);
231  ++expectedCount;
232  tester.assert( true, "CommandOption was created successfully.", __LINE__ );
233  tester.assert( (cmdOpt.getOptionString().compare("-f") == 0),
234  "CommandOption getOptionString() returned '" + cmdOpt.getFullOptionString() + "', expected '-f'",
235  __LINE__ );
236  tester.assert( (cmdOpt.getFullOptionString().compare(" -f ARG") == 0),
237  "CommandOption getFullOptionString() returned '" + cmdOpt.getFullOptionString() + "', expected ' -f ARG'",
238  __LINE__ );
239  tester.assert( (testCmdOptVec.size() == expectedCount), "CommandOption was not added to the supplied vector.", __LINE__ );
240  }
241  catch ( ... )
242  {
243  tester.assert( true, "CommandOption() threw an exception as expected.", __LINE__ );
244  }
245 
246  try // Arg, standard, short flag (bogus)
247  {
248  CommandOption cmdOpt(CommandOption::hasArgument, CommandOption::stdType, ' ', "", "", false, testCmdOptVec);
249  ++expectedCount;
250  tester.assert( false, "CommandOption creation should have failed due to invalid short option.", __LINE__ );
251  }
252  catch ( ... )
253  {
254  tester.assert( true, "CommandOption() threw an exception as expected.", __LINE__ );
255  }
256 
257  try // Arg, standard, long flag (valid)
258  {
259  CommandOption cmdOpt(CommandOption::hasArgument, CommandOption::stdType, 0, "foo", "", false, testCmdOptVec);
260  ++expectedCount;
261  tester.assert( true, "CommandOption was created successfully.", __LINE__ );
262  tester.assert( (cmdOpt.getOptionString().compare("--foo") == 0),
263  "CommandOption getOptionString() returned '" + cmdOpt.getFullOptionString() + "', expected '--foo'",
264  __LINE__ );
265  tester.assert( (cmdOpt.getFullOptionString().compare(" --foo=ARG") == 0),
266  "CommandOption getFullOptionString() returned '" + cmdOpt.getFullOptionString() + "', expected ' --foo=ARG'",
267  __LINE__ );
268  tester.assert( (testCmdOptVec.size() == expectedCount), "CommandOption was not added to the supplied vector.", __LINE__ );
269  }
270  catch ( ... )
271  {
272  tester.assert( true, "CommandOption() threw an exception as expected.", __LINE__ );
273  }
274 
275  try // Arg, standard, long flag (bogus)
276  {
277  CommandOption cmdOpt(CommandOption::hasArgument, CommandOption::stdType, 0, "foo bar", "", false, testCmdOptVec);
278  ++expectedCount;
279  tester.assert( false, "CommandOption creation should have failed due to invalid long option.", __LINE__ );
280  }
281  catch ( ... )
282  {
283  tester.assert( true, "CommandOption() threw an exception as expected.", __LINE__ );
284  }
285 
286  try // Arg, standard, both flags (valid)
287  {
288  CommandOption cmdOpt(CommandOption::hasArgument, CommandOption::stdType, 'f', "foo", "", false, testCmdOptVec);
289  ++expectedCount;
290  tester.assert( true, "CommandOption was created successfully.", __LINE__ );
291  tester.assert( (cmdOpt.getOptionString().compare("-f | --foo") == 0),
292  "CommandOption getOptionString() returned '" + cmdOpt.getOptionString() + "', expected '-f | --foo'",
293  __LINE__ );
294  tester.assert( (cmdOpt.getFullOptionString().compare(" -f, --foo=ARG") == 0),
295  "CommandOption getFullOptionString() returned '" + cmdOpt.getFullOptionString() + "', expected ' -f, --foo=ARG'",
296  __LINE__ );
297  tester.assert( (testCmdOptVec.size() == expectedCount), "CommandOption was not added to the supplied vector.", __LINE__ );
298  }
299  catch ( ... )
300  {
301  tester.assert( false, "CommandOption() threw an exception but should not have.", __LINE__ );
302  }
303 
304  // @todo - Test getDescription()
305 
306  try // Arg, meta, no flags
307  {
308  CommandOption cmdOpt(CommandOption::hasArgument, CommandOption::metaType, 0, "", "", false, testCmdOptVec);
309  ++expectedCount;
310  tester.assert( true, "CommandOption was created successfully.", __LINE__ );
311  tester.assert( (testCmdOptVec.size() == expectedCount), "CommandOption was not added to the supplied vector.", __LINE__ );
312  }
313  catch ( ... )
314  {
315  tester.assert( false, "CommandOption() threw an exception but should not have.", __LINE__ );
316  }
317 
318  return tester.countFails();
319 }
320 
321 
322 /*************************************************************************
323  */
325 {
326  TestUtil tester( "RequiredOption", "Initialization", __FILE__, __LINE__ );
327 
328  defaultCommandOptionList.clear();
329 
330  try // No arg, trailing
331  {
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__ );
338  tester.assert( (defaultCommandOptionList.size() == 1), "RequiredOption was not added to the default list.", __LINE__ );
339  }
340  catch ( ... )
341  {
342  tester.assert( false, "RequiredOption() threw an exception but should not have.", __LINE__ );
343  }
344 
345  defaultCommandOptionList.clear();
346 
347  return tester.countFails();
348 }
349 
350 
351 /*************************************************************************
352  */
354 {
355  TestUtil tester( "CommandOptionNoArg", "Initialization", __FILE__, __LINE__ );
356 
357  defaultCommandOptionList.clear();
358 
359  try
360  {
361  CommandOptionNoArg cmdOpt(0, "", "", false);
362  tester.assert( false, "CommandOptionNoArg creation should have failed due to missing short and long options.", __LINE__ );
363  }
364  catch ( ... )
365  {
366  tester.assert( true, "CommandOptionNoArg() threw an exception as expected.", __LINE__ );
367  }
368 
369  defaultCommandOptionList.clear();
370 
371  try
372  {
373  CommandOptionNoArg cmdOpt('f', "foo", "Foo", false);
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__ );
379  tester.assert( (defaultCommandOptionList.size() == 1), "CommandOptionNoArg was not added to the default list.", __LINE__ );
380  }
381  catch ( ... )
382  {
383  tester.assert( false, "CommandOptionNoArg() threw an exception but should not have.", __LINE__ );
384  }
385 
386  defaultCommandOptionList.clear();
387 
388  return tester.countFails();
389 }
390 
391 
392 /*************************************************************************
393  */
395 {
396  TestUtil tester( "CommandOptionWithArg", "Initialization", __FILE__, __LINE__ );
397 
398  defaultCommandOptionList.clear();
399 
400  try
401  {
402  CommandOptionWithArg cmdOpt(CommandOption::stdType, 0, "", "", false);
403  tester.assert( false, "CommandOptionWithArg creation should have failed due to missing short and long options.", __LINE__ );
404  }
405  catch ( ... )
406  {
407  tester.assert( true, "CommandOptionWithArg() threw an exception as expected.", __LINE__ );
408  }
409 
410  defaultCommandOptionList.clear();
411 
412  try
413  {
414  CommandOptionWithArg cmdOpt(CommandOption::stdType, 'f', "foo", "Foo", false);
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__ );
420  tester.assert( (defaultCommandOptionList.size() == 1), "CommandOptionWithArg was not added to the default list.", __LINE__ );
421  }
422  catch ( ... )
423  {
424  tester.assert( false, "CommandOptionWithArg() threw an exception but should not have.", __LINE__ );
425  }
426 
427  defaultCommandOptionList.clear();
428 
429  return tester.countFails();
430 }
431 
432 
433 /*************************************************************************
434  */
436 {
437  TestUtil tester( "CommandOptionWithAnyArg", "Initialization", __FILE__, __LINE__ );
438 
439  defaultCommandOptionList.clear();
440 
441  try
442  {
443  CommandOptionWithAnyArg cmdOpt(0, "", "", false);
444  tester.assert( false, "CommandOptionWithAnyArg creation should have failed due to missing short and long options.", __LINE__ );
445  }
446  catch ( ... )
447  {
448  tester.assert( true, "CommandOptionWithAnyArg() threw an exception as expected.", __LINE__ );
449  }
450 
451  defaultCommandOptionList.clear();
452 
453  try
454  {
455  CommandOptionWithAnyArg cmdOpt('f', "foo", "Foo", false);
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__ );
461  tester.assert( (defaultCommandOptionList.size() == 1), "CommandOptionWithAnyArg was not added to the default list.", __LINE__ );
462  }
463  catch ( ... )
464  {
465  tester.assert( false, "CommandOptionWithAnyArg() threw an exception but should not have.", __LINE__ );
466  }
467 
468  defaultCommandOptionList.clear();
469 
470  return tester.countFails();
471 }
472 
473 
474 /*************************************************************************
475  */
477 {
478  TestUtil tester( "CommandOptionWithStringArg", "Initialization", __FILE__, __LINE__ );
479 
480  defaultCommandOptionList.clear();
481 
482  try
483  {
484  CommandOptionWithStringArg cmdOpt(0, "", "", false);
485  tester.assert( false, "CommandOptionWithStringArg creation should have failed due to missing short and long options.", __LINE__ );
486  }
487  catch ( ... )
488  {
489  tester.assert( true, "CommandOptionWithStringArg() threw an exception as expected.", __LINE__ );
490  }
491 
492  defaultCommandOptionList.clear();
493 
494  try
495  {
496  CommandOptionWithStringArg cmdOpt('f', "foo", "Foo", false);
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__ );
502  tester.assert( (defaultCommandOptionList.size() == 1), "CommandOptionWithStringArg was not added to the default list.", __LINE__ );
503  }
504  catch ( ... )
505  {
506  tester.assert( false, "CommandOptionWithStringArg() threw an exception but should not have.", __LINE__ );
507  }
508 
509  defaultCommandOptionList.clear();
510 
511  return tester.countFails();
512 }
513 
514 
515 /*************************************************************************
516  */
518 {
519  TestUtil tester( "CommandOptionWithNumberArg", "Initialization", __FILE__, __LINE__ );
520 
521  defaultCommandOptionList.clear();
522 
523  try
524  {
525  CommandOptionWithNumberArg cmdOpt(0, "", "", false);
526  tester.assert( false, "CommandOptionWithNumberArg creation should have failed due to missing short and long options.", __LINE__ );
527  }
528  catch ( ... )
529  {
530  tester.assert( true, "CommandOptionWithNumberArg() threw an exception as expected.", __LINE__ );
531  }
532 
533  defaultCommandOptionList.clear();
534 
535  try
536  {
537  CommandOptionWithNumberArg cmdOpt('f', "foo", "Foo", false);
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__ );
543  tester.assert( (defaultCommandOptionList.size() == 1), "CommandOptionWithNumberArg was not added to the default list.", __LINE__ );
544  }
545  catch ( ... )
546  {
547  tester.assert( false, "CommandOptionWithNumberArg() threw an exception but should not have.", __LINE__ );
548  }
549 
550  defaultCommandOptionList.clear();
551 
552  return tester.countFails();
553 }
554 
555 
556 /*************************************************************************
557  */
559 {
560  TestUtil tester( "CommandOptionWithDecimalArg", "Initialization", __FILE__, __LINE__ );
561 
562  defaultCommandOptionList.clear();
563 
564  try
565  {
566  CommandOptionWithDecimalArg cmdOpt(0, "", "", false);
567  tester.assert( false, "CommandOptionWithDecimalArg creation should have failed due to missing short and long options.", __LINE__ );
568  }
569  catch ( ... )
570  {
571  tester.assert( true, "CommandOptionWithDecimalArg() threw an exception as expected.", __LINE__ );
572  }
573 
574  defaultCommandOptionList.clear();
575 
576  try
577  {
578  CommandOptionWithDecimalArg cmdOpt('f', "foo", "Foo", false);
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__ );
584  tester.assert( (defaultCommandOptionList.size() == 1), "CommandOptionWithDecimalArg was not added to the default list.", __LINE__ );
585  }
586  catch ( ... )
587  {
588  tester.assert( false, "CommandOptionWithDecimalArg() threw an exception but should not have.", __LINE__ );
589  }
590 
591  defaultCommandOptionList.clear();
592 
593  return tester.countFails();
594 }
595 
596 
597 /*************************************************************************
598  */
600 {
601  TestUtil tester( "CommandOptionRest", "Initialization", __FILE__, __LINE__ );
602 
603  defaultCommandOptionList.clear();
604 
605  try
606  {
607  CommandOptionRest cmdOpt("", false);
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__ );
613  tester.assert( (defaultCommandOptionList.size() == 1), "CommandOptionRest was not added to the default list.", __LINE__ );
614  }
615  catch ( ... )
616  {
617  tester.assert( false, "CommandOptionRest() threw an exception but should not have.", __LINE__ );
618  }
619 
620  defaultCommandOptionList.clear();
621 
622  return tester.countFails();
623 }
624 
625 
626 /*************************************************************************
627  */
629 {
630  TUDEF("CommandOptionNOf", "Initialization");
631 
632  defaultCommandOptionList.clear();
633  CommandOptionNOf *cmdOpt = NULL;
634  CommandOptionWithAnyArg *cowaa1 = NULL, *cowaa2 = NULL;
635 
636  try
637  {
638  cmdOpt = new CommandOptionNOf(1);
639  cowaa1 = new CommandOptionWithAnyArg('f', "foo", "Foo", false);
640  cowaa2 = new CommandOptionWithAnyArg('b', "bar", "bar", false);
641  TUPASS("CommandOptionNOf was created successfully.");
642  }
643  catch ( ... )
644  {
645  TUFAIL("Exception in constructor");
646  }
647 
648  TUASSERTE(unsigned long,0,cmdOpt->getCount());
649  TUASSERT(cmdOpt->checkArguments().size() != 0);
650  TUASSERTE(unsigned long,3,defaultCommandOptionList.size());
651 
652  try
653  {
654  cmdOpt->addOption(NULL);
655  TUFAIL("CommandOptionNOf()::addOption() succeeded but should have"
656  " failed due to an invalid option address.");
657  }
658  catch ( ... )
659  {
660  TUPASS("CommandOptionNOf::addOption() threw an exception as"
661  " expected.");
662  }
663 
664  try
665  {
666  cmdOpt->addOption(cowaa1);
667  cmdOpt->addOption(cowaa2);
668  TUPASS("CommandOptionNOf()::addOption() succeeded.");
669  }
670  catch ( ... )
671  {
672  TUFAIL("CommandOptionNOf::addOption() threw an exception but should"
673  " not have.");
674  }
675 
676  delete cowaa1;
677  delete cowaa2;
678  defaultCommandOptionList.clear();
679  delete cmdOpt;
680 
681  TURETURN();
682 }
683 
684 
685 /*************************************************************************
686  */
688 {
689  TestUtil tester( "CommandOptionOneOf", "Initialization", __FILE__, __LINE__ );
690 
691  defaultCommandOptionList.clear();
692 
693  try
694  {
695  CommandOptionOneOf cmdOpt;
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__ );
699  tester.assert( (defaultCommandOptionList.size() == 1), "CommandOptionOneOf was not added to the default list.", __LINE__ );
700 
701  try
702  {
703  cmdOpt.addOption(NULL);
704  tester.assert( false, "CommandOptionOneOf()::addOption() succeeded but should have failed due to an valid option address.", __LINE__ );
705  }
706  catch ( ... )
707  {
708  tester.assert( true, "CommandOptionOneOf::addOption() threw an exception as expected.", __LINE__ );
709  }
710 
711  try
712  {
713  CommandOptionWithAnyArg cowaa('f', "foo", "Foo", false);
714  cmdOpt.addOption(&cowaa);
715  tester.assert( true, "CommandOptionOneOf()::addOption() succeeded.", __LINE__ );
716  }
717  catch ( ... )
718  {
719  tester.assert( false, "CommandOptionOneOf::addOption() threw an exception but should not have.", __LINE__ );
720  }
721  }
722  catch ( ... )
723  {
724  tester.assert( false, "CommandOptionOneOf() threw an exception but should not have.", __LINE__ );
725  }
726  defaultCommandOptionList.clear();
727 
728  return tester.countFails();
729 }
730 
731 
732 /*************************************************************************
733  */
735 {
736  TestUtil tester( "CommandOptionAllOf", "Initialization", __FILE__, __LINE__ );
737 
738  defaultCommandOptionList.clear();
739 
740  try
741  {
742  CommandOptionAllOf cmdOpt;
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__ );
746  tester.assert( (defaultCommandOptionList.size() == 1), "CommandOptionAllOf was not added to the default list.", __LINE__ );
747 
748  try
749  {
750  cmdOpt.addOption(NULL);
751  tester.assert( false, "CommandOptionAllOf()::addOption() succeeded but should have failed due to an valid option address.", __LINE__ );
752  }
753  catch ( ... )
754  {
755  tester.assert( true, "CommandOptionAllOf::addOption() threw an exception as expected.", __LINE__ );
756  }
757 
758  try
759  {
760  CommandOptionWithAnyArg cowaa('f', "foo", "Foo", false);
761  cmdOpt.addOption(&cowaa);
762  tester.assert( true, "CommandOptionAllOf()::addOption() succeeded.", __LINE__ );
763  }
764  catch ( ... )
765  {
766  tester.assert( false, "CommandOptionAllOf::addOption() threw an exception but should not have.", __LINE__ );
767  }
768  }
769  catch ( ... )
770  {
771  tester.assert( false, "CommandOptionAllOf() threw an exception but should not have.", __LINE__ );
772  }
773  defaultCommandOptionList.clear();
774 
775  return tester.countFails();
776 }
777 
778 
779 /*************************************************************************
780  */
782 {
783  TestUtil tester( "CommandOptionMutex", "Initialization", __FILE__, __LINE__ );
784 
785  defaultCommandOptionList.clear();
786 
787  try
788  {
789  CommandOptionMutex cmdOpt(false);
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__ );
793  tester.assert( (defaultCommandOptionList.size() == 1), "CommandOptionMutex was not added to the default list.", __LINE__ );
794 
795  try
796  {
797  cmdOpt.addOption(NULL);
798  tester.assert( false, "CommandOptionMutex()::addOption() succeeded but should have failed due to an valid option address.", __LINE__ );
799  }
800  catch ( ... )
801  {
802  tester.assert( true, "CommandOptionMutex::addOption() threw an exception as expected.", __LINE__ );
803  }
804 
805  try
806  {
807  CommandOptionWithAnyArg cowaa('f', "foo", "Foo", false);
808  cmdOpt.addOption(&cowaa);
809  tester.assert( true, "CommandOptionMutex()::addOption() succeeded.", __LINE__ );
810  }
811  catch ( ... )
812  {
813  tester.assert( false, "CommandOptionMutex::addOption() threw an exception but should not have.", __LINE__ );
814  }
815  }
816  catch ( ... )
817  {
818  tester.assert( false, "CommandOptionMutex() threw an exception but should not have.", __LINE__ );
819  }
820  defaultCommandOptionList.clear();
821 
822  return tester.countFails();
823 }
824 
825 
826 /*************************************************************************
827  */
829 {
830  TestUtil tester( "CommandOptionDependent", "Initialization", __FILE__, __LINE__ );
831 
832  defaultCommandOptionList.clear();
833 
834  try
835  {
837  tester.assert( false, "CommandOptionDependent creation should have failed due to NULL addresses.", __LINE__ );
838  }
839  catch ( ... )
840  {
841  tester.assert( true, "CommandOptionDependent() threw an exception as expected.", __LINE__ );
842  }
843  defaultCommandOptionList.clear();
844 
845  return tester.countFails();
846 }
847 
848 
849 /*************************************************************************
850  */
852 {
853  TestUtil tester( "CommandOptionGroupOr", "Initialization", __FILE__, __LINE__ );
854 
855  defaultCommandOptionList.clear();
856 
857  try
858  {
859  CommandOptionGroupOr cmdOpt;
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__ );
863  tester.assert( (defaultCommandOptionList.size() == 1), "CommandOptionGroupOr was not added to the default list.", __LINE__ );
864 
865  try
866  {
867  cmdOpt.addOption(NULL);
868  tester.assert( false, "CommandOptionGroupOr()::addOption() succeeded but should have failed due to an valid option address.", __LINE__ );
869  }
870  catch ( ... )
871  {
872  tester.assert( true, "CommandOptionGroupOr::addOption() threw an exception as expected.", __LINE__ );
873  }
874 
875  try
876  {
877  CommandOptionWithAnyArg cowaa('f', "foo", "Foo", false);
878  cmdOpt.addOption(&cowaa);
879  tester.assert( true, "CommandOptionGroupOr()::addOption() succeeded.", __LINE__ );
880  }
881  catch ( ... )
882  {
883  tester.assert( false, "CommandOptionGroupOr::addOption() threw an exception but should not have.", __LINE__ );
884  }
885  }
886  catch ( ... )
887  {
888  tester.assert( false, "CommandOptionGroupOr() threw an exception but should not have.", __LINE__ );
889  }
890  defaultCommandOptionList.clear();
891 
892  return tester.countFails();
893 }
894 
895 
896 /*************************************************************************
897  */
899 {
900  TestUtil tester( "CommandOptionGroupAnd", "Initialization", __FILE__, __LINE__ );
901 
902  defaultCommandOptionList.clear();
903 
904  try
905  {
906  CommandOptionGroupAnd cmdOpt;
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__ );
910  tester.assert( (defaultCommandOptionList.size() == 1), "CommandOptionGroupAnd was not added to the default list.", __LINE__ );
911 
912  try
913  {
914  cmdOpt.addOption(NULL);
915  tester.assert( false, "CommandOptionGroupAnd()::addOption() succeeded but should have failed due to an valid option address.", __LINE__ );
916  }
917  catch ( ... )
918  {
919  tester.assert( true, "CommandOptionGroupAnd::addOption() threw an exception as expected.", __LINE__ );
920  }
921 
922  try
923  {
924  CommandOptionWithAnyArg cowaa('f', "foo", "Foo", false);
925  cmdOpt.addOption(&cowaa);
926  tester.assert( true, "CommandOptionGroupAnd()::addOption() succeeded.", __LINE__ );
927  }
928  catch ( ... )
929  {
930  tester.assert( false, "CommandOptionGroupAnd::addOption() threw an exception but should not have.", __LINE__ );
931  }
932  }
933  catch ( ... )
934  {
935  tester.assert( false, "CommandOptionGroupAnd() threw an exception but should not have.", __LINE__ );
936  }
937  defaultCommandOptionList.clear();
938 
939  return tester.countFails();
940 }
941 
942 
943 /*************************************************************************
944  * Run the program.
945  *
946  * @return Total error count for all tests
947  */
948 int main(int argc, char *argv[])
949 {
950  int errorTotal = 0;
951 
952  CommandOption_T testClass;
953 
954  errorTotal += testClass.testCommandOption();
955  errorTotal += testClass.testRequiredOption();
956  errorTotal += testClass.testCommandOptionNoArg();
957  errorTotal += testClass.testCommandOptionWithArg();
958  errorTotal += testClass.testCommandOptionWithAnyArg();
959  errorTotal += testClass.testCommandOptionWithStringArg();
960  errorTotal += testClass.testCommandOptionWithNumberArg();
961  errorTotal += testClass.testCommandOptionWithDecimalArg();
962  errorTotal += testClass.testCommandOptionRest();
963  errorTotal += testClass.testCommandOptionNOf();
964  errorTotal += testClass.testCommandOptionOneOf();
965  errorTotal += testClass.testCommandOptionAllOf();
966  errorTotal += testClass.testCommandOptionMutex();
967  errorTotal += testClass.testCommandOptionDependent();
968  errorTotal += testClass.testCommandOptionGroupOr();
969  errorTotal += testClass.testCommandOptionGroupAnd();
970 
971  std::cout << "Total Failures for " << __FILE__ << ": " << errorTotal << std::endl;
972 
973  return( errorTotal );
974 
975 } // main()
CommandOption_T
Definition: CommandOption_T.cpp:49
gnsstk::CommandOption::getOptionString
virtual std::string getOptionString() const
Definition: CommandOption.cpp:97
gnsstk::CommandOptionWithStringArg::checkArguments
virtual std::string checkArguments()
Definition: CommandOption.cpp:285
gnsstk::TestUtil::countFails
int countFails(void)
Definition: TestUtil.hpp:771
gnsstk::TestUtil::assert
void assert(bool testExpression, const std::string &testMsg, const int lineNumber)
Definition: TestUtil.hpp:607
gnsstk::defaultCommandOptionList
CommandOptionVec defaultCommandOptionList
Definition: CommandOption.cpp:55
gnsstk::CommandOption::getOrder
unsigned long getOrder(unsigned long idx=-1) const
Definition: CommandOption.cpp:158
gnsstk::CommandOptionMutex::checkArguments
virtual std::string checkArguments()
Definition: CommandOption.cpp:306
gnsstk::CommandOptionWithStringArg
Definition: CommandOption.hpp:365
CommandOption_T::testCommandOptionWithNumberArg
int testCommandOptionWithNumberArg()
Definition: CommandOption_T.cpp:517
gnsstk::CommandOptionOneOf::addOption
void addOption(CommandOption *opt)
Add an option to the list of mutually exclusive options.
Definition: CommandOption.cpp:396
gnsstk::CommandOptionAllOf
Definition: CommandOption.hpp:575
TUASSERTE
#define TUASSERTE(TYPE, EXP, GOT)
Definition: TestUtil.hpp:81
gnsstk::CommandOptionNOf
Definition: CommandOption.hpp:501
TUFAIL
#define TUFAIL(MSG)
Definition: TestUtil.hpp:228
CommandOption_T::testRequiredOption
int testRequiredOption()
Definition: CommandOption_T.cpp:324
gnsstk::CommandOptionWithNumberArg::checkArguments
virtual std::string checkArguments()
Definition: CommandOption.cpp:241
gnsstk::CommandOptionRest
CommandOption to take the rest of the command line.
Definition: CommandOption.hpp:457
gnsstk::CommandOptionAllOf::getCount
virtual unsigned long getCount() const
returns the sum of all encapsulated option counts if all are in use, zero otherwise.
Definition: CommandOption.cpp:466
gnsstk::CommandOptionMutex
Definition: CommandOption.hpp:607
gnsstk::CommandOption::getArgString
virtual std::string getArgString() const
Returns a string with the argument format.
Definition: CommandOption.hpp:176
gnsstk::CommandOption::getCount
virtual unsigned long getCount() const
Definition: CommandOption.hpp:188
gnsstk::CommandOptionOneOf::checkArguments
virtual std::string checkArguments()
Definition: CommandOption.cpp:406
NULL
#define NULL
Definition: getopt1.c:64
CommandOption_T::testCommandOptionDependent
int testCommandOptionDependent()
Definition: CommandOption_T.cpp:828
gnsstk::CommandOptionWithAnyArg
Definition: CommandOption.hpp:342
gnsstk::CommandOptionNoArg
Definition: CommandOption.hpp:295
gnsstk::CommandOptionDependent
Definition: CommandOption.hpp:641
gnsstk::CommandOption::checkArguments
virtual std::string checkArguments()
Definition: CommandOption.cpp:225
gnsstk::CommandOptionGroupOr::getCount
virtual unsigned long getCount() const
returns the sum of all encapsulated option counts.
Definition: CommandOption.cpp:531
CommandOption_T::testCommandOptionMutex
int testCommandOptionMutex()
Definition: CommandOption_T.cpp:781
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
gnsstk::CommandOptionGroupAnd
Definition: CommandOption.hpp:710
main
int main(int argc, char *argv[])
Definition: CommandOption_T.cpp:948
CommandOption_T::testCommandOptionGroupAnd
int testCommandOptionGroupAnd()
Definition: CommandOption_T.cpp:898
CommandOption_T::testCommandOptionAllOf
int testCommandOptionAllOf()
Definition: CommandOption_T.cpp:734
gnsstk::CommandOptionRest::checkArguments
virtual std::string checkArguments()
Definition: CommandOption.cpp:233
gnsstk::CommandOptionAllOf::checkArguments
virtual std::string checkArguments()
Definition: CommandOption.cpp:444
TUASSERT
#define TUASSERT(EXPR)
Definition: TestUtil.hpp:63
TestUtil.hpp
CommandOption.hpp
CommandOption_T::testCommandOptionWithArg
int testCommandOptionWithArg()
Definition: CommandOption_T.cpp:394
gnsstk::CommandOptionVec
std::vector< CommandOption * > CommandOptionVec
Definition: CommandOption.hpp:66
TURETURN
#define TURETURN()
Definition: TestUtil.hpp:232
TUPASS
#define TUPASS(MSG)
Definition: TestUtil.hpp:230
gnsstk::CommandOptionGroupOr::checkArguments
virtual std::string checkArguments()
Do not do any checking.
Definition: CommandOption.hpp:691
gnsstk::CommandOptionNOf::addOption
void addOption(CommandOption *opt)
Add an option to the list of mutually exclusive options.
Definition: CommandOption.cpp:343
gnsstk::CommandOption
Definition: CommandOption.hpp:115
gnsstk::CommandOptionWithArg
Definition: CommandOption.hpp:319
gnsstk::CommandOptionWithDecimalArg::checkArguments
virtual std::string checkArguments()
Definition: CommandOption.cpp:263
gnsstk::CommandOptionWithNumberArg
Definition: CommandOption.hpp:394
gnsstk::CommandOptionGroupOr
Definition: CommandOption.hpp:678
TUDEF
#define TUDEF(CLASS, METHOD)
Definition: TestUtil.hpp:56
CommandOption_T::testCommandOptionWithStringArg
int testCommandOptionWithStringArg()
Definition: CommandOption_T.cpp:476
gnsstk::CommandOptionGroupAnd::getCount
virtual unsigned long getCount() const
returns the sum of all encapsulated option counts if all are in use, zero otherwise.
Definition: CommandOption.cpp:540
gnsstk::RequiredOption
Definition: CommandOption.hpp:272
CommandOption_T::testCommandOptionNOf
int testCommandOptionNOf()
Definition: CommandOption_T.cpp:628
gnsstk::CommandOption::getFullOptionString
std::string getFullOptionString() const
Definition: CommandOption.cpp:115
std
Definition: Angle.hpp:142
CommandOption_T::testCommandOptionWithDecimalArg
int testCommandOptionWithDecimalArg()
Definition: CommandOption_T.cpp:558
gnsstk::CommandOption::getValue
const std::vector< std::string > & getValue() const
Definition: CommandOption.hpp:194
gnsstk::CommandOptionWithDecimalArg
Definition: CommandOption.hpp:423
CommandOption_T::testCommandOption
int testCommandOption()
Definition: CommandOption_T.cpp:82
CommandOption_T::testCommandOptionRest
int testCommandOptionRest()
Definition: CommandOption_T.cpp:599
gnsstk::CommandOptionNOf::checkArguments
virtual std::string checkArguments()
Definition: CommandOption.cpp:353
CommandOption_T::testCommandOptionOneOf
int testCommandOptionOneOf()
Definition: CommandOption_T.cpp:687
CommandOption_T::testCommandOptionNoArg
int testCommandOptionNoArg()
Definition: CommandOption_T.cpp:353
CommandOption_T::testCommandOptionWithAnyArg
int testCommandOptionWithAnyArg()
Definition: CommandOption_T.cpp:435
gnsstk::TestUtil
Definition: TestUtil.hpp:265
gnsstk::CommandOptionOneOf
Definition: CommandOption.hpp:540
CommandOption_T::testCommandOptionGroupOr
int testCommandOptionGroupOr()
Definition: CommandOption_T.cpp:851


gnsstk
Author(s):
autogenerated on Wed Oct 25 2023 02:40:38