object-introspection/test/integration/std_variant.toml

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

249 lines
9.5 KiB
TOML
Raw Normal View History

2022-12-19 14:37:51 +00:00
includes = ["variant", "utility"]
definitions = '''
struct Thrower {
explicit Thrower(int) {}
Thrower(const Thrower&) { throw std::domain_error("copy ctor"); }
Thrower& operator=(const Thrower&) = default;
};
'''
[cases]
[cases.char_int64_1]
param_types = ["const std::variant<char, int64_t>&"]
setup = "return 'a';"
expect_json = '''[{
"staticSize":16,
"dynamicSize":0,
2023-03-03 20:09:51 +00:00
"exclusiveSize":15,
2022-12-19 14:37:51 +00:00
"length":1,
"capacity":1,
"elementStaticSize":8,
"members":[
{"typeName":"int8_t", "staticSize":1, "exclusiveSize":1, "dynamicSize":0}
2022-12-19 14:37:51 +00:00
]}]'''
expect_json_v2 = '''[{
"size":16,
"staticSize":16,
"exclusiveSize":15,
"length":1,
"capacity":1,
"members":[
{"typeNames":["int8_t"], "size":1, "staticSize":1, "exclusiveSize":1}
]
}]'''
2022-12-19 14:37:51 +00:00
[cases.char_int64_2]
param_types = ["const std::variant<char, int64_t>&"]
setup = "return 1234;"
expect_json = '''[{
"staticSize":16,
"dynamicSize":0,
2023-03-03 20:09:51 +00:00
"exclusiveSize":8,
2022-12-19 14:37:51 +00:00
"length":1,
"capacity":1,
"elementStaticSize":8,
"members":[
{"typeName":"int64_t", "staticSize":8, "exclusiveSize":8, "dynamicSize":0}
2022-12-19 14:37:51 +00:00
]}]'''
expect_json_v2 = '''[{
"size":16,
"staticSize":16,
"exclusiveSize":8,
"length":1,
"capacity":1,
"members":[
{"typeNames":["int64_t"], "size":8, "staticSize":8, "exclusiveSize":8}
]
}]'''
2022-12-19 14:37:51 +00:00
[cases.vector_int_1]
param_types = ["const std::variant<std::vector<int>, int>&"]
setup = "return std::vector<int>{1,2,3};"
expect_json = '''[{
"staticSize":32,
"dynamicSize":12,
2023-03-03 20:09:51 +00:00
"exclusiveSize":8,
2022-12-19 14:37:51 +00:00
"length":1,
"capacity":1,
"elementStaticSize":24,
"members":[
{
"typeName":"std::vector<int32_t, std::allocator<int32_t>>",
2022-12-19 14:37:51 +00:00
"staticSize":24,
"dynamicSize":12,
2023-03-03 20:09:51 +00:00
"exclusiveSize":36,
2022-12-19 14:37:51 +00:00
"length":3,
"capacity":3,
"elementStaticSize":4
}
]}]'''
expect_json_v2 = '''[{
"size":44,
"staticSize":32,
"exclusiveSize":8,
"length":1,
"capacity":1,
"members":[
{"typeNames":["std::vector<int32_t, std::allocator<int32_t>>"], "size":36, "staticSize":24, "exclusiveSize":24, "members":[
{"typeNames":["int32_t"], "size":4, "staticSize":4, "exclusiveSize":4},
{"typeNames":["int32_t"], "size":4, "staticSize":4, "exclusiveSize":4},
{"typeNames":["int32_t"], "size":4, "staticSize":4, "exclusiveSize":4}
]}
]
}]'''
2022-12-19 14:37:51 +00:00
[cases.vector_int_2]
param_types = ["const std::variant<std::vector<int>, int>&"]
setup = "return 123;"
expect_json = '''[{
"staticSize":32,
"dynamicSize":0,
"length":1,
"capacity":1,
"elementStaticSize":24,
"members":[
{
"typeName":"int32_t",
2022-12-19 14:37:51 +00:00
"staticSize":4,
"dynamicSize":0
}
]}]'''
expect_json_v2 = '''[{
"size":32,
"staticSize":32,
"exclusiveSize":28,
"length":1,
"capacity":1,
"members":[
{"typeNames":["int32_t"], "size":4, "staticSize":4, "exclusiveSize":4}
]
}]'''
2022-12-19 14:37:51 +00:00
[cases.optional]
# This test case ensures that the alignment of std::variant is set
# correctly, as otherwise the size of the std::optional would be wrong
param_types = ["const std::optional<std::variant<char, int64_t>>&"]
setup = "return 123;"
expect_json = '''[{
"staticSize":24,
"dynamicSize":0,
2023-03-03 20:09:51 +00:00
"exclusiveSize":8,
2022-12-19 14:37:51 +00:00
"length":1,
"capacity":1,
"elementStaticSize":16,
"members":[
{
"staticSize":16,
"dynamicSize":0,
2023-03-03 20:09:51 +00:00
"exclusiveSize":8,
2022-12-19 14:37:51 +00:00
"length":1,
"capacity":1,
"elementStaticSize":8,
"members":[
{"typeName":"int64_t", "staticSize":8, "exclusiveSize":8, "dynamicSize":0}
2022-12-19 14:37:51 +00:00
]
}
]}]'''
expect_json_v2 = '''[{
"size":24,
"staticSize":24,
"exclusiveSize":8,
"length":1,
"capacity":1,
"members":[{
"size":16,
"staticSize":16,
"exclusiveSize":8,
"length":1,
"capacity":1,
"members":[
{"typeNames":["int64_t"], "size":8, "staticSize":8, "exclusiveSize":8}
]
}]
}]'''
2022-12-19 14:37:51 +00:00
[cases.empty]
# https://en.cppreference.com/w/cpp/utility/variant/valueless_by_exception
param_types = ["const std::variant<int, Thrower>&"]
setup = '''
std::variant<int, Thrower> var{123};
try {
var = Thrower(456);
}
catch (const std::domain_error &ex) {
// Ignore
}
return var;
'''
expect_json = '''[{
"staticSize":8,
"dynamicSize":0,
2023-03-03 20:09:51 +00:00
"exclusiveSize":8,
2022-12-19 14:37:51 +00:00
"length":1,
"capacity":1,
"elementStaticSize":4,
"NOT":"members"
}]'''
expect_json_v2 = '''[{
"size":8,
"staticSize":8,
"exclusiveSize":8,
"length":0,
"capacity":1,
"members":[]
}]'''
2022-12-19 14:37:51 +00:00
# With less than 256 options, parameter indexes are stored in a uint8_t and
# the invalid index value is 0xff. These tests check that we regonise that
# 0xff can be a valid index if there are at least 256 parameters, and that
# the invalid index value is raised to 0xffff.
[cases.256_params_256]
param_types = ["const std::variant<Thrower,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,char>&"]
setup = "return 'a';"
expect_json = '''[{
"staticSize":8,
"dynamicSize":0,
2023-03-03 20:09:51 +00:00
"exclusiveSize":7,
2022-12-19 14:37:51 +00:00
"length":1,
"capacity":1,
"elementStaticSize":4,
"members":[
{"typeName":"int8_t", "staticSize":1, "exclusiveSize":1, "dynamicSize":0}
2022-12-19 14:37:51 +00:00
]}]'''
expect_json_v2 = '''[{
"size":8,
"staticSize":8,
"exclusiveSize":7,
"length":1,
"capacity":1,
"members":[
{"typeNames":["int8_t"], "size":1, "staticSize":1, "exclusiveSize":1}
]
}]'''
2022-12-19 14:37:51 +00:00
[cases.256_params_empty]
param_types = ["const std::variant<Thrower,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,char>&"]
setup = '''
std::variant<Thrower,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,char> var{'a'};
try {
var = Thrower(456);
}
catch (const std::domain_error &ex) {
// Ignore
}
return var;
'''
expect_json = '''[{
"staticSize":8,
"dynamicSize":0,
"length":1,
"capacity":1,
"elementStaticSize":4,
"NOT":"members"
}]'''
expect_json_v2 = '''[{
"size":8,
"staticSize":8,
"exclusiveSize":8,
"length":0,
"capacity":1,
"members":[]
}]'''