@@ -382,178 +382,172 @@ TEST(LiteralTest, DoubleZeroComparison) {
382382 EXPECT_EQ (neg_zero <=> pos_zero, std::partial_ordering::less);
383383}
384384
385- struct LiteralRoundTripParam {
385+ struct LiteralParam {
386386 std::string test_name;
387- std::vector<uint8_t > input_bytes ;
388- Literal expected_literal ;
387+ std::vector<uint8_t > serialized ;
388+ Literal value ;
389389 std::shared_ptr<PrimitiveType> type;
390390};
391391
392- class LiteralSerializationParam : public ::testing::TestWithParam<LiteralRoundTripParam> {
393- };
392+ class LiteralSerDeParam : public ::testing::TestWithParam<LiteralParam> {};
394393
395- TEST_P (LiteralSerializationParam , RoundTrip) {
394+ TEST_P (LiteralSerDeParam , RoundTrip) {
396395 const auto & param = GetParam ();
397396
398397 // Deserialize from bytes
399- Result<Literal> literal_result = Literal::Deserialize (param.input_bytes , param.type );
398+ Result<Literal> literal_result = Literal::Deserialize (param.serialized , param.type );
400399 ASSERT_TRUE (literal_result.has_value ())
401400 << " Deserialization failed: " << literal_result.error ().message ;
402401
403402 // Check type and value
404- EXPECT_EQ (*literal_result, param.expected_literal );
403+ EXPECT_EQ (*literal_result, param.value );
405404
406405 // Serialize back to bytes
407406 Result<std::vector<uint8_t >> bytes_result = literal_result->Serialize ();
408407 ASSERT_TRUE (bytes_result.has_value ())
409408 << " Serialization failed: " << bytes_result.error ().message ;
410- EXPECT_EQ (*bytes_result, param.input_bytes );
409+ EXPECT_EQ (*bytes_result, param.serialized );
411410
412411 // Deserialize again to verify idempotency
413412 Result<Literal> final_literal = Literal::Deserialize (*bytes_result, param.type );
414413 ASSERT_TRUE (final_literal.has_value ())
415414 << " Final deserialization failed: " << final_literal.error ().message ;
416- EXPECT_EQ (*final_literal, param.expected_literal );
415+ EXPECT_EQ (*final_literal, param.value );
417416}
418417
419418INSTANTIATE_TEST_SUITE_P (
420- BinarySerialization, LiteralSerializationParam ,
419+ BinarySerialization, LiteralSerDeParam ,
421420 ::testing::Values (
422421 // Basic types
423- LiteralRoundTripParam {" BooleanTrue" , {1 }, Literal::Boolean (true ), boolean ()},
424- LiteralRoundTripParam {" BooleanFalse" , {0 }, Literal::Boolean (false ), boolean ()},
422+ LiteralParam {" BooleanTrue" , {1 }, Literal::Boolean (true ), boolean ()},
423+ LiteralParam {" BooleanFalse" , {0 }, Literal::Boolean (false ), boolean ()},
425424
426- LiteralRoundTripParam {" Int" , {32 , 0 , 0 , 0 }, Literal::Int (32 ), int32 ()},
427- LiteralRoundTripParam {
425+ LiteralParam {" Int" , {32 , 0 , 0 , 0 }, Literal::Int (32 ), int32 ()},
426+ LiteralParam {
428427 " IntMaxValue" , {255 , 255 , 255 , 127 }, Literal::Int (2147483647 ), int32 ()},
429- LiteralRoundTripParam{
430- " IntMinValue" , {0 , 0 , 0 , 128 }, Literal::Int (-2147483648 ), int32 ()},
431- LiteralRoundTripParam{
432- " NegativeInt" , {224 , 255 , 255 , 255 }, Literal::Int (-32 ), int32 ()},
433-
434- LiteralRoundTripParam{
435- " Long" , {32 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }, Literal::Long (32 ), int64 ()},
436- LiteralRoundTripParam{" LongMaxValue" ,
437- {255 , 255 , 255 , 255 , 255 , 255 , 255 , 127 },
438- Literal::Long (std::numeric_limits<int64_t >::max ()),
439- int64 ()},
440- LiteralRoundTripParam{" LongMinValue" ,
441- {0 , 0 , 0 , 0 , 0 , 0 , 0 , 128 },
442- Literal::Long (std::numeric_limits<int64_t >::min ()),
443- int64 ()},
444- LiteralRoundTripParam{" NegativeLong" ,
445- {224 , 255 , 255 , 255 , 255 , 255 , 255 , 255 },
446- Literal::Long (-32 ),
447- int64 ()},
448-
449- LiteralRoundTripParam{" Float" , {0 , 0 , 128 , 63 }, Literal::Float (1 .0f ), float32 ()},
450- LiteralRoundTripParam{" FloatNegativeInfinity" ,
451- {0 , 0 , 128 , 255 },
452- Literal::Float (-std::numeric_limits<float >::infinity ()),
453- float32 ()},
454- LiteralRoundTripParam{" FloatMaxValue" ,
455- {255 , 255 , 127 , 127 },
456- Literal::Float (std::numeric_limits<float >::max ()),
457- float32 ()},
458- LiteralRoundTripParam{" FloatMinValue" ,
459- {255 , 255 , 127 , 255 },
460- Literal::Float (std::numeric_limits<float >::lowest ()),
461- float32 ()},
462-
463- LiteralRoundTripParam{
428+ LiteralParam{" IntMinValue" , {0 , 0 , 0 , 128 }, Literal::Int (-2147483648 ), int32 ()},
429+ LiteralParam{" NegativeInt" , {224 , 255 , 255 , 255 }, Literal::Int (-32 ), int32 ()},
430+
431+ LiteralParam{" Long" , {32 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }, Literal::Long (32 ), int64 ()},
432+ LiteralParam{" LongMaxValue" ,
433+ {255 , 255 , 255 , 255 , 255 , 255 , 255 , 127 },
434+ Literal::Long (std::numeric_limits<int64_t >::max ()),
435+ int64 ()},
436+ LiteralParam{" LongMinValue" ,
437+ {0 , 0 , 0 , 0 , 0 , 0 , 0 , 128 },
438+ Literal::Long (std::numeric_limits<int64_t >::min ()),
439+ int64 ()},
440+ LiteralParam{" NegativeLong" ,
441+ {224 , 255 , 255 , 255 , 255 , 255 , 255 , 255 },
442+ Literal::Long (-32 ),
443+ int64 ()},
444+
445+ LiteralParam{" Float" , {0 , 0 , 128 , 63 }, Literal::Float (1 .0f ), float32 ()},
446+ LiteralParam{" FloatNegativeInfinity" ,
447+ {0 , 0 , 128 , 255 },
448+ Literal::Float (-std::numeric_limits<float >::infinity ()),
449+ float32 ()},
450+ LiteralParam{" FloatMaxValue" ,
451+ {255 , 255 , 127 , 127 },
452+ Literal::Float (std::numeric_limits<float >::max ()),
453+ float32 ()},
454+ LiteralParam{" FloatMinValue" ,
455+ {255 , 255 , 127 , 255 },
456+ Literal::Float (std::numeric_limits<float >::lowest ()),
457+ float32 ()},
458+
459+ LiteralParam{
464460 " Double" , {0 , 0 , 0 , 0 , 0 , 0 , 240 , 63 }, Literal::Double (1.0 ), float64 ()},
465- LiteralRoundTripParam{" DoubleNegativeInfinity" ,
466- {0 , 0 , 0 , 0 , 0 , 0 , 240 , 255 },
467- Literal::Double (-std::numeric_limits<double >::infinity ()),
468- float64 ()},
469- LiteralRoundTripParam{" DoubleMaxValue" ,
470- {255 , 255 , 255 , 255 , 255 , 255 , 239 , 127 },
471- Literal::Double (std::numeric_limits<double >::max ()),
472- float64 ()},
473- LiteralRoundTripParam{" DoubleMinValue" ,
474- {255 , 255 , 255 , 255 , 255 , 255 , 239 , 255 },
475- Literal::Double (std::numeric_limits<double >::lowest ()),
476- float64 ()},
477-
478- LiteralRoundTripParam{" String" ,
479- {105 , 99 , 101 , 98 , 101 , 114 , 103 },
480- Literal::String (" iceberg" ),
481- string ()},
482- LiteralRoundTripParam{
483- " StringLong" ,
484- {65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 },
485- Literal::String (" AAAAAAAAAAAAAAAA" ),
486- string ()},
487-
488- LiteralRoundTripParam{" BinaryData" ,
489- {0x01 , 0x02 , 0x03 , 0xFF },
490- Literal::Binary ({0x01 , 0x02 , 0x03 , 0xFF }),
491- binary ()},
492- LiteralRoundTripParam{" BinarySingleByte" , {42 }, Literal::Binary ({42 }), binary ()},
461+ LiteralParam{" DoubleNegativeInfinity" ,
462+ {0 , 0 , 0 , 0 , 0 , 0 , 240 , 255 },
463+ Literal::Double (-std::numeric_limits<double >::infinity ()),
464+ float64 ()},
465+ LiteralParam{" DoubleMaxValue" ,
466+ {255 , 255 , 255 , 255 , 255 , 255 , 239 , 127 },
467+ Literal::Double (std::numeric_limits<double >::max ()),
468+ float64 ()},
469+ LiteralParam{" DoubleMinValue" ,
470+ {255 , 255 , 255 , 255 , 255 , 255 , 239 , 255 },
471+ Literal::Double (std::numeric_limits<double >::lowest ()),
472+ float64 ()},
473+
474+ LiteralParam{" String" ,
475+ {105 , 99 , 101 , 98 , 101 , 114 , 103 },
476+ Literal::String (" iceberg" ),
477+ string ()},
478+ LiteralParam{" StringLong" ,
479+ {65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 },
480+ Literal::String (" AAAAAAAAAAAAAAAA" ),
481+ string ()},
482+
483+ LiteralParam{" BinaryData" ,
484+ {0x01 , 0x02 , 0x03 , 0xFF },
485+ Literal::Binary ({0x01 , 0x02 , 0x03 , 0xFF }),
486+ binary ()},
487+ LiteralParam{" BinarySingleByte" , {42 }, Literal::Binary ({42 }), binary ()},
493488
494489 // Fixed type
495- LiteralRoundTripParam{" FixedLength4" ,
496- {0x01 , 0x02 , 0x03 , 0x04 },
497- Literal::Fixed ({0x01 , 0x02 , 0x03 , 0x04 }),
498- fixed (4 )},
499- LiteralRoundTripParam{
500- " FixedLength8" ,
501- {0xAA , 0xBB , 0xCC , 0xDD , 0xEE , 0xFF , 0x00 , 0x11 },
502- Literal::Fixed ({0xAA , 0xBB , 0xCC , 0xDD , 0xEE , 0xFF , 0x00 , 0x11 }),
503- fixed (8 )},
504- LiteralRoundTripParam{
505- " FixedLength16" ,
506- {0x00 , 0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 , 0x08 , 0x09 , 0x0A , 0x0B , 0x0C ,
507- 0x0D , 0x0E , 0x0F },
508- Literal::Fixed ({0x00 , 0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 , 0x08 , 0x09 ,
509- 0x0A , 0x0B , 0x0C , 0x0D , 0x0E , 0x0F }),
510- fixed (16 )},
511- LiteralRoundTripParam{
512- " FixedSingleByte" , {0xFF }, Literal::Fixed ({0xFF }), fixed (1 )},
490+ LiteralParam{" FixedLength4" ,
491+ {0x01 , 0x02 , 0x03 , 0x04 },
492+ Literal::Fixed ({0x01 , 0x02 , 0x03 , 0x04 }),
493+ fixed (4 )},
494+ LiteralParam{" FixedLength8" ,
495+ {0xAA , 0xBB , 0xCC , 0xDD , 0xEE , 0xFF , 0x00 , 0x11 },
496+ Literal::Fixed ({0xAA , 0xBB , 0xCC , 0xDD , 0xEE , 0xFF , 0x00 , 0x11 }),
497+ fixed (8 )},
498+ LiteralParam{" FixedLength16" ,
499+ {0x00 , 0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 , 0x08 , 0x09 , 0x0A ,
500+ 0x0B , 0x0C , 0x0D , 0x0E , 0x0F },
501+ Literal::Fixed ({0x00 , 0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 , 0x08 ,
502+ 0x09 , 0x0A , 0x0B , 0x0C , 0x0D , 0x0E , 0x0F }),
503+ fixed (16 )},
504+ LiteralParam{" FixedSingleByte" , {0xFF }, Literal::Fixed ({0xFF }), fixed (1 )},
513505
514506 // Temporal types
515- LiteralRoundTripParam{" DateEpoch" , {0 , 0 , 0 , 0 }, Literal::Date (0 ), date ()},
516- LiteralRoundTripParam{" DateNextDay" , {1 , 0 , 0 , 0 }, Literal::Date (1 ), date ()},
517- LiteralRoundTripParam{" DateY2K" , {205 , 42 , 0 , 0 }, Literal::Date (10957 ), date ()},
518- LiteralRoundTripParam{
519- " DateNegative" , {255 , 255 , 255 , 255 }, Literal::Date (-1 ), date ()},
520-
521- LiteralRoundTripParam{
522- " TimeMidnight" , {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }, Literal::Time (0 ), time ()},
523- LiteralRoundTripParam{" TimeNoon" ,
524- {128 , 9 , 230 , 124 , 10 , 0 , 0 , 0 },
525- Literal::Time (45045123456 ),
526- time ()},
527- LiteralRoundTripParam{
507+ LiteralParam{" DateEpoch" , {0 , 0 , 0 , 0 }, Literal::Date (0 ), date ()},
508+ LiteralParam{" DateNextDay" , {1 , 0 , 0 , 0 }, Literal::Date (1 ), date ()},
509+ LiteralParam{" DateY2K" , {205 , 42 , 0 , 0 }, Literal::Date (10957 ), date ()},
510+ LiteralParam{" DateNegative" , {255 , 255 , 255 , 255 }, Literal::Date (-1 ), date ()},
511+
512+ LiteralParam{" TimeMidnight" , {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }, Literal::Time (0 ), time ()},
513+ LiteralParam{" TimeNoon" ,
514+ {128 , 9 , 230 , 124 , 10 , 0 , 0 , 0 },
515+ Literal::Time (45045123456 ),
516+ time ()},
517+ LiteralParam{
528518 " TimeOneSecond" , {64 , 66 , 15 , 0 , 0 , 0 , 0 , 0 }, Literal::Time (1000000 ), time ()},
529519
530- LiteralRoundTripParam{" TimestampEpoch" ,
531- {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 },
532- Literal::Timestamp (0 ),
533- timestamp ()},
534- LiteralRoundTripParam{" TimestampOneSecond" ,
535- {64 , 66 , 15 , 0 , 0 , 0 , 0 , 0 },
536- Literal::Timestamp (1000000 ),
537- timestamp ()},
538- LiteralRoundTripParam{" TimestampNoon2024" ,
539- {128 , 9 , 230 , 124 , 10 , 0 , 0 , 0 },
540- Literal::Timestamp (45045123456 ),
541- timestamp ()},
542-
543- LiteralRoundTripParam{" TimestampTzEpoch" ,
544- {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 },
545- Literal::TimestampTz (0 ),
546- timestamp_tz ()},
547- LiteralRoundTripParam{" TimestampTzOneHour" ,
548- {0 , 164 , 147 , 214 , 0 , 0 , 0 , 0 },
549- Literal::TimestampTz (3600000000 ),
550- timestamp_tz ()}),
551-
552- [](const testing::TestParamInfo<LiteralSerializationParam::ParamType>& info) {
520+ LiteralParam{" TimestampEpoch" ,
521+ {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 },
522+ Literal::Timestamp (0 ),
523+ timestamp ()},
524+ LiteralParam{" TimestampOneSecond" ,
525+ {64 , 66 , 15 , 0 , 0 , 0 , 0 , 0 },
526+ Literal::Timestamp (1000000 ),
527+ timestamp ()},
528+ LiteralParam{" TimestampNoon2024" ,
529+ {128 , 9 , 230 , 124 , 10 , 0 , 0 , 0 },
530+ Literal::Timestamp (45045123456 ),
531+ timestamp ()},
532+
533+ LiteralParam{" TimestampTzEpoch" ,
534+ {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 },
535+ Literal::TimestampTz (0 ),
536+ timestamp_tz ()},
537+ LiteralParam{" TimestampTzOneHour" ,
538+ {0 , 164 , 147 , 214 , 0 , 0 , 0 , 0 },
539+ Literal::TimestampTz (3600000000 ),
540+ timestamp_tz ()},
541+
542+ // Empty values
543+ LiteralParam{" EmptyString" , {}, Literal::String (" " ), string ()},
544+ LiteralParam{" EmptyBinary" , {}, Literal::Binary ({}), binary ()}),
545+
546+ [](const testing::TestParamInfo<LiteralSerDeParam::ParamType>& info) {
553547 return info.param .test_name ;
554548 });
555549
556- TEST (LiteralSerializationTest , EmptyString) {
550+ TEST (LiteralSerDeTest , EmptyString) {
557551 auto empty_string = Literal::String (" " );
558552 auto empty_bytes = empty_string.Serialize ();
559553 ASSERT_TRUE (empty_bytes.has_value ());
@@ -564,7 +558,7 @@ TEST(LiteralSerializationTest, EmptyString) {
564558 EXPECT_TRUE (std::get<std::string>(deserialize_result->value ()).empty ());
565559}
566560
567- TEST (LiteralSerializationTest , EmptyBinary) {
561+ TEST (LiteralSerDeTest , EmptyBinary) {
568562 auto empty_binary = Literal::Binary ({});
569563 auto empty_bytes = empty_binary.Serialize ();
570564 ASSERT_TRUE (empty_bytes.has_value ());
@@ -576,7 +570,7 @@ TEST(LiteralSerializationTest, EmptyBinary) {
576570}
577571
578572// Type promotion tests
579- TEST (LiteralSerializationTest , TypePromotion) {
573+ TEST (LiteralSerDeTest , TypePromotion) {
580574 // 4-byte int data can be deserialized as long
581575 std::vector<uint8_t > int_data = {32 , 0 , 0 , 0 };
582576 auto long_result = Literal::Deserialize (int_data, int64 ());
0 commit comments