Database System 0.1.0
Advanced C++20 Database System with Multi-Backend Support
Loading...
Searching...
No Matches
test_protocol_serializer.cpp File Reference
#include <gtest/gtest.h>
#include <cstdint>
#include <string>
#include <vector>
#include <map>
#include "database/protocol/database_protocol.h"
Include dependency graph for test_protocol_serializer.cpp:

Go to the source code of this file.

Classes

class  MessageHeaderTest
 
class  ConnectProtocolTest
 
class  QueryProtocolTest
 
class  TransactionProtocolTest
 
class  ErrorProtocolTest
 
class  SerializerEdgeCaseTest
 

Functions

 TEST_F (MessageHeaderTest, DefaultMagicAndVersion)
 
 TEST_F (MessageHeaderTest, InvalidMagic)
 
 TEST_F (MessageHeaderTest, InvalidVersion)
 
 TEST_F (MessageHeaderTest, SerializeDeserializeRoundTrip)
 
 TEST_F (MessageHeaderTest, DeserializeHeaderTooSmall)
 
 TEST_F (MessageHeaderTest, DeserializeInvalidMagicReturnsError)
 
 TEST_F (MessageHeaderTest, AllMessageTypes)
 
 TEST_F (MessageHeaderTest, LargeRequestIdAndPayload)
 
 TEST_F (ConnectProtocolTest, ConnectRequestRoundTrip)
 
 TEST_F (ConnectProtocolTest, ConnectRequestEmptyOptions)
 
 TEST_F (ConnectProtocolTest, ConnectRequestTooSmall)
 
 TEST_F (ConnectProtocolTest, ConnectResponseSuccessRoundTrip)
 
 TEST_F (ConnectProtocolTest, ConnectResponseFailureRoundTrip)
 
 TEST_F (ConnectProtocolTest, ConnectResponseEmptyData)
 
 TEST_F (QueryProtocolTest, QueryRequestSelectRoundTrip)
 
 TEST_F (QueryProtocolTest, QueryRequestInsertWithMultipleParams)
 
 TEST_F (QueryProtocolTest, QueryRequestNoParameters)
 
 TEST_F (QueryProtocolTest, QueryRequestAllOperationTypes)
 
 TEST_F (QueryProtocolTest, QueryRequestSpecialCharacters)
 
 TEST_F (QueryProtocolTest, QueryRequestEmptyData)
 
 TEST_F (QueryProtocolTest, QueryResponseSuccessWithRows)
 
 TEST_F (QueryProtocolTest, QueryResponseInsertResult)
 
 TEST_F (QueryProtocolTest, QueryResponseFailure)
 
 TEST_F (QueryProtocolTest, QueryResponseEmptyData)
 
 TEST_F (QueryProtocolTest, QueryResponseLargePayload)
 
 TEST_F (TransactionProtocolTest, BeginTransactionRoundTrip)
 
 TEST_F (TransactionProtocolTest, CommitTransactionRoundTrip)
 
 TEST_F (TransactionProtocolTest, RollbackTransactionRoundTrip)
 
 TEST_F (TransactionProtocolTest, TransactionRequestTooSmall)
 
 TEST_F (TransactionProtocolTest, TransactionResponseSuccessRoundTrip)
 
 TEST_F (TransactionProtocolTest, TransactionResponseFailureRoundTrip)
 
 TEST_F (TransactionProtocolTest, TransactionResponseEmptyData)
 
 TEST_F (ErrorProtocolTest, ErrorResponseRoundTrip)
 
 TEST_F (ErrorProtocolTest, ErrorResponseNegativeCode)
 
 TEST_F (ErrorProtocolTest, ErrorResponseTooSmall)
 
 TEST_F (SerializerEdgeCaseTest, EmptyStringFields)
 
 TEST_F (SerializerEdgeCaseTest, LongStringPreserved)
 
 TEST_F (SerializerEdgeCaseTest, UnicodeStringPreserved)
 
 TEST_F (SerializerEdgeCaseTest, ManyOptionsMapPreserved)
 
 TEST_F (SerializerEdgeCaseTest, QueryRequestManyParameters)
 
 TEST_F (SerializerEdgeCaseTest, HeaderZeroRequestId)
 

Function Documentation

◆ TEST_F() [1/41]

TEST_F ( ConnectProtocolTest ,
ConnectRequestEmptyOptions  )

Definition at line 146 of file test_protocol_serializer.cpp.

146 {
147 connect_request original;
148 original.database_type = "sqlite";
149 original.connection_string = "file:test.db";
150
151 auto bytes = protocol_serializer::serialize(original);
153 ASSERT_TRUE(result.is_ok());
154
155 auto recovered = result.value();
156 EXPECT_EQ(recovered.database_type, "sqlite");
157 EXPECT_EQ(recovered.connection_string, "file:test.db");
158 EXPECT_TRUE(recovered.options.empty());
159}
static kcenon::common::Result< connect_request > deserialize_connect_request(const std::vector< uint8_t > &data)
Deserialize connect request.
static std::vector< uint8_t > serialize(const connect_request &request)
Serialize connect request.
#define ASSERT_TRUE(condition, message)

