blob: 27c2a43073281975dc9a9739fe64c99e618e0e14 [file] [log] [blame]
Alexander Afanasyevfde570c2016-12-19 16:02:55 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Alexander Afanasyev08d18742018-03-15 16:31:28 -04002/*
Davide Pesavento7f27ec12022-03-10 20:10:54 -05003 * Copyright (c) 2014-2022, Regents of the University of California.
Alexander Afanasyevfde570c2016-12-19 16:02:55 -08004 *
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 Pesaventobdd88c12020-11-26 00:35:08 -050020#include "boost-test.hpp"
21
22#include <boost/filesystem.hpp>
23#include <stdlib.h>
Alexander Afanasyevfde570c2016-12-19 16:02:55 -080024
25namespace ndn {
Alexander Afanasyevfde570c2016-12-19 16:02:55 -080026namespace tests {
27
Davide Pesaventobdd88c12020-11-26 00:35:08 -050028class GlobalConfiguration
Alexander Afanasyevfde570c2016-12-19 16:02:55 -080029{
30public:
Davide Pesaventobdd88c12020-11-26 00:35:08 -050031 GlobalConfiguration()
Alexander Afanasyevfde570c2016-12-19 16:02:55 -080032 {
Alexander Afanasyevfde570c2016-12-19 16:02:55 -080033 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 Pesaventobdd88c12020-11-26 00:35:08 -050043 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 Afanasyevfde570c2016-12-19 16:02:55 -080047
48 setenv("NDN_CLIENT_PIB", "pib-sqlite3", 1);
49 setenv("NDN_CLIENT_TPM", "tpm-file", 1);
Alexander Afanasyevfde570c2016-12-19 16:02:55 -080050 }
51
Davide Pesaventobdd88c12020-11-26 00:35:08 -050052 ~GlobalConfiguration() noexcept
Alexander Afanasyevfde570c2016-12-19 16:02:55 -080053 {
54 if (!m_home.empty()) {
Davide Pesaventobdd88c12020-11-26 00:35:08 -050055 setenv("HOME", m_home.data(), 1);
Alexander Afanasyevfde570c2016-12-19 16:02:55 -080056 }
57 if (!m_pib.empty()) {
Davide Pesaventobdd88c12020-11-26 00:35:08 -050058 setenv("NDN_CLIENT_PIB", m_home.data(), 1);
Alexander Afanasyevfde570c2016-12-19 16:02:55 -080059 }
60 if (!m_tpm.empty()) {
Davide Pesaventobdd88c12020-11-26 00:35:08 -050061 setenv("NDN_CLIENT_TPM", m_home.data(), 1);
Alexander Afanasyevfde570c2016-12-19 16:02:55 -080062 }
63 }
64
65private:
66 std::string m_home;
67 std::string m_pib;
68 std::string m_tpm;
69};
70
Davide Pesaventobdd88c12020-11-26 00:35:08 -050071BOOST_TEST_GLOBAL_CONFIGURATION(GlobalConfiguration);
Alexander Afanasyevfde570c2016-12-19 16:02:55 -080072
73} // namespace tests
Alexander Afanasyevfde570c2016-12-19 16:02:55 -080074} // namespace ndn