AddPaddingTest: Tests for unions and memberless classes

This commit is contained in:
Alastair Robertson 2023-07-18 05:54:52 -07:00 committed by Alastair Robertson
parent 1e1b319a69
commit 3aa52deb71

View File

@ -55,7 +55,7 @@ TEST(AddPaddingTest, AtEnd) {
)"); )");
} }
TEST(AddPaddingTest, UnionNotPadded) { TEST(AddPaddingTest, UnionBetweenMembers) {
auto myclass = Class{0, Class::Kind::Union, "MyUnion", 8}; auto myclass = Class{0, Class::Kind::Union, "MyUnion", 8};
auto myint8 = Primitive{Primitive::Kind::Int8}; auto myint8 = Primitive{Primitive::Kind::Int8};
auto myint64 = Primitive{Primitive::Kind::Int64}; auto myint64 = Primitive{Primitive::Kind::Int64};
@ -71,6 +71,23 @@ TEST(AddPaddingTest, UnionNotPadded) {
)"); )");
} }
TEST(AddPaddingTest, UnionAtEnd) {
test(AddPadding::createPass({}), R"(
[0] Union: MyUnion (size: 16)
Member: n1 (offset: 0)
Primitive: int64_t
Member: n2 (offset: 0)
Primitive: int8_t
)",
R"(
[0] Union: MyUnion (size: 16)
Member: n1 (offset: 0)
Primitive: int64_t
Member: n2 (offset: 0)
Primitive: int8_t
)");
}
TEST(AddPaddingTest, Bitfields) { TEST(AddPaddingTest, Bitfields) {
auto myclass = Class{0, Class::Kind::Class, "MyClass", 16}; auto myclass = Class{0, Class::Kind::Class, "MyClass", 16};
auto myint64 = Primitive{Primitive::Kind::Int64}; auto myint64 = Primitive{Primitive::Kind::Int64};
@ -147,4 +164,28 @@ TEST(AddPaddingTest, CodeGenCompatibility) {
)"); )");
} }
TEST(AddPaddingTest, EmptyClass) {
testNoChange(AddPadding::createPass({}), R"(
[0] Class: MyClass (size: 0)
)");
}
TEST(AddPaddingTest, MemberlessClass) {
test(AddPadding::createPass({}), R"(
[0] Class: MyClass (size: 12)
)",
R"(
[0] Class: MyClass (size: 12)
)");
}
TEST(AddPaddingTest, MemberlessUnion) {
test(AddPadding::createPass({}), R"(
[0] Union: MyUnion (size: 16)
)",
R"(
[0] Union: MyUnion (size: 16)
)");
}
// TODO test we follow class members, templates, children // TODO test we follow class members, templates, children