@@ -1154,6 +1154,55 @@ TEST_F(TestBinaryBuilder, TestScalarAppend) {
11541154 }
11551155 }
11561156}
1157+
1158+ TEST_F (TestBinaryBuilder, TestCapacityReserve) {
1159+ vector<string> strings = {" a" , " bb" , " cc" , " ddddd" , " eeeee" };
1160+ int N = static_cast <int >(strings.size ());
1161+ int length = 0
1162+ int data_length = 0 ;
1163+ int capacity = N;
1164+
1165+ ASSERT_OK (builder_->Reserve (capacity));
1166+ ASSERT_OK (builder_->ReserveData (capacity));
1167+
1168+ ASSERT_EQ (static_cast <int >(builder_->length ()), length);
1169+ ASSERT_EQ (static_cast <int >(builder_->capacity ()), capacity);
1170+ ASSERT_EQ (static_cast <int >(builder_->value_data_length ()), data_length);
1171+ ASSERT_EQ (static_cast <int >(builder_->value_data_capacity ()), capacity);
1172+
1173+ for (const string& str : strings) {
1174+ ASSERT_OK (builder_->Append (str));
1175+
1176+ length++;
1177+ data_length += static_cast <int >(str.size ());
1178+
1179+ ASSERT_EQ (static_cast <int >(builder_->length ()), length);
1180+ ASSERT_EQ (static_cast <int >(builder_->capacity ()), capacity);
1181+ ASSERT_EQ (static_cast <int >(builder_->value_data_length ()), data_length);
1182+ if (data_length <= capacity) {
1183+ ASSERT_EQ (static_cast <int >(builder_->value_data_capacity ()), capacity);
1184+ } else {
1185+ ASSERT_EQ (static_cast <int >(builder_->value_data_capacity ()), data_length);
1186+ }
1187+ }
1188+
1189+ int extra_capacity = 10 ;
1190+
1191+ ASSERT_OK (builder_->Reserve (extra_capacity));
1192+ ASSERT_OK (builder_->ReserveData (extra_capacity));
1193+
1194+ ASSERT_EQ (static_cast <int >(builder_->length ()), length);
1195+ ASSERT_EQ (static_cast <int >(builder_->capacity ()), length + extra_capacity);
1196+ ASSERT_EQ (static_cast <int >(builder_->value_data_length ()), data_length);
1197+ ASSERT_EQ (static_cast <int >(builder_->value_data_capacity ()), data_length + extra_capacity);
1198+
1199+ Done ();
1200+
1201+ ASSERT_EQ (N, result_->length ());
1202+ ASSERT_EQ (0 , result_->null_count ());
1203+ ASSERT_EQ (data_length, result_->value_data ()->size ());
1204+ ASSERT_EQ (data_length + extra_capacity, result_->value_data ()->capacity ());
1205+ }
11571206
11581207TEST_F (TestBinaryBuilder, TestZeroLength) {
11591208 // All buffers are null
0 commit comments