MCPcopy Create free account
hub / github.com/apache/fory / TEST

Function TEST

cpp/fory/serialization/struct_compatible_test.cc:443–473  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

441}
442
443TEST(SchemaEvolutionTest, AddingSingleField) {
444 // Serialize V1, deserialize as V2 (V2 should have default value for email)
445 // Create separate Fory instances for V1 and V2
446 auto fory_v1 = Fory::builder().compatible(true).xlang(true).build();
447 auto fory_v2 = Fory::builder().compatible(true).xlang(true).build();
448
449 // Register both PersonV1 and PersonV2 with the SAME type ID for schema
450 // evolution
451 constexpr uint32_t PERSON_TYPE_ID = 999;
452 auto reg1_result = fory_v1.register_struct<PersonV1>(PERSON_TYPE_ID);
453 ASSERT_TRUE(reg1_result.ok()) << reg1_result.error().to_string();
454 auto reg2_result = fory_v2.register_struct<PersonV2>(PERSON_TYPE_ID);
455 ASSERT_TRUE(reg2_result.ok()) << reg2_result.error().to_string();
456
457 // Serialize PersonV1
458 PersonV1 v1{"Alice", 30};
459 auto ser_result = fory_v1.serialize(v1);
460 ASSERT_TRUE(ser_result.ok()) << ser_result.error().to_string();
461
462 std::vector<uint8_t> bytes = std::move(ser_result).value();
463
464 // Deserialize as PersonV2 - email should be default-initialized (empty
465 // string)
466 auto deser_result = fory_v2.deserialize<PersonV2>(bytes.data(), bytes.size());
467 ASSERT_TRUE(deser_result.ok()) << deser_result.error().to_string();
468
469 PersonV2 v2 = std::move(deser_result).value();
470 EXPECT_EQ(v2.name, "Alice");
471 EXPECT_EQ(v2.age, 30);
472 EXPECT_EQ(v2.email, ""); // Default value for missing field
473}
474
475TEST(SchemaEvolutionTest, AddingMultipleFields) {
476 auto fory_v1 = Fory::builder().compatible(true).xlang(true).build();

Callers

nothing calls this directly

Calls 15

single_byte_delta_indexFunction · 0.85
attachMethod · 0.80
detachMethod · 0.80
errorMethod · 0.65
serializeMethod · 0.65
valueMethod · 0.65
stringFunction · 0.50
buildMethod · 0.45
xlangMethod · 0.45
compatibleMethod · 0.45
okMethod · 0.45

Tested by

no test coverage detected