| 343 | }; |
| 344 | |
| 345 | TEST_P(TestWriteCSV, TestWrite) { |
| 346 | ASSERT_OK_AND_ASSIGN(std::shared_ptr<io::BufferOutputStream> out, |
| 347 | io::BufferOutputStream::Create()); |
| 348 | WriteOptions options = GetParam().options; |
| 349 | std::string csv; |
| 350 | auto record_batch = RecordBatchFromJSON(GetParam().schema, GetParam().batch_data); |
| 351 | if (!GetParam().expected_status.ok()) { |
| 352 | // If an error status is expected, check if the expected status code and message |
| 353 | // matches. |
| 354 | EXPECT_RAISES_WITH_MESSAGE_THAT( |
| 355 | Invalid, ::testing::HasSubstr(GetParam().expected_status.message()), |
| 356 | ToCsvString(*record_batch, options)); |
| 357 | } else { |
| 358 | ASSERT_OK_AND_ASSIGN(csv, ToCsvString(*record_batch, options)); |
| 359 | EXPECT_EQ(csv, GetParam().expected_output); |
| 360 | |
| 361 | // Batch size shouldn't matter. |
| 362 | options.batch_size /= 2; |
| 363 | ASSERT_OK_AND_ASSIGN(csv, ToCsvString(*record_batch, options)); |
| 364 | EXPECT_EQ(csv, GetParam().expected_output); |
| 365 | |
| 366 | // Table and Record batch should work identically. |
| 367 | ASSERT_OK_AND_ASSIGN(std::shared_ptr<Table> table, |
| 368 | Table::FromRecordBatches({record_batch})); |
| 369 | ASSERT_OK_AND_ASSIGN(csv, ToCsvString(*table, options)); |
| 370 | EXPECT_EQ(csv, GetParam().expected_output); |
| 371 | |
| 372 | // RecordBatchReader should work identically. |
| 373 | ASSERT_OK_AND_ASSIGN(std::shared_ptr<RecordBatchReader> reader, |
| 374 | RecordBatchReader::Make({record_batch})); |
| 375 | ASSERT_OK_AND_ASSIGN(csv, ToCsvString(reader, options)); |
| 376 | EXPECT_EQ(csv, GetParam().expected_output); |
| 377 | |
| 378 | // The writer should work identically. |
| 379 | ASSERT_OK_AND_ASSIGN(csv, ToCsvStringUsingWriter(*table, options)); |
| 380 | EXPECT_EQ(csv, GetParam().expected_output); |
| 381 | } |
| 382 | } |
| 383 | |
| 384 | INSTANTIATE_TEST_SUITE_P(MultiColumnWriteCSVTest, TestWriteCSV, |
| 385 | ::testing::ValuesIn(GenerateTestCases())); |
nothing calls this directly
no test coverage detected