blob: d4ee7826d108507b9ba8a7e2380fb3283c74db58 [file] [log] [blame]
Davide Pesaventocc2c7172018-01-21 21:41:03 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2014-2018, Regents of the University of California.
4 *
5 * This file is part of ndn-tools (Named Data Networking Essential Tools).
6 * See AUTHORS.md for complete list of ndn-tools authors and contributors.
7 *
8 * ndn-tools is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
11 *
12 * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * ndn-tools, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "boost-test.hpp"
21
22#include <boost/filesystem.hpp>
23#include <fstream>
24#include <stdlib.h>
25
26namespace ndn {
27namespace tools {
28namespace tests {
29
30class GlobalConfiguration
31{
32public:
33 GlobalConfiguration()
34 {
35 const char* envHome = ::getenv("HOME");
36 if (envHome)
37 m_home = envHome;
38
39 boost::filesystem::path dir{TMP_TESTS_PATH};
40 dir /= "test-home";
41 ::setenv("HOME", dir.c_str(), 1);
42
43 boost::filesystem::create_directories(dir);
44 std::ofstream clientConf((dir / ".ndn" / "client.conf").c_str());
45 clientConf << "pib=pib-sqlite3" << std::endl
46 << "tpm=tpm-file" << std::endl;
47 }
48
49 ~GlobalConfiguration()
50 {
51 if (!m_home.empty())
52 ::setenv("HOME", m_home.data(), 1);
53 }
54
55private:
56 std::string m_home;
57};
58
59#if BOOST_VERSION >= 106500
60BOOST_TEST_GLOBAL_CONFIGURATION(GlobalConfiguration);
61#elif BOOST_VERSION >= 105900
62BOOST_GLOBAL_FIXTURE(GlobalConfiguration);
63#else
64BOOST_GLOBAL_FIXTURE(GlobalConfiguration)
65#endif
66
67} // namespace tests
68} // namespace tools
69} // namespace ndn