Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4510497

Browse files
committed
Implemented basic log_record tests (and fixes)
1 parent8452e5c commit4510497

File tree

3 files changed

+79
-4
lines changed

3 files changed

+79
-4
lines changed

‎include/network/logging/logging.hpp‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright2011 A. Joel Lamotte <mjklaim@gmail.com>.
1+
// Copyright(c) 2012 A. Joel Lamotte <mjklaim@gmail.com>.
22
// Distributed under the Boost Software License, Version 1.0.
33
// (See accompanying file LICENSE_1_0.txt or copy at
44
// http://www.boost.org/LICENSE_1_0.txt)
@@ -29,12 +29,17 @@ namespace handler
2929
classlog_record
3030
{
3131
public:
32-
log_record(){}// = default;
32+
log_record()
33+
: m_filename( UNKNOWN_FILE_NAME )
34+
, m_line(0)
35+
{}// = default;
36+
37+
staticconstchar* UNKNOWN_FILE_NAME;
3338

3439
// Implicit construction from anything serializable to text.
3540
template<typename TypeOfSomething >
3641
log_record( TypeOfSomething&& message )
37-
: m_filename("unknown" )
42+
: m_filename(UNKNOWN_FILE_NAME )
3843
, m_line(0)
3944
{
4045
write( std::forward<TypeOfSomething>(message) );
@@ -69,7 +74,7 @@ class log_record
6974
log_record&operator=(const log_record& );// = delete;
7075

7176
std::ostringstream m_text_stream;// stream in which we build the message
72-
std::string m_filename;// ="unknown";
77+
std::string m_filename;// =UNKNOWN_FILE_NAME;
7378
unsignedlong m_line;// = 0;
7479
};
7580

‎libs/network/src/logging/logging.cpp‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
namespacenetwork {namespacelogging {
1515

16+
constchar* log_record::UNKNOWN_FILE_NAME ="unknown";
17+
18+
1619
namespacehandler
1720
{
1821
namespace
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
#defineBOOST_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+
usingnamespacenetwork::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+
constauto message ="This is a test.";
25+
log_recordrecord( 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::stringmessage("This is a test.");
33+
log_recordrecord( 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+
constauto num =42;
41+
log_recordrecord( 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+
constauto line_num =42;
49+
constauto file_name ="somewhere.cpp";
50+
log_recordrecord( 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+
constauto line_num =42;
58+
constauto file_name ="somewhere.cpp";
59+
constauto message ="At line" +std::to_string(line_num) +" we check the code.";
60+
log_recordrecord( 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

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp