Skip to content

Commit a106994

Browse files
TJ Yinfacebook-github-bot
TJ Yin
authored andcommitted
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
1 parent 5bf651b commit a106994

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

third-party/thrift/src/thrift/test/StructTest.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,9 @@ TEST_F(StructTest, TerseFields) {
831831
EXPECT_TRUE(serializedField<ident::exception_field>(terse));
832832
EXPECT_TRUE(serializedField<ident::cpp_ref_struct_field>(terse));
833833
EXPECT_TRUE(serializedField<ident::cpp_ref_union_field>(terse));
834+
EXPECT_TRUE(serializedField<ident::cpp_shared_ref_struct_field>(terse));
835+
EXPECT_TRUE(serializedField<ident::cpp_shared_ref_union_field>(terse));
836+
EXPECT_TRUE(serializedField<ident::cpp_shared_ref_exception_field>(terse));
834837

835838
// cpp.ref exceptions are nullptr by default
836839
EXPECT_FALSE(serializedField<ident::cpp_ref_exception_field>(terse));
@@ -842,6 +845,9 @@ TEST_F(StructTest, TerseFields) {
842845
terse.cpp_ref_struct_field() = nullptr;
843846
terse.cpp_ref_union_field() = nullptr;
844847
terse.cpp_ref_exception_field() = nullptr;
848+
terse.cpp_shared_ref_struct_field() = nullptr;
849+
terse.cpp_shared_ref_union_field() = nullptr;
850+
terse.cpp_shared_ref_exception_field() = nullptr;
845851

846852
// Numeric fields are serialized if they don't equal custom default
847853
EXPECT_TRUE(serializedField<ident::bool_field>(terse));
@@ -864,7 +870,11 @@ TEST_F(StructTest, TerseFields) {
864870
EXPECT_TRUE(serializedField<ident::struct_field>(terse));
865871
EXPECT_TRUE(serializedField<ident::union_field>(terse));
866872
EXPECT_TRUE(serializedField<ident::exception_field>(terse));
873+
EXPECT_TRUE(serializedField<ident::cpp_shared_ref_struct_field>(terse));
874+
EXPECT_TRUE(serializedField<ident::cpp_shared_ref_union_field>(terse));
875+
EXPECT_TRUE(serializedField<ident::cpp_shared_ref_exception_field>(terse));
867876

877+
// @cpp.Ref has special logic that it skips nullptr fields
868878
EXPECT_FALSE(serializedField<ident::cpp_ref_struct_field>(terse));
869879
EXPECT_FALSE(serializedField<ident::cpp_ref_union_field>(terse));
870880
EXPECT_FALSE(serializedField<ident::cpp_ref_exception_field>(terse));

third-party/thrift/src/thrift/test/structs_terse.thrift

+13
Original file line numberDiff line numberDiff line change
@@ -170,16 +170,29 @@ struct TerseFieldsWithCustomDefault {
170170
@cpp.Ref{type = cpp.RefType.Unique}
171171
@cpp.AllowLegacyNonOptionalRef
172172
@cpp.DeprecatedTerseWrite
173+
@cpp.AllowLegacyDeprecatedTerseWritesRef
173174
16: NestedStruct cpp_ref_struct_field;
174175
@cpp.Ref{type = cpp.RefType.Unique}
175176
@cpp.AllowLegacyNonOptionalRef
176177
@cpp.DeprecatedTerseWrite
178+
@cpp.AllowLegacyDeprecatedTerseWritesRef
177179
17: NestedUnion cpp_ref_union_field;
178180
@cpp.Ref{type = cpp.RefType.Unique}
179181
@cpp.AllowLegacyNonOptionalRef
180182
@cpp.DeprecatedTerseWrite
183+
@cpp.AllowLegacyDeprecatedTerseWritesRef
181184
18: NestedException cpp_ref_exception_field;
182185

183186
@cpp.DeprecatedTerseWrite
184187
19: i32 redundant_custom_default = 0;
188+
189+
@cpp.Ref{type = cpp.RefType.Shared}
190+
@cpp.AllowLegacyNonOptionalRef
191+
20: NestedStruct cpp_shared_ref_struct_field;
192+
@cpp.Ref{type = cpp.RefType.Shared}
193+
@cpp.AllowLegacyNonOptionalRef
194+
21: NestedUnion cpp_shared_ref_union_field;
195+
@cpp.Ref{type = cpp.RefType.Shared}
196+
@cpp.AllowLegacyNonOptionalRef
197+
22: NestedException cpp_shared_ref_exception_field;
185198
}

0 commit comments

Comments
 (0)