Skip to content

Commit 6613f78

Browse files
committed
Change way of testing
1 parent cc8065d commit 6613f78

File tree

1 file changed

+84
-1
lines changed

1 file changed

+84
-1
lines changed

tests/test_primitive_array.cpp

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,78 @@ namespace sparrow_ipc
1717
float,
1818
double>;
1919

20+
void compare_arrow_schemas(const ArrowSchema& s1, const ArrowSchema& s2)
21+
{
22+
std::string_view s1_format = (s1.format != nullptr) ? std::string_view(s1.format) : "";
23+
std::string_view s2_format = (s2.format != nullptr) ? std::string_view(s2.format) : "";
24+
CHECK_EQ(s1_format, s2_format);
25+
26+
std::string_view s1_name = (s1.name != nullptr) ? std::string_view(s1.name) : "";
27+
std::string_view s2_name = (s2.name != nullptr) ? std::string_view(s2.name) : "";
28+
CHECK_EQ(s1_name, s2_name);
29+
30+
if (s1.metadata == nullptr)
31+
{
32+
CHECK_EQ(s2.metadata, nullptr);
33+
}
34+
else
35+
{
36+
REQUIRE_NE(s2.metadata, nullptr);
37+
}
38+
39+
CHECK_EQ(s1.flags, s2.flags);
40+
CHECK_EQ(s1.n_children, s2.n_children);
41+
42+
if (s1.n_children > 0)
43+
{
44+
REQUIRE_NE(s1.children, nullptr);
45+
REQUIRE_NE(s2.children, nullptr);
46+
for (int64_t i = 0; i < s1.n_children; ++i)
47+
{
48+
REQUIRE_NE(s1.children[i], nullptr);
49+
REQUIRE_NE(s2.children[i], nullptr);
50+
compare_arrow_schemas(*s1.children[i], *s2.children[i]);
51+
}
52+
}
53+
else
54+
{
55+
CHECK_EQ(s1.children, nullptr);
56+
CHECK_EQ(s2.children, nullptr);
57+
}
58+
59+
if (s1.dictionary != nullptr)
60+
{
61+
REQUIRE_NE(s2.dictionary, nullptr);
62+
compare_arrow_schemas(*s1.dictionary, *s2.dictionary);
63+
}
64+
else
65+
{
66+
CHECK_EQ(s2.dictionary, nullptr);
67+
}
68+
}
69+
70+
void compare_arrow_arrays(const ArrowArray& lhs, const ArrowArray& rhs)
71+
{
72+
CHECK_EQ(lhs.length, rhs.length);
73+
CHECK_EQ(lhs.null_count, rhs.null_count);
74+
CHECK_EQ(lhs.offset, rhs.offset);
75+
CHECK_EQ(lhs.n_buffers, rhs.n_buffers);
76+
CHECK_EQ(lhs.n_children, rhs.n_children);
77+
CHECK_NE(lhs.buffers, rhs.buffers);
78+
CHECK_NE(lhs.private_data, rhs.private_data);
79+
for (size_t i = 0; i < static_cast<size_t>(lhs.n_buffers); ++i)
80+
{
81+
CHECK_NE(lhs.buffers[i], rhs.buffers[i]);
82+
}
83+
auto lhs_buffers = reinterpret_cast<const int8_t**>(lhs.buffers);
84+
auto rhs_buffers = reinterpret_cast<const int8_t**>(rhs.buffers);
85+
86+
for (size_t i = 0; i < static_cast<size_t>(lhs.length); ++i)
87+
{
88+
CHECK_EQ(lhs_buffers[1][i], rhs_buffers[1][i]);
89+
}
90+
}
91+
2092
template <typename T>
2193
void compare_bitmap(sparrow::primitive_array<T>& pa1, sparrow::primitive_array<T>& pa2)
2294
{
@@ -88,7 +160,18 @@ namespace sparrow_ipc
88160

89161
sp::primitive_array<T> deserialized_ar = deserialize_primitive_array<T>(serialized_data);
90162

91-
// CHECK_EQ(ar, deserialized_ar);
163+
auto [arrow_array_ar, arrow_schema_ar] = sp::get_arrow_structures(ar);
164+
auto [arrow_array_deserialized_ar, arrow_schema_deserialized_ar] = sp::get_arrow_structures(deserialized_ar);
165+
166+
// Check ArrowSchema equality
167+
REQUIRE_NE(arrow_schema_ar, nullptr);
168+
REQUIRE_NE(arrow_schema_deserialized_ar, nullptr);
169+
compare_arrow_schemas(*arrow_schema_ar, *arrow_schema_deserialized_ar);
170+
171+
// Check ArrowArray equality
172+
REQUIRE_NE(arrow_array_ar, nullptr);
173+
REQUIRE_NE(arrow_array_deserialized_ar, nullptr);
174+
compare_arrow_arrays(*arrow_array_ar, *arrow_array_deserialized_ar);
92175

93176
compare_bitmap<T>(ar, deserialized_ar);
94177
compare_metadata<T>(ar, deserialized_ar);

0 commit comments

Comments
 (0)