Fix SkTArray copy construction
We can't use memcpy for copy construction, even when MEM_COPY == true.
Change-Id: I50eb369f0fbf77e8f0ad5a148c67d46df0d3ab0e
Reviewed-on: https://skia-review.googlesource.com/9487
Commit-Queue: Florin Malita <fmalita@chromium.org>
Reviewed-by: Mike Klein <mtklein@chromium.org>
Reviewed-by: Ben Wagner <bungeman@google.com>
diff --git a/tests/TArrayTest.cpp b/tests/TArrayTest.cpp
index 675aa33..ee6aabc 100644
--- a/tests/TArrayTest.cpp
+++ b/tests/TArrayTest.cpp
@@ -5,6 +5,7 @@
* found in the LICENSE file.
*/
+#include "SkRefCnt.h"
#include "SkTArray.h"
#include "Test.h"
@@ -117,8 +118,35 @@
test_swap(reporter, arraysMoi, sizes);
}
+template <typename T, bool MEM_MOVE>
+void test_copy_ctor(skiatest::Reporter* reporter, SkTArray<T, MEM_MOVE>&& array) {
+ SkASSERT(array.empty());
+ for (int i = 0; i < 5; ++i) {
+ array.emplace_back(new SkRefCnt);
+ REPORTER_ASSERT(reporter, array.back()->unique());
+ }
+
+ {
+ SkTArray<T, MEM_MOVE> copy(array);
+ for (const auto& ref : array)
+ REPORTER_ASSERT(reporter, !ref->unique());
+ for (const auto& ref : copy)
+ REPORTER_ASSERT(reporter, !ref->unique());
+ }
+
+ for (const auto& ref : array)
+ REPORTER_ASSERT(reporter, ref->unique());
+}
+
DEF_TEST(TArray, reporter) {
TestTSet_basic<true>(reporter);
TestTSet_basic<false>(reporter);
test_swap(reporter);
+
+ test_copy_ctor(reporter, SkTArray<sk_sp<SkRefCnt>, false>());
+ test_copy_ctor(reporter, SkTArray<sk_sp<SkRefCnt>, true>());
+ test_copy_ctor(reporter, SkSTArray< 1, sk_sp<SkRefCnt>, false>());
+ test_copy_ctor(reporter, SkSTArray< 1, sk_sp<SkRefCnt>, true>());
+ test_copy_ctor(reporter, SkSTArray<10, sk_sp<SkRefCnt>, false>());
+ test_copy_ctor(reporter, SkSTArray<10, sk_sp<SkRefCnt>, true>());
}