Skip to content

Commit

Permalink
Change type between struct, union and exception
Browse files Browse the repository at this point in the history
Summary:
This diff added tests to

1. change struct to union
2. change struct to exception
3. change union to struct
4. change union to exception
5. change exception to struct
6. change exception to union

For this test, we only have 1 active field, thus all changes are compatible.

Reviewed By: iahs

Differential Revision: D38509770

fbshipit-source-id: adea13a86f17b48e6b0f521d94cd3d41a160678b
  • Loading branch information
Mizuchi authored and facebook-github-bot committed Aug 9, 2022
1 parent 78d0484 commit 8c66211
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 0 deletions.
61 changes: 61 additions & 0 deletions thrift/conformance/data/CompatibilityGenerator.cpp
Expand Up @@ -43,8 +43,10 @@

// TODO: use FieldQualifier
using apache::thrift::test::testset::FieldModifier;
using apache::thrift::test::testset::detail::exception_ByFieldType;
using apache::thrift::test::testset::detail::mod_set;
using apache::thrift::test::testset::detail::struct_ByFieldType;
using apache::thrift::test::testset::detail::union_ByFieldType;
namespace mp11 = boost::mp11;

namespace apache::thrift::conformance::data {
Expand Down Expand Up @@ -380,6 +382,64 @@ template <class Old, class New>
return ret;
}

template <class TT>
[[nodiscard]] std::vector<TestCase> changeStructType(const Protocol& protocol) {
std::vector<TestCase> ret;
for (const auto& value : ValueGenerator<TT>::getInterestingValues()) {
typename struct_ByFieldType<TT, mod_set<>>::type s;
typename union_ByFieldType<TT, mod_set<>>::type u;
typename exception_ByFieldType<TT, mod_set<>>::type e;

s.field_1() = value.value;
u.field_1_ref() = value.value;
e.field_1() = value.value;

auto get_name = [&](const auto& i) -> std::string_view {
if constexpr (std::is_same_v<
folly::remove_cvref_t<decltype(i)>,
folly::remove_cvref_t<decltype(s)>>) {
return "Struct";
} else if constexpr (std::is_same_v<
folly::remove_cvref_t<decltype(i)>,
folly::remove_cvref_t<decltype(u)>>) {
return "Union";
} else if constexpr (std::is_same_v<
folly::remove_cvref_t<decltype(i)>,
folly::remove_cvref_t<decltype(e)>>) {
return "Exception";
} else {
static_assert(sizeof(i) == 0);
}
};

folly::for_each(std::tuple(s, u, e), [&](auto old_data) {
folly::for_each(std::tuple(s, u, e), [&](auto new_data) {
if constexpr (std::is_same_v<decltype(old_data), decltype(new_data)>) {
return;
}

RoundTripTestCase roundTrip;
roundTrip.request()->value() =
AnyRegistry::generated().store(new_data, protocol);
roundTrip.request()->value()->data() =
*serializeThriftStruct(old_data, protocol);
roundTrip.expectedResponse().emplace().value() =
AnyRegistry::generated().store(new_data, protocol);
TestCase testCase;
testCase.name() = fmt::format(
"testset.{}/{}To{}/{}",
type::getName<TT>(),
get_name(old_data),
get_name(new_data),
value.name);
testCase.test()->roundTrip_ref() = std::move(roundTrip);
ret.push_back(std::move(testCase));
});
});
}
return ret;
}

