Toolbox
snapshot
The Reactive C++ Toolbox
Loading...
Searching...
No Matches
toolbox
util
Stream.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) 2022 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 "
Stream.hpp
"
18
19
#include <boost/test/unit_test.hpp>
20
21
#include <array>
22
#include <sstream>
23
24
using namespace
std
;
25
using namespace
toolbox
;
26
27
BOOST_AUTO_TEST_SUITE
(
StreamSuite
)
28
29
BOOST_AUTO_TEST_CASE
(
OStaticStreamCase
)
30
{
31
OStaticStream<7>
os;
32
BOOST_CHECK
(os.
empty
());
33
os <<
"foo"
;
34
BOOST_CHECK_EQUAL
(os.
size
(), 3U);
35
BOOST_CHECK_EQUAL
(os.
str
(),
"foo"
);
36
os <<
','
<<
"bar"
;
37
BOOST_CHECK_EQUAL
(os.
size
(), 7U);
38
BOOST_CHECK_EQUAL
(os.
str
(),
"foo,bar"
);
39
40
os.
reset
();
41
BOOST_CHECK
(os.
empty
());
42
os << 12345678;
43
BOOST_CHECK_EQUAL
(os.
size
(), 7U);
44
BOOST_CHECK_EQUAL
(os.
str
(),
"1234567"
);
45
BOOST_CHECK
(!os);
46
47
os.
reset
();
48
BOOST_CHECK
(!!os);
49
BOOST_CHECK_EQUAL
((os <<
"test"
).str(),
"test"
);
50
}
51
52
BOOST_AUTO_TEST_CASE
(
OStreamJoinerCase
)
53
{
54
array<string, 3>
arr
{{
"foo"
,
"bar"
,
"baz"
}};
55
stringstream os;
56
copy
(
arr
.begin(),
arr
.end(),
OStreamJoiner
{os,
','
});
57
BOOST_CHECK_EQUAL
(os.str(),
"foo,bar,baz"
);
58
}
59
60
BOOST_AUTO_TEST_CASE
(
OStreamResetCase
)
61
{
62
OStaticStream<6>
os{};
63
// overflows the buffer, setting a bad flag
64
os <<
"foobarbaz"
;
65
BOOST_CHECK_EQUAL
(os.data(),
"foobar"
);
66
// resets flag, allowing yes to be written
67
os.reset();
68
os <<
"yes"
;
69
BOOST_CHECK_EQUAL
(os.data(),
"yesbar"
);
70
}
71
72
BOOST_AUTO_TEST_SUITE_END
()
BOOST_CHECK_EQUAL
BOOST_CHECK_EQUAL(v.size(), 10U)
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(OStaticStreamCase)
Definition
Stream.ut.cpp:29
toolbox::OStaticStream
Definition
Stream.hpp:173
toolbox::util::OStaticStream::empty
bool empty() const noexcept
Definition
Stream.hpp:191
toolbox::util::OStaticStream::size
std::size_t size() const noexcept
Definition
Stream.hpp:192
toolbox::util::OStaticStream::reset
void reset() noexcept
Reset the current position back to the beginning of the buffer.
Definition
Stream.hpp:200
toolbox::util::OStaticStream::str
std::string_view str() const noexcept
Definition
Stream.hpp:194
std
STL namespace.
toolbox::util::OStreamJoiner
std::experimental::ostream_joiner< char > OStreamJoiner
Definition
Stream.hpp:217
toolbox::util::bind
constexpr auto bind() noexcept
Definition
Slot.hpp:92
toolbox
Definition
Benchmark.cpp:26
Stream.hpp
BOOST_CHECK
BOOST_CHECK(isnan(stod(""sv, numeric_limits< double >::quiet_NaN())))
Generated by
1.9.8