blob: bf4d8649944ef8c5a89898b8cd8b169e78a0e4d8 [file] [log] [blame]
Zhiyi Zhang8617a792017-01-17 16:45:56 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2017, Regents of the University of California.
4 *
5 * This file is part of ndncert, a certificate management system based on NDN.
6 *
7 * ndncert is free software: you can redistribute it and/or modify it under the terms
8 * of the GNU General Public License as published by the Free Software Foundation, either
9 * version 3 of the License, or (at your option) any later version.
10 *
11 * ndncert is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License along with
16 * ndncert, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * See AUTHORS.md for complete list of ndncert authors and contributors.
19 */
20
21#include "ndncert-config.hpp"
22
23#include <boost/version.hpp>
24#include <boost/filesystem.hpp>
25
26#include "test-common.hpp"
27
28namespace ndn {
29namespace chronoshare {
30namespace tests {
31
32class GlobalConfigurationFixture : boost::noncopyable
33{
34public:
35 GlobalConfigurationFixture()
36 {
37 if (getenv("HOME") != nullptr) {
38 m_home = getenv("HOME");
39 }
40 if (getenv("NDN_CLIENT_PIB") != nullptr) {
41 m_pib = getenv("NDN_CLIENT_PIB");
42 }
43 if (getenv("NDN_CLIENT_TPM") != nullptr) {
44 m_tpm = getenv("NDN_CLIENT_TPM");
45 }
46
47 boost::filesystem::path dir(TMP_TESTS_PATH);
48 dir /= "test-home";
49 setenv("HOME", dir.generic_string().c_str(), 1);
50
51 if (exists(dir)) {
52 remove_all(dir);
53 }
54
55 setenv("NDN_CLIENT_PIB", ("pib-sqlite3:" + dir.string()).c_str(), 1);
56 setenv("NDN_CLIENT_TPM", ("tpm-file:" + dir.string()).c_str(), 1);
57 create_directories(dir);
58 }
59
60 ~GlobalConfigurationFixture()
61 {
62 if (!m_home.empty()) {
63 setenv("HOME", m_home.c_str(), 1);
64 }
65 if (!m_pib.empty()) {
66 setenv("NDN_CLIENT_PIB", m_pib.c_str(), 1);
67 }
68 if (!m_tpm.empty()) {
69 setenv("NDN_CLIENT_TPM", m_tpm.c_str(), 1);
70 }
71 }
72
73private:
74 std::string m_home;
75 std::string m_pib;
76 std::string m_tpm;
77};
78
79BOOST_GLOBAL_FIXTURE(GlobalConfigurationFixture)
80#if (BOOST_VERSION >= 105900)
81;
82#endif // BOOST_VERSION >= 105900
83
84} // namespace tests
85} // namespace chronoshare
86} // namespace ndn