blob: 2423b10afd5de1dc85628a40a53e44772be0ee12 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
#ifndef BOOST_TEST_NO_MAIN
#define BOOST_TEST_NO_MAIN
#endif
#include <boost/test/unit_test.hpp>
#include <gmock/gmock.h>
#include <loggers.h>
#include <iostream>
using logging::TRACE_LEVEL;
using logging::WARN_LEVEL;
using logging::Logger;
using logging::LoggerPtr;
using logging::describe_log_level;
using logging::log_level;
// One dummy test so that this can be dropped in before the actual
// test suite is written.
BOOST_AUTO_TEST_CASE(dummy)
{
}
// The Google mock library emits Google Test failures; we need to be
// able to convert those to Boost.Test failures.
class gtest_to_boost_adaptor : public testing::EmptyTestEventListener
{
void OnTestPartResult(const testing::TestPartResult &test_part_result)
{
if(test_part_result.nonfatally_failed())
BOOST_ERROR(test_part_result.file_name()
<< ":"
<< test_part_result.line_number()
<< ": "
<< test_part_result.summary());
else if(test_part_result.fatally_failed())
BOOST_FAIL(test_part_result.file_name()
<< ":"
<< test_part_result.line_number()
<< ": "
<< test_part_result.summary());
}
};
bool init_unit_test()
{
return true;
}
char *argv0 = NULL;
namespace
{
void log_to_stdout(const char *sourceFilename,
int sourceLineNumber,
log_level level,
LoggerPtr logger,
const std::string &msg)
{
std::cout << sourceFilename
<< ":" << sourceLineNumber
<< " " << describe_log_level(level)
<< " - " << msg << std::endl << std::flush;
}
}
int main(int argc, char **argv)
{
argv0 = argv[0];
::testing::InitGoogleMock(&argc, argv);
{
::testing::TestEventListeners &listeners =
::testing::UnitTest::GetInstance()->listeners();
listeners.Append(new gtest_to_boost_adaptor);
}
bool debug = false;
for(int i = 1; i < argc; ++i)
{
if(!strcmp(argv[i], "--debug"))
debug = true;
}
if(debug)
Logger::getLogger("")->setLevel(TRACE_LEVEL);
else
Logger::getLogger("")->setLevel(WARN_LEVEL);
Logger::getLogger("")->connect_message_logged(sigc::ptr_fun(&log_to_stdout));
return boost::unit_test::unit_test_main(init_unit_test, argc, argv);
}
|