diff options
author | bungeman <bungeman@google.com> | 2016-04-20 10:22:20 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-04-20 10:22:20 -0700 |
commit | 0d9e9bee17aa2901582c5461ae60f7241fc0cd59 (patch) | |
tree | 7062135aa1a3fad1e8352162fc3c7d9efc7f34f0 /tests/TArrayTest.cpp | |
parent | 36db3f44b6cd71d1f462626601ec7c33fdcc187c (diff) |
SkTArray movable and swap for move only elements.
SkTArray cannot currently contain move only elements because its swap
currently requires the SkTArray to be copyable. This makes SkTArray
movable and makes its swap move instead of copy.
Review URL: https://codereview.chromium.org/1904663004
Diffstat (limited to 'tests/TArrayTest.cpp')
-rw-r--r-- | tests/TArrayTest.cpp | 44 |
1 files changed, 32 insertions, 12 deletions
diff --git a/tests/TArrayTest.cpp b/tests/TArrayTest.cpp index abf1075bc5..675aa33bf8 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); |