MCPcopy Create free account
hub / github.com/apache/arrow / TEST

Function TEST

cpp/src/arrow/ipc/message_internal_test.cc:53–91  ·  view source on GitHub ↗

GH-40361: Test that Flatbuffer serialization matches a known output byte-for-byte. Our Flatbuffers code should not depend on argument evaluation order as it's undefined (https://en.cppreference.com/w/cpp/language/eval_order) and may lead to unnecessary platform- or toolchain-specific differences in serialization.

Source from the content-addressed store, hash-verified

51// lead to unnecessary platform- or toolchain-specific differences in
52// serialization.
53TEST(TestMessageInternal, TestByteIdentical) {
54 DictionaryFieldMapper mapper;
55
56 // Create a simple Schema with just two metadata KVPs
57 auto f0 = field("f0", int64());
58 auto f1 = field("f1", int64());
59 std::vector<std::shared_ptr<Field>> fields = {f0, f1};
60 std::shared_ptr<KeyValueMetadata> metadata =
61 KeyValueMetadata::Make({"key_1", "key_2"}, {"key_1_value", "key_2_value"});
62 auto schema = ::arrow::schema({f0}, Endianness::Little, metadata);
63
64 // Serialize the Schema to a Buffer
65 ASSERT_OK_AND_ASSIGN(auto out_buffer,
66 WriteSchemaMessage(*schema, mapper, IpcWriteOptions::Defaults()));
67
68 // This is example output from macOS+ARM+LLVM
69 const uint8_t expected[] = {
70 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x00, 0x0E, 0x00, 0x06, 0x00, 0x05, 0x00,
71 0x08, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x01, 0x04, 0x00, 0x10, 0x00, 0x00, 0x00,
72 0x00, 0x00, 0x0A, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x04, 0x00, 0x08, 0x00, 0x0A, 0x00,
73 0x00, 0x00, 0x6C, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
74 0x38, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xD8, 0xFF, 0xFF, 0xFF, 0x18, 0x00,
75 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0B, 0x00, 0x00, 0x00, 0x6B, 0x65, 0x79, 0x5F,
76 0x32, 0x5F, 0x76, 0x61, 0x6C, 0x75, 0x65, 0x00, 0x05, 0x00, 0x00, 0x00, 0x6B, 0x65,
77 0x79, 0x5F, 0x32, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0C, 0x00, 0x04, 0x00, 0x08, 0x00,
78 0x08, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0B, 0x00,
79 0x00, 0x00, 0x6B, 0x65, 0x79, 0x5F, 0x31, 0x5F, 0x76, 0x61, 0x6C, 0x75, 0x65, 0x00,
80 0x05, 0x00, 0x00, 0x00, 0x6B, 0x65, 0x79, 0x5F, 0x31, 0x00, 0x00, 0x00, 0x01, 0x00,
81 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x10, 0x00, 0x14, 0x00, 0x08, 0x00, 0x06, 0x00,
82 0x07, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x10, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,
83 0x01, 0x02, 0x10, 0x00, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
84 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x66, 0x30, 0x00, 0x00, 0x08, 0x00,
85 0x0C, 0x00, 0x08, 0x00, 0x07, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
86 0x40, 0x00, 0x00, 0x00};
87
88 Buffer expected_buffer(expected, sizeof(expected));
89
90 AssertBufferEqual(expected_buffer, *out_buffer);
91}
92
93TEST(TestMessageInternal, TestEndiannessRoundtrip) {
94 DictionaryFieldMapper mapper;

Callers

nothing calls this directly

Calls 4

AssertBufferEqualFunction · 0.85
schemaFunction · 0.70
fieldFunction · 0.50
MakeFunction · 0.50

Tested by

no test coverage detected