()
| 2020 | #[test] |
| 2021 | #[ignore] |
| 2022 | fn test_ref_schema_consistent() { |
| 2023 | let data_file_path = get_data_file(); |
| 2024 | let bytes = fs::read(&data_file_path).unwrap(); |
| 2025 | |
| 2026 | let mut fory = Fory::builder() |
| 2027 | .compatible(false) |
| 2028 | .xlang(true) |
| 2029 | .track_ref(true) |
| 2030 | .build(); |
| 2031 | fory.register::<RefInnerSchemaConsistent>(501).unwrap(); |
| 2032 | fory.register::<RefOuterSchemaConsistent>(502).unwrap(); |
| 2033 | |
| 2034 | let outer: RefOuterSchemaConsistent = fory.deserialize(&bytes).unwrap(); |
| 2035 | |
| 2036 | // Both inner1 and inner2 should have values |
| 2037 | assert!(outer.inner1.is_some(), "inner1 should not be None"); |
| 2038 | assert!(outer.inner2.is_some(), "inner2 should not be None"); |
| 2039 | |
| 2040 | // Both should have the same values (they reference the same object in Java) |
| 2041 | let inner1 = outer.inner1.as_ref().unwrap(); |
| 2042 | let inner2 = outer.inner2.as_ref().unwrap(); |
| 2043 | assert_eq!(inner1.id, 42); |
| 2044 | assert_eq!(inner1.name, "shared_inner"); |
| 2045 | // Compare the values (Rc contents) |
| 2046 | assert_eq!( |
| 2047 | inner1.as_ref(), |
| 2048 | inner2.as_ref(), |
| 2049 | "inner1 and inner2 should have equal values" |
| 2050 | ); |
| 2051 | |
| 2052 | // With Rc, after deserialization with ref tracking, both fields should point to the same Rc |
| 2053 | assert!( |
| 2054 | Rc::ptr_eq(inner1, inner2), |
| 2055 | "inner1 and inner2 should be the same Rc (reference identity)" |
| 2056 | ); |
| 2057 | |
| 2058 | // Re-serialize and write back |
| 2059 | let new_bytes = fory.serialize(&outer).unwrap(); |
| 2060 | fs::write(&data_file_path, new_bytes).unwrap(); |
| 2061 | } |
| 2062 | |
| 2063 | /// Test cross-language reference tracking in COMPATIBLE mode (compatible=true). |
| 2064 | /// |
nothing calls this directly
no test coverage detected