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 | 2840dbc | 2019-04-16 23:14:21 -0400 | [diff] [blame] | 3 | * Copyright (c) 2014-2019, 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 | |
| 34 | namespace nfd { |
| 35 | namespace tests { |
| 36 | |
Davide Pesavento | a6f2d24 | 2018-01-20 19:05:05 -0500 | [diff] [blame] | 37 | class GlobalConfiguration |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 38 | { |
| 39 | public: |
Davide Pesavento | a6f2d24 | 2018-01-20 19:05:05 -0500 | [diff] [blame] | 40 | GlobalConfiguration() |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 41 | { |
Davide Pesavento | a6f2d24 | 2018-01-20 19:05:05 -0500 | [diff] [blame] | 42 | const char* envHome = ::getenv("HOME"); |
| 43 | if (envHome) |
| 44 | m_home = envHome; |
| 45 | |
Davide Pesavento | 2840dbc | 2019-04-16 23:14:21 -0400 | [diff] [blame] | 46 | auto testHome = boost::filesystem::path(UNIT_TEST_CONFIG_PATH) / "test-home"; |
| 47 | if (::setenv("HOME", testHome.c_str(), 1) != 0) |
| 48 | NDN_THROW(std::runtime_error("setenv() failed")); |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 49 | |
Davide Pesavento | 2840dbc | 2019-04-16 23:14:21 -0400 | [diff] [blame] | 50 | boost::filesystem::create_directories(testHome); |
Alexander Afanasyev | bc9ed49 | 2016-01-26 11:38:11 -0800 | [diff] [blame] | 51 | |
Davide Pesavento | 2840dbc | 2019-04-16 23:14:21 -0400 | [diff] [blame] | 52 | std::ofstream clientConf((testHome / ".ndn" / "client.conf").c_str()); |
Davide Pesavento | a6f2d24 | 2018-01-20 19:05:05 -0500 | [diff] [blame] | 53 | clientConf << "pib=pib-sqlite3" << std::endl |
Alexander Afanasyev | bc9ed49 | 2016-01-26 11:38:11 -0800 | [diff] [blame] | 54 | << "tpm=tpm-file" << std::endl; |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 55 | } |
Alexander Afanasyev | bc9ed49 | 2016-01-26 11:38:11 -0800 | [diff] [blame] | 56 | |
Davide Pesavento | 2840dbc | 2019-04-16 23:14:21 -0400 | [diff] [blame] | 57 | ~GlobalConfiguration() noexcept |
Alexander Afanasyev | bc9ed49 | 2016-01-26 11:38:11 -0800 | [diff] [blame] | 58 | { |
Davide Pesavento | 2840dbc | 2019-04-16 23:14:21 -0400 | [diff] [blame] | 59 | if (m_home.empty()) |
| 60 | ::unsetenv("HOME"); |
| 61 | else |
Davide Pesavento | a6f2d24 | 2018-01-20 19:05:05 -0500 | [diff] [blame] | 62 | ::setenv("HOME", m_home.data(), 1); |
Alexander Afanasyev | bc9ed49 | 2016-01-26 11:38:11 -0800 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | private: |
| 66 | std::string m_home; |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 67 | }; |
| 68 | |
Davide Pesavento | a6f2d24 | 2018-01-20 19:05:05 -0500 | [diff] [blame] | 69 | #if BOOST_VERSION >= 106500 |
| 70 | BOOST_TEST_GLOBAL_CONFIGURATION(GlobalConfiguration); |
| 71 | #elif BOOST_VERSION >= 105900 |
| 72 | BOOST_GLOBAL_FIXTURE(GlobalConfiguration); |
| 73 | #else |
| 74 | BOOST_GLOBAL_FIXTURE(GlobalConfiguration) |
| 75 | #endif |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 76 | |
| 77 | } // namespace tests |
| 78 | } // namespace nfd |