Salome HOME
Merge from BR_V7_main_Field branch (02/09/2013)
[modules/geom.git] / src / XAO / tests / TestUtils.hxx
1 #ifndef __XAO_TESTUTILS_HXX__
2 #define __XAO_TESTUTILS_HXX__
3
4 #include <fstream>
5 #include <cstdlib>
6
7 namespace XAO
8 {
9     class TestUtils
10     {
11     public:
12         static std::string getTestFilePath(const std::string& fileName)
13         {
14             std::string dataDir = getenv("GEOM_SRC_DIR");
15             dataDir += "/src/XAO/tests/data/" + fileName;
16             return dataDir;
17         }
18
19         static char* readTextFile(const std::string& filePath)
20         {
21             std::ifstream rstr;
22             int length;
23             rstr.open(filePath.c_str());
24             rstr.seekg(0, rstr.end);        // go to the end
25             length = rstr.tellg();          // report location (this is the length)
26             rstr.seekg(0, rstr.beg);        // go back to the beginning
27             char* txt = new char[length];   // allocate memory for a buffer of appropriate dimension
28             rstr.read(txt, length);         // read the whole file into the buffer
29             rstr.close();
30
31             return txt;
32         }
33     };
34 }
35
36 #endif /* __XAO_TESTUTILS_HXX__ */