Bitcoin Core  22.99.0
P2P Digital Currency
logging_tests.cpp
Go to the documentation of this file.
1 // Copyright (c) 2019 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #include <logging.h>
6 #include <logging/timer.h>
8 
9 #include <chrono>
10 
11 #include <boost/test/unit_test.hpp>
12 
14 
15 BOOST_AUTO_TEST_CASE(logging_timer)
16 {
17  SetMockTime(1);
18  auto micro_timer = BCLog::Timer<std::chrono::microseconds>("tests", "end_msg");
19  SetMockTime(2);
20  BOOST_CHECK_EQUAL(micro_timer.LogMsg("test micros"), "tests: test micros (1000000μs)");
21 
22  SetMockTime(1);
23  auto ms_timer = BCLog::Timer<std::chrono::milliseconds>("tests", "end_msg");
24  SetMockTime(2);
25  BOOST_CHECK_EQUAL(ms_timer.LogMsg("test ms"), "tests: test ms (1000.00ms)");
26 
27  SetMockTime(1);
28  auto sec_timer = BCLog::Timer<std::chrono::seconds>("tests", "end_msg");
29  SetMockTime(2);
30  BOOST_CHECK_EQUAL(sec_timer.LogMsg("test secs"), "tests: test secs (1.00s)");
31 }
32 
setup_common.h
BCLog::Timer
RAII-style object that outputs timing information to logs.
Definition: timer.h:22
BOOST_FIXTURE_TEST_SUITE
#define BOOST_FIXTURE_TEST_SUITE(a, b)
Definition: object.cpp:14
BOOST_AUTO_TEST_SUITE_END
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(logging_timer)
Definition: logging_tests.cpp:15
SetMockTime
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.
Definition: time.cpp:101
timer.h
BasicTestingSetup
Basic testing setup.
Definition: setup_common.h:76
BOOST_CHECK_EQUAL
#define BOOST_CHECK_EQUAL(v1, v2)
Definition: object.cpp:18