Version: 8.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TestUtils.hxx
Go to the documentation of this file.
1 // Copyright (C) 2013-2016 CEA/DEN, EDF R&D, OPEN CASCADE
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& fileName)
32  {
33  std::string dataDir = getenv("GEOM_SRC_DIR");
34  dataDir += "/src/XAO/tests/data/";
35  dataDir += fileName;
36  return dataDir;
37  }
38 
39  static char* readTextFile(const std::string& filePath)
40  {
41  std::ifstream rstr;
42  int length;
43  rstr.open(filePath.c_str(), std::ios_base::binary);
44  rstr.seekg(0, rstr.end); // go to the end
45  length = rstr.tellg(); // report location (this is the length)
46  rstr.seekg(0, rstr.beg); // go back to the beginning
47  char* txt = new char[length+1]; // allocate memory for a buffer of appropriate dimension
48  rstr.read(txt, length); // read the whole file into the buffer
49  txt[length] = '\0';
50  rstr.close();
51 
52  return txt;
53  }
54  };
55 }
56 
57 #endif /* __XAO_TESTUTILS_HXX__ */