Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Alexander Afanasyev | c8823bc | 2014-02-09 19:33:33 -0800 | [diff] [blame] | 2 | /** |
Alexander Afanasyev | 667370f | 2016-08-24 11:54:53 -0700 | [diff] [blame] | 3 | * Copyright (c) 2013-2016 Regents of the University of California. |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 6 | * |
Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 7 | * ndn-cxx library is free software: you can redistribute it and/or modify it under the |
| 8 | * terms of the GNU Lesser General Public License as published by the Free Software |
| 9 | * Foundation, either version 3 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * ndn-cxx library 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 Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received copies of the GNU General Public License and GNU Lesser |
| 16 | * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
| 17 | * <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 20 | */ |
| 21 | |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame] | 22 | #define BOOST_TEST_MODULE ndn-cxx Tests |
Alexander Afanasyev | 9fae3db | 2015-12-07 18:04:32 -0800 | [diff] [blame] | 23 | #define BOOST_TEST_DYN_LINK |
| 24 | #define BOOST_TEST_ALTERNATIVE_INIT_API |
| 25 | |
Alexander Afanasyev | 667370f | 2016-08-24 11:54:53 -0700 | [diff] [blame] | 26 | #include <boost/version.hpp> |
| 27 | |
| 28 | #if BOOST_VERSION >= 106200 |
| 29 | // Boost.Test v3.3 (Boost 1.62) natively supports multi-logger output |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 30 | #include "boost-test.hpp" |
Alexander Afanasyev | 667370f | 2016-08-24 11:54:53 -0700 | [diff] [blame] | 31 | #else |
| 32 | #define BOOST_TEST_NO_MAIN |
| 33 | #include "boost-test.hpp" |
| 34 | |
Alexander Afanasyev | 9fae3db | 2015-12-07 18:04:32 -0800 | [diff] [blame] | 35 | #include "boost-multi-log-formatter.hpp" |
| 36 | |
| 37 | #include <boost/program_options/options_description.hpp> |
| 38 | #include <boost/program_options/variables_map.hpp> |
| 39 | #include <boost/program_options/parsers.hpp> |
| 40 | |
| 41 | #include <fstream> |
| 42 | #include <iostream> |
| 43 | |
| 44 | static bool |
| 45 | init_tests() |
| 46 | { |
| 47 | init_unit_test(); |
| 48 | |
| 49 | namespace po = boost::program_options; |
| 50 | namespace ut = boost::unit_test; |
| 51 | |
| 52 | po::options_description extraOptions; |
| 53 | std::string logger; |
| 54 | std::string outputFile = "-"; |
| 55 | extraOptions.add_options() |
| 56 | ("log_format2", po::value<std::string>(&logger), "Type of second log formatter: HRF or XML") |
| 57 | ("log_sink2", po::value<std::string>(&outputFile)->default_value(outputFile), "Second log sink, - for stdout") |
| 58 | ; |
| 59 | po::variables_map vm; |
| 60 | try { |
| 61 | po::store(po::command_line_parser(ut::framework::master_test_suite().argc, |
| 62 | ut::framework::master_test_suite().argv) |
| 63 | .options(extraOptions) |
| 64 | .run(), |
| 65 | vm); |
| 66 | po::notify(vm); |
| 67 | } |
| 68 | catch (const std::exception& e) { |
| 69 | std::cerr << "ERROR: " << e.what() << "\n" |
| 70 | << extraOptions << std::endl; |
| 71 | return false; |
| 72 | } |
| 73 | |
| 74 | if (vm.count("log_format2") == 0) { |
| 75 | // second logger is not configured |
| 76 | return true; |
| 77 | } |
| 78 | |
| 79 | std::shared_ptr<ut::unit_test_log_formatter> formatter; |
| 80 | if (logger == "XML") { |
| 81 | formatter = std::make_shared<ut::output::xml_log_formatter>(); |
| 82 | } |
| 83 | else if (logger == "HRF") { |
| 84 | formatter = std::make_shared<ut::output::compiler_log_formatter>(); |
| 85 | } |
| 86 | else { |
| 87 | std::cerr << "ERROR: only HRF or XML log formatter can be specified" << std::endl; |
| 88 | return false; |
| 89 | } |
| 90 | |
| 91 | std::shared_ptr<std::ostream> output; |
| 92 | if (outputFile == "-") { |
| 93 | output = std::shared_ptr<std::ostream>(&std::cout, std::bind([]{})); |
| 94 | } |
| 95 | else { |
| 96 | output = std::make_shared<std::ofstream>(outputFile.c_str()); |
| 97 | } |
| 98 | |
| 99 | auto multiFormatter = new ut::output::multi_log_formatter; |
| 100 | multiFormatter->add(formatter, output); |
| 101 | ut::unit_test_log.set_formatter(multiFormatter); |
| 102 | |
| 103 | return true; |
| 104 | } |
| 105 | |
| 106 | int |
| 107 | main(int argc, char* argv[]) |
| 108 | { |
| 109 | return ::boost::unit_test::unit_test_main(&init_tests, argc, argv); |
| 110 | } |
Alexander Afanasyev | 667370f | 2016-08-24 11:54:53 -0700 | [diff] [blame] | 111 | |
| 112 | #endif // BOOST_VERSION >= 106200 |