Salome HOME
Various fixes for test runs - introducing MEDCOUPLING_RESOURCE_DIR env variable
[tools/medcoupling.git] / src / INTERP_KERNELTest / TestInterpKernelUtils.cxx
index 25b1c1154755d695bf2b5f6c4f2928aae2349540..6d466befbf2d994ae8fbc7760b006d3c1fc75df2 100644 (file)
@@ -1,4 +1,4 @@
-// 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
@@ -29,6 +29,7 @@
 #endif
 #include <sstream>
 #include <fstream>
+#include <algorithm>
 
 namespace INTERP_TEST
 {
@@ -36,22 +37,34 @@ namespace INTERP_TEST
   {
     std::string resourceFile = "";
     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())
-        return resourceFile;
+        // 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;
     }
     // else
-    resourceFile = getcwd(NULL, 0);
+    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);
+    std::ifstream my_file(resourceFile.c_str());
     if (!my_file.good())
       {
         std::stringstream ss;