Skip to content

Commit 66de5de

Browse files
committed
- Adding UTF-8 tests for string variable-sized buffers
1 parent 82530a4 commit 66de5de

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

src/processing/typed_buffer_values_test.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,3 +501,46 @@ TEST(TypedBufferValuesTest, StringVariableSized_EmptyStringsMixedWithNonEmpty) {
501501
EXPECT_EQ(collected[6], "bravo");
502502
EXPECT_EQ(collected[7], "charlie");
503503
}
504+
505+
TEST(TypedBufferValuesTest, StringVariableSized_UTF8_ReadBack) {
506+
// Variable-sized strings with UTF-8 content
507+
std::vector<uint8_t> bytes;
508+
509+
// "Привет" (Russian, 12 bytes)
510+
std::string russian = "Привет";
511+
append_u32_le(bytes, static_cast<uint32_t>(russian.size()));
512+
bytes.insert(bytes.end(), russian.begin(), russian.end());
513+
514+
// "مرحبا" (Arabic, 10 bytes)
515+
std::string arabic = "مرحبا";
516+
append_u32_le(bytes, static_cast<uint32_t>(arabic.size()));
517+
bytes.insert(bytes.end(), arabic.begin(), arabic.end());
518+
519+
// "🎉🎊🎈" (Emojis, 12 bytes)
520+
std::string emojis = "🎉🎊🎈";
521+
append_u32_le(bytes, static_cast<uint32_t>(emojis.size()));
522+
bytes.insert(bytes.end(), emojis.begin(), emojis.end());
523+
524+
TypedBufferStringVariableSized buffer{tcb::span<const uint8_t>(bytes)};
525+
526+
EXPECT_EQ(buffer.GetElement(0), "Привет");
527+
EXPECT_EQ(buffer.GetElement(1), "مرحبا");
528+
EXPECT_EQ(buffer.GetElement(2), "🎉🎊🎈");
529+
}
530+
531+
TEST(TypedBufferValuesTest, StringVariableSized_UTF8_WriteRoundTrip) {
532+
TypedBufferStringVariableSized writer(4u, 256u, true);
533+
534+
writer.SetElement(0, std::string_view("Héllo Wörld"));
535+
writer.SetElement(1, std::string_view("中文测试"));
536+
writer.SetElement(2, std::string_view("Emoji: 🚀🌟💻"));
537+
writer.SetElement(3, std::string_view("Ελληνικά"));
538+
539+
std::vector<uint8_t> finalized = writer.FinalizeAndTakeBuffer();
540+
TypedBufferStringVariableSized reader{tcb::span<const uint8_t>(finalized)};
541+
542+
EXPECT_EQ(reader.GetElement(0), "Héllo Wörld");
543+
EXPECT_EQ(reader.GetElement(1), "中文测试");
544+
EXPECT_EQ(reader.GetElement(2), "Emoji: 🚀🌟💻");
545+
EXPECT_EQ(reader.GetElement(3), "Ελληνικά");
546+
}

0 commit comments

Comments
 (0)