2017-03-22 22:53:30 +08:00
|
|
|
#include "bolt_common.hpp"
|
|
|
|
|
2017-04-06 20:30:04 +08:00
|
|
|
#include "communication/bolt/v1/encoder/chunked_encoder_buffer.hpp"
|
2017-03-22 22:53:30 +08:00
|
|
|
#include "communication/bolt/v1/encoder/encoder.hpp"
|
|
|
|
#include "communication/bolt/v1/encoder/result_stream.hpp"
|
2017-04-10 18:22:48 +08:00
|
|
|
#include "query/typed_value.hpp"
|
|
|
|
|
|
|
|
using query::TypedValue;
|
2017-03-22 22:53:30 +08:00
|
|
|
|
2018-03-23 23:32:17 +08:00
|
|
|
using BufferT = communication::bolt::ChunkedEncoderBuffer<TestOutputStream>;
|
2017-03-28 18:42:04 +08:00
|
|
|
using EncoderT = communication::bolt::Encoder<BufferT>;
|
|
|
|
using ResultStreamT = communication::bolt::ResultStream<EncoderT>;
|
|
|
|
|
|
|
|
const uint8_t header_output[] =
|
|
|
|
"\x00\x29\xB1\x70\xA1\x86\x66\x69\x65\x6C\x64\x73\x9A\x82\x61\x61\x82\x62"
|
|
|
|
"\x62\x82\x63\x63\x82\x64\x64\x82\x65\x65\x82\x66\x66\x82\x67\x67\x82\x68"
|
|
|
|
"\x68\x82\x69\x69\x82\x6A\x6A\x00\x00";
|
|
|
|
const uint8_t result_output[] =
|
|
|
|
"\x00\x0A\xB1\x71\x92\x05\x85\x68\x65\x6C\x6C\x6F\x00\x00";
|
|
|
|
const uint8_t summary_output[] =
|
|
|
|
"\x00\x0C\xB1\x70\xA1\x87\x63\x68\x61\x6E\x67\x65\x64\x0A\x00\x00";
|
2017-03-22 22:53:30 +08:00
|
|
|
|
|
|
|
TEST(Bolt, ResultStream) {
|
2018-03-23 23:32:17 +08:00
|
|
|
TestOutputStream output_stream;
|
|
|
|
BufferT buffer(output_stream);
|
2017-03-28 18:42:04 +08:00
|
|
|
EncoderT encoder(buffer);
|
|
|
|
ResultStreamT result_stream(encoder);
|
2018-03-23 23:32:17 +08:00
|
|
|
std::vector<uint8_t> &output = output_stream.output;
|
2017-03-22 22:53:30 +08:00
|
|
|
|
|
|
|
std::vector<std::string> headers;
|
2017-03-28 18:42:04 +08:00
|
|
|
for (int i = 0; i < 10; ++i)
|
|
|
|
headers.push_back(std::string(2, (char)('a' + i)));
|
2017-03-22 22:53:30 +08:00
|
|
|
|
2017-04-15 21:14:12 +08:00
|
|
|
result_stream.Header(headers);
|
|
|
|
buffer.FlushFirstChunk();
|
2017-03-28 18:42:04 +08:00
|
|
|
PrintOutput(output);
|
|
|
|
CheckOutput(output, header_output, 45);
|
2017-03-22 22:53:30 +08:00
|
|
|
|
2017-03-28 18:42:04 +08:00
|
|
|
std::vector<TypedValue> result{TypedValue(5),
|
|
|
|
TypedValue(std::string("hello"))};
|
2017-03-22 22:53:30 +08:00
|
|
|
result_stream.Result(result);
|
2017-03-28 18:42:04 +08:00
|
|
|
buffer.Flush();
|
|
|
|
PrintOutput(output);
|
|
|
|
CheckOutput(output, result_output, 14);
|
2017-03-22 22:53:30 +08:00
|
|
|
|
|
|
|
std::map<std::string, TypedValue> summary;
|
|
|
|
summary.insert(std::make_pair(std::string("changed"), TypedValue(10)));
|
|
|
|
result_stream.Summary(summary);
|
2017-03-28 18:42:04 +08:00
|
|
|
buffer.Flush();
|
|
|
|
PrintOutput(output);
|
|
|
|
CheckOutput(output, summary_output, 16);
|
2017-03-22 22:53:30 +08:00
|
|
|
}
|
|
|
|
|
2017-03-28 18:42:04 +08:00
|
|
|
int main(int argc, char **argv) {
|
2017-06-21 17:29:13 +08:00
|
|
|
google::InitGoogleLogging(argv[0]);
|
2017-03-22 22:53:30 +08:00
|
|
|
::testing::InitGoogleTest(&argc, argv);
|
|
|
|
return RUN_ALL_TESTS();
|
|
|
|
}
|