Repository: apache/arrow
File: cpp/src/arrow/ipc/read_write_test.cc (C++)

Code before:
  }
}

TEST_F(TestIpcRoundTrip, DefaultMetadataVersion) {
  TestMetadataVersion(MetadataVersion::V5);
}

TEST_F(TestIpcRoundTrip, SpecificMetadataVersion) {
  options_.metadata_version = MetadataVersion::V4;
  TestMetadataVersion(MetadataVersion::V4);
  options_.metadata_version = MetadataVersion::V5;
  TestMetadataVersion(MetadataVersion::V5);
}

TEST(TestReadMessage, CorruptedSmallInput) {
  std::string data = "abc";
  auto reader = io::BufferReader::FromString(data);
  ASSERT_RAISES(Invalid, ReadMessage(reader.get()));

  // But no error on unsignaled EOS
  auto reader2 = io::BufferReader::FromString("");
  ASSERT_OK_AND_ASSIGN(auto message, ReadMessage(reader2.get()));
  ASSERT_EQ(nullptr, message);
}

TEST(TestMetadata, GetMetadataVersion) {
  ASSERT_EQ(MetadataVersion::V1, ipc::internal::GetMetadataVersion(
                                     flatbuf::MetadataVersion::MetadataVersion_V1));
  ASSERT_EQ(MetadataVersion::V2, ipc::internal::GetMetadataVersion(
                                     flatbuf::MetadataVersion::MetadataVersion_V2));
  ASSERT_EQ(MetadataVersion::V3, ipc::internal::GetMetadataVersion(
                                     flatbuf::MetadataVersion::MetadataVersion_V3));
  ASSERT_EQ(MetadataVersion::V4, ipc::internal::GetMetadataVersion(
                                     flatbuf::MetadataVersion::MetadataVersion_V4));
  ASSERT_EQ(MetadataVersion::V5, ipc::internal::GetMetadataVersion(
                                     flatbuf::MetadataVersion::MetadataVersion_V5));
  ASSERT_EQ(MetadataVersion::V1, ipc::internal::GetMetadataVersion(
                                     flatbuf::MetadataVersion::MetadataVersion_MIN));
  ASSERT_EQ(MetadataVersion::V5, ipc::internal::GetMetadataVersion(
                                     flatbuf::MetadataVersion::MetadataVersion_MAX));
}

TEST_P(TestIpcRoundTrip, SliceRoundTrip) {
  std::shared_ptr<RecordBatch> batch;
  ASSERT_OK((*GetParam())(&batch));  // NOLINT clang-tidy gtest issue

  // Skip the zero-length case
  if (batch->num_rows() < 2) {
    return;
  }


Review comment (suggestion):
Note that this could be written more succinctly:
```c++
  // Values array
  auto child_data = ArrayFromJSON(int32(), "[1, 2, 3, 4, 5]")->data();
```

Code after:
  }
}

TEST_F(TestIpcRoundTrip, DefaultMetadataVersion) {
  TestMetadataVersion(MetadataVersion::V5);
}

TEST_F(TestIpcRoundTrip, SpecificMetadataVersion) {
  options_.metadata_version = MetadataVersion::V4;
  TestMetadataVersion(MetadataVersion::V4);
  options_.metadata_version = MetadataVersion::V5;
  TestMetadataVersion(MetadataVersion::V5);
}

TEST_F(TestIpcRoundTrip, ListWithSlicedValues) {
  // This tests serialization of a sliced ListArray that got sliced "the Rust
  // way": by slicing the value_offsets buffer, but keeping top-level offset at
  // 0.
  auto child_data = ArrayFromJSON(int32(), "[1, 2, 3, 4, 5]")->data();

  // Offsets buffer [2, 5]
  TypedBufferBuilder<int32_t> offsets_builder;
  ASSERT_OK(offsets_builder.Reserve(2));
  ASSERT_OK(offsets_builder.Append(2));
  ASSERT_OK(offsets_builder.Append(5));
  ASSERT_OK_AND_ASSIGN(auto offsets_buffer, offsets_builder.Finish());

  auto list_data = ArrayData::Make(list(int32()),
                                   /*num_rows=*/1,
                                   /*buffers=*/{nullptr, offsets_buffer});
  list_data->child_data = {child_data};
  std::shared_ptr<Array> list_array = MakeArray(list_data);
  ASSERT_OK(list_array->ValidateFull());

  CheckRoundtrip(list_array);
}

TEST(TestReadMessage, CorruptedSmallInput) {
  std::string data = "abc";
  auto reader = io::BufferReader::FromString(data);
  ASSERT_RAISES(Invalid, ReadMessage(reader.get()));

  // But no error on unsignaled EOS
  auto reader2 = io::BufferReader::FromString("");
  ASSERT_OK_AND_ASSIGN(auto message, ReadMessage(reader2.get()));
  ASSERT_EQ(nullptr, message);
}

TEST(TestMetadata, GetMetadataVersion) {
  ASSERT_EQ(MetadataVersion::V1, ipc::internal::GetMetadataVersion(
                                     flatbuf::MetadataVersion::MetadataVersion_V1));