File: testMetaCommand.cxx

package info (click to toggle)
insighttoolkit4 4.13.3withdata-dfsg1-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 489,260 kB
  • sloc: cpp: 557,342; ansic: 146,850; fortran: 34,788; python: 16,572; sh: 2,187; lisp: 2,070; tcl: 993; java: 362; perl: 200; makefile: 129; csh: 81; pascal: 69; xml: 19; ruby: 10
file content (88 lines) | stat: -rw-r--r-- 4,461 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*=========================================================================
 *
 *  Copyright Insight Software Consortium
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0.txt
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 *=========================================================================*/

#include <fstream>


#include <metaCommand.h>

int testMetaCommand(int argc, char * argv[])
{
  MetaCommand command;
  command.SetOption("ExpectedFailStatus","ExpectedFailStatus",true,"Use to check that proper failures are listed.");
  command.AddOptionField("ExpectedFailStatus","ExpectedFailStatus", MetaCommand::INT,true,"1","Expected fail status is true");

  command.SetOption("SumOfValues","sum",true,"Sum of values passed into command line, Default values are 100");
  command.AddOptionField("SumOfValues","SumOfValues", MetaCommand::INT,true);

  command.SetOption("Required1Complete_rs","r1c_rs",true, "RequiredOption1");
  command.AddOptionField("Required1Complete_rs","Required1Complete_rs", MetaCommand::STRING,true);
  command.SetOptionComplete("Required1Complete_rs",true);

  command.SetOption("Required2_ri","r2_ri",true,"Required2");
  command.AddOptionField("Required2_ri","Required2_ri", MetaCommand::INT,true);

  command.SetOption("OptionalField1_ri","o1_ri",false, "Optional Field 1");
  command.AddOptionField("OptionalField1_ri","OptionalField1_ri", MetaCommand::INT,true,"100","A value of 100");

  command.SetOption("OptionalField2_ri","o2_ri",false, "Optional Field 1");
  command.AddOptionField("OptionalField2_ri","OptionalField2_ri", MetaCommand::INT,true,"100","A value of 100");

  command.SetOption("OptionalField1_oi","o1_oi",false, "Optional Field 2");
  command.AddOptionField("OptionalField1_oi","OptionalField1_oi", MetaCommand::INT,false,"100","A value of 100");

  command.SetOption("OptionalField2_oi","o2_oi",false, "Optional Field 2");
  command.AddOptionField("OptionalField2_oi","OptionalField2_oi", MetaCommand::INT,false,"100","A value of 100");

  command.SetOption("OptionalField3_ri_oi","o3_ri_oi",false, "Optional Field 3, one required, one optional flag");
  command.AddOptionField("OptionalField3_ri_oi","OptionalField3_ri", MetaCommand::INT,true);
  command.AddOptionField("OptionalField3_ri_oi","OptionalField3_oi", MetaCommand::INT,false,"100","A value of 100");

  if(command.Parse(argc,argv) == true )
    {
    const int SumValue=
      +( command.GetOptionWasSet("Required2_ri")         ? command.GetValueAsInt("Required2_ri","Required2_ri") : 0 )
      +( command.GetOptionWasSet("OptionalField1_ri")    ? command.GetValueAsInt("OptionalField1_ri","OptionalField1_ri"): 0 )
      +( command.GetOptionWasSet("OptionalField2_ri")    ? command.GetValueAsInt("OptionalField2_ri","OptionalField2_ri"): 0 )
      +( command.GetOptionWasSet("OptionalField1_oi")    ? command.GetValueAsInt("OptionalField1_oi","OptionalField1_oi"): 0 )
      +( command.GetOptionWasSet("OptionalField2_oi")    ? command.GetValueAsInt("OptionalField2_oi","OptionalField2_oi"): 0 )
      +( command.GetOptionWasSet("OptionalField3_ri_oi") ? command.GetValueAsInt("OptionalField3_ri_oi","OptionalField3_ri"): 0 )
      +( command.GetOptionWasSet("OptionalField3_ri_oi") ? command.GetValueAsInt("OptionalField3_ri_oi","OptionalField3_oi"): 0 );
    std::cout << "Computed " <<  SumValue << " expected " << command.GetValueAsInt("SumOfValues") << std::endl;

    if(command.GetValueAsInt("ExpectedFailStatus","ExpectedFailStatus") == 1)
      {
      std::cout << "Expected parse failure that did not occur, so test failed" << std::endl;
      return 1;
      }
    else
      {
      return ( command.GetValueAsInt("SumOfValues") - SumValue );
      }
    }
    else
    {
    if(command.GetValueAsInt("ExpectedFailStatus","ExpectedFailStatus") == 1)
      {
      std::cout << "Expected parse failure, so test succeeded" << std::endl;
      return 0;
      }
    }
  std::cout << "Unexpected parse failure, so test failed" << std::endl;
  return 1;
}