Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TestRocstar.C
Go to the documentation of this file.
1 #include "ComLine.H"
11 #include "TestRocstar.H"
12 
13 namespace Rocstar{
14 
15 
45  int Test(int argc,char *argv[])
46  {
47 
48  // The default verbosity is 0
49  int verblevel = 0;
50 
51  // This line creates the Rocstar::TestComLine object and passes in
52  // the command line arguments as a (const char **).
53  TestComLine comline((const char **)(argv));
54  // The call to comline.Initialize() reads the command line arguments
55  // from the array passed in the previous line.
56  comline.Initialize();
57  // The ProcessOptions() call does detailed examination of the command
58  // line arguments to check for user errors or other problems. This call
59  // will return non-zero if there were errors on the commandline.
60  int clerr = comline.ProcessOptions();
61  // Check if the user just wanted to get the help and exit
62  if(!comline.GetOption("help").empty()){
63  // Print out the "long usage" (i.e. help) message to stdout
64  std::cout << comline.LongUsage() << std::endl;
65  if(verblevel > 2)
66  std::cout << "Rocstar::Test: Exiting test function (success)" << std::endl;
67  return(0);
68  }
69  if(clerr){
70  std::cout << comline.ErrorReport() << std::endl
71  << std::endl << comline.ShortUsage() << std::endl;
72  if(verblevel > 2)
73  std::cout << "Rocstar::Test: Exiting test function (fail)" << std::endl;
74  return(1);
75  }
76  // These outstreams allow the output to file to be set up and separated
77  // from the stdout.
78  std::ofstream Ouf;
79  std::ostream *Out = &std::cout;
80 
81  // The next few lines populate some strings based on the
82  // users input from the commandline.
83  std::string OutFileName(comline.GetOption("output"));
84  std::string TestName(comline.GetOption("name"));
85  std::string ListName(comline.GetOption("list"));
86  std::string sverb(comline.GetOption("verblevel"));
87 
88  // The following block parses and sets the verbosity level
89  if(!sverb.empty()){
90  verblevel = 1;
91  if(sverb != ".true."){
92  std::istringstream Istr(sverb);
93  Istr >> verblevel;
94  if(verblevel < 0)
95  verblevel = 1;
96  }
97  }
98 
99  // This block sets up the output file if the user specified one
100  if(!OutFileName.empty()){
101  Ouf.open(OutFileName.c_str());
102  if(!Ouf){
103  std::cout << "Rocstar::Test> Error: Could not open output file, "
104  << OutFileName << " for test output. Exiting (fail)." << std::endl;
105  return(1);
106  }
107  Out = &Ouf;
108  }
109 
110  if(verblevel > 2)
111  std::cout << "Rocstar::Test: Entering test function" << std::endl;
112 
113  // Make an instance of the Rocstar testing object, Rocstar::TestingObject
115  // Make an instance of the Rocstar results object, Rocstar::TestResults
116  Rocstar::TestResults results;
117 
118  // If the user specified a name, then run only the named test
119  if(!TestName.empty()){
120  // This call runs a test by name
121  test.RunTest(TestName,results);
122  }
123  // Otherwise, if the user specified a list, then read the list and
124  // run the listed tests.
125  else if(!ListName.empty()){
126  std::ifstream ListInf;
127  ListInf.open(ListName.c_str());
128  if(!ListInf){
129  std::cout << "Rocstar::Test> Error: Could not open list of tests in file "
130  << ListName << ". Exiting (fail)." << std::endl;
131  return(1);
132  }
133  std::string testname;
134  while(std::getline(ListInf,testname))
135  test.RunTest(testname,results);
136  ListInf.close();
137  }
138  else {
139  // This call runs all the tests for the Rocstar namespace.
140  test.Process(results);
141  }
142  *Out << results << std::endl;
143 
144  if(Ouf)
145  Ouf.close();
146 
147  if(verblevel > 2)
148  *Out << "Rocstar::Test: Exiting test function (success)" << std::endl;
149 
150  return(0);
151  }
152 };
153 
154 int main(int argc,char *argv[])
155 {
156  return(Rocstar::Test(argc,argv));
157 }
virtual void Process(ResultsType &result)
Runs all tests implemented by the Rocstar::TestingObject.
Definition: RocstarTest.H:255
Project-specific testing object.
Definition: RocstarTest.H:71
virtual void RunTest(const std::string &name, ResultsType &result)
Runs a test specified by name.
Definition: RocstarTest.H:269
void test(void)
Definition: flotsam.C:99
ComLineObject for Rocstar testing command-line interface.
Definition: TestRocstar.H:16
Testing utilities for Rocstar.
int main(int argc, char *argv[])
Definition: blastest.C:94
int Test(int argc, char *argv[])
Drives the Rocstar::TestObject.
Definition: TestRocstar.C:45
IRAD::Util::TestResults TestResults
Project-specific test results type.
Definition: RocstarTest.H:41