object-introspection/test/test_type_identifier.cpp
Alastair Robertson 784b900218 TypeGraph: Replace allocators with DummyAllocator
When we were previously removing allocators, we were only able to work
with containers whose allocators appeared as their last template
parameter.

Now we can replace allocators in the middle of a parameter list.

This fixes tests for folly::sorted_vector_set.
2023-05-31 15:49:37 +01:00

110 lines
2.9 KiB
C++

#include <gtest/gtest.h>
#include "oi/type_graph/Printer.h"
#include "oi/type_graph/TypeIdentifier.h"
#include "oi/type_graph/Types.h"
#include "test/type_graph_utils.h"
using namespace type_graph;
TEST(TypeIdentifierTest, StubbedParam) {
auto myint = Primitive{Primitive::Kind::Int32};
auto myparam = Class{Class::Kind::Struct, "MyParam", 4};
myparam.members.push_back(Member{&myint, "a", 0});
auto container = getVector();
container.templateParams.push_back(TemplateParam{&myint});
container.templateParams.push_back(TemplateParam{&myparam});
container.templateParams.push_back(TemplateParam{&myint});
test(TypeIdentifier::createPass(), {container}, R"(
[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};
auto myalloc = Class{Class::Kind::Struct, "MyAlloc", 8};
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});
container.templateParams.push_back(TemplateParam{&myint});
test(TypeIdentifier::createPass(), {container}, R"(
[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
)");
}
TEST(TypeIdentifierTest, AllocatorNoParam) {
auto myint = Primitive{Primitive::Kind::Int32};
auto myalloc = Class{Class::Kind::Struct, "MyAlloc", 8};
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});
test(TypeIdentifier::createPass(), {container}, R"(
[0] Container: std::vector (size: 24)
Param
Primitive: int32_t
Param
[1] Struct: MyAlloc (size: 8)
Function: allocate
Function: deallocate
)",
R"(
[0] Container: std::vector (size: 24)
Param
Primitive: int32_t
Param
DummyAllocator (size: 8)
Primitive: int32_t
)");
}