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

Side by Side Diff: tests/RefCntTest.cpp

Issue 719113004: Followup: remove unnecessary SkTRefArray (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: count Created 6 years, 1 month 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
« no previous file with comments | « src/core/SkTRefArray.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
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkRefCnt.h" 8 #include "SkRefCnt.h"
9 #include "SkTRefArray.h"
10 #include "SkThreadUtils.h" 9 #include "SkThreadUtils.h"
11 #include "SkTypes.h" 10 #include "SkTypes.h"
12 #include "SkWeakRefCnt.h" 11 #include "SkWeakRefCnt.h"
13 #include "Test.h" 12 #include "Test.h"
14 13
15 class InstCounterClass { 14 class InstCounterClass {
16 public: 15 public:
17 InstCounterClass() { fCount = gInstCounter++; } 16 InstCounterClass() { fCount = gInstCounter++; }
18 InstCounterClass(const InstCounterClass& src) { 17 InstCounterClass(const InstCounterClass& src) {
19 fCount = src.fCount; 18 fCount = src.fCount;
20 gInstCounter += 1; 19 gInstCounter += 1;
21 } 20 }
22 virtual ~InstCounterClass() { gInstCounter -= 1; } 21 virtual ~InstCounterClass() { gInstCounter -= 1; }
23 22
24 static int gInstCounter; 23 static int gInstCounter;
25 int fCount; 24 int fCount;
26 }; 25 };
27 26
28 int InstCounterClass::gInstCounter; 27 int InstCounterClass::gInstCounter;
29 28
30 static void test_refarray(skiatest::Reporter* reporter) {
31 REPORTER_ASSERT(reporter, 0 == InstCounterClass::gInstCounter);
32
33 const int N = 10;
34 SkTRefArray<InstCounterClass>* array = SkTRefArray<InstCounterClass>::Create (N);
35
36 REPORTER_ASSERT(reporter, 1 == array->getRefCnt());
37 REPORTER_ASSERT(reporter, N == array->count());
38
39 REPORTER_ASSERT(reporter, N == InstCounterClass::gInstCounter);
40 array->unref();
41 REPORTER_ASSERT(reporter, 0 == InstCounterClass::gInstCounter);
42
43 // Now test the copy factory
44
45 int i;
46 InstCounterClass* src = new InstCounterClass[N];
47 REPORTER_ASSERT(reporter, N == InstCounterClass::gInstCounter);
48 for (i = 0; i < N; ++i) {
49 REPORTER_ASSERT(reporter, i == src[i].fCount);
50 }
51
52 array = SkTRefArray<InstCounterClass>::Create(src, N);
53 REPORTER_ASSERT(reporter, 1 == array->getRefCnt());
54 REPORTER_ASSERT(reporter, N == array->count());
55
56 REPORTER_ASSERT(reporter, 2*N == InstCounterClass::gInstCounter);
57 for (i = 0; i < N; ++i) {
58 REPORTER_ASSERT(reporter, i == (*array)[i].fCount);
59 }
60
61 delete[] src;
62 REPORTER_ASSERT(reporter, N == InstCounterClass::gInstCounter);
63
64 for (i = 0; i < N; ++i) {
65 REPORTER_ASSERT(reporter, i == (*array)[i].fCount);
66 }
67 array->unref();
68 REPORTER_ASSERT(reporter, 0 == InstCounterClass::gInstCounter);
69 }
70
71 static void bounce_ref(void* data) { 29 static void bounce_ref(void* data) {
72 SkRefCnt* ref = static_cast<SkRefCnt*>(data); 30 SkRefCnt* ref = static_cast<SkRefCnt*>(data);
73 for (int i = 0; i < 100000; ++i) { 31 for (int i = 0; i < 100000; ++i) {
74 ref->ref(); 32 ref->ref();
75 ref->unref(); 33 ref->unref();
76 } 34 }
77 } 35 }
78 36
79 static void test_refCnt(skiatest::Reporter* reporter) { 37 static void test_refCnt(skiatest::Reporter* reporter) {
80 SkRefCnt* ref = new SkRefCnt(); 38 SkRefCnt* ref = new SkRefCnt();
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 thing4.join(); 94 thing4.join();
137 95
138 REPORTER_ASSERT(reporter, ref->getRefCnt() == 1); 96 REPORTER_ASSERT(reporter, ref->getRefCnt() == 1);
139 REPORTER_ASSERT(reporter, ref->getWeakCnt() == 1); 97 REPORTER_ASSERT(reporter, ref->getWeakCnt() == 1);
140 ref->unref(); 98 ref->unref();
141 } 99 }
142 100
143 DEF_TEST(RefCnt, reporter) { 101 DEF_TEST(RefCnt, reporter) {
144 test_refCnt(reporter); 102 test_refCnt(reporter);
145 test_weakRefCnt(reporter); 103 test_weakRefCnt(reporter);
146 test_refarray(reporter);
147 } 104 }
OLDNEW
« no previous file with comments | « src/core/SkTRefArray.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698