blob: 49c3e9cb14487e2867e3ecd02d32e9393cc1a280 [file] [log] [blame]
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -07001/* -*- 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 Afanasyev2aa39622014-01-22 11:51:11 -08009 *
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070010 * This file is part of NFD (Named Data Networking Forwarding Daemon).
11 * See AUTHORS.md for complete list of NFD authors and contributors.
Alexander Afanasyev2aa39622014-01-22 11:51:11 -080012 *
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070013 * 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 Afanasyev2aa39622014-01-22 11:51:11 -080024
Alexander Afanasyevf22ebaf2015-12-17 21:23:05 -080025#define BOOST_TEST_NO_MAIN
26#define BOOST_TEST_DYN_LINK
27#define BOOST_TEST_ALTERNATIVE_INIT_API
Alexander Afanasyev2aa39622014-01-22 11:51:11 -080028
Alexander Afanasyev8552a382014-05-15 20:13:42 -070029#include "boost-test.hpp"
Alexander Afanasyevf22ebaf2015-12-17 21:23:05 -080030#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
39static bool
40init_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
101int
102main(int argc, char* argv[])
103{
104 return ::boost::unit_test::unit_test_main(&init_tests, argc, argv);
105}