-// Copyright (C) 2007-2012 CEA/DEN, EDF R&D
+// Copyright (C) 2007-2016 CEA/DEN, EDF R&D
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
//
#include "TestInterpKernelUtils.hxx"
+#include "InterpKernelException.hxx"
#include <cstdlib>
+#ifdef WIN32
+#include<direct.h>
+#define getcwd _getcwd
+#else
+#include <unistd.h>
+#endif
+#include <sstream>
+#include <fstream>
namespace INTERP_TEST
{
- std::string getResourceFile( const std::string& filename )
+ std::string getResourceFile( const std::string& filename, int levelUp)
{
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/";
+ if ( getenv("MEDCOUPLING_ROOT_DIR") ) {
+ // use MEDCOUPLING_ROOT_DIR env.var
+ resourceFile = getenv("MEDCOUPLING_ROOT_DIR");
+ resourceFile += "/share/resources/med/";
+ resourceFile += filename;
+ std::ifstream my_file(resourceFile.c_str());
+ if (my_file.good())
+ return resourceFile;
}
+ // else
+ char * tmp_c = getcwd(NULL, 0);
+ resourceFile = tmp_c;
+ free(tmp_c);
+ resourceFile += "/";
+ for(int i=0; i<levelUp; i++)
+ resourceFile += "../";
+ resourceFile += "resources/";
resourceFile += filename;
+ std::ifstream my_file(resourceFile.c_str());
+ if (!my_file.good())
+ {
+ std::stringstream ss;
+ ss << "INTERP_TEST::getResourceFile(): could not open resource test file: " << filename << "\n";
+ throw INTERP_KERNEL::Exception(ss.str().c_str());
+ }
+
return resourceFile;
}