Back to index

salome-med  6.5.0
Functions
MEDSPLITTERTest_Utils Namespace Reference

Functions

string getResourceFile (const string &filename)
 Get path to the resources file.
string getTmpDirectory ()
 Returns writable temporary directory.
std::string makeTmpFile (const std::string &tmpfile, const std::string &srcfile)
 Creates a copy of source file (if source file is specified) in the temporary directory and returns a path to the tmp file.

Function Documentation

std::string MEDSPLITTERTest_Utils::getResourceFile ( const string &  filename)

Get path to the resources file.

When running 'make test' source file is taken from MED_SRC/resources folder. Otherwise, file is searched in ${MED_ROOT_DIR}/share/salome/resources/med folder.

Parameters:
filenamename of the resource file (should not include a path)
Returns:
full path to the resource file

Definition at line 40 of file MEDSPLITTERTest_Utils.cxx.

{
  string resourceFile = "";

  if ( getenv("top_srcdir") ) {
    // we are in 'make check' step
    resourceFile = getenv("top_srcdir");
    resourceFile += "/resources/";
  }
  else if ( getenv("MED_ROOT_DIR") ) {
    // use MED_ROOT_DIR env.var
    resourceFile = getenv("MED_ROOT_DIR");
    resourceFile += "/share/salome/resources/med/";
  }
  resourceFile += filename;
#ifndef WIN32
  if (access(resourceFile.data(), F_OK) != 0)
#else
  if (  GetFileAttributes (  resourceFile.c_str()  ) == 0xFFFFFFFF  )
    if (  GetLastError () == ERROR_FILE_NOT_FOUND  )
#endif
    CPPUNIT_FAIL(MEDMEM::STRING("Resource file ")<< filename << " not found");
  
  return resourceFile;
}

Here is the caller graph for this function:

Returns writable temporary directory.

Returns:
full path to the temporary directory

Definition at line 73 of file MEDSPLITTERTest_Utils.cxx.

{
  string path;

  list<string> dirs;
  if ( getenv("TMP") ) dirs.push_back( getenv("TMP" ));
  if ( getenv("TMPDIR") ) dirs.push_back( getenv("TMPDIR" ));
  dirs.push_back( "/tmp" );
#ifndef WIN32
  for ( list<string>::iterator dir = dirs.begin(); dir != dirs.end(); ++dir )
    if ( access( dir->data(), W_OK ) == 0 )
      return *dir;
#endif

  CPPUNIT_FAIL("Can't find writable temporary directory. Set TMP environment variable correctly");
  return "";
}
std::string MEDSPLITTERTest_Utils::makeTmpFile ( const std::string &  tmpfile,
const std::string &  srcfile 
)

Creates a copy of source file (if source file is specified) in the temporary directory and returns a path to the tmp file.

Parameters:
tmpfilename of the temporary file (without path)
srcfilesource file
Returns:
path to the temporary file

Definition at line 102 of file MEDSPLITTERTest_Utils.cxx.

{
  std::string tmpf = getTmpDirectory() + "/" + tmpfile;
  if ( srcfile != "" ) {
    std::string cmd  = "cp " + srcfile + " " + tmpf + " ; chmod +w " + tmpf;
    system( cmd.c_str() );
  }
  return tmpf;
}

Here is the call graph for this function: