blob: 3c980ed1ab0797045d40d9ec0f856b241a827344 [file] [log] [blame]
Yingdi Yuc9843cf2014-08-04 17:52:19 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyevbe998ac2017-05-06 13:11:42 -07003 * Copyright (c) 2014-2017, Regents of the University of California
Yingdi Yuc9843cf2014-08-04 17:52:19 -07004 *
Alexander Afanasyevbe998ac2017-05-06 13:11:42 -07005 * This file is part of NDN DeLorean, An Authentication System for Data Archives in
6 * Named Data Networking. See AUTHORS.md for complete list of NDN DeLorean authors
7 * and contributors.
Yingdi Yuc9843cf2014-08-04 17:52:19 -07008 *
Alexander Afanasyevbe998ac2017-05-06 13:11:42 -07009 * NDN DeLorean is free software: you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License as published by the Free Software
11 * Foundation, either version 3 of the License, or (at your option) any later
12 * version.
Yingdi Yuc9843cf2014-08-04 17:52:19 -070013 *
Alexander Afanasyevbe998ac2017-05-06 13:11:42 -070014 * NDN DeLorean is distributed in the hope that it will be useful, but WITHOUT ANY
15 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
16 * PARTICULAR PURPOSE. See the GNU General Public License for more details.
Yingdi Yuc9843cf2014-08-04 17:52:19 -070017 *
Alexander Afanasyevbe998ac2017-05-06 13:11:42 -070018 * You should have received a copy of the GNU General Public License along with NDN
19 * DeLorean, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
20 */
Yingdi Yuc9843cf2014-08-04 17:52:19 -070021
Yingdi Yuc9843cf2014-08-04 17:52:19 -070022
Alexander Afanasyev49e2e4c2017-05-06 13:42:57 -070023#define BOOST_TEST_DYN_LINK
24#define BOOST_TEST_ALTERNATIVE_INIT_API
25#define BOOST_TEST_MODULE NDN DeLorean Unit Tests
26
27#include <boost/version.hpp>
28
29#if BOOST_VERSION >= 106200
30// Boost.Test v3.3 (Boost 1.62) natively supports multi-logger output
Yingdi Yuc9843cf2014-08-04 17:52:19 -070031#include "boost-test.hpp"
Alexander Afanasyev49e2e4c2017-05-06 13:42:57 -070032#else
33#define BOOST_TEST_NO_MAIN
34#include "boost-test.hpp"
35
36#include "boost-multi-log-formatter.hpp"
37
38#include <boost/program_options/options_description.hpp>
39#include <boost/program_options/variables_map.hpp>
40#include <boost/program_options/parsers.hpp>
41
42#include <fstream>
43#include <iostream>
44
45static bool
46init_tests()
47{
48 init_unit_test();
49
50 namespace po = boost::program_options;
51 namespace ut = boost::unit_test;
52
53 po::options_description extraOptions;
54 std::string logger;
55 std::string outputFile = "-";
56 extraOptions.add_options()
57 ("log_format2", po::value<std::string>(&logger), "Type of second log formatter: HRF or XML")
58 ("log_sink2", po::value<std::string>(&outputFile)->default_value(outputFile), "Second log sink, - for stdout")
59 ;
60 po::variables_map vm;
61 try {
62 po::store(po::command_line_parser(ut::framework::master_test_suite().argc,
63 ut::framework::master_test_suite().argv)
64 .options(extraOptions)
65 .run(),
66 vm);
67 po::notify(vm);
68 }
69 catch (const std::exception& e) {
70 std::cerr << "ERROR: " << e.what() << "\n"
71 << extraOptions << std::endl;
72 return false;
73 }
74
75 if (vm.count("log_format2") == 0) {
76 // second logger is not configured
77 return true;
78 }
79
80 std::shared_ptr<ut::unit_test_log_formatter> formatter;
81 if (logger == "XML") {
82 formatter = std::make_shared<ut::output::xml_log_formatter>();
83 }
84 else if (logger == "HRF") {
85 formatter = std::make_shared<ut::output::compiler_log_formatter>();
86 }
87 else {
88 std::cerr << "ERROR: only HRF or XML log formatter can be specified" << std::endl;
89 return false;
90 }
91
92 std::shared_ptr<std::ostream> output;
93 if (outputFile == "-") {
94 output = std::shared_ptr<std::ostream>(&std::cout, std::bind([]{}));
95 }
96 else {
97 output = std::make_shared<std::ofstream>(outputFile.c_str());
98 }
99
100 auto multiFormatter = new ut::output::multi_log_formatter;
101 multiFormatter->add(formatter, output);
102 ut::unit_test_log.set_formatter(multiFormatter);
103
104 return true;
105}
106
107int
108main(int argc, char* argv[])
109{
110 return ::boost::unit_test::unit_test_main(&init_tests, argc, argv);
111}
112
113#endif // BOOST_VERSION >= 106200