2023-05-26 13:52:09 +01:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
|
|
#include "oi/type_graph/AddPadding.h"
|
|
|
|
#include "oi/type_graph/Types.h"
|
2023-05-31 14:26:46 +01:00
|
|
|
#include "test/type_graph_utils.h"
|
2023-05-26 13:52:09 +01:00
|
|
|
|
|
|
|
using namespace type_graph;
|
|
|
|
|
|
|
|
TEST(AddPaddingTest, BetweenMembers) {
|
2023-11-13 16:50:09 +00:00
|
|
|
test(AddPadding::createPass(),
|
|
|
|
R"(
|
2023-08-01 19:06:02 +01:00
|
|
|
[0] Class: MyClass (size: 16)
|
|
|
|
Member: n1 (offset: 0)
|
|
|
|
Primitive: int8_t
|
|
|
|
Member: n2 (offset: 8)
|
|
|
|
Primitive: int64_t
|
|
|
|
)",
|
|
|
|
R"(
|
2023-05-26 13:52:09 +01:00
|
|
|
[0] Class: MyClass (size: 16)
|
|
|
|
Member: n1 (offset: 0)
|
|
|
|
Primitive: int8_t
|
2023-06-29 09:15:03 +01:00
|
|
|
Member: __oi_padding (offset: 1)
|
2023-05-26 13:52:09 +01:00
|
|
|
[1] Array: (length: 7)
|
|
|
|
Primitive: int8_t
|
|
|
|
Member: n2 (offset: 8)
|
|
|
|
Primitive: int64_t
|
|
|
|
)");
|
|
|
|
}
|
|
|
|
|
2023-07-26 14:35:21 +01:00
|
|
|
TEST(AddPaddingTest, AtBeginning) {
|
2023-11-13 16:50:09 +00:00
|
|
|
test(AddPadding::createPass(),
|
|
|
|
R"(
|
2023-07-26 14:35:21 +01:00
|
|
|
[0] Struct: MyStruct (size: 16)
|
|
|
|
Member: n1 (offset: 8)
|
|
|
|
Primitive: int64_t
|
|
|
|
)",
|
|
|
|
R"(
|
|
|
|
[0] Struct: MyStruct (size: 16)
|
|
|
|
Member: __oi_padding (offset: 0)
|
|
|
|
[1] Array: (length: 8)
|
|
|
|
Primitive: int8_t
|
|
|
|
Member: n1 (offset: 8)
|
|
|
|
Primitive: int64_t
|
|
|
|
)");
|
|
|
|
}
|
|
|
|
|
2023-05-26 13:52:09 +01:00
|
|
|
TEST(AddPaddingTest, AtEnd) {
|
2023-11-13 16:50:09 +00:00
|
|
|
test(AddPadding::createPass(),
|
|
|
|
R"(
|
2023-08-01 19:06:02 +01:00
|
|
|
[0] Struct: MyStruct (size: 16)
|
|
|
|
Member: n1 (offset: 0)
|
|
|
|
Primitive: int64_t
|
|
|
|
Member: n2 (offset: 8)
|
|
|
|
Primitive: int8_t
|
|
|
|
)",
|
|
|
|
R"(
|
2023-05-26 13:52:09 +01:00
|
|
|
[0] Struct: MyStruct (size: 16)
|
|
|
|
Member: n1 (offset: 0)
|
|
|
|
Primitive: int64_t
|
|
|
|
Member: n2 (offset: 8)
|
|
|
|
Primitive: int8_t
|
2023-06-29 09:15:03 +01:00
|
|
|
Member: __oi_padding (offset: 9)
|
2023-05-26 13:52:09 +01:00
|
|
|
[1] Array: (length: 7)
|
|
|
|
Primitive: int8_t
|
|
|
|
)");
|
|
|
|
}
|
|
|
|
|
2023-07-18 13:54:52 +01:00
|
|
|
TEST(AddPaddingTest, UnionBetweenMembers) {
|
2023-11-13 16:50:09 +00:00
|
|
|
test(AddPadding::createPass(),
|
|
|
|
R"(
|
2023-08-01 19:06:02 +01:00
|
|
|
[0] Union: MyUnion (size: 8)
|
|
|
|
Member: n1 (offset: 0)
|
|
|
|
Primitive: int64_t
|
|
|
|
Member: n2 (offset: 0)
|
|
|
|
Primitive: int8_t
|
|
|
|
)",
|
|
|
|
R"(
|
2023-05-26 13:52:09 +01:00
|
|
|
[0] Union: MyUnion (size: 8)
|
|
|
|
Member: n1 (offset: 0)
|
|
|
|
Primitive: int64_t
|
|
|
|
Member: n2 (offset: 0)
|
|
|
|
Primitive: int8_t
|
|
|
|
)");
|
|
|
|
}
|
|
|
|
|
2023-07-18 13:54:52 +01:00
|
|
|
TEST(AddPaddingTest, UnionAtEnd) {
|
2023-11-13 16:50:09 +00:00
|
|
|
test(AddPadding::createPass(),
|
|
|
|
R"(
|
2023-07-18 13:54:52 +01:00
|
|
|
[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
|
2023-07-18 14:15:59 +01:00
|
|
|
Member: __oi_padding (offset: 0)
|
|
|
|
[1] Array: (length: 16)
|
|
|
|
Primitive: int8_t
|
2023-07-18 13:54:52 +01:00
|
|
|
)");
|
|
|
|
}
|
|
|
|
|
2023-06-29 09:15:03 +01:00
|
|
|
TEST(AddPaddingTest, Bitfields) {
|
2023-11-13 16:50:09 +00:00
|
|
|
test(AddPadding::createPass(),
|
|
|
|
R"(
|
2023-08-01 19:06:02 +01:00
|
|
|
[0] Class: MyClass (size: 16)
|
|
|
|
Member: b1 (offset: 0, bitsize: 3)
|
|
|
|
Primitive: int64_t
|
|
|
|
Member: b2 (offset: 0.375, bitsize: 2)
|
|
|
|
Primitive: int8_t
|
|
|
|
Member: b3 (offset: 1, bitsize: 1)
|
|
|
|
Primitive: int8_t
|
|
|
|
Member: b4 (offset: 8, bitsize: 24)
|
|
|
|
Primitive: int64_t
|
|
|
|
Member: n (offset: 12)
|
|
|
|
Primitive: int16_t
|
|
|
|
)",
|
|
|
|
R"(
|
2023-06-29 09:15:03 +01:00
|
|
|
[0] Class: MyClass (size: 16)
|
|
|
|
Member: b1 (offset: 0, bitsize: 3)
|
|
|
|
Primitive: int64_t
|
|
|
|
Member: b2 (offset: 0.375, bitsize: 2)
|
|
|
|
Primitive: int8_t
|
|
|
|
Member: __oi_padding (offset: 0.625, bitsize: 3)
|
2023-07-19 16:12:45 +01:00
|
|
|
Primitive: int8_t
|
2023-06-29 09:15:03 +01:00
|
|
|
Member: b3 (offset: 1, bitsize: 1)
|
|
|
|
Primitive: int8_t
|
2023-07-19 16:12:45 +01:00
|
|
|
Member: __oi_padding (offset: 1.125, bitsize: 7)
|
|
|
|
Primitive: int8_t
|
|
|
|
Member: __oi_padding (offset: 2)
|
|
|
|
[1] Array: (length: 6)
|
|
|
|
Primitive: int8_t
|
2023-06-29 09:15:03 +01:00
|
|
|
Member: b4 (offset: 8, bitsize: 24)
|
|
|
|
Primitive: int64_t
|
|
|
|
Member: __oi_padding (offset: 11)
|
2023-07-19 16:12:45 +01:00
|
|
|
[2] Array: (length: 1)
|
2023-06-29 09:15:03 +01:00
|
|
|
Primitive: int8_t
|
|
|
|
Member: n (offset: 12)
|
|
|
|
Primitive: int16_t
|
|
|
|
Member: __oi_padding (offset: 14)
|
2023-07-19 16:12:45 +01:00
|
|
|
[3] Array: (length: 2)
|
2023-06-29 09:15:03 +01:00
|
|
|
Primitive: int8_t
|
|
|
|
)");
|
|
|
|
}
|
|
|
|
|
2023-07-18 13:54:52 +01:00
|
|
|
TEST(AddPaddingTest, EmptyClass) {
|
2023-07-11 17:58:21 +01:00
|
|
|
testNoChange(AddPadding::createPass(), R"(
|
2023-07-18 13:54:52 +01:00
|
|
|
[0] Class: MyClass (size: 0)
|
|
|
|
)");
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(AddPaddingTest, MemberlessClass) {
|
2023-11-13 16:50:09 +00:00
|
|
|
test(AddPadding::createPass(),
|
|
|
|
R"(
|
2023-07-18 13:54:52 +01:00
|
|
|
[0] Class: MyClass (size: 12)
|
|
|
|
)",
|
|
|
|
R"(
|
|
|
|
[0] Class: MyClass (size: 12)
|
2023-07-18 13:38:47 +01:00
|
|
|
Member: __oi_padding (offset: 0)
|
|
|
|
[1] Array: (length: 12)
|
|
|
|
Primitive: int8_t
|
2023-07-18 13:54:52 +01:00
|
|
|
)");
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(AddPaddingTest, MemberlessUnion) {
|
2023-11-13 16:50:09 +00:00
|
|
|
test(AddPadding::createPass(),
|
|
|
|
R"(
|
2023-07-18 13:54:52 +01:00
|
|
|
[0] Union: MyUnion (size: 16)
|
|
|
|
)",
|
|
|
|
R"(
|
|
|
|
[0] Union: MyUnion (size: 16)
|
2023-07-18 14:15:59 +01:00
|
|
|
Member: __oi_padding (offset: 0)
|
|
|
|
[1] Array: (length: 16)
|
|
|
|
Primitive: int8_t
|
2023-07-18 13:54:52 +01:00
|
|
|
)");
|
|
|
|
}
|
|
|
|
|
2023-05-26 13:52:09 +01:00
|
|
|
// TODO test we follow class members, templates, children
|