References ASSERT_TRUE, database::protocol::connect_request::connection_string, database::protocol::connect_request::database_type, database::protocol::protocol_serializer::deserialize_connect_request(), and database::protocol::protocol_serializer::serialize().

Here is the call graph for this function:

◆ TEST_F() [2/41]

TEST_F ( ConnectProtocolTest ,
ConnectRequestRoundTrip  )

Definition at line 126 of file test_protocol_serializer.cpp.

126 {
127 connect_request original;
128 original.database_type = "postgresql";
129 original.connection_string = "host=localhost port=5432 dbname=testdb";
130 original.options = {{"timeout", "30"}, {"ssl", "true"}};
131
132 auto bytes = protocol_serializer::serialize(original);
133 EXPECT_FALSE(bytes.empty());
134
136 ASSERT_TRUE(result.is_ok());
137
138 auto recovered = result.value();
139 EXPECT_EQ(recovered.database_type, original.database_type);
140 EXPECT_EQ(recovered.connection_string, original.connection_string);
141 EXPECT_EQ(recovered.options.size(), original.options.size());
142 EXPECT_EQ(recovered.options.at("timeout"), "30");
143 EXPECT_EQ(recovered.options.at("ssl"), "true");
144}
std::map< std::string, std::string > options

References ASSERT_TRUE, database::protocol::connect_request::connection_string, database::protocol::connect_request::database_type, database::protocol::protocol_serializer::deserialize_connect_request(), database::protocol::connect_request::options, and database::protocol::protocol_serializer::serialize().

Here is the call graph for this function:

◆ TEST_F() [3/41]

TEST_F ( ConnectProtocolTest ,
ConnectRequestTooSmall  )

Definition at line 161 of file test_protocol_serializer.cpp.

161 {
162 std::vector<uint8_t> data = {0x01, 0x02};
164 EXPECT_TRUE(result.is_err());
165}

References database::protocol::protocol_serializer::deserialize_connect_request().

Here is the call graph for this function:

◆ TEST_F() [4/41]

TEST_F ( ConnectProtocolTest ,
ConnectResponseEmptyData  )

Definition at line 199 of file test_protocol_serializer.cpp.

199 {
200 std::vector<uint8_t> data;
202 EXPECT_TRUE(result.is_err());
203}
static kcenon::common::Result< connect_response > deserialize_connect_response(const std::vector< uint8_t > &data)
Deserialize connect response.

References database::protocol::protocol_serializer::deserialize_connect_response().

Here is the call graph for this function:

◆ TEST_F() [5/41]

TEST_F ( ConnectProtocolTest ,
ConnectResponseFailureRoundTrip  )

Definition at line 183 of file test_protocol_serializer.cpp.

183 {
184 connect_response original;
185 original.success = false;
186 original.session_id = "";
187 original.error_message = "Authentication failed: invalid credentials";
188
189 auto bytes = protocol_serializer::serialize(original);
191 ASSERT_TRUE(result.is_ok());
192
193 auto recovered = result.value();
194 EXPECT_FALSE(recovered.success);
195 EXPECT_TRUE(recovered.session_id.empty());
196 EXPECT_EQ(recovered.error_message, "Authentication failed: invalid credentials");
197}

References ASSERT_TRUE, database::protocol::protocol_serializer::deserialize_connect_response(), database::protocol::connect_response::error_message, database::protocol::protocol_serializer::serialize(), database::protocol::connect_response::session_id, and database::protocol::connect_response::success.

Here is the call graph for this function:

◆ TEST_F() [6/41]

TEST_F ( ConnectProtocolTest ,
ConnectResponseSuccessRoundTrip  )

Definition at line 167 of file test_protocol_serializer.cpp.

167 {
168 connect_response original;
169 original.success = true;
170 original.session_id = "sess-abc-123-def-456";
171 original.error_message = "";
172
173 auto bytes = protocol_serializer::serialize(original);
175 ASSERT_TRUE(result.is_ok());
176
177 auto recovered = result.value();
178 EXPECT_TRUE(recovered.success);
179 EXPECT_EQ(recovered.session_id, "sess-abc-123-def-456");
180 EXPECT_TRUE(recovered.error_message.empty());
181}

References ASSERT_TRUE, database::protocol::protocol_serializer::deserialize_connect_response(), database::protocol::connect_response::error_message, database::protocol::protocol_serializer::serialize(), database::protocol::connect_response::session_id, and database::protocol::connect_response::success.

Here is the call graph for this function:

◆ TEST_F() [7/41]

TEST_F ( ErrorProtocolTest ,
ErrorResponseNegativeCode  )

Definition at line 493 of file test_protocol_serializer.cpp.

493 {
494 error_response original;
495 original.error_code = -1;
496 original.error_message = "Internal server error";
497 original.error_context = "";
498
499 auto bytes = protocol_serializer::serialize(original);
501 ASSERT_TRUE(result.is_ok());
502
503 auto recovered = result.value();
504 EXPECT_EQ(recovered.error_code, -1);
505 EXPECT_EQ(recovered.error_message, "Internal server error");
506 EXPECT_TRUE(recovered.error_context.empty());
507}
static kcenon::common::Result< error_response > deserialize_error_response(const std::vector< uint8_t > &data)
Deserialize error response.

References ASSERT_TRUE, database::protocol::protocol_serializer::deserialize_error_response(), database::protocol::error_response::error_code, database::protocol::error_response::error_context, database::protocol::error_response::error_message, and database::protocol::protocol_serializer::serialize().

Here is the call graph for this function:

◆ TEST_F() [8/41]

TEST_F ( ErrorProtocolTest ,
ErrorResponseRoundTrip  )

Definition at line 477 of file test_protocol_serializer.cpp.

477 {
478 error_response original;
479 original.error_code = 1001;
480 original.error_message = "Table not found";
481 original.error_context = "SELECT * FROM nonexistent_table";
482
483 auto bytes = protocol_serializer::serialize(original);
485 ASSERT_TRUE(result.is_ok());
486
487 auto recovered = result.value();
488 EXPECT_EQ(recovered.error_code, 1001);
489 EXPECT_EQ(recovered.error_message, "Table not found");
490 EXPECT_EQ(recovered.error_context, "SELECT * FROM nonexistent_table");
491}

References ASSERT_TRUE, database::protocol::protocol_serializer::deserialize_error_response(), database::protocol::error_response::error_code, database::protocol::error_response::error_context, database::protocol::error_response::error_message, and database::protocol::protocol_serializer::serialize().

Here is the call graph for this function:

◆ TEST_F() [9/41]

TEST_F ( ErrorProtocolTest ,
ErrorResponseTooSmall  )

Definition at line 509 of file test_protocol_serializer.cpp.

509 {
510 std::vector<uint8_t> data = {0x01, 0x02};
512 EXPECT_TRUE(result.is_err());
513}

References database::protocol::protocol_serializer::deserialize_error_response().

Here is the call graph for this function:

◆ TEST_F() [10/41]

TEST_F ( MessageHeaderTest ,
AllMessageTypes  )

Definition at line 83 of file test_protocol_serializer.cpp.

83 {
84 const message_type types[] = {
85 message_type::CONNECT_REQUEST, message_type::CONNECT_RESPONSE,
86 message_type::DISCONNECT, message_type::PING, message_type::PONG,
87 message_type::QUERY_REQUEST, message_type::QUERY_RESPONSE,
88 message_type::BEGIN_TRANSACTION, message_type::COMMIT_TRANSACTION,
89 message_type::ROLLBACK_TRANSACTION, message_type::TRANSACTION_RESPONSE,
90 message_type::PREPARE_STATEMENT, message_type::EXECUTE_PREPARED,
91 message_type::CLOSE_PREPARED, message_type::ERROR_RESPONSE
92 };
93
94 for (auto type : types) {
95 message_header header;
96 header.type = type;
97 header.request_id = 42;
98 header.payload_size = 0;
99
100 auto bytes = protocol_serializer::serialize_header(header);
101 auto result = protocol_serializer::deserialize_header(bytes);
102 ASSERT_TRUE(result.is_ok()) << "Failed for message_type " << static_cast<uint16_t>(type);
103 EXPECT_EQ(result.value().type, type);
104 }
105}
static kcenon::common::Result< message_header > deserialize_header(const std::vector< uint8_t > &data)
Deserialize message header from bytes.
static std::vector< uint8_t > serialize_header(const message_header &header)
Serialize message header to bytes.
message_type
Database protocol message types.
Common header for all protocol messages.

References ASSERT_TRUE, database::protocol::protocol_serializer::deserialize_header(), database::protocol::message_header::payload_size, database::protocol::message_header::request_id, database::protocol::protocol_serializer::serialize_header(), and database::protocol::message_header::type.

Here is the call graph for this function:

◆ TEST_F() [11/41]

◆ TEST_F() [12/41]

TEST_F ( MessageHeaderTest ,
DeserializeHeaderTooSmall  )

Definition at line 65 of file test_protocol_serializer.cpp.

65 {
66 std::vector<uint8_t> data = {0x01, 0x02, 0x03};
68 EXPECT_TRUE(result.is_err());
69}

References database::protocol::protocol_serializer::deserialize_header().

Here is the call graph for this function:

◆ TEST_F() [13/41]

TEST_F ( MessageHeaderTest ,
DeserializeInvalidMagicReturnsError  )

Definition at line 71 of file test_protocol_serializer.cpp.

71 {
72 // Build a 20-byte buffer with wrong magic
73 std::vector<uint8_t> data(20, 0);
74 // Write garbage magic (little-endian)
75 data[0] = 0xEF; data[1] = 0xBE; data[2] = 0xAD; data[3] = 0xDE;
76 // Write valid version (1, little-endian)
77 data[4] = 0x01; data[5] = 0x00;
78
80 EXPECT_TRUE(result.is_err());
81}

References database::protocol::protocol_serializer::deserialize_header().

Here is the call graph for this function:

◆ TEST_F() [14/41]

