blob: f9bf6b624449dfea6d9f50649d78407bad548ef6 [file] [log] [blame]
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014, Regents of the University of California.
4 *
5 * This file is part of NDNS (Named Data Networking Domain Name Service).
6 * See AUTHORS.md for complete list of NDNS authors and contributors.
7 *
8 * NDNS 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 * NDNS 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 * NDNS, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#define BOOST_TEST_MAIN 1
21#define BOOST_TEST_DYN_LINK 1
22
Alexander Afanasyevaa46c272016-03-09 12:54:12 -080023#include "config.hpp"
24#include "logger.hpp"
25
Alexander Afanasyevc7c99002015-10-09 17:27:30 -070026#include <boost/version.hpp>
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070027#include <boost/test/unit_test.hpp>
Alexander Afanasyevc7c99002015-10-09 17:27:30 -070028#include <boost/noncopyable.hpp>
Alexander Afanasyevaa46c272016-03-09 12:54:12 -080029#include <boost/filesystem.hpp>
Alexander Afanasyev59a42ec2014-09-02 18:21:16 -070030
Alexander Afanasyevaa46c272016-03-09 12:54:12 -080031#include <fstream>
32#include <iostream>
Alexander Afanasyev59a42ec2014-09-02 18:21:16 -070033
34namespace ndn {
35namespace ndns {
36namespace tests {
37
Alexander Afanasyevaa46c272016-03-09 12:54:12 -080038class GlobalConfigurationFixture : boost::noncopyable
Alexander Afanasyev59a42ec2014-09-02 18:21:16 -070039{
40public:
Alexander Afanasyevaa46c272016-03-09 12:54:12 -080041 GlobalConfigurationFixture()
Alexander Afanasyev59a42ec2014-09-02 18:21:16 -070042 {
43 log::init("unit-tests.log4cxx");
Alexander Afanasyevaa46c272016-03-09 12:54:12 -080044
45 if (std::getenv("HOME"))
46 m_home = std::getenv("HOME");
47
48 boost::filesystem::path dir(TEST_CONFIG_PATH);
49 dir /= "test-home";
50 setenv("HOME", dir.generic_string().c_str(), 1);
51 boost::filesystem::create_directories(dir);
52 std::ofstream clientConf((dir / ".ndn" / "client.conf").generic_string().c_str());
53 clientConf << "pib=pib-sqlite3\n"
54 << "tpm=tpm-file" << std::endl;
Alexander Afanasyev59a42ec2014-09-02 18:21:16 -070055 }
Alexander Afanasyevaa46c272016-03-09 12:54:12 -080056
57 ~GlobalConfigurationFixture()
58 {
59 if (!m_home.empty()) {
60 setenv("HOME", m_home.c_str(), 1);
61 }
62 }
63
64private:
65 std::string m_home;
Alexander Afanasyev59a42ec2014-09-02 18:21:16 -070066};
67
Alexander Afanasyevaa46c272016-03-09 12:54:12 -080068BOOST_GLOBAL_FIXTURE(GlobalConfigurationFixture)
Alexander Afanasyevc7c99002015-10-09 17:27:30 -070069#if (BOOST_VERSION >= 105900)
70;
71#endif // BOOST_VERSION >= 105900
Alexander Afanasyev59a42ec2014-09-02 18:21:16 -070072
73} // namespace tests
74} // namespace ndns
75} // namespace ndn