Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | a6f2d24 | 2018-01-20 19:05:05 -0500 | [diff] [blame] | 2 | /* |
Davide Pesavento | c52cd5e | 2022-03-05 20:40:54 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2022, Regents of the University of California, |
Alexander Afanasyev | bc9ed49 | 2016-01-26 11:38:11 -0800 | [diff] [blame] | 4 | * 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 Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 10 | * |
| 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 Afanasyev | bc9ed49 | 2016-01-26 11:38:11 -0800 | [diff] [blame] | 24 | */ |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 25 | |
Davide Pesavento | 2840dbc | 2019-04-16 23:14:21 -0400 | [diff] [blame] | 26 | #include "core/common.hpp" |
Davide Pesavento | a6f2d24 | 2018-01-20 19:05:05 -0500 | [diff] [blame] | 27 | |
Davide Pesavento | 2840dbc | 2019-04-16 23:14:21 -0400 | [diff] [blame] | 28 | #include "tests/boost-test.hpp" |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 29 | |
| 30 | #include <boost/filesystem.hpp> |
Alexander Afanasyev | bc9ed49 | 2016-01-26 11:38:11 -0800 | [diff] [blame] | 31 | #include <fstream> |
Davide Pesavento | a6f2d24 | 2018-01-20 19:05:05 -0500 | [diff] [blame] | 32 | #include <stdlib.h> |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 33 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 34 | namespace nfd::tests { |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 35 | |
Davide Pesavento | a6f2d24 | 2018-01-20 19:05:05 -0500 | [diff] [blame] | 36 | class GlobalConfiguration |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 37 | { |
| 38 | public: |
Davide Pesavento | a6f2d24 | 2018-01-20 19:05:05 -0500 | [diff] [blame] | 39 | GlobalConfiguration() |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 40 | { |
Davide Pesavento | a6f2d24 | 2018-01-20 19:05:05 -0500 | [diff] [blame] | 41 | const char* envHome = ::getenv("HOME"); |
| 42 | if (envHome) |
| 43 | m_home = envHome; |
| 44 | |
Davide Pesavento | 2135375 | 2020-11-20 00:43:44 -0500 | [diff] [blame] | 45 | auto testHome = boost::filesystem::path(UNIT_TESTS_TMPDIR) / "test-home"; |
Davide Pesavento | 2840dbc | 2019-04-16 23:14:21 -0400 | [diff] [blame] | 46 | if (::setenv("HOME", testHome.c_str(), 1) != 0) |
| 47 | NDN_THROW(std::runtime_error("setenv() failed")); |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 48 | |
Davide Pesavento | 2840dbc | 2019-04-16 23:14:21 -0400 | [diff] [blame] | 49 | boost::filesystem::create_directories(testHome); |
Alexander Afanasyev | bc9ed49 | 2016-01-26 11:38:11 -0800 | [diff] [blame] | 50 | |
Davide Pesavento | 2840dbc | 2019-04-16 23:14:21 -0400 | [diff] [blame] | 51 | std::ofstream clientConf((testHome / ".ndn" / "client.conf").c_str()); |
Davide Pesavento | a6f2d24 | 2018-01-20 19:05:05 -0500 | [diff] [blame] | 52 | clientConf << "pib=pib-sqlite3" << std::endl |
Alexander Afanasyev | bc9ed49 | 2016-01-26 11:38:11 -0800 | [diff] [blame] | 53 | << "tpm=tpm-file" << std::endl; |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 54 | } |
Alexander Afanasyev | bc9ed49 | 2016-01-26 11:38:11 -0800 | [diff] [blame] | 55 | |
Davide Pesavento | 2840dbc | 2019-04-16 23:14:21 -0400 | [diff] [blame] | 56 | ~GlobalConfiguration() noexcept |
Alexander Afanasyev | bc9ed49 | 2016-01-26 11:38:11 -0800 | [diff] [blame] | 57 | { |
Davide Pesavento | 2840dbc | 2019-04-16 23:14:21 -0400 | [diff] [blame] | 58 | if (m_home.empty()) |
| 59 | ::unsetenv("HOME"); |
| 60 | else |
Davide Pesavento | a6f2d24 | 2018-01-20 19:05:05 -0500 | [diff] [blame] | 61 | ::setenv("HOME", m_home.data(), 1); |
Alexander Afanasyev | bc9ed49 | 2016-01-26 11:38:11 -0800 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | private: |
| 65 | std::string m_home; |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 66 | }; |
| 67 | |
Davide Pesavento | a6f2d24 | 2018-01-20 19:05:05 -0500 | [diff] [blame] | 68 | BOOST_TEST_GLOBAL_CONFIGURATION(GlobalConfiguration); |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 69 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 70 | } // namespace nfd::tests |