template <typename TT>
Test createCompatibilityTest(const Protocol& protocol) {
Test test;
Expand Down Expand Up @@ -434,6 +494,7 @@ Test createCompatibilityTest(const Protocol& protocol) {
addToTest(changeEnumValueTestCases(protocol));
addToTest({addFieldWithCustomDefaultTestCase<TT>(protocol)});
addToTest({addOptionalFieldWithCustomDefaultTestCase<TT>(protocol)});
addToTest(changeStructType<TT>(protocol));

return test;
}
Expand Down
72 changes: 72 additions & 0 deletions thrift/conformance/data/nonconforming.txt
Expand Up @@ -15,6 +15,30 @@ cpp2/CompatibilityTest/testset/ChangeEnumType/Standard.2.MissingField._1.Binary
cpp2/CompatibilityTest/testset/ChangeEnumType/Standard.2.MissingField._1.Compact
cpp2/CompatibilityTest/testset/ChangeEnumType/Standard.2.ValueMismatch._1.Binary
cpp2/CompatibilityTest/testset/ChangeEnumType/Standard.2.ValueMismatch._1.Compact
cpp2/CompatibilityTest/testset.float/StructToUnion/NaN.Binary
cpp2/CompatibilityTest/testset.float/StructToUnion/NaN.Compact
cpp2/CompatibilityTest/testset.double/StructToUnion/NaN.Binary
cpp2/CompatibilityTest/testset.double/StructToUnion/NaN.Compact
cpp2/CompatibilityTest/testset.float/StructToException/NaN.Binary
cpp2/CompatibilityTest/testset.float/StructToException/NaN.Compact
cpp2/CompatibilityTest/testset.double/StructToException/NaN.Binary
cpp2/CompatibilityTest/testset.double/StructToException/NaN.Compact
cpp2/CompatibilityTest/testset.float/UnionToStruct/NaN.Binary
cpp2/CompatibilityTest/testset.float/UnionToStruct/NaN.Compact
cpp2/CompatibilityTest/testset.double/UnionToStruct/NaN.Binary
cpp2/CompatibilityTest/testset.double/UnionToStruct/NaN.Compact
cpp2/CompatibilityTest/testset.float/UnionToException/NaN.Binary
cpp2/CompatibilityTest/testset.float/UnionToException/NaN.Compact
cpp2/CompatibilityTest/testset.double/UnionToException/NaN.Binary
cpp2/CompatibilityTest/testset.double/UnionToException/NaN.Compact
cpp2/CompatibilityTest/testset.float/ExceptionToStruct/NaN.Binary
cpp2/CompatibilityTest/testset.float/ExceptionToStruct/NaN.Compact
cpp2/CompatibilityTest/testset.double/ExceptionToStruct/NaN.Binary
cpp2/CompatibilityTest/testset.double/ExceptionToStruct/NaN.Compact
cpp2/CompatibilityTest/testset.float/ExceptionToUnion/NaN.Binary
cpp2/CompatibilityTest/testset.float/ExceptionToUnion/NaN.Compact
cpp2/CompatibilityTest/testset.double/ExceptionToUnion/NaN.Binary
cpp2/CompatibilityTest/testset.double/ExceptionToUnion/NaN.Compact
#
#
# Python: NaN
Expand All @@ -33,6 +57,30 @@ python/CompatibilityTest/testset/ChangeEnumType/Standard.2.MissingField._1.Binar
python/CompatibilityTest/testset/ChangeEnumType/Standard.2.MissingField._1.Compact
python/CompatibilityTest/testset/ChangeEnumType/Standard.2.ValueMismatch._1.Binary
python/CompatibilityTest/testset/ChangeEnumType/Standard.2.ValueMismatch._1.Compact
python/CompatibilityTest/testset.float/StructToUnion/NaN.Binary
python/CompatibilityTest/testset.float/StructToUnion/NaN.Compact
python/CompatibilityTest/testset.double/StructToUnion/NaN.Binary
python/CompatibilityTest/testset.double/StructToUnion/NaN.Compact
python/CompatibilityTest/testset.float/StructToException/NaN.Binary
python/CompatibilityTest/testset.float/StructToException/NaN.Compact
python/CompatibilityTest/testset.double/StructToException/NaN.Binary
python/CompatibilityTest/testset.double/StructToException/NaN.Compact
python/CompatibilityTest/testset.float/UnionToStruct/NaN.Binary
python/CompatibilityTest/testset.float/UnionToStruct/NaN.Compact
python/CompatibilityTest/testset.double/UnionToStruct/NaN.Binary
python/CompatibilityTest/testset.double/UnionToStruct/NaN.Compact
python/CompatibilityTest/testset.float/UnionToException/NaN.Binary
python/CompatibilityTest/testset.float/UnionToException/NaN.Compact
python/CompatibilityTest/testset.double/UnionToException/NaN.Binary
python/CompatibilityTest/testset.double/UnionToException/NaN.Compact
python/CompatibilityTest/testset.float/ExceptionToStruct/NaN.Binary
python/CompatibilityTest/testset.float/ExceptionToStruct/NaN.Compact
python/CompatibilityTest/testset.double/ExceptionToStruct/NaN.Binary
python/CompatibilityTest/testset.double/ExceptionToStruct/NaN.Compact
python/CompatibilityTest/testset.float/ExceptionToUnion/NaN.Binary
python/CompatibilityTest/testset.float/ExceptionToUnion/NaN.Compact
python/CompatibilityTest/testset.double/ExceptionToUnion/NaN.Binary
python/CompatibilityTest/testset.double/ExceptionToUnion/NaN.Compact
#
#
# Java: NaN
Expand Down Expand Up @@ -61,6 +109,30 @@ java2/CompatibilityTest/testset/ChangeEnumType/Standard.2.MissingField._1.Binary
java2/CompatibilityTest/testset/ChangeEnumType/Standard.2.MissingField._1.Compact
java2/CompatibilityTest/testset/ChangeEnumType/Standard.2.ValueMismatch._1.Binary
java2/CompatibilityTest/testset/ChangeEnumType/Standard.2.ValueMismatch._1.Compact
java2/CompatibilityTest/testset.float/StructToUnion/NaN.Binary
java2/CompatibilityTest/testset.float/StructToUnion/NaN.Compact
java2/CompatibilityTest/testset.double/StructToUnion/NaN.Binary
java2/CompatibilityTest/testset.double/StructToUnion/NaN.Compact
java2/CompatibilityTest/testset.float/StructToException/NaN.Binary
java2/CompatibilityTest/testset.float/StructToException/NaN.Compact
java2/CompatibilityTest/testset.double/StructToException/NaN.Binary
java2/CompatibilityTest/testset.double/StructToException/NaN.Compact
java2/CompatibilityTest/testset.float/UnionToStruct/NaN.Binary
java2/CompatibilityTest/testset.float/UnionToStruct/NaN.Compact
java2/CompatibilityTest/testset.double/UnionToStruct/NaN.Binary
java2/CompatibilityTest/testset.double/UnionToStruct/NaN.Compact
java2/CompatibilityTest/testset.float/UnionToException/NaN.Binary
java2/CompatibilityTest/testset.float/UnionToException/NaN.Compact
java2/CompatibilityTest/testset.double/UnionToException/NaN.Binary
java2/CompatibilityTest/testset.double/UnionToException/NaN.Compact
java2/CompatibilityTest/testset.float/ExceptionToStruct/NaN.Binary
java2/CompatibilityTest/testset.float/ExceptionToStruct/NaN.Compact
java2/CompatibilityTest/testset.double/ExceptionToStruct/NaN.Binary
java2/CompatibilityTest/testset.double/ExceptionToStruct/NaN.Compact
java2/CompatibilityTest/testset.float/ExceptionToUnion/NaN.Binary
java2/CompatibilityTest/testset.float/ExceptionToUnion/NaN.Compact
java2/CompatibilityTest/testset.double/ExceptionToUnion/NaN.Binary
java2/CompatibilityTest/testset.double/ExceptionToUnion/NaN.Compact
#
#
# Java: These compatibility tests are failing in Java.
Expand Down

0 comments on commit 8c66211

Please sign in to comment.