Back to index

salome-med  6.5.0
Functions
MEDMEMTest_Utils.cxx File Reference
#include "MEDMEMTest_Utils.hxx"
#include <cstdlib>
#include <list>
#include <stdexcept>

Go to the source code of this file.

Functions

std::string getResourceFile (const std::string &filename)
 Get path to the resources file.
std::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.
std::string fixSlashes (const std::string &path)
 On WINDOWS, replaces all forward slashes by back slashes to avoid mixed slashes in one path.

Function Documentation

std::string fixSlashes ( const std::string &  path)

On WINDOWS, replaces all forward slashes by back slashes to avoid mixed slashes in one path.

Definition at line 124 of file MEDMEMTest_Utils.cxx.

{
#ifdef WNT
  std::string fixedpath = path;
  for ( int i=0; i < path.size(); ++i )
    if (path[i] == '/')
      fixedpath[i] = '\\';
  return fixedpath;
#else
  return path;
#endif
}

Here is the caller graph for this function:

std::string getResourceFile ( const std::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 41 of file MEDMEMTest_Utils.cxx.

{
  std::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;
  return fixSlashes( resourceFile );
}

Here is the call graph for this function:

std::string getTmpDirectory ( )

Returns writable temporary directory.

Returns:
full path to the temporary directory

Definition at line 66 of file MEDMEMTest_Utils.cxx.

{
  std::string path;

  std::list<std::string> dirs;
  if ( getenv("TEMP") )   dirs.push_back( getenv("TEMP" ));
  if ( getenv("TMP") )    dirs.push_back( getenv("TMP" ));
  if ( getenv("TMPDIR") ) dirs.push_back( getenv("TMPDIR" ));
  dirs.push_back( "/tmp" );

  std::string tmpd = "";
  for ( std::list<std::string>::iterator dir = dirs.begin(); dir != dirs.end() && tmpd == "" ; ++dir ) {
#ifdef WNT
    if ( GetFileAttributes(dir->data()) & FILE_ATTRIBUTE_DIRECTORY )
#else
    if ( access( dir->data(), W_OK ) == 0 )
#endif
      tmpd = dir->data();
  }

  if ( tmpd == "" )
    throw std::runtime_error("Can't find writable temporary directory. Set TMP environment variable");

  return tmpd;
}

Here is the caller graph for this function:

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.

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

Definition at line 103 of file MEDMEMTest_Utils.cxx.

{
  std::string tmpf = fixSlashes( getTmpDirectory() + "/" + tmpfile );
  if ( srcfile != "" ) {
#ifdef WNT
    std::string cmd  = "copy " + fixSlashes( srcfile ) + " " + tmpf;
#else
    std::string cmd  = "cp " + srcfile + " " + tmpf + " ; chmod +w " + tmpf;
#endif
    system( cmd.c_str() );
  }
  return tmpf;
}

Here is the caller graph for this function: