Integration tests: Add tests for alignment of unions

This commit is contained in:
Alastair Robertson 2023-07-18 10:37:09 -07:00 committed by Alastair Robertson
parent 1334e08d05
commit fd54d0ea83
2 changed files with 33 additions and 0 deletions

View File

@ -25,6 +25,11 @@ definitions = '''
alignas(32) char c32;
};
union UnionMember {
char c1;
alignas(32) char c2;
};
struct MemberAlignmentOverriden {
char c;
alignas(32) Align16 alignmentIncreased;
@ -106,6 +111,22 @@ definitions = '''
{"typeName": "char", "staticSize": 1, "exclusiveSize": 1},
{"typeName": "char", "staticSize": 1, "exclusiveSize": 1}
]}]}]'''
[cases.wrapper_union_member]
param_types = ["const Wrapper<UnionMember>&"]
setup = "return {};"
expect_json = '''[
{"staticSize": 64, "exclusiveSize": 31, "members": [
{"typeName": "int8_t", "staticSize": 1, "exclusiveSize": 1},
{"typeName": "UnionMember", "staticSize": 32, "exclusiveSize": 32, "NOT":"members"}
]}]'''
[cases.container_union_member]
skip = "container alignment is broken (#143)"
param_types = ["const std::optional<UnionMember>&"]
setup = "return {};"
expect_json = '''[
{"staticSize": 64, "exclusiveSize": 32, "members": [
{"typeName": "UnionMember", "staticSize": 32, "exclusiveSize": 32, "NOT":"members"}
]}]'''
[cases.wrapper_member_override]
param_types = ["const Wrapper<MemberAlignmentOverriden>&"]
setup = "return {};"

View File

@ -10,6 +10,7 @@ definitions = '''
MyUnion(int n_) : n(n_) {}
MyUnion(const std::vector<int>& vec_) : vec(vec_) {}
MyUnion(const std::unordered_map<std::string, std::string>& map_) : map(map_) {}
MyUnion(const MyUnion& /*other*/) { /* we don't know which field to copy */ }
~MyUnion() {}
};
@ -52,6 +53,17 @@ definitions = '''
param_types = ["const MyUnion&"]
setup = 'return std::unordered_map<std::string, std::string>{{"a", "b"}, {"c","d"}};'
expect_json = '[{"staticSize":56, "dynamicSize":0, "exclusiveSize":56, "NOT":"members"}]'
[cases.alignment]
# Wrap the union in a pair as a way of inferring its alignment
param_types = ["const std::pair<char, MyUnion>&"]
setup = 'return {{0, MyUnion{123}}};'
expect_json = '''[
{"staticSize":64, "dynamicSize":0, "exclusiveSize":7, "members":[
{"staticSize":1, "dynamicSize":0, "exclusiveSize":1},
{"staticSize":56, "dynamicSize":0, "exclusiveSize":56, "NOT":"members"}
]}]'''
[cases.tagged_int]
param_types = ["const TaggedUnion&"]
setup = "return TaggedUnion{MyUnion{123}, 0};"