TEST_F ( MessageHeaderTest ,
InvalidMagic  )

Definition at line 33 of file test_protocol_serializer.cpp.

33 {
34 message_header header;
35 header.magic = 0xDEADBEEF;
36 EXPECT_FALSE(header.is_valid());
37}

References database::protocol::message_header::is_valid(), and database::protocol::message_header::magic.

Here is the call graph for this function:

◆ TEST_F() [15/41]

TEST_F ( MessageHeaderTest ,
InvalidVersion  )

Definition at line 39 of file test_protocol_serializer.cpp.

39 {
40 message_header header;
41 header.version = 99;
42 EXPECT_FALSE(header.is_valid());
43}

References database::protocol::message_header::is_valid(), and database::protocol::message_header::version.

Here is the call graph for this function:

◆ TEST_F() [16/41]

TEST_F ( MessageHeaderTest ,
LargeRequestIdAndPayload  )

Definition at line 107 of file test_protocol_serializer.cpp.

107 {
108 message_header header;
109 header.type = message_type::QUERY_REQUEST;
110 header.request_id = UINT64_MAX;
111 header.payload_size = UINT32_MAX;
112
113 auto bytes = protocol_serializer::serialize_header(header);
114 auto result = protocol_serializer::deserialize_header(bytes);
115 ASSERT_TRUE(result.is_ok());
116 EXPECT_EQ(result.value().request_id, UINT64_MAX);
117 EXPECT_EQ(result.value().payload_size, UINT32_MAX);
118}

References ASSERT_TRUE, database::protocol::protocol_serializer::deserialize_header(), database::protocol::message_header::payload_size, database::protocol::message_header::request_id, database::protocol::protocol_serializer::serialize_header(), and database::protocol::message_header::type.

Here is the call graph for this function:

◆ TEST_F() [17/41]

TEST_F ( MessageHeaderTest ,
SerializeDeserializeRoundTrip  )

Definition at line 45 of file test_protocol_serializer.cpp.

45 {
46 message_header original;
47 original.type = message_type::QUERY_REQUEST;
48 original.request_id = 12345;
49 original.payload_size = 100;
50
51 auto bytes = protocol_serializer::serialize_header(original);
52 EXPECT_EQ(bytes.size(), 20u);
53
54 auto result = protocol_serializer::deserialize_header(bytes);
55 ASSERT_TRUE(result.is_ok());
56
57 auto recovered = result.value();
58 EXPECT_EQ(recovered.magic, original.magic);
59 EXPECT_EQ(recovered.version, original.version);
60 EXPECT_EQ(recovered.type, original.type);
61 EXPECT_EQ(recovered.request_id, original.request_id);
62 EXPECT_EQ(recovered.payload_size, original.payload_size);
63}

References ASSERT_TRUE, database::protocol::protocol_serializer::deserialize_header(), database::protocol::message_header::magic, database::protocol::message_header::payload_size, database::protocol::message_header::request_id, database::protocol::protocol_serializer::serialize_header(), database::protocol::message_header::type, and database::protocol::message_header::version.

Here is the call graph for this function:

◆ TEST_F() [18/41]

TEST_F ( QueryProtocolTest ,
QueryRequestAllOperationTypes  )

Definition at line 260 of file test_protocol_serializer.cpp.

260 {
261 const query_operation ops[] = {
262 query_operation::SELECT, query_operation::INSERT,
263 query_operation::UPDATE, query_operation::DELETE,
264 query_operation::CREATE, query_operation::ALTER,
265 query_operation::DROP, query_operation::OTHER
266 };
267
268 for (auto op : ops) {
269 query_request original;
270 original.operation = op;
271 original.query_string = "test query";
272
273 auto bytes = protocol_serializer::serialize(original);
275 ASSERT_TRUE(result.is_ok()) << "Failed for operation " << static_cast<int>(op);
276 EXPECT_EQ(result.value().operation, op);
277 }
278}
static kcenon::common::Result< query_request > deserialize_query_request(const std::vector< uint8_t > &data)
Deserialize query request.
query_operation
Type of query operation.

References ASSERT_TRUE, database::protocol::protocol_serializer::deserialize_query_request(), database::protocol::query_request::operation, database::protocol::query_request::query_string, and database::protocol::protocol_serializer::serialize().

Here is the call graph for this function:

◆ TEST_F() [19/41]

TEST_F ( QueryProtocolTest ,
QueryRequestEmptyData  )

Definition at line 298 of file test_protocol_serializer.cpp.

298 {
299 std::vector<uint8_t> data;
301 EXPECT_TRUE(result.is_err());
302}

References database::protocol::protocol_serializer::deserialize_query_request().

Here is the call graph for this function:

◆ TEST_F() [20/41]

TEST_F ( QueryProtocolTest ,
QueryRequestInsertWithMultipleParams  )

Definition at line 228 of file test_protocol_serializer.cpp.

