blob: f0c136a95a48a267620de8f669da5f3ddc19463b [file] [log] [blame]
Davide Pesaventocc2c7172018-01-21 21:41:03 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
Davide Pesavento66777622020-10-09 18:46:03 -04003 * Copyright (c) 2014-2020, Regents of the University of California.
Davide Pesaventocc2c7172018-01-21 21:41:03 -05004 *
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
Davide Pesavento66777622020-10-09 18:46:03 -040020#include "core/common.hpp"
21
22#include "tests/boost-test.hpp"
Davide Pesaventocc2c7172018-01-21 21:41:03 -050023
24#include <boost/filesystem.hpp>
25#include <fstream>
26#include <stdlib.h>
27
28namespace ndn {
Davide Pesaventocc2c7172018-01-21 21:41:03 -050029namespace tests {
30
31class GlobalConfiguration
32{
33public:
34 GlobalConfiguration()
35 {
36 const char* envHome = ::getenv("HOME");
37 if (envHome)
38 m_home = envHome;
39
Davide Pesavento66777622020-10-09 18:46:03 -040040 auto testHome = boost::filesystem::path(UNIT_TESTS_TMPDIR) / "test-home";
41 if (::setenv("HOME", testHome.c_str(), 1) != 0)
42 NDN_THROW(std::runtime_error("setenv() failed"));
Davide Pesaventocc2c7172018-01-21 21:41:03 -050043
Davide Pesavento66777622020-10-09 18:46:03 -040044 boost::filesystem::create_directories(testHome);
45
46 std::ofstream clientConf((testHome / ".ndn" / "client.conf").c_str());
Davide Pesaventocc2c7172018-01-21 21:41:03 -050047 clientConf << "pib=pib-sqlite3" << std::endl
48 << "tpm=tpm-file" << std::endl;
49 }
50
Davide Pesavento66777622020-10-09 18:46:03 -040051 ~GlobalConfiguration() noexcept
Davide Pesaventocc2c7172018-01-21 21:41:03 -050052 {
Davide Pesavento66777622020-10-09 18:46:03 -040053 if (m_home.empty())
54 ::unsetenv("HOME");
55 else
Davide Pesaventocc2c7172018-01-21 21:41:03 -050056 ::setenv("HOME", m_home.data(), 1);
57 }
58
59private:
60 std::string m_home;
61};
62
63#if BOOST_VERSION >= 106500
64BOOST_TEST_GLOBAL_CONFIGURATION(GlobalConfiguration);
65#elif BOOST_VERSION >= 105900
66BOOST_GLOBAL_FIXTURE(GlobalConfiguration);
67#else
68BOOST_GLOBAL_FIXTURE(GlobalConfiguration)
69#endif
70
71} // namespace tests
Davide Pesaventocc2c7172018-01-21 21:41:03 -050072} // namespace ndn