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

Function test_ref_compatible

rust/tests/tests/test_cross_language.rs:2070–2109  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2068#[test]
2069#[ignore]
2070fn test_ref_compatible() {
2071 let data_file_path = get_data_file();
2072 let bytes = fs::read(&data_file_path).unwrap();
2073
2074 let mut fory = Fory::builder()
2075 .compatible(true)
2076 .xlang(true)
2077 .track_ref(true)
2078 .build();
2079 fory.register::<RefInnerCompatible>(503).unwrap();
2080 fory.register::<RefOuterCompatible>(504).unwrap();
2081
2082 let outer: RefOuterCompatible = fory.deserialize(&bytes).unwrap();
2083
2084 // Both inner1 and inner2 should have values
2085 assert!(outer.inner1.is_some(), "inner1 should not be None");
2086 assert!(outer.inner2.is_some(), "inner2 should not be None");
2087
2088 // Both should have the same values (they reference the same object in Java)
2089 let inner1 = outer.inner1.as_ref().unwrap();
2090 let inner2 = outer.inner2.as_ref().unwrap();
2091 assert_eq!(inner1.id, 99);
2092 assert_eq!(inner1.name, "compatible_shared");
2093 // Compare the values (Rc contents)
2094 assert_eq!(
2095 inner1.as_ref(),
2096 inner2.as_ref(),
2097 "inner1 and inner2 should have equal values"
2098 );
2099
2100 // With Rc, after deserialization with ref tracking, both fields should point to the same Rc
2101 assert!(
2102 Rc::ptr_eq(inner1, inner2),
2103 "inner1 and inner2 should be the same Rc (reference identity)"
2104 );
2105
2106 // Re-serialize and write back
2107 let new_bytes = fory.serialize(&outer).unwrap();
2108 fs::write(&data_file_path, new_bytes).unwrap();
2109}
2110
2111/// Test collection element ref override round-trip.
2112#[test]

Callers

nothing calls this directly

Calls 10

get_data_fileFunction · 0.70
deserializeMethod · 0.65
serializeMethod · 0.65
readFunction · 0.50
writeFunction · 0.50
unwrapMethod · 0.45
buildMethod · 0.45
track_refMethod · 0.45
xlangMethod · 0.45
compatibleMethod · 0.45

Tested by

no test coverage detected