228 {
229 query_request original;
230 original.operation = query_operation::INSERT;
231 original.query_string = "INSERT INTO users (name, email, age) VALUES (?, ?, ?)";
232 original.parameters = {"Alice", "alice@example.com", "30"};
233
234 auto bytes = protocol_serializer::serialize(original);
236 ASSERT_TRUE(result.is_ok());
237
238 auto recovered = result.value();
239 EXPECT_EQ(recovered.operation, query_operation::INSERT);
240 ASSERT_EQ(recovered.parameters.size(), 3u);
241 EXPECT_EQ(recovered.parameters[0], "Alice");
242 EXPECT_EQ(recovered.parameters[1], "alice@example.com");
243 EXPECT_EQ(recovered.parameters[2], "30");
244}
std::vector< std::string > parameters
#define ASSERT_EQ(expected, actual, message)

References ASSERT_EQ, ASSERT_TRUE, database::protocol::protocol_serializer::deserialize_query_request(), database::protocol::query_request::operation, database::protocol::query_request::parameters, database::protocol::query_request::query_string, and database::protocol::protocol_serializer::serialize().

Here is the call graph for this function:

◆ TEST_F() [21/41]

TEST_F ( QueryProtocolTest ,
QueryRequestNoParameters  )

Definition at line 246 of file test_protocol_serializer.cpp.

246 {
247 query_request original;
248 original.operation = query_operation::CREATE;
249 original.query_string = "CREATE TABLE test (id INTEGER PRIMARY KEY)";
250
251 auto bytes = protocol_serializer::serialize(original);
253 ASSERT_TRUE(result.is_ok());
254
255 auto recovered = result.value();
256 EXPECT_EQ(recovered.operation, query_operation::CREATE);
257 EXPECT_TRUE(recovered.parameters.empty());
258}

References ASSERT_TRUE, database::protocol::protocol_serializer::deserialize_query_request(), database::protocol::query_request::operation, database::protocol::query_request::query_string, and database::protocol::protocol_serializer::serialize().

Here is the call graph for this function:

◆ TEST_F() [22/41]

TEST_F ( QueryProtocolTest ,
QueryRequestSelectRoundTrip  )

Definition at line 211 of file test_protocol_serializer.cpp.

211 {
212 query_request original;
213 original.operation = query_operation::SELECT;
214 original.query_string = "SELECT * FROM users WHERE id = ?";
215 original.parameters = {"42"};
216
217 auto bytes = protocol_serializer::serialize(original);
219 ASSERT_TRUE(result.is_ok());
220
221 auto recovered = result.value();
222 EXPECT_EQ(recovered.operation, query_operation::SELECT);
223 EXPECT_EQ(recovered.query_string, original.query_string);
224 ASSERT_EQ(recovered.parameters.size(), 1u);
225 EXPECT_EQ(recovered.parameters[0], "42");
226}

References ASSERT_EQ, ASSERT_TRUE, database::protocol::protocol_serializer::deserialize_query_request(), database::protocol::query_request::operation, database::protocol::query_request::parameters, database::protocol::query_request::query_string, and database::protocol::protocol_serializer::serialize().

Here is the call graph for this function:

◆ TEST_F() [23/41]

TEST_F ( QueryProtocolTest ,
QueryRequestSpecialCharacters  )

Definition at line 280 of file test_protocol_serializer.cpp.

280 {
281 query_request original;
282 original.operation = query_operation::SELECT;
283 original.query_string = "SELECT * FROM users WHERE name LIKE ?";
284 original.parameters = {"O'Brien", "50%", "tab\tchar", "newline\nchar"};
285
286 auto bytes = protocol_serializer::serialize(original);
288 ASSERT_TRUE(result.is_ok());
289
290 auto recovered = result.value();
291 ASSERT_EQ(recovered.parameters.size(), 4u);
292 EXPECT_EQ(recovered.parameters[0], "O'Brien");
293 EXPECT_EQ(recovered.parameters[1], "50%");
294 EXPECT_EQ(recovered.parameters[2], "tab\tchar");
295 EXPECT_EQ(recovered.parameters[3], "newline\nchar");
296}

References ASSERT_EQ, ASSERT_TRUE, database::protocol::protocol_serializer::deserialize_query_request(), database::protocol::query_request::operation, database::protocol::query_request::parameters, database::protocol::query_request::query_string, and database::protocol::protocol_serializer::serialize().

Here is the call graph for this function:

◆ TEST_F() [24/41]

TEST_F ( QueryProtocolTest ,
QueryResponseEmptyData  )

Definition at line 367 of file test_protocol_serializer.cpp.

367 {
368 std::vector<uint8_t> data;
370 EXPECT_TRUE(result.is_err());
371}
static kcenon::common::Result< query_response > deserialize_query_response(const std::vector< uint8_t > &data)
Deserialize query response.

References database::protocol::protocol_serializer::deserialize_query_response().

Here is the call graph for this function:

◆ TEST_F() [25/41]

TEST_F ( QueryProtocolTest ,
QueryResponseFailure  )

Definition at line 351 of file test_protocol_serializer.cpp.

