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

Side by Side Diff: tests/TDArrayTest.cpp

Issue 14502003: Add SkSTDArray. Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Clean up. Created 5 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 unified diff | Download patch | Annotate | Revision Log
« include/core/SkTDArray.h ('K') | « include/core/SkTDArray.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 2013 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 "Test.h"
9 #include "SkTDArray.h"
10
11 static void basic_empty(skiatest::Reporter* reporter, SkTDArray<int>& a) {
12 REPORTER_ASSERT(reporter, a.isEmpty());
13 REPORTER_ASSERT(reporter, !a.contains(-1));
14 REPORTER_ASSERT(reporter, !a.contains(0));
15 REPORTER_ASSERT(reporter, !a.contains(1));
16 REPORTER_ASSERT(reporter, a.count() == 0);
17 }
18
19 static void basic_add_first(skiatest::Reporter* reporter, SkTDArray<int>& a) {
20 int* elem;
21 REPORTER_ASSERT(reporter, elem = a.append());
22 *elem = 0;
23 REPORTER_ASSERT(reporter, !a.isEmpty());
24 REPORTER_ASSERT(reporter, !a.contains(-1));
25 REPORTER_ASSERT(reporter, a.contains(0));
26 REPORTER_ASSERT(reporter, !a.contains(1));
27 REPORTER_ASSERT(reporter, a.count() == 1);
28 REPORTER_ASSERT(reporter, a.begin() != NULL);
29 }
30
31 static void basic_add_second(skiatest::Reporter* reporter, SkTDArray<int>& a) {
32 int* elem;
33 REPORTER_ASSERT(reporter, elem = a.append());
34 *elem = 1;
35 REPORTER_ASSERT(reporter, !a.isEmpty());
36 REPORTER_ASSERT(reporter, !a.contains(-1));
37 REPORTER_ASSERT(reporter, a.contains(0));
38 REPORTER_ASSERT(reporter, a.contains(1));
39 REPORTER_ASSERT(reporter, a.count() == 2);
40 REPORTER_ASSERT(reporter, a.begin() != NULL);
41 }
42
43 int testArray[] = {1, 2, 3};
44
45 static void basic(skiatest::Reporter* reporter) {
46 SkTDArray<int> a;
47 basic_empty(reporter, a);
48 basic_add_first(reporter, a);
49
50 SkSTDArray<1, int> b;
51 basic_empty(reporter, b);
52 basic_add_first(reporter, b);
53
54 SkSTDArray<1, int> c(b);
55
56 int* storage = b.begin();
57 basic_add_second(reporter, b);
58 int* alloc = b.begin();
59 REPORTER_ASSERT(reporter, storage != alloc);
60
61 REPORTER_ASSERT(reporter, c.count() == 1 && c[0] == 0);
62
63 b = c;
64 REPORTER_ASSERT(reporter, b.count() == c.count() && b.count() == 1);
65 REPORTER_ASSERT(reporter, b[0] == 0);
66 REPORTER_ASSERT(reporter, c[0] == 0);
67
68 SkSTDArray<3, int> d(testArray, SK_ARRAY_COUNT(testArray));
69 REPORTER_ASSERT(reporter, d.count() == 3);
70
71 SkSTDArray<2, int> e;
72 e = d;
73 REPORTER_ASSERT(reporter, e.count() == 3);
74
75 #ifdef SK_DEBUG
76 a.validate();
77 b.validate();
78 c.validate();
79 d.validate();
80 #endif
81
82 c.reset();
83 REPORTER_ASSERT(reporter, c.count() == 0);
84
85 int* data = b.detach();
86 REPORTER_ASSERT(reporter, b.count() == 0);
87 sk_free(data);
88
89 a = c;
90 REPORTER_ASSERT(reporter, a.count() == c.count() && a.count() == 0);
91
92 #ifdef SK_DEBUG
93 a.validate();
94 b.validate();
95 c.validate();
96 #endif
97 }
98
99 DEF_TEST(TDArray, reporter) {
100 basic(reporter);
101 }
OLDNEW
« include/core/SkTDArray.h ('K') | « include/core/SkTDArray.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698