diff options
author | Mikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com> | 2019-09-09 18:35:23 +0300 |
---|---|---|
committer | Mikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com> | 2019-09-10 11:51:17 +0300 |
commit | 151ea331f87a8d3655b0b1a36f3e74de4ff708b9 (patch) | |
tree | 90056e643ae93b59f7fe434cc52db62581a037c1 /test | |
parent | 5207a360746d7d0541e21ca4e8d22b432f41d8f5 (diff) | |
download | qtlocation-mapboxgl-151ea331f87a8d3655b0b1a36f3e74de4ff708b9.tar.gz |
[core] Use mapbox::base::TypeWrapper instead of utils::peer
Diffstat (limited to 'test')
-rw-r--r-- | test/test-files.json | 1 | ||||
-rw-r--r-- | test/util/peer.test.cpp | 189 |
2 files changed, 0 insertions, 190 deletions
diff --git a/test/test-files.json b/test/test-files.json index f5e4013029..b239ac5ad8 100644 --- a/test/test-files.json +++ b/test/test-files.json @@ -93,7 +93,6 @@ "test/util/merge_lines.test.cpp", "test/util/number_conversions.test.cpp", "test/util/offscreen_texture.test.cpp", - "test/util/peer.test.cpp", "test/util/position.test.cpp", "test/util/projection.test.cpp", "test/util/run_loop.test.cpp", diff --git a/test/util/peer.test.cpp b/test/util/peer.test.cpp deleted file mode 100644 index a808dd27d1..0000000000 --- a/test/util/peer.test.cpp +++ /dev/null @@ -1,189 +0,0 @@ -#include <mbgl/test/util.hpp> - -#include <mbgl/util/peer.hpp> - -using namespace mbgl::util; - -class TestType { -public: - TestType() { - str[0] = 'a'; - } - - //Detect moves - TestType(TestType&& t): i1(t.i1+1), i2(t.i2+2) { - str[0] = t.str[0]+1; - } - - TestType(const TestType&) = delete; - TestType& operator=(const TestType&) = delete; - - int i1 = 0; - int i2 = 1; - char str[256]; -}; - -bool IsStackAllocated (const peer& a, const void* obj1) { - auto a_ptr = (uintptr_t)(&a); - auto obj = (uintptr_t)(obj1); - return (obj >= a_ptr && obj < a_ptr + sizeof(peer)); -}; - -TEST(Peer, Empty) { - EXPECT_FALSE(peer().has_value()); -} - -TEST(Peer, BasicTypes) { - peer i = 3; - EXPECT_TRUE(i.has_value()); - EXPECT_TRUE(i.get<decltype(3)>() == 3); - - auto iValue = i.get<decltype(3)>(); - EXPECT_TRUE(iValue == 3); - - EXPECT_TRUE(peer(4).has_value()); - EXPECT_TRUE(peer(4).get<decltype(4)>() == 4); - - peer f = 6.2f; - EXPECT_TRUE(f.has_value()); - EXPECT_TRUE(f.get<decltype(6.2f)>() == 6.2f); - - const float fValue = f.get<decltype(6.2f)>(); - EXPECT_TRUE(fValue == 6.2f); - - EXPECT_TRUE(peer(1.0f).has_value()); - EXPECT_TRUE(peer(1.0f).get<decltype(1.0f)>() == 1.0f); - - peer c = 'z'; - EXPECT_TRUE(c.has_value()); - EXPECT_TRUE(c.get<decltype('z')>() == 'z'); - - EXPECT_TRUE(peer('z').has_value()); - EXPECT_TRUE(peer('z').get<decltype('z')>() == 'z'); -} - -TEST(Peer, BasicTypes_Move) { - peer i = 3; - EXPECT_TRUE(i.has_value()); - - peer f = 6.2f; - EXPECT_TRUE(f.has_value()); - - f = std::move(i); - EXPECT_FALSE(i.has_value()); - - EXPECT_TRUE(f.has_value()); - EXPECT_TRUE(f.get<decltype(3)>() == 3); -} - -TEST(Peer, SmallType) { - struct T { - T(int32_t* p_) : p(p_) { - (*p)++; - } - - T(T&& t) noexcept : p(t.p) { - (*p)++; - } - - ~T() { - (*p)--; - } - - T(const T&) = delete; - T& operator=(const T&) = delete; - - int32_t* p; - }; - - int32_t p = 0; - - { - peer u1 = peer(T(&p)); - EXPECT_EQ(p, 1); - - auto u2(std::move(u1)); - EXPECT_EQ(p, 1); - } - - EXPECT_EQ(p, 0); -} - -TEST(Peer, LargeType) { - TestType t1; - peer u1 = peer(std::move(t1)); - EXPECT_TRUE(u1.has_value()); - - //TestType should be moved into owning peer - EXPECT_EQ(u1.get<TestType>().i1, 1); - - auto u2(std::move(u1)); - EXPECT_FALSE(u1.has_value()); - - //TestType should not be moved when owning peer is moved; - EXPECT_EQ(u2.get<TestType>().i1, 1); - - // TestType should not be moved out of owning peer - auto& t2 = u2.get<TestType>(); - EXPECT_TRUE(u2.has_value()); - EXPECT_EQ(t2.i1, 1); -} - -TEST(Peer, Pointer) { - auto t1 = new TestType(); - - auto u1 = peer(std::move(t1)); - EXPECT_TRUE(u1.has_value()); - - //Only the pointer should be moved - TestType * t2 = u1.get<TestType *>(); - EXPECT_EQ(t2->i1, 0); - - peer u2(4); - std::swap(u2, u1); - - EXPECT_TRUE(u1.has_value()); - - EXPECT_TRUE(u2.has_value()); - - t2 = u2.get<TestType *>(); - EXPECT_EQ(t2->i1, 0); - delete t2; -} - - -TEST(Peer, UniquePtr) { - auto t1 = std::make_unique<TestType>(); - auto u1 = peer(std::move(t1)); - - EXPECT_EQ(t1.get(), nullptr); - EXPECT_TRUE(u1.has_value()); - - u1 = peer(); - EXPECT_FALSE(u1.has_value()); - - peer u2; - auto* t3 = new TestType(); - u2 = std::unique_ptr<TestType>(t3); - EXPECT_TRUE(u2.has_value()); -} - -TEST(Peer, SharedPtr) { - - std::shared_ptr<int> shared(new int(3)); - std::weak_ptr<int> weak = shared; - peer u1 = 0; - - EXPECT_EQ(weak.use_count(), 1); - peer u2 = shared; - EXPECT_EQ(weak.use_count(), 2); - - u1 = std::move(u2); - EXPECT_EQ(weak.use_count(), 2); - std::swap(u2, u1); - EXPECT_EQ(weak.use_count(), 2); - u2 = 0; - EXPECT_EQ(weak.use_count(), 1); - shared = nullptr; - EXPECT_EQ(weak.use_count(), 0); -} |