blob: dfae750e3349d4f89cd347369a0063a50464ed2a [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
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040034namespace nfd::tests {
Steve DiBenedettobf6a93d2014-03-21 14:03:02 -060035
Davide Pesaventoa6f2d242018-01-20 19:05:05 -050036class GlobalConfiguration
Steve DiBenedettobf6a93d2014-03-21 14:03:02 -060037{
38public:
Davide Pesaventoa6f2d242018-01-20 19:05:05 -050039 GlobalConfiguration()
Steve DiBenedettobf6a93d2014-03-21 14:03:02 -060040 {
Davide Pesaventoa6f2d242018-01-20 19:05:05 -050041 const char* envHome = ::getenv("HOME");
42 if (envHome)
43 m_home = envHome;
44
Davide Pesavento21353752020-11-20 00:43:44 -050045 auto testHome = boost::filesystem::path(UNIT_TESTS_TMPDIR) / "test-home";
Davide Pesavento2840dbc2019-04-16 23:14:21 -040046 if (::setenv("HOME", testHome.c_str(), 1) != 0)
47 NDN_THROW(std::runtime_error("setenv() failed"));
Steve DiBenedettobf6a93d2014-03-21 14:03:02 -060048
Davide Pesavento2840dbc2019-04-16 23:14:21 -040049 boost::filesystem::create_directories(testHome);
Alexander Afanasyevbc9ed492016-01-26 11:38:11 -080050
Davide Pesavento2840dbc2019-04-16 23:14:21 -040051 std::ofstream clientConf((testHome / ".ndn" / "client.conf").c_str());
Davide Pesaventoa6f2d242018-01-20 19:05:05 -050052 clientConf << "pib=pib-sqlite3" << std::endl
Alexander Afanasyevbc9ed492016-01-26 11:38:11 -080053 << "tpm=tpm-file" << std::endl;
Steve DiBenedettobf6a93d2014-03-21 14:03:02 -060054 }
Alexander Afanasyevbc9ed492016-01-26 11:38:11 -080055
Davide Pesavento2840dbc2019-04-16 23:14:21 -040056 ~GlobalConfiguration() noexcept
Alexander Afanasyevbc9ed492016-01-26 11:38:11 -080057 {
Davide Pesavento2840dbc2019-04-16 23:14:21 -040058 if (m_home.empty())
59 ::unsetenv("HOME");
60 else
Davide Pesaventoa6f2d242018-01-20 19:05:05 -050061 ::setenv("HOME", m_home.data(), 1);
Alexander Afanasyevbc9ed492016-01-26 11:38:11 -080062 }
63
64private:
65 std::string m_home;
Steve DiBenedettobf6a93d2014-03-21 14:03:02 -060066};
67
Davide Pesaventoa6f2d242018-01-20 19:05:05 -050068BOOST_TEST_GLOBAL_CONFIGURATION(GlobalConfiguration);
Steve DiBenedettobf6a93d2014-03-21 14:03:02 -060069
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040070} // namespace nfd::tests