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

Side by Side Diff: tests/TArrayTest.cpp

Issue 208153008: Add test for SkTArray. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 6 years, 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « include/core/SkTArray.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "SkTArray.h"
9 #include "Test.h"
10
11 // Tests the SkTArray<T> class template.
12
13 template <bool MEM_COPY>
14 static void TestTSet_basic(skiatest::Reporter* reporter) {
15 SkTArray<int, MEM_COPY> a;
16
17 // Starts empty.
18 REPORTER_ASSERT(reporter, a.empty());
19 REPORTER_ASSERT(reporter, a.count() == 0);
20
21 // { }, add a default constructed element
22 REPORTER_ASSERT(reporter, a.push_back());
23 REPORTER_ASSERT(reporter, !a.empty());
24 REPORTER_ASSERT(reporter, a.count() == 1);
25
26 // { 0 }, removeShuffle the only element.
27 a.removeShuffle(0);
28 REPORTER_ASSERT(reporter, a.empty());
29 REPORTER_ASSERT(reporter, a.count() == 0);
30
31 // { }, add a default, add a 1, remove first
32 REPORTER_ASSERT(reporter, a.push_back());
33 REPORTER_ASSERT(reporter, a.push_back() = 1);
34 a.removeShuffle(0);
35 REPORTER_ASSERT(reporter, !a.empty());
36 REPORTER_ASSERT(reporter, a.count() == 1);
37 REPORTER_ASSERT(reporter, a[0] == 1);
38
39 // { 1 }, replace with new array
40 int b[5] = { 0, 1, 2, 3, 4 };
41 a.reset(b, SK_ARRAY_COUNT(b));
42 REPORTER_ASSERT(reporter, a.count() == SK_ARRAY_COUNT(b));
43 REPORTER_ASSERT(reporter, a[2] == 2);
44 REPORTER_ASSERT(reporter, a[4] == 4);
45
46 // { 0, 1, 2, 3, 4 }, removeShuffle the last
47 a.removeShuffle(4);
48 REPORTER_ASSERT(reporter, a.count() == SK_ARRAY_COUNT(b) - 1);
49 REPORTER_ASSERT(reporter, a[3] == 3);
50
51 // { 0, 1, 2, 3 }, remove a middle, note shuffle
52 a.removeShuffle(1);
53 REPORTER_ASSERT(reporter, a.count() == SK_ARRAY_COUNT(b) - 2);
54 REPORTER_ASSERT(reporter, a[0] == 0);
55 REPORTER_ASSERT(reporter, a[1] == 3);
56 REPORTER_ASSERT(reporter, a[2] == 2);
57
58 // {0, 3, 2 }
59 }
60
61 DEF_TEST(TArray, reporter) {
62 TestTSet_basic<true>(reporter);
63 TestTSet_basic<false>(reporter);
64 }
OLDNEW
« no previous file with comments | « include/core/SkTArray.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698