blob: 61d0cbd604e83eda20859fab7601a84efc4d501c [file] [log] [blame]
Zhiyi Zhang5d80e1e2020-09-25 11:34:54 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2017-2020, 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 "boost-test.hpp"
Zhiyi Zhang5d80e1e2020-09-25 11:34:54 -070022#include <boost/filesystem.hpp>
23#include <fstream>
24#include <stdlib.h>
25
26namespace ndn {
27namespace ndncert {
28namespace tests {
29
30class GlobalConfiguration
31{
32public:
33 GlobalConfiguration()
34 {
35 const char* envHome = ::getenv("HOME");
36 if (envHome)
37 m_home = envHome;
38
39 boost::filesystem::path dir{TMP_TESTS_PATH};
40 dir /= "test-home";
41 ::setenv("HOME", dir.c_str(), 1);
42
43 boost::filesystem::create_directories(dir);
44 std::ofstream clientConf((dir / ".ndn" / "client.conf").c_str());
45 clientConf << "pib=pib-sqlite3" << std::endl
46 << "tpm=tpm-file" << std::endl;
47 }
48
49 ~GlobalConfiguration()
50 {
51 if (!m_home.empty())
52 ::setenv("HOME", m_home.data(), 1);
53 }
54
55private:
56 std::string m_home;
57};
58
59#if BOOST_VERSION >= 106500
60BOOST_TEST_GLOBAL_CONFIGURATION(GlobalConfiguration);
61#elif BOOST_VERSION >= 105900
62BOOST_GLOBAL_FIXTURE(GlobalConfiguration);
63#else
64BOOST_GLOBAL_FIXTURE(GlobalConfiguration)
65#endif
66
67} // namespace tests
68} // namespace ndncert
69} // namespace ndn