1+ // Copyright (c) 2012 A. Joel Lamotte <mjklaim@gmail.com>
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+ #include < string>
7+
8+ #define BOOST_TEST_MODULE logging log_record
9+ #include < boost/config/warning_disable.hpp>
10+ #include < boost/test/unit_test.hpp>
11+
12+ #include < network/logging/logging.hpp>
13+ #define NETWORK_ENABLE_LOGGING
14+ #include < network/detail/debug.hpp>
15+
16+ using namespace network ::logging;
17+
18+ BOOST_AUTO_TEST_CASE (default_constructor) {
19+ log_record record;
20+ BOOST_CHECK ( record.message () ==" " );
21+ BOOST_CHECK ( record.filename () == log_record::UNKNOWN_FILE_NAME );
22+ BOOST_CHECK ( record.line () ==0 );
23+ }
24+
25+ BOOST_AUTO_TEST_CASE (cstring_constructor) {
26+ const auto message =" This is a test." ;
27+ log_recordrecord ( message );
28+ BOOST_CHECK ( record.message () == message );
29+ BOOST_CHECK ( record.filename () == log_record::UNKNOWN_FILE_NAME );
30+ BOOST_CHECK ( record.line () ==0 );
31+ }
32+
33+ BOOST_AUTO_TEST_CASE (string_constructor) {
34+ const std::stringmessage (" This is a test." );
35+ log_recordrecord ( message );
36+ BOOST_CHECK ( record.message () == message );
37+ BOOST_CHECK ( record.filename () == log_record::UNKNOWN_FILE_NAME );
38+ BOOST_CHECK ( record.line () ==0 );
39+ }
40+
41+ BOOST_AUTO_TEST_CASE (int_constructor) {
42+ const auto num =42 ;
43+ log_recordrecord ( num );
44+ BOOST_CHECK ( record.message () ==std::to_string ( num ) );
45+ BOOST_CHECK ( record.filename () == log_record::UNKNOWN_FILE_NAME );
46+ BOOST_CHECK ( record.line () ==0 );
47+ }
48+
49+ BOOST_AUTO_TEST_CASE (info_constructor) {
50+ const auto line_num =42 ;
51+ const auto file_name =" somewhere.cpp" ;
52+ log_recordrecord ( file_name, line_num );
53+ BOOST_CHECK ( record.message () ==" " );
54+ BOOST_CHECK ( record.filename () == file_name );
55+ BOOST_CHECK ( record.line () == line_num );
56+ }
57+
58+ BOOST_AUTO_TEST_CASE (text_stream) {
59+ const auto line_num =42 ;
60+ const auto file_name =" somewhere.cpp" ;
61+ const auto message =" At line" +std::to_string (line_num) +" we check the code." ;
62+ log_recordrecord ( file_name, line_num );
63+
64+ record <<" At line" << line_num <<" we check the code." ;
65+
66+ BOOST_CHECK ( record.message () == message );
67+ BOOST_CHECK ( record.filename () == file_name );
68+ BOOST_CHECK ( record.line () == line_num );
69+ }
70+
71+ BOOST_AUTO_TEST_CASE (raw_log) {
72+ log (" This is a raw log." );
73+ }
74+
75+ BOOST_AUTO_TEST_CASE (macro_log) {
76+ NETWORK_MESSAGE (" This is a log through the macro." );
77+ NETWORK_MESSAGE (" This is a log through the macro, with a stream! Num=" <<42 <<" - OK!" );
78+ }