summaryrefslogtreecommitdiff
path: root/test/test-streams.cpp
blob: 9e79bd6616515b259031c2f9494e5b17e5297b3a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#define BOOST_TEST_MODULE StreamSupport
#include <boost/test/data/test_case.hpp>
#include <boost/test/unit_test.hpp>

#include "helpers.h"
#include <streamSupport.h>

BOOST_FIXTURE_TEST_SUITE(stream, std::stringstream);

template<typename In> using ToStream = std::tuple<In, std::string_view>;
BOOST_DATA_TEST_CASE(bytes,
		boost::unit_test::data::make<ToStream<std::byte>>({
				//{0x00_b, "0x00"},
				{0x10_b, "0x10"},
				{0xFE_b, "0xfe"},
				{0xff_b, "0xff"},
		}),
		in, exp)
{
	*this << in;
	BOOST_CHECK_EQUAL(this->str(), exp);
}

BOOST_DATA_TEST_CASE(tms,
		boost::unit_test::data::make<ToStream<tm>>({
				{make_tm(2016, 1, 4, 12, 13, 14), "2016-01-04 12:13:14"},
				{make_tm(2016, 12, 31, 0, 0, 1), "2016-12-31 00:00:01"},
		}),
		in, exp)
{
	*this << in;
	BOOST_CHECK_EQUAL(this->str(), exp);
}

BOOST_DATA_TEST_CASE(rts,
		boost::unit_test::data::make<ToStream<MyGrate::MySQL::DateTime>>({
				{{{2016, 1, 4}, {12, 13, 14}}, "2016-01-04 12:13:14"},
				{{{2016, 12, 31}, {0, 0, 1}}, "2016-12-31 00:00:01"},
		}),
		in, exp)
{
	*this << in;
	BOOST_CHECK_EQUAL(this->str(), exp);
}

BOOST_DATA_TEST_CASE(tss,
		boost::unit_test::data::make<ToStream<timespec>>({
				{{0, 0}, "0.000000000"},
				{{0, 1}, "0.000000001"},
				{{1, 0}, "1.000000000"},
				{{123, 0}, "123.000000000"},
				{{123, 999999999}, "123.999999999"},
		}),
		in, exp)
{
	*this << in;
	BOOST_CHECK_EQUAL(this->str(), exp);
}
constexpr std::byte somebits[3] {0x00_b, 0xFF_b, 0xa1_b};
BOOST_DATA_TEST_CASE(bss,
		boost::unit_test::data::make<ToStream<MyGrate::BitSet>>({
				{{MyGrate::BitSet {somebits}}, "[0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,1,0,1]"},
		}),
		in, exp)
{
	*this << in;
	BOOST_CHECK_EQUAL(this->str(), exp);
}

BOOST_AUTO_TEST_CASE(mariadb_string)
{
	char buf[5] = "test";
	MARIADB_STRING str {buf, strlen(buf)};
	*this << str;
	BOOST_CHECK_EQUAL(this->str(), buf);
}

BOOST_AUTO_TEST_CASE(array)
{
	std::array<int, 3> arr {1, 123456, -78910};
	*this << arr;
	BOOST_CHECK_EQUAL(this->str(), "[1,123456,-78910]");
}

BOOST_AUTO_TEST_CASE(vector)
{
	std::vector<int> arr {1, 123456, -78910};
	*this << arr;
	BOOST_CHECK_EQUAL(this->str(), "[1,123456,-78910]");
}

BOOST_AUTO_TEST_SUITE_END();