351 {
352 query_response original;
353 original.success = false;
354 original.error_code = 1045;
355 original.error_message = "Access denied for user 'root'@'localhost'";
356
357 auto bytes = protocol_serializer::serialize(original);
359 ASSERT_TRUE(result.is_ok());
360
361 auto recovered = result.value();
362 EXPECT_FALSE(recovered.success);
363 EXPECT_EQ(recovered.error_code, 1045);
364 EXPECT_EQ(recovered.error_message, "Access denied for user 'root'@'localhost'");
365}

References ASSERT_TRUE, database::protocol::protocol_serializer::deserialize_query_response(), database::protocol::query_response::error_code, database::protocol::query_response::error_message, database::protocol::protocol_serializer::serialize(), and database::protocol::query_response::success.

Here is the call graph for this function:

◆ TEST_F() [26/41]

TEST_F ( QueryProtocolTest ,
QueryResponseInsertResult  )

Definition at line 332 of file test_protocol_serializer.cpp.

332 {
333 query_response original;
334 original.success = true;
335 original.affected_rows = 1;
336 original.last_insert_id = 42;
337 original.error_code = 0;
338
339 auto bytes = protocol_serializer::serialize(original);
341 ASSERT_TRUE(result.is_ok());
342
343 auto recovered = result.value();
344 EXPECT_TRUE(recovered.success);
345 EXPECT_EQ(recovered.affected_rows, 1u);
346 EXPECT_EQ(recovered.last_insert_id, 42u);
347 EXPECT_TRUE(recovered.column_names.empty());
348 EXPECT_TRUE(recovered.rows.empty());
349}

References database::protocol::query_response::affected_rows, ASSERT_TRUE, database::protocol::protocol_serializer::deserialize_query_response(), database::protocol::query_response::error_code, database::protocol::query_response::last_insert_id, database::protocol::protocol_serializer::serialize(), and database::protocol::query_response::success.

Here is the call graph for this function:

◆ TEST_F() [27/41]

TEST_F ( QueryProtocolTest ,
QueryResponseLargePayload  )

Definition at line 373 of file test_protocol_serializer.cpp.

373 {
374 query_response original;
375 original.success = true;
376 original.column_names = {"id", "data"};
377
378 for (int i = 0; i < 100; ++i) {
379 original.rows.push_back({
380 {"id", std::to_string(i)},
381 {"data", std::string(256, 'x')}
382 });
383 }
384
385 auto bytes = protocol_serializer::serialize(original);
387 ASSERT_TRUE(result.is_ok());
388
389 auto recovered = result.value();
390 ASSERT_EQ(recovered.rows.size(), 100u);
391 EXPECT_EQ(recovered.rows[50].at("id"), "50");
392 EXPECT_EQ(recovered.rows[50].at("data").size(), 256u);
393}
std::vector< std::map< std::string, std::string > > rows
std::vector< std::string > column_names

References ASSERT_EQ, ASSERT_TRUE, database::protocol::query_response::column_names, database::protocol::protocol_serializer::deserialize_query_response(), database::protocol::query_response::rows, database::protocol::protocol_serializer::serialize(), and database::protocol::query_response::success.

Here is the call graph for this function:

◆ TEST_F() [28/41]

TEST_F ( QueryProtocolTest ,
QueryResponseSuccessWithRows  )

Definition at line 304 of file test_protocol_serializer.cpp.

304 {
305 query_response original;
306 original.success = true;
307 original.affected_rows = 0;
308 original.last_insert_id = 0;
309 original.error_code = 0;
310 original.column_names = {"id", "name", "email"};
311 original.rows = {
312 {{"id", "1"}, {"name", "Alice"}, {"email", "alice@test.com"}},
313 {{"id", "2"}, {"name", "Bob"}, {"email", "bob@test.com"}}
314 };
315
316 auto bytes = protocol_serializer::serialize(original);
318 ASSERT_TRUE(result.is_ok());
319
320 auto recovered = result.value();
321 EXPECT_TRUE(recovered.success);
322 EXPECT_EQ(recovered.affected_rows, 0u);
323 ASSERT_EQ(recovered.column_names.size(), 3u);
324 EXPECT_EQ(recovered.column_names[0], "id");
325 EXPECT_EQ(recovered.column_names[1], "name");
326 EXPECT_EQ(recovered.column_names[2], "email");
327 ASSERT_EQ(recovered.rows.size(), 2u);
328 EXPECT_EQ(recovered.rows[0].at("name"), "Alice");
329 EXPECT_EQ(recovered.rows[1].at("email"), "bob@test.com");
330}

References database::protocol::query_response::affected_rows, ASSERT_EQ, ASSERT_TRUE, database::protocol::query_response::column_names, database::protocol::protocol_serializer::deserialize_query_response(), database::protocol::query_response::error_code, database::protocol::query_response::last_insert_id, database::protocol::query_response::rows, database::protocol::protocol_serializer::serialize(), and database::protocol::query_response::success.

Here is the call graph for this function:

◆ TEST_F() [29/41]

TEST_F ( SerializerEdgeCaseTest ,
EmptyStringFields  )

Definition at line 521 of file test_protocol_serializer.cpp.

