2023-07-13 15:23:02 +01:00
|
|
|
# TODO: The dynamic union tests should be updated when tagged union support is in:
|
|
|
|
# https://github.com/facebookexperimental/object-introspection/issues/234
|
|
|
|
thrift_definitions = '''
|
|
|
|
union StaticUnion {
|
|
|
|
1: i32 a;
|
|
|
|
2: i32 b;
|
|
|
|
3: i32 c;
|
|
|
|
}
|
|
|
|
|
|
|
|
union DynamicUnion {
|
|
|
|
1: i32 n;
|
|
|
|
2: list<i32> vec;
|
|
|
|
}
|
|
|
|
'''
|
|
|
|
raw_definitions = '''
|
|
|
|
namespace cpp2 {
|
|
|
|
void StaticUnion::__fbthrift_clear() {}
|
|
|
|
void DynamicUnion::__fbthrift_clear() {}
|
2023-12-12 17:51:00 +00:00
|
|
|
DynamicUnion::~DynamicUnion() {}
|
2023-07-13 15:23:02 +01:00
|
|
|
}
|
|
|
|
'''
|
|
|
|
|
|
|
|
[cases]
|
|
|
|
[cases.static]
|
|
|
|
param_types = ["const cpp2::StaticUnion&"]
|
|
|
|
setup = '''
|
|
|
|
cpp2::StaticUnion ret;
|
|
|
|
return ret;
|
|
|
|
'''
|
|
|
|
expect_json = '''[{
|
|
|
|
"staticSize":8,
|
|
|
|
"dynamicSize":0,
|
|
|
|
"members":[
|
2024-01-10 18:08:44 +00:00
|
|
|
{"typeName":"cpp2::StaticUnion::storage_type", "name":"value_", "staticSize":4},
|
2023-07-13 15:23:02 +01:00
|
|
|
{"typeName":"underlying_type_t<cpp2::StaticUnion::Type>", "name":"type_", "staticSize":4}
|
|
|
|
]}]'''
|
2023-08-16 20:40:36 +01:00
|
|
|
expect_json_v2 = '''[{
|
|
|
|
"staticSize":8,
|
|
|
|
"exclusiveSize":0,
|
2024-01-03 17:30:31 +00:00
|
|
|
"size":8,
|
2023-08-16 20:40:36 +01:00
|
|
|
"members":[
|
2024-01-10 18:08:44 +00:00
|
|
|
{"typeNames":["cpp2::StaticUnion::storage_type"], "name":"value_", "staticSize":4, "exclusiveSize":4, "size":4},
|
2024-01-03 17:30:31 +00:00
|
|
|
{"typeNames":["underlying_type_t<cpp2::StaticUnion::Type>", "type", "int32_t"], "name":"type_", "staticSize":4, "exclusiveSize":4, "size":4}
|
2023-08-16 20:40:36 +01:00
|
|
|
]}]'''
|
2023-07-13 15:23:02 +01:00
|
|
|
[cases.dynamic_int]
|
|
|
|
param_types = ["const cpp2::DynamicUnion&"]
|
|
|
|
setup = '''
|
|
|
|
cpp2::DynamicUnion ret;
|
|
|
|
ret.set_n(123);
|
|
|
|
return ret;
|
|
|
|
'''
|
|
|
|
expect_json = '''[{
|
|
|
|
"staticSize":32,
|
|
|
|
"dynamicSize":0,
|
|
|
|
"members":[
|
2024-01-10 18:08:44 +00:00
|
|
|
{"typeName":"cpp2::DynamicUnion::storage_type", "name":"value_", "staticSize":24},
|
2023-07-13 15:23:02 +01:00
|
|
|
{"typeName":"underlying_type_t<cpp2::DynamicUnion::Type>", "name":"type_", "staticSize":4}
|
|
|
|
]}]'''
|
2023-08-16 20:40:36 +01:00
|
|
|
expect_json_v2 = '''[{
|
|
|
|
"staticSize":32,
|
|
|
|
"exclusiveSize":4,
|
2024-01-03 17:30:31 +00:00
|
|
|
"size":32,
|
2023-08-16 20:40:36 +01:00
|
|
|
"members":[
|
2024-01-10 18:08:44 +00:00
|
|
|
{"typeNames":["cpp2::DynamicUnion::storage_type"], "name":"value_", "staticSize":24, "exclusiveSize":24, "size":24},
|
2024-01-03 17:30:31 +00:00
|
|
|
{"typeNames":["underlying_type_t<cpp2::DynamicUnion::Type>", "type", "int32_t"], "name":"type_", "staticSize":4, "exclusiveSize":4, "size":4}
|
2023-08-16 20:40:36 +01:00
|
|
|
]}]'''
|
2023-07-13 15:23:02 +01:00
|
|
|
[cases.dynamic_vec]
|
|
|
|
param_types = ["const cpp2::DynamicUnion&"]
|
|
|
|
setup = '''
|
|
|
|
cpp2::DynamicUnion ret;
|
|
|
|
ret.set_vec({1,2,3});
|
|
|
|
return ret;
|
|
|
|
'''
|
|
|
|
expect_json = '''[{
|
|
|
|
"staticSize":32,
|
|
|
|
"dynamicSize":0,
|
|
|
|
"members":[
|
2024-01-10 18:08:44 +00:00
|
|
|
{"typeName":"cpp2::DynamicUnion::storage_type", "name":"value_", "staticSize":24},
|
2023-07-13 15:23:02 +01:00
|
|
|
{"typeName":"underlying_type_t<cpp2::DynamicUnion::Type>", "name":"type_", "staticSize":4}
|
|
|
|
]}]'''
|
2023-08-16 20:40:36 +01:00
|
|
|
expect_json_v2 = '''[{
|
|
|
|
"staticSize":32,
|
|
|
|
"exclusiveSize":4,
|
2024-01-03 17:30:31 +00:00
|
|
|
"size":32,
|
2023-08-16 20:40:36 +01:00
|
|
|
"members":[
|
2024-01-10 18:08:44 +00:00
|
|
|
{"typeNames":["cpp2::DynamicUnion::storage_type"], "name":"value_", "staticSize":24, "exclusiveSize":24, "size":24},
|
2024-01-03 17:30:31 +00:00
|
|
|
{"typeNames":["underlying_type_t<cpp2::DynamicUnion::Type>", "type", "int32_t"], "name":"type_", "staticSize":4, "exclusiveSize":4, "size":4}
|
2023-08-16 20:40:36 +01:00
|
|
|
]}]'''
|