Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 1 | /* -*- 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 Afanasyev | aa46c27 | 2016-03-09 12:54:12 -0800 | [diff] [blame^] | 23 | #include "config.hpp" |
| 24 | #include "logger.hpp" |
| 25 | |
Alexander Afanasyev | c7c9900 | 2015-10-09 17:27:30 -0700 | [diff] [blame] | 26 | #include <boost/version.hpp> |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 27 | #include <boost/test/unit_test.hpp> |
Alexander Afanasyev | c7c9900 | 2015-10-09 17:27:30 -0700 | [diff] [blame] | 28 | #include <boost/noncopyable.hpp> |
Alexander Afanasyev | aa46c27 | 2016-03-09 12:54:12 -0800 | [diff] [blame^] | 29 | #include <boost/filesystem.hpp> |
Alexander Afanasyev | 59a42ec | 2014-09-02 18:21:16 -0700 | [diff] [blame] | 30 | |
Alexander Afanasyev | aa46c27 | 2016-03-09 12:54:12 -0800 | [diff] [blame^] | 31 | #include <fstream> |
| 32 | #include <iostream> |
Alexander Afanasyev | 59a42ec | 2014-09-02 18:21:16 -0700 | [diff] [blame] | 33 | |
| 34 | namespace ndn { |
| 35 | namespace ndns { |
| 36 | namespace tests { |
| 37 | |
Alexander Afanasyev | aa46c27 | 2016-03-09 12:54:12 -0800 | [diff] [blame^] | 38 | class GlobalConfigurationFixture : boost::noncopyable |
Alexander Afanasyev | 59a42ec | 2014-09-02 18:21:16 -0700 | [diff] [blame] | 39 | { |
| 40 | public: |
Alexander Afanasyev | aa46c27 | 2016-03-09 12:54:12 -0800 | [diff] [blame^] | 41 | GlobalConfigurationFixture() |
Alexander Afanasyev | 59a42ec | 2014-09-02 18:21:16 -0700 | [diff] [blame] | 42 | { |
| 43 | log::init("unit-tests.log4cxx"); |
Alexander Afanasyev | aa46c27 | 2016-03-09 12:54:12 -0800 | [diff] [blame^] | 44 | |
| 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 Afanasyev | 59a42ec | 2014-09-02 18:21:16 -0700 | [diff] [blame] | 55 | } |
Alexander Afanasyev | aa46c27 | 2016-03-09 12:54:12 -0800 | [diff] [blame^] | 56 | |
| 57 | ~GlobalConfigurationFixture() |
| 58 | { |
| 59 | if (!m_home.empty()) { |
| 60 | setenv("HOME", m_home.c_str(), 1); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | private: |
| 65 | std::string m_home; |
Alexander Afanasyev | 59a42ec | 2014-09-02 18:21:16 -0700 | [diff] [blame] | 66 | }; |
| 67 | |
Alexander Afanasyev | aa46c27 | 2016-03-09 12:54:12 -0800 | [diff] [blame^] | 68 | BOOST_GLOBAL_FIXTURE(GlobalConfigurationFixture) |
Alexander Afanasyev | c7c9900 | 2015-10-09 17:27:30 -0700 | [diff] [blame] | 69 | #if (BOOST_VERSION >= 105900) |
| 70 | ; |
| 71 | #endif // BOOST_VERSION >= 105900 |
Alexander Afanasyev | 59a42ec | 2014-09-02 18:21:16 -0700 | [diff] [blame] | 72 | |
| 73 | } // namespace tests |
| 74 | } // namespace ndns |
| 75 | } // namespace ndn |