blob: 49a330c347e44c27c93464a63c620c427b180a38 [file] [log] [blame]
Davide Pesaventocc2c7172018-01-21 21:41:03 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
Davide Pesaventob3570c62022-02-19 19:19:00 -05003 * Copyright (c) 2014-2022, 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
Davide Pesaventob3570c62022-02-19 19:19:00 -050028namespace ndn::tests {
Davide Pesaventocc2c7172018-01-21 21:41:03 -050029
30class GlobalConfiguration
31{
32public:
33 GlobalConfiguration()
34 {
35 const char* envHome = ::getenv("HOME");
36 if (envHome)
37 m_home = envHome;
38
Davide Pesavento66777622020-10-09 18:46:03 -040039 auto testHome = boost::filesystem::path(UNIT_TESTS_TMPDIR) / "test-home";
40 if (::setenv("HOME", testHome.c_str(), 1) != 0)
41 NDN_THROW(std::runtime_error("setenv() failed"));
Davide Pesaventocc2c7172018-01-21 21:41:03 -050042
Davide Pesavento66777622020-10-09 18:46:03 -040043 boost::filesystem::create_directories(testHome);
44
45 std::ofstream clientConf((testHome / ".ndn" / "client.conf").c_str());
Davide Pesaventocc2c7172018-01-21 21:41:03 -050046 clientConf << "pib=pib-sqlite3" << std::endl
47 << "tpm=tpm-file" << std::endl;
48 }
49
Davide Pesavento66777622020-10-09 18:46:03 -040050 ~GlobalConfiguration() noexcept
Davide Pesaventocc2c7172018-01-21 21:41:03 -050051 {
Davide Pesavento66777622020-10-09 18:46:03 -040052 if (m_home.empty())
53 ::unsetenv("HOME");
54 else
Davide Pesaventocc2c7172018-01-21 21:41:03 -050055 ::setenv("HOME", m_home.data(), 1);
56 }
57
58private:
59 std::string m_home;
60};
61
62#if BOOST_VERSION >= 106500
63BOOST_TEST_GLOBAL_CONFIGURATION(GlobalConfiguration);
64#elif BOOST_VERSION >= 105900
65BOOST_GLOBAL_FIXTURE(GlobalConfiguration);
66#else
67BOOST_GLOBAL_FIXTURE(GlobalConfiguration)
68#endif
69
Davide Pesaventob3570c62022-02-19 19:19:00 -050070} // namespace ndn::tests