521 {
522 connect_request original;
523 original.database_type = "";
524 original.connection_string = "";
525
526 auto bytes = protocol_serializer::serialize(original);
528 ASSERT_TRUE(result.is_ok());
529
530 auto recovered = result.value();
531 EXPECT_TRUE(recovered.database_type.empty());
532 EXPECT_TRUE(recovered.connection_string.empty());
533}

References ASSERT_TRUE, database::protocol::connect_request::connection_string, database::protocol::connect_request::database_type, database::protocol::protocol_serializer::deserialize_connect_request(), and database::protocol::protocol_serializer::serialize().

Here is the call graph for this function:

◆ TEST_F() [30/41]

TEST_F ( SerializerEdgeCaseTest ,
HeaderZeroRequestId  )

Definition at line 594 of file test_protocol_serializer.cpp.

594 {
595 message_header header;
596 header.type = message_type::PING;
597 header.request_id = 0;
598 header.payload_size = 0;
599
600 auto bytes = protocol_serializer::serialize_header(header);
601 auto result = protocol_serializer::deserialize_header(bytes);
602 ASSERT_TRUE(result.is_ok());
603 EXPECT_EQ(result.value().request_id, 0u);
604 EXPECT_EQ(result.value().payload_size, 0u);
605}

References ASSERT_TRUE, database::protocol::protocol_serializer::deserialize_header(), database::protocol::message_header::payload_size, database::protocol::message_header::request_id, database::protocol::protocol_serializer::serialize_header(), and database::protocol::message_header::type.

Here is the call graph for this function:

◆ TEST_F() [31/41]

TEST_F ( SerializerEdgeCaseTest ,
LongStringPreserved  )

Definition at line 535 of file test_protocol_serializer.cpp.

535 {
536 connect_request original;
537 original.database_type = "postgresql";
538 original.connection_string = std::string(4096, 'A');
539
540 auto bytes = protocol_serializer::serialize(original);
542 ASSERT_TRUE(result.is_ok());
543 EXPECT_EQ(result.value().connection_string.size(), 4096u);
544}

References ASSERT_TRUE, database::protocol::connect_request::connection_string, database::protocol::connect_request::database_type, database::protocol::protocol_serializer::deserialize_connect_request(), and database::protocol::protocol_serializer::serialize().

Here is the call graph for this function:

◆ TEST_F() [32/41]

TEST_F ( SerializerEdgeCaseTest ,
ManyOptionsMapPreserved  )

Definition at line 557 of file test_protocol_serializer.cpp.

557 {
558 connect_request original;
559 original.database_type = "postgresql";
560 original.connection_string = "localhost";
561
562 for (int i = 0; i < 50; ++i) {
563 original.options["key_" + std::to_string(i)] = "val_" + std::to_string(i);
564 }
565
566 auto bytes = protocol_serializer::serialize(original);
568 ASSERT_TRUE(result.is_ok());
569
570 auto recovered = result.value();
571 EXPECT_EQ(recovered.options.size(), 50u);
572 EXPECT_EQ(recovered.options.at("key_25"), "val_25");
573}

References ASSERT_TRUE, database::protocol::connect_request::connection_string, database::protocol::connect_request::database_type, database::protocol::protocol_serializer::deserialize_connect_request(), database::protocol::connect_request::options, and database::protocol::protocol_serializer::serialize().

Here is the call graph for this function:

◆ TEST_F() [33/41]

TEST_F ( SerializerEdgeCaseTest ,
QueryRequestManyParameters  )

Definition at line 575 of file test_protocol_serializer.cpp.

575 {
576 query_request original;
577 original.operation = query_operation::SELECT;
578 original.query_string = "BULK QUERY";
579
580 for (int i = 0; i < 100; ++i) {
581 original.parameters.push_back("param_" + std::to_string(i));
582 }
583
584 auto bytes = protocol_serializer::serialize(original);
586 ASSERT_TRUE(result.is_ok());
587
588 auto recovered = result.value();
589 ASSERT_EQ(recovered.parameters.size(), 100u);
590 EXPECT_EQ(recovered.parameters[0], "param_0");
591 EXPECT_EQ(recovered.parameters[99], "param_99");
592}

References ASSERT_EQ, ASSERT_TRUE, database::protocol::protocol_serializer::deserialize_query_request(), database::protocol::query_request::operation, database::protocol::query_request::parameters, database::protocol::query_request::query_string, and database::protocol::protocol_serializer::serialize().

Here is the call graph for this function:

◆ TEST_F() [34/41]

TEST_F ( SerializerEdgeCaseTest ,
UnicodeStringPreserved  )

Definition at line 546 of file test_protocol_serializer.cpp.

546 {
547 connect_request original;
548 original.database_type = "postgresql";
549 original.connection_string = "dbname=\xE4\xB8\xAD\xE6\x96\x87\xE6\xB5\x8B\xE8\xAF\x95";
550
551 auto bytes = protocol_serializer::serialize(original);
553 ASSERT_TRUE(result.is_ok());
554 EXPECT_EQ(result.value().connection_string, original.connection_string);
555}

