blob: 35ceeedf53d73b85c6e6fecbaa99c40739ac8186 [file] [log] [blame]
Eric Newberry716ab602016-12-29 21:49:57 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014-2017, Regents of the University of California.
4 *
5 * This file is part of ndn-tools (Named Data Networking Essential Tools).
6 * See AUTHORS.md for complete list of ndn-tools authors and contributors.
7 *
8 * ndn-tools 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 * ndn-tools 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 * ndn-tools, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <boost/version.hpp>
21#include <boost/filesystem.hpp>
22
23#include "test-common.hpp"
24
25namespace ndn {
26namespace tools {
27namespace tests {
28
29class GlobalConfigurationFixture : boost::noncopyable
30{
31public:
32 GlobalConfigurationFixture()
33 {
34 if (getenv("HOME") != nullptr) {
35 m_home = getenv("HOME");
36 }
37 if (getenv("NDN_CLIENT_PIB") != nullptr) {
38 m_pib = getenv("NDN_CLIENT_PIB");
39 }
40 if (getenv("NDN_CLIENT_TPM") != nullptr) {
41 m_tpm = getenv("NDN_CLIENT_TPM");
42 }
43
44 boost::filesystem::path dir(TMP_TESTS_PATH);
45 dir /= "test-home";
46 setenv("HOME", dir.generic_string().c_str(), 1);
47
48 if (exists(dir)) {
49 remove_all(dir);
50 }
51
52 setenv("NDN_CLIENT_PIB", ("pib-sqlite3:" + dir.string()).c_str(), 1);
53 setenv("NDN_CLIENT_TPM", ("tpm-file:" + dir.string()).c_str(), 1);
54 create_directories(dir);
55 }
56
57 ~GlobalConfigurationFixture()
58 {
59 if (!m_home.empty()) {
60 setenv("HOME", m_home.c_str(), 1);
61 }
62 if (!m_pib.empty()) {
63 setenv("NDN_CLIENT_PIB", m_pib.c_str(), 1);
64 }
65 if (!m_tpm.empty()) {
66 setenv("NDN_CLIENT_TPM", m_tpm.c_str(), 1);
67 }
68 }
69
70private:
71 std::string m_home;
72 std::string m_pib;
73 std::string m_tpm;
74};
75
76BOOST_GLOBAL_FIXTURE(GlobalConfigurationFixture)
77#if (BOOST_VERSION >= 105900)
78;
79#endif // BOOST_VERSION >= 105900
80
81} // namespace tests
82} // namespace tools
83} // namespace ndn