ElmerFoamFSI  2.0
ElmerFoamFSI is fluid-solid interaction simulation application built up from OpenFOAM CFD and Elmer CSM coupled through the IMPACT multiphysics software integration infrastructure.
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Macros Groups Pages
int ElmerModuleDriver::Test ( int  argc,
char *  argv[] 
)

Drives the ElmerModuleDriver::TestObject.

Parameters
argcnumber of string command line tokens
argvstring command line tokens
Returns
0 if successful, 1 otherwise

Drives the ElmerModuleDriver::TestObject, which should encapsulate all the tests for the ElmerModuleDriver namespace (and thus the project).

Command line documentation:

      elmermoduledriver_test [-h] [-v [level] -o <filename> -l <filename> -n <TestName> ] 

      -h,--help
         Print out long version of help and exit.

      -v,--verblevel [level]
         Set the verbosity level. (default = 0)

      -o,--output <filename>
         Set the output file to <filename>. (default = stdout)

      -l,--list <filename>
         Set the list file name to <filename>. (no default). The list file should be a text file with one test name per line.

      -n,--name <TestName>
         Run test by name. (no default)

      -s,--source <pathname>  

Definition at line 48 of file TestElmerModuleDriver.C.

References TestComLine::Initialize(), TestingObject< ResultsType >::Process(), TestingObject< ResultsType >::RunTest(), and TestingObject< ResultsType >::SetSourceDirPath().

Referenced by main().

49  {
50  int com_initialized = COM_initialized();
51  bool com_initialized_pass = (com_initialized <= 0);
52 
53  COM_init(&argc, &argv);
54  if(com_initialized_pass)
55  com_initialized = (COM_initialized() > 0);
56  else
57  std::cout << "COM not initialized!" << std::endl;
58 
59  // The default verbosity is 0
60  int verblevel = 0;
61 
62  // This line creates the ElmerModuleDriver::TestComLine object and passes in
63  // the command line arguments as a (const char **).
64  TestComLine comline((const char **)(argv));
65  // The call to comline.Initialize() reads the command line arguments
66  // from the array passed in the previous line.
67  comline.Initialize();
68  // The ProcessOptions() call does detailed examination of the command
69  // line arguments to check for user errors or other problems. This call
70  // will return non-zero if there were errors on the commandline.
71  int clerr = comline.ProcessOptions();
72  // Check if the user just wanted to get the help and exit
73  if(!comline.GetOption("help").empty()){
74  // Print out the "long usage" (i.e. help) message to stdout
75  std::cout << comline.LongUsage() << std::endl;
76  if(verblevel > 2)
77  std::cout << "ElmerModuleDriver::Test: Exiting test function (success)" << std::endl;
78  return(0);
79  }
80  if(clerr){
81  std::cout << comline.ErrorReport() << std::endl
82  << std::endl << comline.ShortUsage() << std::endl;
83  if(verblevel > 2)
84  std::cout << "ElmerModuleDriver::Test: Exiting test function (fail)" << std::endl;
85  return(1);
86  }
87  // These outstreams allow the output to file to be set up and separated
88  // from the stdout.
89  std::ofstream Ouf;
90  std::ostream *Out = &std::cout;
91 
92  // The next few lines populate some strings based on the
93  // users input from the commandline.
94  std::string OutFileName(comline.GetOption("output"));
95  std::string TestName(comline.GetOption("name"));
96  std::string ListName(comline.GetOption("list"));
97  std::string sverb(comline.GetOption("verblevel"));
98  std::string SourcePath(comline.GetOption("source"));
99 
100  // The following block parses and sets the verbosity level
101  if(!sverb.empty()){
102  verblevel = 1;
103  if(sverb != ".true."){
104  std::istringstream Istr(sverb);
105  Istr >> verblevel;
106  if(verblevel < 0)
107  verblevel = 1;
108  }
109  }
110 
111  // This block sets up the output file if the user specified one
112  if(!OutFileName.empty()){
113  Ouf.open(OutFileName.c_str());
114  if(!Ouf){
115  std::cout << "ElmerModuleDriver::Test> Error: Could not open output file, "
116  << OutFileName << " for test output. Exiting (fail)." << std::endl;
117  return(1);
118  }
119  Out = &Ouf;
120  }
121 
122  if(verblevel > 2)
123  std::cout << "ElmerModuleDriver::Test: Entering test function" << std::endl;
124 
125  // Make an instance of the ElmerModuleDriver testing object, ElmerModuleDriver::TestingObject
127  // Make an instance of the ElmerModuleDriver results object, ElmerModuleDriver::TestResults
129 
130  //Set the source directory for the testing object if it was input
131  if(!SourcePath.empty()){
132  test.SetSourceDirPath(SourcePath);
133  }
134 
135  // If the user specified a name, then run only the named test
136  if(!TestName.empty()){
137  // This call runs a test by name
138  test.RunTest(TestName,results);
139  }
140  // Otherwise, if the user specified a list, then read the list and
141  // run the listed tests.
142  else if(!ListName.empty()){
143  std::ifstream ListInf;
144  ListInf.open(ListName.c_str());
145  if(!ListInf){
146  std::cout << "ElmerModuleDriver::Test> Error: Could not open list of tests in file "
147  << ListName << ". Exiting (fail)." << std::endl;
148  return(1);
149  }
150  std::string testname;
151  while(std::getline(ListInf,testname))
152  test.RunTest(testname,results);
153  ListInf.close();
154  }
155  else {
156  // This call runs all the tests for the ElmerModuleDriver namespace.
157  test.Process(results);
158  }
159 
160  COM_finalize();
161  if(com_initialized_pass)
162  com_initialized_pass = (COM_initialized() <= 0);
163 
164  *Out << results << std::endl;
165 
166  if(Ouf)
167  Ouf.close();
168 
169  if(verblevel > 2)
170  *Out << "ElmerModuleDriver::Test: Exiting test function (success)" << std::endl;
171 
172  return(0);
173  }
virtual void RunTest(const std::string &name, ResultsType &result)
Runs a test specified by name.
void SetSourceDirPath(std::string input)
Sets the string value of the testing source directory.
Project-specific testing object.
IRAD::Util::TestResults TestResults
Project-specific test results type.
virtual void Process(ResultsType &result)

Here is the call graph for this function:

Here is the caller graph for this function: