|
| 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 | + |
| 14 | +using namespace network::logging; |
| 15 | + |
| 16 | +BOOST_AUTO_TEST_CASE(default_constructor) { |
| 17 | + log_record record; |
| 18 | + BOOST_CHECK( record.message() == "" ); |
| 19 | + BOOST_CHECK( record.filename() == log_record::UNKNOWN_FILE_NAME ); |
| 20 | + BOOST_CHECK( record.line() == 0 ); |
| 21 | +} |
| 22 | + |
| 23 | +BOOST_AUTO_TEST_CASE(cstring_constructor) { |
| 24 | + const auto message = "This is a test."; |
| 25 | + log_record record( message ); |
| 26 | + BOOST_CHECK( record.message() == message ); |
| 27 | + BOOST_CHECK( record.filename() == log_record::UNKNOWN_FILE_NAME ); |
| 28 | + BOOST_CHECK( record.line() == 0 ); |
| 29 | +} |
| 30 | + |
| 31 | +BOOST_AUTO_TEST_CASE(string_constructor) { |
| 32 | + const std::string message("This is a test."); |
| 33 | + log_record record( message ); |
| 34 | + BOOST_CHECK( record.message() == message ); |
| 35 | + BOOST_CHECK( record.filename() == log_record::UNKNOWN_FILE_NAME ); |
| 36 | + BOOST_CHECK( record.line() == 0 ); |
| 37 | +} |
| 38 | + |
| 39 | +BOOST_AUTO_TEST_CASE(int_constructor) { |
| 40 | + const auto num = 42; |
| 41 | + log_record record( num ); |
| 42 | + BOOST_CHECK( record.message() == std::to_string( num ) ); |
| 43 | + BOOST_CHECK( record.filename() == log_record::UNKNOWN_FILE_NAME ); |
| 44 | + BOOST_CHECK( record.line() == 0 ); |
| 45 | +} |
| 46 | + |
| 47 | +BOOST_AUTO_TEST_CASE(info_constructor) { |
| 48 | + const auto line_num = 42; |
| 49 | + const auto file_name = "somewhere.cpp"; |
| 50 | + log_record record( file_name, line_num ); |
| 51 | + BOOST_CHECK( record.message() == "" ); |
| 52 | + BOOST_CHECK( record.filename() == file_name ); |
| 53 | + BOOST_CHECK( record.line() == line_num ); |
| 54 | +} |
| 55 | + |
| 56 | +BOOST_AUTO_TEST_CASE(text_stream) { |
| 57 | + const auto line_num = 42; |
| 58 | + const auto file_name = "somewhere.cpp"; |
| 59 | + const auto message = "At line " + std::to_string(line_num) + " we check the code."; |
| 60 | + log_record record( file_name, line_num ); |
| 61 | + |
| 62 | + record << "At line " << line_num << " we check the code."; |
| 63 | + |
| 64 | + BOOST_CHECK( record.message() == message ); |
| 65 | + BOOST_CHECK( record.filename() == file_name ); |
| 66 | + BOOST_CHECK( record.line() == line_num ); |
| 67 | +} |
0 commit comments