References ASSERT_TRUE, database::protocol::connect_request::connection_string, database::protocol::connect_request::database_type, database::protocol::protocol_serializer::deserialize_connect_request(), and database::protocol::protocol_serializer::serialize().

Here is the call graph for this function:

◆ TEST_F() [35/41]

TEST_F ( TransactionProtocolTest ,
BeginTransactionRoundTrip  )

Definition at line 401 of file test_protocol_serializer.cpp.

401 {
402 transaction_request original;
403 original.operation = message_type::BEGIN_TRANSACTION;
404
405 auto bytes = protocol_serializer::serialize(original);
407 ASSERT_TRUE(result.is_ok());
408 EXPECT_EQ(result.value().operation, message_type::BEGIN_TRANSACTION);
409}
static kcenon::common::Result< transaction_request > deserialize_transaction_request(const std::vector< uint8_t > &data)
Deserialize transaction request.

References ASSERT_TRUE, database::protocol::protocol_serializer::deserialize_transaction_request(), database::protocol::transaction_request::operation, and database::protocol::protocol_serializer::serialize().

Here is the call graph for this function:

◆ TEST_F() [36/41]

TEST_F ( TransactionProtocolTest ,
CommitTransactionRoundTrip  )

Definition at line 411 of file test_protocol_serializer.cpp.

411 {
412 transaction_request original;
413 original.operation = message_type::COMMIT_TRANSACTION;
414
415 auto bytes = protocol_serializer::serialize(original);
417 ASSERT_TRUE(result.is_ok());
418 EXPECT_EQ(result.value().operation, message_type::COMMIT_TRANSACTION);
419}

References ASSERT_TRUE, database::protocol::protocol_serializer::deserialize_transaction_request(), database::protocol::transaction_request::operation, and database::protocol::protocol_serializer::serialize().

Here is the call graph for this function:

◆ TEST_F() [37/41]

TEST_F ( TransactionProtocolTest ,
RollbackTransactionRoundTrip  )

Definition at line 421 of file test_protocol_serializer.cpp.

421 {
422 transaction_request original;
423 original.operation = message_type::ROLLBACK_TRANSACTION;
424
425 auto bytes = protocol_serializer::serialize(original);
427 ASSERT_TRUE(result.is_ok());
428 EXPECT_EQ(result.value().operation, message_type::ROLLBACK_TRANSACTION);
429}

References ASSERT_TRUE, database::protocol::protocol_serializer::deserialize_transaction_request(), database::protocol::transaction_request::operation, and database::protocol::protocol_serializer::serialize().

Here is the call graph for this function:

◆ TEST_F() [38/41]

TEST_F ( TransactionProtocolTest ,
TransactionRequestTooSmall  )

Definition at line 431 of file test_protocol_serializer.cpp.

431 {
432 std::vector<uint8_t> data = {0x01};
434 EXPECT_TRUE(result.is_err());
435}

References database::protocol::protocol_serializer::deserialize_transaction_request().

Here is the call graph for this function:

◆ TEST_F() [39/41]

TEST_F ( TransactionProtocolTest ,
TransactionResponseEmptyData  )

Definition at line 465 of file test_protocol_serializer.cpp.

465 {
466 std::vector<uint8_t> data;
468 EXPECT_TRUE(result.is_err());
469}
static kcenon::common::Result< transaction_response > deserialize_transaction_response(const std::vector< uint8_t > &data)
Deserialize transaction response.

References database::protocol::protocol_serializer::deserialize_transaction_response().

Here is the call graph for this function:

◆ TEST_F() [40/41]

TEST_F ( TransactionProtocolTest ,
TransactionResponseFailureRoundTrip  )

Definition at line 451 of file test_protocol_serializer.cpp.

451 {
452 transaction_response original;
453 original.success = false;
454 original.error_message = "Deadlock detected";
455
456 auto bytes = protocol_serializer::serialize(original);
458 ASSERT_TRUE(result.is_ok());
459
460 auto recovered = result.value();
461 EXPECT_FALSE(recovered.success);
462 EXPECT_EQ(recovered.error_message, "Deadlock detected");
463}

References ASSERT_TRUE, database::protocol::protocol_serializer::deserialize_transaction_response(), database::protocol::transaction_response::error_message, database::protocol::protocol_serializer::serialize(), and database::protocol::transaction_response::success.

Here is the call graph for this function:

◆ TEST_F() [41/41]

TEST_F ( TransactionProtocolTest ,
TransactionResponseSuccessRoundTrip  )

Definition at line 437 of file test_protocol_serializer.cpp.

437 {
438 transaction_response original;
439 original.success = true;
440 original.error_message = "";
441
442 auto bytes = protocol_serializer::serialize(original);
444 ASSERT_TRUE(result.is_ok());
445
446 auto recovered = result.value();
447 EXPECT_TRUE(recovered.success);
448 EXPECT_TRUE(recovered.error_message.empty());
449}

References ASSERT_TRUE, database::protocol::protocol_serializer::deserialize_transaction_response(), database::protocol::transaction_response::error_message, database::protocol::protocol_serializer::serialize(), and database::protocol::transaction_response::success.

Here is the call graph for this function: