summaryrefslogtreecommitdiff
path: root/test/util/unique_any.test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/util/unique_any.test.cpp')
-rw-r--r--test/util/unique_any.test.cpp40
1 files changed, 21 insertions, 19 deletions
diff --git a/test/util/unique_any.test.cpp b/test/util/unique_any.test.cpp
index 9b622cd284..ffd9e87be6 100644
--- a/test/util/unique_any.test.cpp
+++ b/test/util/unique_any.test.cpp
@@ -1,6 +1,7 @@
#include <mbgl/test/util.hpp>
#include <mbgl/util/unique_any.hpp>
+#include <mbgl/util/typeid.hpp>
using namespace mbgl::util;
@@ -31,59 +32,59 @@ bool IsStackAllocated (const unique_any& a, const void* obj1) {
TEST(UniqueAny, Empty) {
EXPECT_FALSE(unique_any().has_value());
- EXPECT_TRUE(unique_any().type() == typeid(void));
+ EXPECT_TRUE(unique_any().type() == TypeID::getID<void>());
EXPECT_THROW(any_cast<int>(unique_any()), bad_any_cast);
}
TEST(UniqueAny, BasicTypes) {
unique_any i = 3;
EXPECT_TRUE(i.has_value());
- EXPECT_TRUE(i.type() == typeid(int));
+ EXPECT_TRUE(i.type() == TypeID::getID<int>());
EXPECT_TRUE(IsStackAllocated(i, any_cast<int>(&i)));
auto iValue = any_cast<int>(i);
EXPECT_TRUE(iValue == 3);
EXPECT_TRUE(unique_any(4).has_value());
- EXPECT_TRUE(unique_any(4).type() == typeid(int));
+ EXPECT_TRUE(unique_any(4).type() == TypeID::getID<int>());
unique_any f = 6.2f;
EXPECT_TRUE(f.has_value());
- EXPECT_TRUE(f.type() == typeid(float));
+ EXPECT_TRUE(f.type() == TypeID::getID<float>());
EXPECT_TRUE(IsStackAllocated(f, any_cast<float>(&f)));
const float fValue = any_cast<const float>(f);
EXPECT_TRUE(fValue == 6.2f);
EXPECT_TRUE(unique_any(1.0f).has_value());
- EXPECT_TRUE(unique_any(1.0f).type() == typeid(float));
+ EXPECT_TRUE(unique_any(1.0f).type() == TypeID::getID<float>());
unique_any c = 'z';
EXPECT_TRUE(c.has_value());
- EXPECT_TRUE(c.type() == typeid(char));
+ EXPECT_TRUE(c.type() == TypeID::getID<char>());
EXPECT_TRUE(IsStackAllocated(c, any_cast<char>(&c)));
EXPECT_THROW(any_cast<float>(c), bad_any_cast);
EXPECT_TRUE(unique_any('4').has_value());
- EXPECT_TRUE(unique_any('4').type() == typeid(char));
+ EXPECT_TRUE(unique_any('4').type() == TypeID::getID<char>());
}
TEST(UniqueAny, BasicTypes_Move) {
unique_any i = 3;
EXPECT_TRUE(i.has_value());
- EXPECT_TRUE(i.type() == typeid(int));
+ EXPECT_TRUE(i.type() == TypeID::getID<int>());
unique_any f = 6.2f;
EXPECT_TRUE(f.has_value());
- EXPECT_TRUE(f.type() == typeid(float));
+ EXPECT_TRUE(f.type() == TypeID::getID<float>());
f = std::move(i);
EXPECT_FALSE(i.has_value());
- EXPECT_TRUE(i.type() == typeid(void));
+ EXPECT_TRUE(i.type() == TypeID::getID<void>());
EXPECT_TRUE(f.has_value());
- EXPECT_TRUE(f.type() == typeid(int));
+ EXPECT_TRUE(f.type() == TypeID::getID<int>());
}
@@ -124,15 +125,15 @@ TEST(UniqueAny, LargeType) {
TestType t1;
unique_any u1 = unique_any(std::move(t1));
EXPECT_TRUE(u1.has_value());
- EXPECT_TRUE(u1.type() == typeid(TestType));
+ EXPECT_TRUE(u1.type() == TypeID::getID<TestType>());
EXPECT_FALSE(IsStackAllocated(u1, any_cast<TestType>(&u1)));
//TestType should be moved into owning unique_any
EXPECT_EQ(any_cast<TestType>(&u1)->i1, 1);
auto u2(std::move(u1));
- EXPECT_TRUE(u2.type() == typeid(TestType));
- EXPECT_TRUE(u1.type() == typeid(void));
+ EXPECT_TRUE(u2.type() == TypeID::getID<TestType>());
+ EXPECT_TRUE(u1.type() == TypeID::getID<void>());
//TestType should not be moved when owning unique_any is moved;
EXPECT_EQ(any_cast<TestType>(&u2)->i1, 1);
@@ -142,7 +143,7 @@ TEST(UniqueAny, LargeType) {
// First out of the unique_any, and then in the return statement
auto t2 = any_cast<TestType>(std::move(u2));
EXPECT_EQ(t2.i1, 3);
- EXPECT_TRUE(u2.type() == typeid(void));
+ EXPECT_TRUE(u2.type() == TypeID::getID<void>());
}
TEST(UniqueAny, Pointer) {
@@ -150,7 +151,8 @@ TEST(UniqueAny, Pointer) {
auto u1 = unique_any(std::move(t1));
EXPECT_TRUE(u1.has_value());
- EXPECT_TRUE(u1.type() == typeid(TestType *));
+ EXPECT_TRUE(u1.type() == TypeID::getID<TestType *>());
+ EXPECT_FALSE(u1.type() == TypeID::getID<void *>());
EXPECT_TRUE(IsStackAllocated(u1, any_cast<TestType *>(&u1)));
//Only the pointer should be moved
@@ -161,10 +163,10 @@ TEST(UniqueAny, Pointer) {
std::swap(u2, u1);
EXPECT_TRUE(u1.has_value());
- EXPECT_TRUE(u1.type() == typeid(int));
+ EXPECT_TRUE(u1.type() == TypeID::getID<int>());
EXPECT_TRUE(u2.has_value());
- EXPECT_TRUE(u2.type() == typeid(TestType *));
+ EXPECT_TRUE(u2.type() == TypeID::getID<TestType *>());
t2 = *any_cast<TestType *>(&u2);
EXPECT_EQ(t2->i1, 0);
@@ -178,7 +180,7 @@ TEST(UniqueAny, UniquePtr) {
EXPECT_EQ(t1.get(), nullptr);
EXPECT_TRUE(u1.has_value());
- EXPECT_TRUE(u1.type() == typeid(std::unique_ptr<TestType>));
+ EXPECT_TRUE(u1.type() == TypeID::getID<std::unique_ptr<TestType>>());
EXPECT_TRUE(IsStackAllocated(u1, any_cast<std::unique_ptr<TestType>>(&u1)));