Changeset View
Changeset View
Standalone View
Standalone View
src/test/timedata_tests.cpp
// Copyright (c) 2011-2019 The Bitcoin Core developers | // Copyright (c) 2011-2019 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
// | // | ||||
#include <timedata.h> | #include <timedata.h> | ||||
#include <netaddress.h> | #include <netaddress.h> | ||||
#include <noui.h> | #include <noui.h> | ||||
#include <test/lib/logging.h> | |||||
#include <warnings.h> | #include <warnings.h> | ||||
#include <test/setup_common.h> | #include <test/setup_common.h> | ||||
#include <string> | |||||
#include <boost/test/unit_test.hpp> | #include <boost/test/unit_test.hpp> | ||||
#include <string> | |||||
BOOST_FIXTURE_TEST_SUITE(timedata_tests, BasicTestingSetup) | BOOST_FIXTURE_TEST_SUITE(timedata_tests, BasicTestingSetup) | ||||
BOOST_AUTO_TEST_CASE(util_MedianFilter) { | BOOST_AUTO_TEST_CASE(util_MedianFilter) { | ||||
CMedianFilter<int> filter(5, 15); | CMedianFilter<int> filter(5, 15); | ||||
BOOST_CHECK_EQUAL(filter.median(), 15); | BOOST_CHECK_EQUAL(filter.median(), 15); | ||||
filter.input(20); // [15 20] | filter.input(20); // [15 20] | ||||
Show All 28 Lines | BOOST_AUTO_TEST_CASE(addtimedata) { | ||||
BOOST_CHECK_EQUAL(GetTimeOffset(), 0); | BOOST_CHECK_EQUAL(GetTimeOffset(), 0); | ||||
// Part 1: Add large offsets to test a warning message that our clock may be | // Part 1: Add large offsets to test a warning message that our clock may be | ||||
// wrong. | // wrong. | ||||
MultiAddTimeData(3, DEFAULT_MAX_TIME_ADJUSTMENT + 1); | MultiAddTimeData(3, DEFAULT_MAX_TIME_ADJUSTMENT + 1); | ||||
// Filter size is 1 + 3 = 4: It is always initialized with a single element | // Filter size is 1 + 3 = 4: It is always initialized with a single element | ||||
// (offset 0) | // (offset 0) | ||||
noui_suppress(); | { | ||||
ASSERT_DEBUG_LOG( | |||||
"Please check that your computer's date and time are correct!"); | |||||
// filter size 5 | // filter size 5 | ||||
MultiAddTimeData(1, DEFAULT_MAX_TIME_ADJUSTMENT + 1); | MultiAddTimeData(1, DEFAULT_MAX_TIME_ADJUSTMENT + 1); | ||||
noui_reconnect(); | } | ||||
BOOST_CHECK(GetWarnings("gui").find("clock is wrong") != std::string::npos); | BOOST_CHECK(GetWarnings("gui").find("clock is wrong") != std::string::npos); | ||||
// nTimeOffset is not changed if the median of offsets exceeds | // nTimeOffset is not changed if the median of offsets exceeds | ||||
// DEFAULT_MAX_TIME_ADJUSTMENT | // DEFAULT_MAX_TIME_ADJUSTMENT | ||||
BOOST_CHECK_EQUAL(GetTimeOffset(), 0); | BOOST_CHECK_EQUAL(GetTimeOffset(), 0); | ||||
// Part 2: Test positive and negative medians by adding more offsets | // Part 2: Test positive and negative medians by adding more offsets | ||||
Show All 36 Lines |