1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "ParaMEDMEMTest.hxx"
21 #include "TestInterpKernelUtils.hxx"
22 #include <cppunit/TestAssert.h>
36 //================================================================================
38 * \brief Returns writable temporary directory
39 * \return full path to the temporary directory
41 //================================================================================
43 std::string ParaMEDMEMTest::getTmpDirectory()
47 std::list<std::string> dirs;
48 if ( getenv("TMP") ) dirs.push_back( getenv("TMP" ));
49 if ( getenv("TMPDIR") ) dirs.push_back( getenv("TMPDIR" ));
50 dirs.push_back( "/tmp" );
52 std::string tmpd = "";
53 for ( std::list<std::string>::iterator dir = dirs.begin(); dir != dirs.end() && tmpd == "" ; ++dir ) {
54 if ( access( dir->data(), W_OK ) == 0 ) {
60 throw std::runtime_error("Can't find writable temporary directory. Set TMP environment variable");
65 //================================================================================
67 * \brief Creates a copy of source file (if source file is specified)
68 * in the temporary directory and returns a path to the tmp file
70 * \param tmpfile name of the temporary file (without path)
71 * \param srcfile source file
72 * \return path to the temporary file
74 //================================================================================
75 std::string ParaMEDMEMTest::makeTmpFile( const std::string& tmpfile, const std::string& srcfile )
77 std::string tmpf = getTmpDirectory() + "/" + tmpfile;
78 if ( srcfile != "" ) {
79 std::string cmd = "cp " + srcfile + " " + tmpf + " ; chmod +w " + tmpf;
80 system( cmd.c_str() );
87 * Tool to remove temporary files.
88 * Allows automatique removal of temporary files in case of test failure.
90 ParaMEDMEMTest_TmpFilesRemover::~ParaMEDMEMTest_TmpFilesRemover()
92 std::set<std::string>::iterator it = myTmpFiles.begin();
93 for (; it != myTmpFiles.end(); it++) {
94 if (access((*it).data(), F_OK) == 0)
98 //cout << "~ParaMEDMEMTest_TmpFilesRemover()" << endl;
101 bool ParaMEDMEMTest_TmpFilesRemover::Register(const std::string theTmpFile)
103 return (myTmpFiles.insert(theTmpFile)).second;