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
virtual int GetInputData ( std::string  suffix,
std::string  TestDir 
)
inlinevirtual

Function to copy input data from source testing directory for use in unit tests.

Parameters
suffixstd::string for the input data location (it is appended to the source directory inputted on the command line)
TestDirstd::string path for directory to run the test in

Definition at line 325 of file ElmerModuleDriverTest.H.

References TestingObject< ResultsType >::SourceDirPath.

Referenced by TestingObject< ResultsType >::Test__ElasticBeam3D_LoadFunction(), and TestingObject< ResultsType >::Test__ElmerUnitTests().

325  {
326 
327  std::cout << "In GetInputData" << std::endl;
328  std::string DirName;
329  std::string OrgDir;
330 
331  //Save original working directory for later
332  OrgDir = IRAD::Sys::CWD();
333 
334  //Create full path for test input data directory
335  DirName = SourceDirPath + suffix;
336 
337  //Check if data directory exists
338  if(!IRAD::Sys::FILEEXISTS(DirName)){
339  std::cout << "GetInputData Error: Could not find data directory, "
340  << DirName << ". Exiting (fail)." << std::endl;
341  return -1;
342  }
343 
344  std::ifstream Inf;
345  std::ofstream Ouf;
346  std::string InFileName;
347  std::string OutFileName;
348  int IntDir;
349 
350  //Create TestDir directory in current directory (if it doesn't
351  //already exist) to run our tests in.
352  if(!IRAD::Sys::FILEEXISTS(TestDir)){
353  IntDir = IRAD::Sys::CreateDirectory(TestDir);
354  if(IntDir == -1){
355  std::cout << "GetInputData Error: Could not make directory, "
356  << TestDir << ". Exiting (fail)." << std::endl;
357  return -1;
358  }
359  }
360 
361  //Open the input test data directory
362  IRAD::Sys::Directory SourceDir(DirName);
363 
364  //Change directories to TestDir directory for running
365  IntDir = IRAD::Sys::ChDir(TestDir);
366  if(IntDir == -1){
367  std::cout << "GetInputData Error: Could not change directories to "
368  << TestDir << ". Exiting (fail)." << std::endl;
369  return -1;
370  }
371 
372  //Copy input data to TestDir directory for running
373  for(std::vector<std::string>::iterator it = SourceDir.begin();
374  it != SourceDir.end(); ++it){
375  InFileName = DirName + "/" + *it;
376  OutFileName = IRAD::Sys::CWD() + "/" + *it;
377  // copy source to distnation recursively
378  if(IRAD::Sys::ISLINK(InFileName))
379  // preserve links, don't traverse
380  int IntDir = IRAD::Sys::SymLink(InFileName, OutFileName);
381  else if(IRAD::Sys::ISDIR(InFileName)) {
382  // recursively copy directories
383  int IntDir = GetInputData(InFileName, OutFileName);
384  } else {
385  // copy files, travserse into directories recursively
386  Inf.open(InFileName.c_str());
387  Ouf.open(OutFileName.c_str());
388  Ouf << Inf.rdbuf();
389  Ouf.close();
390  Inf.close();
391  }
392 
393  }
394 
395  //Change directories to back to original directory
396  IntDir = IRAD::Sys::ChDir(OrgDir);
397  if(IntDir == -1){
398  std::cout << "GetInputData Error: Could not change directories to "
399  << OrgDir << ". Exiting (fail)." << std::endl;
400  return -1;
401  }
402 
403  return 0;
404  }
std::string SourceDirPath
The string for the testing source directory.
virtual int GetInputData(std::string suffix, std::string TestDir)
Function to copy input data from source testing directory for use in unit tests.

Here is the caller graph for this function: