2017-08-15 20:17:50 +00:00
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
#include <IO/LimitReadBuffer.h>
|
|
|
|
#include <IO/copyData.h>
|
|
|
|
#include <IO/WriteBufferFromString.h>
|
|
|
|
#include <IO/ReadHelpers.h>
|
|
|
|
|
|
|
|
|
2017-12-01 18:36:55 +00:00
|
|
|
int main(int, char **)
|
|
|
|
try
|
2017-08-15 20:17:50 +00:00
|
|
|
{
|
2017-12-01 18:36:55 +00:00
|
|
|
using namespace DB;
|
2017-08-15 20:17:50 +00:00
|
|
|
|
2017-12-01 18:36:55 +00:00
|
|
|
std::stringstream s;
|
2017-08-15 20:17:50 +00:00
|
|
|
|
2017-12-01 18:36:55 +00:00
|
|
|
{
|
|
|
|
std::string src = "1";
|
2017-08-15 20:17:50 +00:00
|
|
|
|
2017-12-01 18:36:55 +00:00
|
|
|
std::string dst;
|
2017-08-15 20:17:50 +00:00
|
|
|
|
2018-09-02 03:00:04 +00:00
|
|
|
ReadBuffer in(src.data(), src.size(), 0);
|
2017-08-15 20:17:50 +00:00
|
|
|
|
2018-08-20 02:23:35 +00:00
|
|
|
LimitReadBuffer limit_in(in, 1, false);
|
2017-08-15 20:17:50 +00:00
|
|
|
|
2017-12-01 18:36:55 +00:00
|
|
|
{
|
|
|
|
WriteBufferFromString out(dst);
|
2017-08-15 20:17:50 +00:00
|
|
|
|
2017-12-01 18:36:55 +00:00
|
|
|
copyData(limit_in, out);
|
2017-08-15 20:17:50 +00:00
|
|
|
}
|
|
|
|
|
2017-12-01 18:36:55 +00:00
|
|
|
if (limit_in.count() != 1)
|
|
|
|
{
|
|
|
|
s << "Failed!, incorrect count(): " << limit_in.count();
|
|
|
|
throw Exception(s.str());
|
|
|
|
}
|
2017-08-15 20:17:50 +00:00
|
|
|
|
2017-12-01 18:36:55 +00:00
|
|
|
if (in.count() != limit_in.count())
|
|
|
|
{
|
|
|
|
s << "Failed!, incorrect underlying buffer's count(): " << in.count();
|
|
|
|
throw Exception(s.str());
|
|
|
|
}
|
|
|
|
if (src != dst)
|
|
|
|
{
|
|
|
|
s << "Failed!, incorrect destination value, read: " << dst << ", expected: " << src;
|
|
|
|
throw Exception(s.str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
{
|
|
|
|
std::string src = "abc";
|
2018-09-02 03:00:04 +00:00
|
|
|
ReadBuffer in(src.data(), src.size(), 0);
|
2017-08-15 20:17:50 +00:00
|
|
|
|
2017-12-01 18:36:55 +00:00
|
|
|
std::string dst;
|
2017-08-15 20:17:50 +00:00
|
|
|
|
2017-12-01 18:36:55 +00:00
|
|
|
{
|
|
|
|
WriteBufferFromString out(dst);
|
2017-08-15 20:17:50 +00:00
|
|
|
|
2017-12-01 18:36:55 +00:00
|
|
|
char x;
|
|
|
|
readChar(x, in);
|
2017-08-15 20:17:50 +00:00
|
|
|
|
2018-08-20 02:23:35 +00:00
|
|
|
LimitReadBuffer limit_in(in, 1, false);
|
2017-08-15 20:17:50 +00:00
|
|
|
|
2017-12-01 18:36:55 +00:00
|
|
|
copyData(limit_in, out);
|
2017-08-15 20:17:50 +00:00
|
|
|
|
|
|
|
|
2017-12-01 18:36:55 +00:00
|
|
|
if (in.count() != 2)
|
2017-08-15 20:17:50 +00:00
|
|
|
{
|
2017-12-01 18:36:55 +00:00
|
|
|
s << "Failed!, Incorrect underlying buffer's count: " << in.count() << ", expected: " << 2;
|
|
|
|
throw Exception(s.str());
|
2017-08-15 20:17:50 +00:00
|
|
|
}
|
|
|
|
|
2017-12-01 18:36:55 +00:00
|
|
|
if (limit_in.count() != 1)
|
2017-08-15 20:17:50 +00:00
|
|
|
{
|
2017-12-01 18:36:55 +00:00
|
|
|
s << "Failed!, Incorrect count: " << limit_in.count() << ", expected: " << 1;
|
|
|
|
throw Exception(s.str());
|
2017-08-15 20:17:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-01 18:36:55 +00:00
|
|
|
if (dst != "b")
|
2017-08-15 20:17:50 +00:00
|
|
|
{
|
2017-12-01 18:36:55 +00:00
|
|
|
s << "Failed!, Incorrect destination value: " << dst << ", expected 'b'";
|
|
|
|
throw Exception(dst);
|
|
|
|
}
|
2017-08-15 20:17:50 +00:00
|
|
|
|
2017-12-01 18:36:55 +00:00
|
|
|
char y;
|
|
|
|
readChar(y, in);
|
|
|
|
if (y != 'c')
|
|
|
|
{
|
|
|
|
s << "Failed!, Read incorrect value from underlying buffer: " << y << ", expected 'c'";
|
|
|
|
throw Exception(s.str());
|
|
|
|
}
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
}
|
2017-08-15 20:17:50 +00:00
|
|
|
|
2017-12-01 18:36:55 +00:00
|
|
|
{
|
|
|
|
std::string src = "abc";
|
2018-09-02 03:00:04 +00:00
|
|
|
ReadBuffer in(src.data(), src.size(), 0);
|
2017-08-15 20:17:50 +00:00
|
|
|
|
2017-12-01 18:36:55 +00:00
|
|
|
{
|
2018-08-20 02:23:35 +00:00
|
|
|
LimitReadBuffer limit_in(in, 1, false);
|
2017-08-15 20:17:50 +00:00
|
|
|
|
2017-12-01 18:36:55 +00:00
|
|
|
char x;
|
|
|
|
readChar(x, limit_in);
|
|
|
|
|
|
|
|
if (limit_in.count() != 1)
|
2017-08-15 20:17:50 +00:00
|
|
|
{
|
2017-12-01 18:36:55 +00:00
|
|
|
s << "Failed!, Incorrect count: " << limit_in.count() << ", expected: " << 1;
|
|
|
|
throw Exception(s.str());
|
2017-08-15 20:17:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-01 18:36:55 +00:00
|
|
|
if (in.count() != 1)
|
|
|
|
{
|
|
|
|
s << "Failed!, Incorrect final count from underlying buffer: " << in.count() << ", expected: 1";
|
|
|
|
throw Exception(s.str());
|
|
|
|
}
|
2017-08-15 20:17:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2017-12-01 18:36:55 +00:00
|
|
|
catch (const DB::Exception & e)
|
|
|
|
{
|
|
|
|
std::cerr << e.what() << ", " << e.displayText() << std::endl;
|
|
|
|
return 1;
|
|
|
|
}
|