Salome HOME
updated copyright message
[modules/shaper.git] / src / XAO / tests / TestUtils.hxx
1 // Copyright (C) 2013-2023  CEA, EDF
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef __XAO_TESTUTILS_HXX__
21 #define __XAO_TESTUTILS_HXX__
22
23 #include <fstream>
24 #include <cstdlib>
25
26 namespace XAO
27 {
28     class TestUtils
29     {
30     public:
31         static std::string getTestFilePath(const std::string& filePath)
32         {
33             std::string dataDir = getenv("DATA_DIR");
34             dataDir += filePath;
35             return dataDir;
36         }
37
38         static char* readTextFile(const std::string& filePath)
39         {
40             std::ifstream rstr;
41             int length;
42             rstr.open(filePath.c_str(), std::ios_base::binary);
43             rstr.seekg(0, rstr.end);        // go to the end
44             length = rstr.tellg();          // report location (this is the length)
45             rstr.seekg(0, rstr.beg);        // go back to the beginning
46             char* txt = new char[length+1]; // allocate memory for a buffer of appropriate dimension
47             rstr.read(txt, length);         // read the whole file into the buffer
48             txt[length] = '\0';
49             rstr.close();
50
51             return txt;
52         }
53     };
54 }
55
56 #endif /* __XAO_TESTUTILS_HXX__ */