object-introspection/test/test_remove_members.cpp
Jake Hillion db93feb180 incomplete: name type in compiler errors
Summary:

We have a good type representation in the Type Graph of an incomplete type and
the underlying type that represents. However, this incomplete type still ends
up in the generated code as `void` which loses information. For example, a
container that can't contain void may fail to compile because it was
initialised with `void` but really its because the type it was supposed to be
initialised with (say, `Foo`) had incomplete debug information.

This change identifies that a type is incomplete in the output by generating it
as an incomplete type `struct Incomplete<struct Foo>`. This allows us to name
the type correctly in the TreeBuilder output and filter for incomplete types,
as well as getting appropriate compiler errors if it mustn't be incomplete.

Test Plan:
- CI
- Added a unit test to namegen.
- Enabled and added an extra pointers_incomplete test.

This change is tricky to test because it isn't really user visible. The types
still use their `inputName` which is unchanged in any successful output - this
change is used so the compiler fails with a more detailed error.
2024-01-09 15:08:25 +00:00

206 lines
4.9 KiB
C++

#include <gtest/gtest.h>
#include "oi/type_graph/RemoveMembers.h"
#include "oi/type_graph/Types.h"
#include "test/type_graph_utils.h"
using namespace type_graph;
TEST(RemoveMembersTest, Match) {
const std::vector<std::pair<std::string, std::string>>& membersToIgnore = {
{"ClassA", "b"},
};
test(RemoveMembers::createPass(membersToIgnore),
R"(
[0] Class: ClassA (size: 12)
Member: a (offset: 0)
[1] Class: ClassB (size: 4)
Member: b (offset: 4)
[1]
Member: c (offset: 8)
[1]
)",
R"(
[0] Class: ClassA (size: 12)
Member: a (offset: 0)
[1] Class: ClassB (size: 4)
Member: c (offset: 8)
[1]
)");
}
TEST(RemoveMembersTest, TypeMatchMemberMiss) {
const std::vector<std::pair<std::string, std::string>>& membersToIgnore = {
{"ClassA", "x"},
};
testNoChange(RemoveMembers::createPass(membersToIgnore), R"(
[0] Class: ClassA (size: 12)
Member: a (offset: 0)
[1] Class: ClassB (size: 4)
Member: b (offset: 4)
[1]
Member: c (offset: 8)
[1]
)");
}
TEST(RemoveMembersTest, MemberMatchWrongType) {
const std::vector<std::pair<std::string, std::string>>& membersToIgnore = {
{"ClassB", "b"},
};
testNoChange(RemoveMembers::createPass(membersToIgnore), R"(
[0] Class: ClassA (size: 12)
Member: a (offset: 0)
[1] Class: ClassB (size: 4)
Member: b (offset: 4)
[1]
Member: c (offset: 8)
[1]
)");
}
TEST(RemoveMembersTest, RecurseClassParam) {
const std::vector<std::pair<std::string, std::string>>& membersToIgnore = {
{"ClassA", "b"},
};
test(RemoveMembers::createPass(membersToIgnore),
R"(
[0] Class: MyClass (size: 0)
Param
[1] Class: ClassA (size: 12)
Member: a (offset: 0)
Primitive: int32_t
Member: b (offset: 4)
Primitive: int32_t
Member: c (offset: 8)
Primitive: int32_t
)",
R"(
[0] Class: MyClass (size: 0)
Param
[1] Class: ClassA (size: 12)
Member: a (offset: 0)
Primitive: int32_t
Member: c (offset: 8)
Primitive: int32_t
)");
}
TEST(RemoveMembersTest, RecurseClassParent) {
const std::vector<std::pair<std::string, std::string>>& membersToIgnore = {
{"ClassA", "b"},
};
test(RemoveMembers::createPass(membersToIgnore),
R"(
[0] Class: MyClass (size: 0)
Parent (offset: 0)
[1] Class: ClassA (size: 12)
Member: a (offset: 0)
Primitive: int32_t
Member: b (offset: 4)
Primitive: int32_t
Member: c (offset: 8)
Primitive: int32_t
)",
R"(
[0] Class: MyClass (size: 0)
Parent (offset: 0)
[1] Class: ClassA (size: 12)
Member: a (offset: 0)
Primitive: int32_t
Member: c (offset: 8)
Primitive: int32_t
)");
}
TEST(RemoveMembersTest, RecurseClassMember) {
const std::vector<std::pair<std::string, std::string>>& membersToIgnore = {
{"ClassA", "b"},
};
test(RemoveMembers::createPass(membersToIgnore),
R"(
[0] Class: MyClass (size: 0)
Member: xxx (offset: 0)
[1] Class: ClassA (size: 12)
Member: a (offset: 0)
Primitive: int32_t
Member: b (offset: 4)
Primitive: int32_t
Member: c (offset: 8)
Primitive: int32_t
)",
R"(
[0] Class: MyClass (size: 0)
Member: xxx (offset: 0)
[1] Class: ClassA (size: 12)
Member: a (offset: 0)
Primitive: int32_t
Member: c (offset: 8)
Primitive: int32_t
)");
}
TEST(RemoveMembersTest, RecurseClassChild) {
const std::vector<std::pair<std::string, std::string>>& membersToIgnore = {
{"ClassA", "b"},
};
test(RemoveMembers::createPass(membersToIgnore),
R"(
[0] Class: MyClass (size: 0)
Child
[1] Class: ClassA (size: 12)
Member: a (offset: 0)
Primitive: int32_t
Member: b (offset: 4)
Primitive: int32_t
Member: c (offset: 8)
Primitive: int32_t
)",
R"(
[0] Class: MyClass (size: 0)
Child
[1] Class: ClassA (size: 12)
Member: a (offset: 0)
Primitive: int32_t
Member: c (offset: 8)
Primitive: int32_t
)");
}
TEST(RemoveMembersTest, Union) {
test(RemoveMembers::createPass({}),
R"(
[0] Union: MyUnion (size: 4)
Member: a (offset: 0)
Primitive: int32_t
Member: b (offset: 0)
Primitive: int32_t
)",
R"(
[0] Union: MyUnion (size: 4)
)");
}
TEST(RemoveMembersTest, Incomplete) {
test(RemoveMembers::createPass({}),
R"(
[0] Class: ClassA (size: 12)
Member: a (offset: 0)
Primitive: int32_t
Member: b (offset: 4)
[1] Incomplete: [MyIncompleteType]
Member: c (offset: 8)
Primitive: int32_t
)",
R"(
[0] Class: ClassA (size: 12)
Member: a (offset: 0)
Primitive: int32_t
Member: c (offset: 8)
Primitive: int32_t
)");
}