-// Copyright (C) 2007-2015 CEA/DEN, EDF R&D
+// Copyright (C) 2007-2020 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
#endif
#include <sstream>
#include <fstream>
+#include <algorithm>
namespace INTERP_TEST
{
- std::string getResourceFile( const std::string& filename )
+ std::string getResourceFile( const std::string& filename, int levelUp)
{
std::string resourceFile = "";
- bool good = false;
-
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);
- if (my_file.good())
- good = true;
+ // 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;
+ }
+ if ( getenv("MEDCOUPLING_RESOURCE_DIR") ) {
+ // use MEDCOUPLING_RESOURCE_DIR env.var
+ resourceFile = getenv("MEDCOUPLING_RESOURCE_DIR");
+ resourceFile.erase(std::remove(resourceFile.begin(), resourceFile.end(), ':'), resourceFile.end());
+ resourceFile += "/";
+ resourceFile += filename;
+ std::ifstream my_file(resourceFile.c_str());
+ if (my_file.good())
+ return resourceFile;
}
- if (!good)
+ // 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())
{
- resourceFile = getcwd(NULL, 0);
- resourceFile += "/../../resources/";
- std::ifstream my_file(resourceFile);
- 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());
- }
+ 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;