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