2023-05-26 13:52:09 +01:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
|
|
#include "oi/type_graph/TypeIdentifier.h"
|
2023-05-31 14:49:47 +01:00
|
|
|
#include "oi/type_graph/Types.h"
|
|
|
|
#include "test/type_graph_utils.h"
|
2023-05-26 13:52:09 +01:00
|
|
|
|
|
|
|
using namespace type_graph;
|
|
|
|
|
2023-05-31 14:49:47 +01:00
|
|
|
TEST(TypeIdentifierTest, StubbedParam) {
|
|
|
|
auto myint = Primitive{Primitive::Kind::Int32};
|
|
|
|
|
2023-07-05 09:14:05 +01:00
|
|
|
auto myparam = Class{1, Class::Kind::Struct, "MyParam", 4};
|
2023-07-05 10:33:44 +01:00
|
|
|
myparam.members.push_back(Member{myint, "a", 0});
|
2023-05-31 14:49:47 +01:00
|
|
|
|
|
|
|
auto container = getVector();
|
2023-07-05 10:33:44 +01:00
|
|
|
container.templateParams.push_back(TemplateParam{myint});
|
|
|
|
container.templateParams.push_back(TemplateParam{myparam});
|
|
|
|
container.templateParams.push_back(TemplateParam{myint});
|
2023-05-31 14:49:47 +01:00
|
|
|
|
2023-06-28 16:17:45 +01:00
|
|
|
test(TypeIdentifier::createPass({}), {container}, R"(
|
2023-05-31 14:49:47 +01:00
|
|
|
[0] Container: std::vector (size: 24)
|
|
|
|
Param
|
|
|
|
Primitive: int32_t
|
|
|
|
Param
|
|
|
|
[1] Struct: MyParam (size: 4)
|
|
|
|
Member: a (offset: 0)
|
|
|
|
Primitive: int32_t
|
|
|
|
Param
|
|
|
|
Primitive: int32_t
|
|
|
|
)",
|
|
|
|
R"(
|
|
|
|
[0] Container: std::vector (size: 24)
|
|
|
|
Param
|
|
|
|
Primitive: int32_t
|
|
|
|
Param
|
|
|
|
Dummy (size: 4)
|
|
|
|
Param
|
|
|
|
Primitive: int32_t
|
|
|
|
)");
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(TypeIdentifierTest, Allocator) {
|
|
|
|
auto myint = Primitive{Primitive::Kind::Int32};
|
|
|
|
|
2023-07-05 09:14:05 +01:00
|
|
|
auto myalloc = Class{1, Class::Kind::Struct, "MyAlloc", 8};
|
2023-07-05 10:33:44 +01:00
|
|
|
myalloc.templateParams.push_back(TemplateParam{myint});
|
2023-05-31 14:49:47 +01:00
|
|
|
myalloc.functions.push_back(Function{"allocate"});
|
|
|
|
myalloc.functions.push_back(Function{"deallocate"});
|
|
|
|
|
|
|
|
auto container = getVector();
|
2023-07-05 10:33:44 +01:00
|
|
|
container.templateParams.push_back(TemplateParam{myint});
|
|
|
|
container.templateParams.push_back(TemplateParam{myalloc});
|
|
|
|
container.templateParams.push_back(TemplateParam{myint});
|
2023-05-31 14:49:47 +01:00
|
|
|
|
2023-06-28 16:17:45 +01:00
|
|
|
test(TypeIdentifier::createPass({}), {container}, R"(
|
2023-05-31 14:49:47 +01:00
|
|
|
[0] Container: std::vector (size: 24)
|
|
|
|
Param
|
|
|
|
Primitive: int32_t
|
|
|
|
Param
|
|
|
|
[1] Struct: MyAlloc (size: 8)
|
|
|
|
Param
|
|
|
|
Primitive: int32_t
|
|
|
|
Function: allocate
|
|
|
|
Function: deallocate
|
|
|
|
Param
|
|
|
|
Primitive: int32_t
|
|
|
|
)",
|
|
|
|
R"(
|
|
|
|
[0] Container: std::vector (size: 24)
|
|
|
|
Param
|
|
|
|
Primitive: int32_t
|
|
|
|
Param
|
|
|
|
DummyAllocator (size: 8)
|
|
|
|
Primitive: int32_t
|
|
|
|
Param
|
|
|
|
Primitive: int32_t
|
|
|
|
)");
|
|
|
|
}
|
|
|
|
|
2023-06-26 16:07:12 +01:00
|
|
|
TEST(TypeIdentifierTest, AllocatorSize1) {
|
2023-05-31 14:49:47 +01:00
|
|
|
auto myint = Primitive{Primitive::Kind::Int32};
|
|
|
|
|
2023-07-05 09:14:05 +01:00
|
|
|
auto myalloc = Class{1, Class::Kind::Struct, "MyAlloc", 1};
|
2023-07-05 10:33:44 +01:00
|
|
|
myalloc.templateParams.push_back(TemplateParam{myint});
|
2023-05-31 14:49:47 +01:00
|
|
|
myalloc.functions.push_back(Function{"allocate"});
|
|
|
|
myalloc.functions.push_back(Function{"deallocate"});
|
|
|
|
|
|
|
|
auto container = getVector();
|
2023-07-05 10:33:44 +01:00
|
|
|
container.templateParams.push_back(TemplateParam{myint});
|
|
|
|
container.templateParams.push_back(TemplateParam{myalloc});
|
|
|
|
container.templateParams.push_back(TemplateParam{myint});
|
2023-05-31 14:49:47 +01:00
|
|
|
|
2023-06-28 16:17:45 +01:00
|
|
|
test(TypeIdentifier::createPass({}), {container}, R"(
|
2023-05-31 14:49:47 +01:00
|
|
|
[0] Container: std::vector (size: 24)
|
|
|
|
Param
|
|
|
|
Primitive: int32_t
|
|
|
|
Param
|
2023-06-26 16:07:12 +01:00
|
|
|
[1] Struct: MyAlloc (size: 1)
|
|
|
|
Param
|
|
|
|
Primitive: int32_t
|
2023-05-31 14:49:47 +01:00
|
|
|
Function: allocate
|
|
|
|
Function: deallocate
|
2023-06-26 16:07:12 +01:00
|
|
|
Param
|
|
|
|
Primitive: int32_t
|
2023-05-31 14:49:47 +01:00
|
|
|
)",
|
|
|
|
R"(
|
|
|
|
[0] Container: std::vector (size: 24)
|
|
|
|
Param
|
|
|
|
Primitive: int32_t
|
|
|
|
Param
|
2023-06-26 16:07:12 +01:00
|
|
|
DummyAllocator (size: 0)
|
2023-05-31 14:49:47 +01:00
|
|
|
Primitive: int32_t
|
2023-06-26 16:07:12 +01:00
|
|
|
Param
|
|
|
|
Primitive: int32_t
|
2023-05-31 14:49:47 +01:00
|
|
|
)");
|
|
|
|
}
|
2023-07-06 14:10:04 +01:00
|
|
|
|
|
|
|
TEST(TypeIdentifierTest, PassThroughTypes) {
|
|
|
|
auto myint = Primitive{Primitive::Kind::Int32};
|
|
|
|
|
|
|
|
auto myalloc = Class{1, Class::Kind::Class, "std::allocator", 1};
|
|
|
|
myalloc.templateParams.push_back(TemplateParam{myint});
|
|
|
|
myalloc.functions.push_back(Function{"allocate"});
|
|
|
|
myalloc.functions.push_back(Function{"deallocate"});
|
|
|
|
|
|
|
|
auto container = getVector();
|
|
|
|
container.templateParams.push_back(TemplateParam{myint});
|
|
|
|
container.templateParams.push_back(TemplateParam{myalloc});
|
|
|
|
|
|
|
|
std::vector<ContainerInfo> passThroughTypes;
|
|
|
|
passThroughTypes.emplace_back("std::allocator", DUMMY_TYPE, "memory");
|
|
|
|
|
|
|
|
test(TypeIdentifier::createPass(passThroughTypes), {container}, R"(
|
|
|
|
[0] Container: std::vector (size: 24)
|
|
|
|
Param
|
|
|
|
Primitive: int32_t
|
|
|
|
Param
|
|
|
|
[1] Class: std::allocator (size: 1)
|
|
|
|
Param
|
|
|
|
Primitive: int32_t
|
|
|
|
Function: allocate
|
|
|
|
Function: deallocate
|
|
|
|
)",
|
|
|
|
R"(
|
|
|
|
[0] Container: std::vector (size: 24)
|
|
|
|
Param
|
|
|
|
Primitive: int32_t
|
|
|
|
Param
|
|
|
|
[1] Container: std::allocator (size: 1)
|
|
|
|
Param
|
|
|
|
Primitive: int32_t
|
|
|
|
)");
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(TypeIdentifierTest, ContainerNotReplaced) {
|
|
|
|
auto myint = Primitive{Primitive::Kind::Int32};
|
|
|
|
|
|
|
|
ContainerInfo allocatorInfo{"std::allocator", DUMMY_TYPE, "memory"};
|
|
|
|
auto myalloc = Container{1, allocatorInfo, 1};
|
|
|
|
myalloc.templateParams.push_back(TemplateParam{myint});
|
|
|
|
|
|
|
|
auto container = getVector();
|
|
|
|
container.templateParams.push_back(TemplateParam{myint});
|
|
|
|
container.templateParams.push_back(TemplateParam{myalloc});
|
|
|
|
|
|
|
|
test(TypeIdentifier::createPass({}), {container}, R"(
|
|
|
|
[0] Container: std::vector (size: 24)
|
|
|
|
Param
|
|
|
|
Primitive: int32_t
|
|
|
|
Param
|
|
|
|
[1] Container: std::allocator (size: 1)
|
|
|
|
Param
|
|
|
|
Primitive: int32_t
|
|
|
|
)",
|
|
|
|
R"(
|
|
|
|
[0] Container: std::vector (size: 24)
|
|
|
|
Param
|
|
|
|
Primitive: int32_t
|
|
|
|
Param
|
|
|
|
Dummy (size: 0, align: 8)
|
|
|
|
)");
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(TypeIdentifierTest, DummyNotReplaced) {
|
|
|
|
auto myint = Primitive{Primitive::Kind::Int32};
|
|
|
|
|
|
|
|
auto dummy = Dummy{22, 0};
|
|
|
|
|
|
|
|
auto container = getVector();
|
|
|
|
container.templateParams.push_back(TemplateParam{myint});
|
|
|
|
container.templateParams.push_back(TemplateParam{dummy});
|
|
|
|
|
|
|
|
test(TypeIdentifier::createPass({}), {container}, R"(
|
|
|
|
[0] Container: std::vector (size: 24)
|
|
|
|
Param
|
|
|
|
Primitive: int32_t
|
|
|
|
Param
|
|
|
|
Dummy (size: 22)
|
|
|
|
)",
|
|
|
|
R"(
|
|
|
|
[0] Container: std::vector (size: 24)
|
|
|
|
Param
|
|
|
|
Primitive: int32_t
|
|
|
|
Param
|
|
|
|
Dummy (size: 22)
|
|
|
|
)");
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(TypeIdentifierTest, DummyAllocatorNotReplaced) {
|
|
|
|
auto myint = Primitive{Primitive::Kind::Int32};
|
|
|
|
|
|
|
|
auto dummy = DummyAllocator{myint, 22, 0};
|
|
|
|
|
|
|
|
auto container = getVector();
|
|
|
|
container.templateParams.push_back(TemplateParam{myint});
|
|
|
|
container.templateParams.push_back(TemplateParam{dummy});
|
|
|
|
|
|
|
|
test(TypeIdentifier::createPass({}), {container}, R"(
|
|
|
|
[0] Container: std::vector (size: 24)
|
|
|
|
Param
|
|
|
|
Primitive: int32_t
|
|
|
|
Param
|
|
|
|
DummyAllocator (size: 22)
|
|
|
|
Primitive: int32_t
|
|
|
|
)",
|
|
|
|
R"(
|
|
|
|
[0] Container: std::vector (size: 24)
|
|
|
|
Param
|
|
|
|
Primitive: int32_t
|
|
|
|
Param
|
|
|
|
DummyAllocator (size: 22)
|
|
|
|
Primitive: int32_t
|
|
|
|
)");
|
|
|
|
}
|