Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Unified Diff: tests/TArrayTest.cpp

Issue 1904663004: SkTArray movable and swap for move only elements. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« include/private/SkTArray.h ('K') | « include/private/SkTArray.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/TArrayTest.cpp
diff --git a/tests/TArrayTest.cpp b/tests/TArrayTest.cpp
index abf1075bc5be94a21741ae2f5e4c9f22071fb0bc..675aa33bf86e2b43287b8d2d194fd82dbddce4ba 100644
--- a/tests/TArrayTest.cpp
+++ b/tests/TArrayTest.cpp
@@ -58,15 +58,10 @@ static void TestTSet_basic(skiatest::Reporter* reporter) {
// {0, 3, 2 }
}
-static void test_swap(skiatest::Reporter* reporter) {
- SkTArray<int> arr;
- SkSTArray< 5, int> arr5;
- SkSTArray<10, int> arr10;
- SkSTArray<20, int> arr20;
-
- SkTArray<int>* arrays[] = { &arr, &arr5, &arr10, &arr20 };
- int sizes[] = {0, 1, 5, 10, 15, 20, 25};
-
+template <typename T> static void test_swap(skiatest::Reporter* reporter,
+ SkTArray<T>* (&arrays)[4],
+ int (&sizes)[7])
+{
for (auto a : arrays) {
for (auto b : arrays) {
if (a == b) {
@@ -87,16 +82,41 @@ static void test_swap(skiatest::Reporter* reporter) {
REPORTER_ASSERT(reporter, a->count() == sizeB);
curr = 0;
- for (int x : *b) { REPORTER_ASSERT(reporter, x == curr++); }
- for (int x : *a) { REPORTER_ASSERT(reporter, x == curr++); }
+ for (auto&& x : *b) { REPORTER_ASSERT(reporter, x == curr++); }
+ for (auto&& x : *a) { REPORTER_ASSERT(reporter, x == curr++); }
a->swap(a);
curr = sizeA;
- for (int x : *a) { REPORTER_ASSERT(reporter, x == curr++); }
+ for (auto&& x : *a) { REPORTER_ASSERT(reporter, x == curr++); }
}}
}}
}
+static void test_swap(skiatest::Reporter* reporter) {
+ int sizes[] = {0, 1, 5, 10, 15, 20, 25};
+
+ SkTArray<int> arr;
+ SkSTArray< 5, int> arr5;
+ SkSTArray<10, int> arr10;
+ SkSTArray<20, int> arr20;
+ SkTArray<int>* arrays[] = { &arr, &arr5, &arr10, &arr20 };
+ test_swap(reporter, arrays, sizes);
+
+ struct MoveOnlyInt {
+ MoveOnlyInt(int i) : fInt(i) {}
+ MoveOnlyInt(MoveOnlyInt&& that) : fInt(that.fInt) {}
+ bool operator==(int i) { return fInt == i; }
+ int fInt;
+ };
+
+ SkTArray<MoveOnlyInt> moi;
+ SkSTArray< 5, MoveOnlyInt> moi5;
+ SkSTArray<10, MoveOnlyInt> moi10;
+ SkSTArray<20, MoveOnlyInt> moi20;
+ SkTArray<MoveOnlyInt>* arraysMoi[] = { &moi, &moi5, &moi10, &moi20 };
+ test_swap(reporter, arraysMoi, sizes);
+}
+
DEF_TEST(TArray, reporter) {
TestTSet_basic<true>(reporter);
TestTSet_basic<false>(reporter);
« include/private/SkTArray.h ('K') | « include/private/SkTArray.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698