blob: cec1aa9322391da105fa5e8894b0adb67f9f7c6e [file] [log] [blame]
Alexander Afanasyev8495a4a2016-12-25 15:27:25 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyeva9369b42017-01-11 11:58:00 -08003 * Copyright (c) 2013-2017, Regents of the University of California.
Alexander Afanasyev8495a4a2016-12-25 15:27:25 -08004 *
Alexander Afanasyeva9369b42017-01-11 11:58:00 -08005 * This file is part of ChronoShare, a decentralized file sharing application over NDN.
Alexander Afanasyev8495a4a2016-12-25 15:27:25 -08006 *
Alexander Afanasyeva9369b42017-01-11 11:58:00 -08007 * ChronoShare 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.
Alexander Afanasyev8495a4a2016-12-25 15:27:25 -080010 *
Alexander Afanasyeva9369b42017-01-11 11:58:00 -080011 * ChronoShare 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.
Alexander Afanasyev8495a4a2016-12-25 15:27:25 -080014 *
Alexander Afanasyeva9369b42017-01-11 11:58:00 -080015 * You should have received copies of the GNU General Public License along with
16 * ChronoShare, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * See AUTHORS.md for complete list of ChronoShare authors and contributors.
Alexander Afanasyev8495a4a2016-12-25 15:27:25 -080019 */
20
21#include "core/chronoshare-config.hpp"
22
Alexander Afanasyeva9369b42017-01-11 11:58:00 -080023#include <boost/version.hpp>
24#include <boost/filesystem.hpp>
25
Alexander Afanasyev8495a4a2016-12-25 15:27:25 -080026#include "test-common.hpp"
27
28namespace ndn {
29namespace chronoshare {
30namespace tests {
31
32class GlobalConfigurationFixture : boost::noncopyable
33{
34public:
35 GlobalConfigurationFixture()
36 {
Alexander Afanasyev8495a4a2016-12-25 15:27:25 -080037 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(UNIT_TEST_CONFIG_PATH);
48 dir /= "test-home";
49 setenv("HOME", dir.generic_string().c_str(), 1);
50
Yukai Tu09e02fd2016-10-24 13:48:01 -070051 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);
Alexander Afanasyev8495a4a2016-12-25 15:27:25 -080058 }
59
60 ~GlobalConfigurationFixture()
61 {
62 if (!m_home.empty()) {
63 setenv("HOME", m_home.c_str(), 1);
64 }
65 if (!m_pib.empty()) {
Yukai Tu09e02fd2016-10-24 13:48:01 -070066 setenv("NDN_CLIENT_PIB", m_pib.c_str(), 1);
Alexander Afanasyev8495a4a2016-12-25 15:27:25 -080067 }
68 if (!m_tpm.empty()) {
Yukai Tu09e02fd2016-10-24 13:48:01 -070069 setenv("NDN_CLIENT_TPM", m_tpm.c_str(), 1);
Alexander Afanasyev8495a4a2016-12-25 15:27:25 -080070 }
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