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