From 721b463404c2fc2c145a049b7b732cb91a1c9283 Mon Sep 17 00:00:00 2001 From: TJ Yin Date: Thu, 30 Jan 2025 11:26:33 -0800 Subject: [PATCH] Add test for deprecated_terse_writes with cpp.Ref{Shared} behavior Summary: Unlike cpp.Ref{Unique}, we serialize non-optional cpp.Ref{Shared} even if it's nullptr. Reviewed By: thedavekwon Differential Revision: D68807799 fbshipit-source-id: 95e2657a1c5d8ef06ddaa53c9753a871b23c579e --- thrift/test/StructTest.cpp | 10 ++++++++++ thrift/test/structs_terse.thrift | 13 +++++++++++++ 2 files changed, 23 insertions(+) diff --git a/thrift/test/StructTest.cpp b/thrift/test/StructTest.cpp index a2413a6a587..a69af52efde 100644 --- a/thrift/test/StructTest.cpp +++ b/thrift/test/StructTest.cpp @@ -831,6 +831,9 @@ TEST_F(StructTest, TerseFields) { EXPECT_TRUE(serializedField(terse)); EXPECT_TRUE(serializedField(terse)); EXPECT_TRUE(serializedField(terse)); + EXPECT_TRUE(serializedField(terse)); + EXPECT_TRUE(serializedField(terse)); + EXPECT_TRUE(serializedField(terse)); // cpp.ref exceptions are nullptr by default EXPECT_FALSE(serializedField(terse)); @@ -842,6 +845,9 @@ TEST_F(StructTest, TerseFields) { terse.cpp_ref_struct_field() = nullptr; terse.cpp_ref_union_field() = nullptr; terse.cpp_ref_exception_field() = nullptr; + terse.cpp_shared_ref_struct_field() = nullptr; + terse.cpp_shared_ref_union_field() = nullptr; + terse.cpp_shared_ref_exception_field() = nullptr; // Numeric fields are serialized if they don't equal custom default EXPECT_TRUE(serializedField(terse)); @@ -864,7 +870,11 @@ TEST_F(StructTest, TerseFields) { EXPECT_TRUE(serializedField(terse)); EXPECT_TRUE(serializedField(terse)); EXPECT_TRUE(serializedField(terse)); + EXPECT_TRUE(serializedField(terse)); + EXPECT_TRUE(serializedField(terse)); + EXPECT_TRUE(serializedField(terse)); + // @cpp.Ref has special logic that it skips nullptr fields EXPECT_FALSE(serializedField(terse)); EXPECT_FALSE(serializedField(terse)); EXPECT_FALSE(serializedField(terse)); diff --git a/thrift/test/structs_terse.thrift b/thrift/test/structs_terse.thrift index 2dac8dc5263..3a73f307988 100644 --- a/thrift/test/structs_terse.thrift +++ b/thrift/test/structs_terse.thrift @@ -170,16 +170,29 @@ struct TerseFieldsWithCustomDefault { @cpp.Ref{type = cpp.RefType.Unique} @cpp.AllowLegacyNonOptionalRef @cpp.DeprecatedTerseWrite + @cpp.AllowLegacyDeprecatedTerseWritesRef 16: NestedStruct cpp_ref_struct_field; @cpp.Ref{type = cpp.RefType.Unique} @cpp.AllowLegacyNonOptionalRef @cpp.DeprecatedTerseWrite + @cpp.AllowLegacyDeprecatedTerseWritesRef 17: NestedUnion cpp_ref_union_field; @cpp.Ref{type = cpp.RefType.Unique} @cpp.AllowLegacyNonOptionalRef @cpp.DeprecatedTerseWrite + @cpp.AllowLegacyDeprecatedTerseWritesRef 18: NestedException cpp_ref_exception_field; @cpp.DeprecatedTerseWrite 19: i32 redundant_custom_default = 0; + + @cpp.Ref{type = cpp.RefType.Shared} + @cpp.AllowLegacyNonOptionalRef + 20: NestedStruct cpp_shared_ref_struct_field; + @cpp.Ref{type = cpp.RefType.Shared} + @cpp.AllowLegacyNonOptionalRef + 21: NestedUnion cpp_shared_ref_union_field; + @cpp.Ref{type = cpp.RefType.Shared} + @cpp.AllowLegacyNonOptionalRef + 22: NestedException cpp_shared_ref_exception_field; }