Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -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 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology |
Alexander Afanasyev | 2aa3962 | 2014-01-22 11:51:11 -0800 | [diff] [blame] | 9 | * |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 10 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 11 | * See AUTHORS.md for complete list of NFD authors and contributors. |
Alexander Afanasyev | 2aa3962 | 2014-01-22 11:51:11 -0800 | [diff] [blame] | 12 | * |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 13 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 14 | * of the GNU General Public License as published by the Free Software Foundation, |
| 15 | * either version 3 of the License, or (at your option) any later version. |
| 16 | * |
| 17 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 18 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 19 | * PURPOSE. See the GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License along with |
| 22 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 23 | **/ |
Alexander Afanasyev | 2aa3962 | 2014-01-22 11:51:11 -0800 | [diff] [blame] | 24 | |
Alexander Afanasyev | f22ebaf | 2015-12-17 21:23:05 -0800 | [diff] [blame^] | 25 | #define BOOST_TEST_NO_MAIN |
| 26 | #define BOOST_TEST_DYN_LINK |
| 27 | #define BOOST_TEST_ALTERNATIVE_INIT_API |
Alexander Afanasyev | 2aa3962 | 2014-01-22 11:51:11 -0800 | [diff] [blame] | 28 | |
Alexander Afanasyev | 8552a38 | 2014-05-15 20:13:42 -0700 | [diff] [blame] | 29 | #include "boost-test.hpp" |
Alexander Afanasyev | f22ebaf | 2015-12-17 21:23:05 -0800 | [diff] [blame^] | 30 | #include "boost-multi-log-formatter.hpp" |
| 31 | |
| 32 | #include <boost/program_options/options_description.hpp> |
| 33 | #include <boost/program_options/variables_map.hpp> |
| 34 | #include <boost/program_options/parsers.hpp> |
| 35 | |
| 36 | #include <fstream> |
| 37 | #include <iostream> |
| 38 | |
| 39 | static bool |
| 40 | init_tests() |
| 41 | { |
| 42 | init_unit_test(); |
| 43 | |
| 44 | namespace po = boost::program_options; |
| 45 | namespace ut = boost::unit_test; |
| 46 | |
| 47 | po::options_description extraOptions; |
| 48 | std::string logger; |
| 49 | std::string outputFile = "-"; |
| 50 | extraOptions.add_options() |
| 51 | ("log_format2", po::value<std::string>(&logger), "Type of second log formatter: HRF or XML") |
| 52 | ("log_sink2", po::value<std::string>(&outputFile)->default_value(outputFile), "Second log sink, - for stdout") |
| 53 | ; |
| 54 | po::variables_map vm; |
| 55 | try { |
| 56 | po::store(po::command_line_parser(ut::framework::master_test_suite().argc, |
| 57 | ut::framework::master_test_suite().argv) |
| 58 | .options(extraOptions) |
| 59 | .run(), |
| 60 | vm); |
| 61 | po::notify(vm); |
| 62 | } |
| 63 | catch (const std::exception& e) { |
| 64 | std::cerr << "ERROR: " << e.what() << "\n" |
| 65 | << extraOptions << std::endl; |
| 66 | return false; |
| 67 | } |
| 68 | |
| 69 | if (vm.count("log_format2") == 0) { |
| 70 | // second logger is not configured |
| 71 | return true; |
| 72 | } |
| 73 | |
| 74 | std::shared_ptr<ut::unit_test_log_formatter> formatter; |
| 75 | if (logger == "XML") { |
| 76 | formatter = std::make_shared<ut::output::xml_log_formatter>(); |
| 77 | } |
| 78 | else if (logger == "HRF") { |
| 79 | formatter = std::make_shared<ut::output::compiler_log_formatter>(); |
| 80 | } |
| 81 | else { |
| 82 | std::cerr << "ERROR: only HRF or XML log formatter can be specified" << std::endl; |
| 83 | return false; |
| 84 | } |
| 85 | |
| 86 | std::shared_ptr<std::ostream> output; |
| 87 | if (outputFile == "-") { |
| 88 | output = std::shared_ptr<std::ostream>(&std::cout, std::bind([]{})); |
| 89 | } |
| 90 | else { |
| 91 | output = std::make_shared<std::ofstream>(outputFile.c_str()); |
| 92 | } |
| 93 | |
| 94 | auto multiFormatter = new ut::output::multi_log_formatter; |
| 95 | multiFormatter->add(formatter, output); |
| 96 | ut::unit_test_log.set_formatter(multiFormatter); |
| 97 | |
| 98 | return true; |
| 99 | } |
| 100 | |
| 101 | int |
| 102 | main(int argc, char* argv[]) |
| 103 | { |
| 104 | return ::boost::unit_test::unit_test_main(&init_tests, argc, argv); |
| 105 | } |