forked from ClickHouse/ClickHouse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlimit_read_buffer2.cpp
More file actions
140 lines (110 loc) · 3.53 KB
/
Copy pathlimit_read_buffer2.cpp
File metadata and controls
140 lines (110 loc) · 3.53 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include <sstream>
#include <IO/LimitReadBuffer.h>
#include <IO/copyData.h>
#include <IO/WriteBufferFromString.h>
#include <IO/ReadHelpers.h>
namespace DB
{
namespace ErrorCodes
{
extern const int LOGICAL_ERROR;
}
}
int main(int, char **)
try
{
using namespace DB;
std::stringstream s; // STYLE_CHECK_ALLOW_STD_STRING_STREAM
s.exceptions(std::ios::failbit);
{
std::string src = "1";
std::string dst;
ReadBuffer in(src.data(), src.size(), 0);
LimitReadBuffer limit_in(in, 1, false);
{
WriteBufferFromString out(dst);
copyData(limit_in, out);
}
if (limit_in.count() != 1)
{
s << "Failed!, incorrect count(): " << limit_in.count();
throw Exception(s.str(), ErrorCodes::LOGICAL_ERROR);
}
if (in.count() != limit_in.count())
{
s << "Failed!, incorrect underlying buffer's count(): " << in.count();
throw Exception(s.str(), ErrorCodes::LOGICAL_ERROR);
}
if (src != dst)
{
s << "Failed!, incorrect destination value, read: " << dst << ", expected: " << src;
throw Exception(s.str(), ErrorCodes::LOGICAL_ERROR);
}
}
{
std::string src = "abc";
ReadBuffer in(src.data(), src.size(), 0);
std::string dst;
{
WriteBufferFromString out(dst);
char x;
readChar(x, in);
LimitReadBuffer limit_in(in, 1, false);
copyData(limit_in, out);
if (in.count() != 2)
{
s << "Failed!, Incorrect underlying buffer's count: " << in.count() << ", expected: " << 2;
throw Exception(s.str(), ErrorCodes::LOGICAL_ERROR);
}
if (limit_in.count() != 1)
{
s << "Failed!, Incorrect count: " << limit_in.count() << ", expected: " << 1;
throw Exception(s.str(), ErrorCodes::LOGICAL_ERROR);
}
}
if (dst != "b")
{
s << "Failed!, Incorrect destination value: " << dst << ", expected 'b'";
throw Exception(dst, ErrorCodes::LOGICAL_ERROR);
}
char y;
readChar(y, in);
if (y != 'c')
{
s << "Failed!, Read incorrect value from underlying buffer: " << y << ", expected 'c'";
throw Exception(s.str(), ErrorCodes::LOGICAL_ERROR);
}
while (!in.eof())
in.ignore();
if (in.count() != 3)
{
s << "Failed!, Incorrect final count from underlying buffer: " << in.count() << ", expected: 3";
throw Exception(s.str(), ErrorCodes::LOGICAL_ERROR);
}
}
{
std::string src = "abc";
ReadBuffer in(src.data(), src.size(), 0);
{
LimitReadBuffer limit_in(in, 1, false);
char x;
readChar(x, limit_in);
if (limit_in.count() != 1)
{
s << "Failed!, Incorrect count: " << limit_in.count() << ", expected: " << 1;
throw Exception(s.str(), ErrorCodes::LOGICAL_ERROR);
}
}
if (in.count() != 1)
{
s << "Failed!, Incorrect final count from underlying buffer: " << in.count() << ", expected: 1";
throw Exception(s.str(), ErrorCodes::LOGICAL_ERROR);
}
}
return 0;
}
catch (const DB::Exception & e)
{
std::cerr << e.what() << ", " << e.displayText() << std::endl;
return 1;
}