2023-05-26 13:52:09 +01:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
|
|
#include "oi/type_graph/RemoveTopLevelPointer.h"
|
|
|
|
#include "oi/type_graph/Types.h"
|
2023-06-23 12:43:30 +01:00
|
|
|
#include "test/type_graph_utils.h"
|
2023-05-26 13:52:09 +01:00
|
|
|
|
|
|
|
using namespace type_graph;
|
|
|
|
|
|
|
|
TEST(RemoveTopLevelPointerTest, TopLevelPointerRemoved) {
|
2023-07-04 16:55:10 +01:00
|
|
|
auto myint = Primitive{Primitive::Kind::Int32};
|
2023-05-26 13:52:09 +01:00
|
|
|
|
2023-07-05 09:14:05 +01:00
|
|
|
auto myclass = Class{1, Class::Kind::Class, "MyClass", 4};
|
2023-07-05 10:33:44 +01:00
|
|
|
myclass.members.push_back(Member{myint, "n", 0});
|
2023-05-26 13:52:09 +01:00
|
|
|
|
2023-07-05 10:33:44 +01:00
|
|
|
auto ptrA = Pointer{0, myclass};
|
2023-05-26 13:52:09 +01:00
|
|
|
|
2023-07-04 16:55:10 +01:00
|
|
|
test(RemoveTopLevelPointer::createPass(), {ptrA}, R"(
|
2023-05-26 13:52:09 +01:00
|
|
|
[0] Class: MyClass (size: 4)
|
|
|
|
Member: n (offset: 0)
|
|
|
|
Primitive: int32_t
|
|
|
|
)");
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(RemoveTopLevelPointerTest, TopLevelClassUntouched) {
|
2023-07-04 16:55:10 +01:00
|
|
|
auto myint = Primitive{Primitive::Kind::Int32};
|
2023-05-26 13:52:09 +01:00
|
|
|
|
2023-07-05 09:14:05 +01:00
|
|
|
auto myclass = Class{0, Class::Kind::Class, "MyClass", 4};
|
2023-07-05 10:33:44 +01:00
|
|
|
myclass.members.push_back(Member{myint, "n", 0});
|
2023-05-26 13:52:09 +01:00
|
|
|
|
2023-07-04 16:55:10 +01:00
|
|
|
test(RemoveTopLevelPointer::createPass(), {myclass}, R"(
|
2023-05-26 13:52:09 +01:00
|
|
|
[0] Class: MyClass (size: 4)
|
|
|
|
Member: n (offset: 0)
|
|
|
|
Primitive: int32_t
|
|
|
|
)");
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(RemoveTopLevelPointerTest, IntermediatePointerUntouched) {
|
2023-07-04 16:55:10 +01:00
|
|
|
auto myint = Primitive{Primitive::Kind::Int32};
|
2023-07-05 10:33:44 +01:00
|
|
|
auto ptrInt = Pointer{1, myint};
|
2023-05-26 13:52:09 +01:00
|
|
|
|
2023-07-05 09:14:05 +01:00
|
|
|
auto myclass = Class{0, Class::Kind::Class, "MyClass", 4};
|
2023-07-05 10:33:44 +01:00
|
|
|
myclass.members.push_back(Member{ptrInt, "n", 0});
|
2023-05-26 13:52:09 +01:00
|
|
|
|
2023-07-04 16:55:10 +01:00
|
|
|
test(RemoveTopLevelPointer::createPass(), {myclass}, R"(
|
2023-05-26 13:52:09 +01:00
|
|
|
[0] Class: MyClass (size: 4)
|
|
|
|
Member: n (offset: 0)
|
|
|
|
[1] Pointer
|
|
|
|
Primitive: int32_t
|
|
|
|
)");
|
|
|
|
}
|