1 // (C) Copyright Raffi Enficiaud 2017.
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
5
6 // See http://www.boost.org/libs/test for the library home page.
7
8 #define BOOST_TEST_MODULE message in dataset
9
10 #include <boost/test/unit_test.hpp>
11
12 #include <boost/test/unit_test_suite.hpp>
13 #include <boost/test/unit_test_log.hpp>
14 #include <boost/test/results_collector.hpp>
15 #include <boost/test/data/monomorphic.hpp>
16 #include <boost/test/data/test_case.hpp>
17
18 #include <boost/test/framework.hpp>
19 #include <boost/test/unit_test_parameters.hpp>
20 #include <boost/test/utils/nullstream.hpp>
21
22 #include "logger-for-tests.hpp"
23
24 // STL
25 #include <iostream>
26 #include <ios>
27
28
29 using boost::test_tools::output_test_stream;
30 using namespace boost::unit_test;
31
32
33
34 #line 34
35 std::string filenames[] = { "util/test_image1.jpg", "util/test_image2.jpg" };
BOOST_DATA_TEST_CASE(test_update,boost::unit_test::data::make (filenames))36 BOOST_DATA_TEST_CASE(test_update,
37 boost::unit_test::data::make(filenames))
38 {
39 std::string field_name = "Volume";
40 int value = 100;
41
42 BOOST_TEST_MESSAGE("Testing update :");
43 BOOST_TEST_MESSAGE("Update " << field_name << " with " << value);
44 }
45
check_pattern_loggers(output_test_stream & output,output_format log_format,test_unit_id id,bool bt_module_failed=false,log_level ll=log_successful_tests)46 void check_pattern_loggers(
47 output_test_stream& output,
48 output_format log_format,
49 test_unit_id id,
50 bool bt_module_failed = false,
51 log_level ll = log_successful_tests )
52 {
53 boost::unit_test::unit_test_log.set_format(log_format);
54 boost::unit_test::unit_test_log.set_stream(output);
55 boost::unit_test::unit_test_log.set_threshold_level(ll);
56
57 // output before fixture registration
58 output << "* " << log_format << "-format *******************************************************************";
59 output << std::endl;
60
61 framework::finalize_setup_phase( id );
62
63 bool setup_error_caught = false;
64 try {
65 framework::run( id, false ); // do not continue the test tree to have the test_log_start/end
66 }
67 catch (framework::setup_error&) {
68 BOOST_TEST_MESSAGE("Framework setup_error caught");
69 setup_error_caught = true;
70 }
71
72 output << std::endl;
73
74 // we do not want the result of the comparison go to the "output" stream
75 boost::unit_test::unit_test_log.set_format(OF_CLF);
76 boost::unit_test::unit_test_log.set_stream(std::cout);
77
78 BOOST_TEST( bt_module_failed == (( results_collector.results( id ).result_code() != 0 ) ));
79 BOOST_TEST( output.match_pattern(true) ); // flushes the stream at the end of the comparison.
80 }
81
check_pattern_loggers(output_test_stream & output,test_suite * ts,bool bt_module_failed=false)82 void check_pattern_loggers(
83 output_test_stream& output,
84 test_suite* ts,
85 bool bt_module_failed = false)
86 {
87 ts->p_default_status.value = test_unit::RS_ENABLED;
88
89 check_pattern_loggers( output, OF_CLF, ts->p_id, bt_module_failed );
90 check_pattern_loggers( output, OF_XML, ts->p_id, bt_module_failed );
91 check_pattern_loggers( output, OF_JUNIT, ts->p_id, bt_module_failed, log_successful_tests );
92 check_pattern_loggers( output, OF_JUNIT, ts->p_id, bt_module_failed, log_cpp_exception_errors ); // should branch to the log log_all_errors
93 }
94
95 struct guard {
~guardguard96 ~guard()
97 {
98 boost::unit_test::unit_test_log.set_format( runtime_config::get<output_format>( runtime_config::btrt_log_format ) );
99 boost::unit_test::unit_test_log.set_stream( std::cout );
100 }
101 };
102
103
104 //____________________________________________________________________________//
105
106
BOOST_AUTO_TEST_CASE(messages_in_datasets)107 BOOST_AUTO_TEST_CASE( messages_in_datasets )
108 {
109 guard G;
110 boost::ignore_unused( G );
111
112 #define PATTERN_FILE_NAME "messages-in-datasets-test.pattern"
113
114 std::string pattern_file_name(
115 framework::master_test_suite().argc == 1
116 ? (runtime_config::save_pattern() ? PATTERN_FILE_NAME : "./baseline-outputs/" PATTERN_FILE_NAME )
117 : framework::master_test_suite().argv[1] );
118
119 output_test_stream_for_loggers test_output( pattern_file_name,
120 !runtime_config::save_pattern(),
121 true,
122 __FILE__ );
123
124 auto dataset = boost::unit_test::data::make(filenames);
125
126 test_unit_generator const& generator = boost::unit_test::data::ds_detail::test_case_gen<test_updatecase, decltype(dataset)>(
127 "fake_name",
128 __FILE__,
129 200,
130 std::forward<decltype(dataset)>(dataset) );
131 test_suite* ts = BOOST_TEST_SUITE( "fake_datatest_case" );
132 while(test_unit *tu = generator.next()) {
133 ts->add(tu);
134 }
135
136 check_pattern_loggers(test_output, ts);
137 }
138