Alexander Afanasyev | fde570c | 2016-12-19 16:02:55 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 2 | /* |
Davide Pesavento | 7f27ec1 | 2022-03-10 20:10:54 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2022, Regents of the University of California. |
Alexander Afanasyev | fde570c | 2016-12-19 16:02:55 -0800 | [diff] [blame] | 4 | * |
| 5 | * This file is part of NDNS (Named Data Networking Domain Name Service). |
| 6 | * See AUTHORS.md for complete list of NDNS authors and contributors. |
| 7 | * |
| 8 | * NDNS 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 | * NDNS 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 | * NDNS, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 18 | */ |
| 19 | |
Davide Pesavento | bdd88c1 | 2020-11-26 00:35:08 -0500 | [diff] [blame] | 20 | #include "boost-test.hpp" |
| 21 | |
| 22 | #include <boost/filesystem.hpp> |
| 23 | #include <stdlib.h> |
Alexander Afanasyev | fde570c | 2016-12-19 16:02:55 -0800 | [diff] [blame] | 24 | |
| 25 | namespace ndn { |
Alexander Afanasyev | fde570c | 2016-12-19 16:02:55 -0800 | [diff] [blame] | 26 | namespace tests { |
| 27 | |
Davide Pesavento | bdd88c1 | 2020-11-26 00:35:08 -0500 | [diff] [blame] | 28 | class GlobalConfiguration |
Alexander Afanasyev | fde570c | 2016-12-19 16:02:55 -0800 | [diff] [blame] | 29 | { |
| 30 | public: |
Davide Pesavento | bdd88c1 | 2020-11-26 00:35:08 -0500 | [diff] [blame] | 31 | GlobalConfiguration() |
Alexander Afanasyev | fde570c | 2016-12-19 16:02:55 -0800 | [diff] [blame] | 32 | { |
Alexander Afanasyev | fde570c | 2016-12-19 16:02:55 -0800 | [diff] [blame] | 33 | if (getenv("HOME") != nullptr) { |
| 34 | m_home = getenv("HOME"); |
| 35 | } |
| 36 | if (getenv("NDN_CLIENT_PIB") != nullptr) { |
| 37 | m_pib = getenv("NDN_CLIENT_PIB"); |
| 38 | } |
| 39 | if (getenv("NDN_CLIENT_TPM") != nullptr) { |
| 40 | m_tpm = getenv("NDN_CLIENT_TPM"); |
| 41 | } |
| 42 | |
Davide Pesavento | bdd88c1 | 2020-11-26 00:35:08 -0500 | [diff] [blame] | 43 | auto testHome = boost::filesystem::path(UNIT_TESTS_TMPDIR) / "test-home"; |
| 44 | setenv("HOME", testHome.c_str(), 1); |
| 45 | |
| 46 | boost::filesystem::create_directories(testHome); |
Alexander Afanasyev | fde570c | 2016-12-19 16:02:55 -0800 | [diff] [blame] | 47 | |
| 48 | setenv("NDN_CLIENT_PIB", "pib-sqlite3", 1); |
| 49 | setenv("NDN_CLIENT_TPM", "tpm-file", 1); |
Alexander Afanasyev | fde570c | 2016-12-19 16:02:55 -0800 | [diff] [blame] | 50 | } |
| 51 | |
Davide Pesavento | bdd88c1 | 2020-11-26 00:35:08 -0500 | [diff] [blame] | 52 | ~GlobalConfiguration() noexcept |
Alexander Afanasyev | fde570c | 2016-12-19 16:02:55 -0800 | [diff] [blame] | 53 | { |
| 54 | if (!m_home.empty()) { |
Davide Pesavento | bdd88c1 | 2020-11-26 00:35:08 -0500 | [diff] [blame] | 55 | setenv("HOME", m_home.data(), 1); |
Alexander Afanasyev | fde570c | 2016-12-19 16:02:55 -0800 | [diff] [blame] | 56 | } |
| 57 | if (!m_pib.empty()) { |
Davide Pesavento | bdd88c1 | 2020-11-26 00:35:08 -0500 | [diff] [blame] | 58 | setenv("NDN_CLIENT_PIB", m_home.data(), 1); |
Alexander Afanasyev | fde570c | 2016-12-19 16:02:55 -0800 | [diff] [blame] | 59 | } |
| 60 | if (!m_tpm.empty()) { |
Davide Pesavento | bdd88c1 | 2020-11-26 00:35:08 -0500 | [diff] [blame] | 61 | setenv("NDN_CLIENT_TPM", m_home.data(), 1); |
Alexander Afanasyev | fde570c | 2016-12-19 16:02:55 -0800 | [diff] [blame] | 62 | } |
| 63 | } |
| 64 | |
| 65 | private: |
| 66 | std::string m_home; |
| 67 | std::string m_pib; |
| 68 | std::string m_tpm; |
| 69 | }; |
| 70 | |
Davide Pesavento | bdd88c1 | 2020-11-26 00:35:08 -0500 | [diff] [blame] | 71 | BOOST_TEST_GLOBAL_CONFIGURATION(GlobalConfiguration); |
Alexander Afanasyev | fde570c | 2016-12-19 16:02:55 -0800 | [diff] [blame] | 72 | |
| 73 | } // namespace tests |
Alexander Afanasyev | fde570c | 2016-12-19 16:02:55 -0800 | [diff] [blame] | 74 | } // namespace ndn |