Toolbox snapshot
The Reactive C++ Toolbox
Loading...
Searching...
No Matches
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
24using namespace std;
25using namespace toolbox;
26
28
30{
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
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
61{
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
BOOST_CHECK_EQUAL(v.size(), 10U)
BOOST_AUTO_TEST_CASE(OStaticStreamCase)
Definition Stream.ut.cpp:29
bool empty() const noexcept
Definition Stream.hpp:191
std::size_t size() const noexcept
Definition Stream.hpp:192
void reset() noexcept
Reset the current position back to the beginning of the buffer.
Definition Stream.hpp:200
std::string_view str() const noexcept
Definition Stream.hpp:194
STL namespace.
std::experimental::ostream_joiner< char > OStreamJoiner
Definition Stream.hpp:217
constexpr auto bind() noexcept
Definition Slot.hpp:92
BOOST_CHECK(isnan(stod(""sv, numeric_limits< double >::quiet_NaN())))