Toolbox snapshot
The Reactive C++ Toolbox
Loading...
Searching...
No Matches
Time.ut.cpp
Go to the documentation of this file.
1// The Reactive C++ Toolbox.
2// Copyright (C) 2013-2019 Swirly Cloud Limited
3// Copyright (C) 2021 Reactive Markets Limited
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16
17#include "Time.hpp"
18
19#include <boost/test/unit_test.hpp>
20
21namespace std::chrono {
22template <typename RepT, typename PeriodT>
23ostream& operator<<(ostream& os, duration<RepT, PeriodT> d)
24{
25 return os << d.count();
26}
27} // namespace std::chrono
28
29using namespace std;
30using namespace toolbox;
31
33
35{
39
40 BOOST_CHECK_EQUAL(parse_nanos("000000001"), 1ns);
41 BOOST_CHECK_EQUAL(parse_nanos("000000012"), 12ns);
42 BOOST_CHECK_EQUAL(parse_nanos("000000123"), 123ns);
43
44 BOOST_CHECK_EQUAL(parse_nanos("000001"), 1us);
45 BOOST_CHECK_EQUAL(parse_nanos("000012"), 12us);
46 BOOST_CHECK_EQUAL(parse_nanos("000123"), 123us);
47
51
52 BOOST_CHECK_EQUAL(parse_nanos("123456789999"), 123456789ns);
53}
54
56{
58 BOOST_CHECK(!parse_time_only("12:34:5"sv));
59 BOOST_CHECK(!parse_time_only("x2:34:56"sv));
60 BOOST_CHECK(!parse_time_only("1x:34:56"sv));
61 BOOST_CHECK(!parse_time_only("12x34:56"sv));
62 BOOST_CHECK(!parse_time_only("12:x4:56"sv));
63 BOOST_CHECK(!parse_time_only("12:3x:56"sv));
64 BOOST_CHECK(!parse_time_only("12:34x56"sv));
65 BOOST_CHECK(!parse_time_only("12:34:x6"sv));
66 BOOST_CHECK(!parse_time_only("12:34:5x"sv));
67
69 BOOST_CHECK_EQUAL(*parse_time_only("12:00:00"sv), 12h);
71 BOOST_CHECK_EQUAL(*parse_time_only("00:00:56"sv), 56s);
72
73 BOOST_CHECK_EQUAL(*parse_time_only("00:00:56."sv), 56s);
74 BOOST_CHECK_EQUAL(*parse_time_only("00:00:00.789"sv), 789ms);
75 BOOST_CHECK_EQUAL(*parse_time_only("00:00:00.000789"sv), 789us);
76 BOOST_CHECK_EQUAL(*parse_time_only("00:00:00.000000789"sv), 789ns);
77}
78
BOOST_CHECK_EQUAL(v.size(), 10U)
BOOST_AUTO_TEST_CASE(TimeParseNanosCase)
Definition Time.ut.cpp:34
ostream & operator<<(ostream &os, duration< RepT, PeriodT > d)
Definition Timer.ut.cpp:23
STL namespace.
int64_t min(const Histogram &h) noexcept
Definition Utility.cpp:41
constexpr std::optional< Nanos > parse_time_only(std::string_view sv) noexcept
Definition Time.hpp:399
constexpr auto parse_nanos(std::string_view sv) noexcept
Definition Time.hpp:360
std::string_view sv
Definition Tokeniser.hpp:26
constexpr auto bind() noexcept
Definition Slot.hpp:92
BOOST_CHECK(isnan(stod(""sv, numeric_limits< double >::quiet_NaN())))