summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2018-06-18 16:24:58 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2018-06-25 13:14:52 -0700
commitd176e9bb46c4ab539e6cc5f6c7d17bc68d95e205 (patch)
treed060da460dec129fef73b8ee410d2b9bd6afaa30 /test
parentf3341dd589c6330c0cfd6e8e381398d08493b48a (diff)
downloadqtlocation-mapboxgl-d176e9bb46c4ab539e6cc5f6c7d17bc68d95e205.tar.gz
[core] Fix issues in unique_any
* Eliminate unnecessary temporary in VTableStack::move, which also fixes calling the destructor on the incorrect instance * Make move consistent: it destructs the src, not the dest, which is always empty * delete doesn't need a null guard * Conversions to void* don't need a cast
Diffstat (limited to 'test')
-rw-r--r--test/util/unique_any.test.cpp40
1 files changed, 36 insertions, 4 deletions
diff --git a/test/util/unique_any.test.cpp b/test/util/unique_any.test.cpp
index 9357b9c0ec..9b622cd284 100644
--- a/test/util/unique_any.test.cpp
+++ b/test/util/unique_any.test.cpp
@@ -10,15 +10,14 @@ public:
str[0] = 'a';
}
- TestType(unique_any& p) : TestType() {
- p = std::unique_ptr<TestType>(this);
- }
-
//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;
int i2;
char str[256];
@@ -88,6 +87,39 @@ TEST(UniqueAny, BasicTypes_Move) {
}
+TEST(UniqueAny, 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;
+
+ {
+ unique_any u1 = unique_any(T(&p));
+ EXPECT_EQ(p, 1);
+
+ auto u2(std::move(u1));
+ EXPECT_EQ(p, 1);
+ }
+
+ EXPECT_EQ(p, 0);
+}
+
TEST(UniqueAny, LargeType) {
TestType t1;
unique_any u1 = unique_any(std::move(t1));