blob: d9f582b426397a7c971c6a422403e2e1414fc7e3 [file] [log] [blame]
Alexander Afanasyevc169a812014-05-20 20:37:29 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -08002/**
Alexander Afanasyeve6c65e22015-01-28 19:56:03 -08003 * Copyright (c) 2013-2015 Regents of the University of California.
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07006 *
Alexander Afanasyevc169a812014-05-20 20:37:29 -04007 * 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 Afanasyev5fa9e9a2013-12-24 19:45:07 -080020 */
21
Alexander Afanasyeve6c65e22015-01-28 19:56:03 -080022#define BOOST_TEST_MODULE ndn-cxx Unit Tests
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -080023
Alexander Afanasyev9fae3db2015-12-07 18:04:32 -080024#define BOOST_TEST_NO_MAIN
25#define BOOST_TEST_DYN_LINK
26#define BOOST_TEST_ALTERNATIVE_INIT_API
27
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070028#include "boost-test.hpp"
Alexander Afanasyev9fae3db2015-12-07 18:04:32 -080029#include "boost-multi-log-formatter.hpp"
30
31#include <boost/program_options/options_description.hpp>
32#include <boost/program_options/variables_map.hpp>
33#include <boost/program_options/parsers.hpp>
34
35#include <fstream>
36#include <iostream>
37
38static bool
39init_tests()
40{
41 init_unit_test();
42
43 namespace po = boost::program_options;
44 namespace ut = boost::unit_test;
45
46 po::options_description extraOptions;
47 std::string logger;
48 std::string outputFile = "-";
49 extraOptions.add_options()
50 ("log_format2", po::value<std::string>(&logger), "Type of second log formatter: HRF or XML")
51 ("log_sink2", po::value<std::string>(&outputFile)->default_value(outputFile), "Second log sink, - for stdout")
52 ;
53 po::variables_map vm;
54 try {
55 po::store(po::command_line_parser(ut::framework::master_test_suite().argc,
56 ut::framework::master_test_suite().argv)
57 .options(extraOptions)
58 .run(),
59 vm);
60 po::notify(vm);
61 }
62 catch (const std::exception& e) {
63 std::cerr << "ERROR: " << e.what() << "\n"
64 << extraOptions << std::endl;
65 return false;
66 }
67
68 if (vm.count("log_format2") == 0) {
69 // second logger is not configured
70 return true;
71 }
72
73 std::shared_ptr<ut::unit_test_log_formatter> formatter;
74 if (logger == "XML") {
75 formatter = std::make_shared<ut::output::xml_log_formatter>();
76 }
77 else if (logger == "HRF") {
78 formatter = std::make_shared<ut::output::compiler_log_formatter>();
79 }
80 else {
81 std::cerr << "ERROR: only HRF or XML log formatter can be specified" << std::endl;
82 return false;
83 }
84
85 std::shared_ptr<std::ostream> output;
86 if (outputFile == "-") {
87 output = std::shared_ptr<std::ostream>(&std::cout, std::bind([]{}));
88 }
89 else {
90 output = std::make_shared<std::ofstream>(outputFile.c_str());
91 }
92
93 auto multiFormatter = new ut::output::multi_log_formatter;
94 multiFormatter->add(formatter, output);
95 ut::unit_test_log.set_formatter(multiFormatter);
96
97 return true;
98}
99
100int
101main(int argc, char* argv[])
102{
103 return ::boost::unit_test::unit_test_main(&init_tests, argc, argv);
104}