blob: d3ab83a4b9e711cde16c933e81ba15d52ad2f987 [file] [log] [blame]
Steve DiBenedettobf6a93d2014-03-21 14:03:02 -06001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesaventoa6f2d242018-01-20 19:05:05 -05002/*
Davide Pesaventoc52cd5e2022-03-05 20:40:54 -05003 * Copyright (c) 2014-2022, Regents of the University of California,
Alexander Afanasyevbc9ed492016-01-26 11:38:11 -08004 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis.
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070010 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
Alexander Afanasyevbc9ed492016-01-26 11:38:11 -080024 */
Steve DiBenedettobf6a93d2014-03-21 14:03:02 -060025
Davide Pesavento2840dbc2019-04-16 23:14:21 -040026#include "core/common.hpp"
Davide Pesaventoa6f2d242018-01-20 19:05:05 -050027
Davide Pesavento2840dbc2019-04-16 23:14:21 -040028#include "tests/boost-test.hpp"
Steve DiBenedettobf6a93d2014-03-21 14:03:02 -060029
30#include <boost/filesystem.hpp>
Alexander Afanasyevbc9ed492016-01-26 11:38:11 -080031#include <fstream>
Davide Pesaventoa6f2d242018-01-20 19:05:05 -050032#include <stdlib.h>
Steve DiBenedettobf6a93d2014-03-21 14:03:02 -060033
34namespace nfd {
35namespace tests {
36
Davide Pesaventoa6f2d242018-01-20 19:05:05 -050037class GlobalConfiguration
Steve DiBenedettobf6a93d2014-03-21 14:03:02 -060038{
39public:
Davide Pesaventoa6f2d242018-01-20 19:05:05 -050040 GlobalConfiguration()
Steve DiBenedettobf6a93d2014-03-21 14:03:02 -060041 {
Davide Pesaventoa6f2d242018-01-20 19:05:05 -050042 const char* envHome = ::getenv("HOME");
43 if (envHome)
44 m_home = envHome;
45
Davide Pesavento21353752020-11-20 00:43:44 -050046 auto testHome = boost::filesystem::path(UNIT_TESTS_TMPDIR) / "test-home";
Davide Pesavento2840dbc2019-04-16 23:14:21 -040047 if (::setenv("HOME", testHome.c_str(), 1) != 0)
48 NDN_THROW(std::runtime_error("setenv() failed"));
Steve DiBenedettobf6a93d2014-03-21 14:03:02 -060049
Davide Pesavento2840dbc2019-04-16 23:14:21 -040050 boost::filesystem::create_directories(testHome);
Alexander Afanasyevbc9ed492016-01-26 11:38:11 -080051
Davide Pesavento2840dbc2019-04-16 23:14:21 -040052 std::ofstream clientConf((testHome / ".ndn" / "client.conf").c_str());
Davide Pesaventoa6f2d242018-01-20 19:05:05 -050053 clientConf << "pib=pib-sqlite3" << std::endl
Alexander Afanasyevbc9ed492016-01-26 11:38:11 -080054 << "tpm=tpm-file" << std::endl;
Steve DiBenedettobf6a93d2014-03-21 14:03:02 -060055 }
Alexander Afanasyevbc9ed492016-01-26 11:38:11 -080056
Davide Pesavento2840dbc2019-04-16 23:14:21 -040057 ~GlobalConfiguration() noexcept
Alexander Afanasyevbc9ed492016-01-26 11:38:11 -080058 {
Davide Pesavento2840dbc2019-04-16 23:14:21 -040059 if (m_home.empty())
60 ::unsetenv("HOME");
61 else
Davide Pesaventoa6f2d242018-01-20 19:05:05 -050062 ::setenv("HOME", m_home.data(), 1);
Alexander Afanasyevbc9ed492016-01-26 11:38:11 -080063 }
64
65private:
66 std::string m_home;
Steve DiBenedettobf6a93d2014-03-21 14:03:02 -060067};
68
Davide Pesaventoa6f2d242018-01-20 19:05:05 -050069BOOST_TEST_GLOBAL_CONFIGURATION(GlobalConfiguration);
Steve DiBenedettobf6a93d2014-03-21 14:03:02 -060070
71} // namespace tests
72} // namespace nfd