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

Commitf89c2f2

Browse files
committed
Implemented custom log handler tests.
1 parent4510497 commitf89c2f2

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
#include<sstream>
8+
9+
#defineBOOST_TEST_MODULE logging log_record
10+
#include<boost/config/warning_disable.hpp>
11+
#include<boost/test/unit_test.hpp>
12+
13+
#include<network/logging/logging.hpp>
14+
15+
usingnamespacenetwork::logging;
16+
17+
BOOST_AUTO_TEST_CASE(custom_log_handler_output) {
18+
19+
std::stringstream log_output;
20+
auto custom_log_handler = [&](const log_record& log )
21+
{
22+
log_output <<"[CPPNETLIB]<" << log.filename() <<":" << log.line() <<">"
23+
<< log.message();
24+
};
25+
26+
constauto line_num =42;
27+
constauto file_name ="somewhere.cpp";
28+
constauto message ="At line" +std::to_string(line_num) +" we check the code.";
29+
30+
set_log_record_handler( custom_log_handler );
31+
log_record( file_name, line_num ) <<"At line" << line_num <<" we check the code.";
32+
33+
constauto result_output = log_output.str();
34+
35+
BOOST_CHECK( !result_output.empty() );
36+
BOOST_CHECK( result_output =="[CPPNETLIB]<somewhere.cpp:42>" + message );
37+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp