fw4spl
Data.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2015.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #include "fwTest/Exception.hpp"
8 #include "fwTest/Data.hpp"
9 
10 #include <boost/filesystem/operations.hpp>
11 
12 #include <cstdlib>
13 #include <sstream>
14 
15 
16 namespace fwTest
17 {
18 
19 const std::string Data::s_TEST_DATA_DIR_ENV_VAR("FWTEST_DATA_DIR");
20 
21 ::boost::filesystem::path Data::dir()
22 {
23  char * val = std::getenv(s_TEST_DATA_DIR_ENV_VAR.c_str());
24  if (val == 0)
25  {
26  std::stringstream msg;
27  msg << "The '" << s_TEST_DATA_DIR_ENV_VAR
28  << "' environment variable is not set.";
29  throw fwTest::Exception(msg.str());
30  }
31 
32  ::boost::filesystem::path datadir(val);
33 
34  if (!::boost::filesystem::exists(datadir))
35  {
36  std::stringstream msg;
37  msg << "The path'" << datadir
38  << "' doesn't seem to exist.";
39  throw fwTest::Exception(msg.str());
40  }
41 
42  return datadir;
43 }
44 
45 
46 } // namespace fwTest
47 
48 
Definition: Data.hpp:15