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

Side by Side Diff: tests/UtilsTest.cpp

Issue 382523002: Revert "Remove ability for Release code to call getRefCnt() or getWeakRefCnt()." (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 5 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
« no previous file with comments | « tests/SurfaceTest.cpp ('k') | tools/RefCntIs.h » ('j') | 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 2011 Google Inc. 2 * Copyright 2011 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 "SkRandom.h" 8 #include "SkRandom.h"
9 #include "SkRefCnt.h" 9 #include "SkRefCnt.h"
10 #include "SkTSearch.h" 10 #include "SkTSearch.h"
11 #include "SkTSort.h" 11 #include "SkTSort.h"
12 #include "SkUtils.h" 12 #include "SkUtils.h"
13 #include "RefCntIs.h"
14 #include "Test.h" 13 #include "Test.h"
15 14
16 class RefClass : public SkRefCnt { 15 class RefClass : public SkRefCnt {
17 public: 16 public:
18 SK_DECLARE_INST_COUNT(RefClass) 17 SK_DECLARE_INST_COUNT(RefClass)
19 18
20 RefClass(int n) : fN(n) {} 19 RefClass(int n) : fN(n) {}
21 int get() const { return fN; } 20 int get() const { return fN; }
22 21
23 private: 22 private:
24 int fN; 23 int fN;
25 24
26 typedef SkRefCnt INHERITED; 25 typedef SkRefCnt INHERITED;
27 }; 26 };
28 27
29 static void test_autounref(skiatest::Reporter* reporter) { 28 static void test_autounref(skiatest::Reporter* reporter) {
30 RefClass obj(0); 29 RefClass obj(0);
31 REPORTER_ASSERT(reporter, RefCntIs(obj, 1)); 30 REPORTER_ASSERT(reporter, 1 == obj.getRefCnt());
32 31
33 SkAutoTUnref<RefClass> tmp(&obj); 32 SkAutoTUnref<RefClass> tmp(&obj);
34 REPORTER_ASSERT(reporter, &obj == tmp.get()); 33 REPORTER_ASSERT(reporter, &obj == tmp.get());
35 REPORTER_ASSERT(reporter, RefCntIs(obj, 1)); 34 REPORTER_ASSERT(reporter, 1 == obj.getRefCnt());
36 35
37 REPORTER_ASSERT(reporter, &obj == tmp.detach()); 36 REPORTER_ASSERT(reporter, &obj == tmp.detach());
38 REPORTER_ASSERT(reporter, RefCntIs(obj, 1)); 37 REPORTER_ASSERT(reporter, 1 == obj.getRefCnt());
39 REPORTER_ASSERT(reporter, NULL == tmp.detach()); 38 REPORTER_ASSERT(reporter, NULL == tmp.detach());
40 REPORTER_ASSERT(reporter, NULL == tmp.get()); 39 REPORTER_ASSERT(reporter, NULL == tmp.get());
41 40
42 obj.ref(); 41 obj.ref();
43 REPORTER_ASSERT(reporter, RefCntIs(obj, 2)); 42 REPORTER_ASSERT(reporter, 2 == obj.getRefCnt());
44 { 43 {
45 SkAutoTUnref<RefClass> tmp2(&obj); 44 SkAutoTUnref<RefClass> tmp2(&obj);
46 } 45 }
47 REPORTER_ASSERT(reporter, RefCntIs(obj, 1)); 46 REPORTER_ASSERT(reporter, 1 == obj.getRefCnt());
48 } 47 }
49 48
50 static void test_autostarray(skiatest::Reporter* reporter) { 49 static void test_autostarray(skiatest::Reporter* reporter) {
51 RefClass obj0(0); 50 RefClass obj0(0);
52 RefClass obj1(1); 51 RefClass obj1(1);
53 REPORTER_ASSERT(reporter, RefCntIs(obj0, 1)); 52 REPORTER_ASSERT(reporter, 1 == obj0.getRefCnt());
54 REPORTER_ASSERT(reporter, RefCntIs(obj1, 1)); 53 REPORTER_ASSERT(reporter, 1 == obj1.getRefCnt());
55 54
56 { 55 {
57 SkAutoSTArray<2, SkRefPtr<RefClass> > tmp; 56 SkAutoSTArray<2, SkRefPtr<RefClass> > tmp;
58 REPORTER_ASSERT(reporter, 0 == tmp.count()); 57 REPORTER_ASSERT(reporter, 0 == tmp.count());
59 58
60 tmp.reset(0); // test out reset(0) when already at 0 59 tmp.reset(0); // test out reset(0) when already at 0
61 tmp.reset(4); // this should force a new allocation 60 tmp.reset(4); // this should force a new allocation
62 REPORTER_ASSERT(reporter, 4 == tmp.count()); 61 REPORTER_ASSERT(reporter, 4 == tmp.count());
63 tmp[0] = &obj0; 62 tmp[0] = &obj0;
64 tmp[1] = &obj1; 63 tmp[1] = &obj1;
65 REPORTER_ASSERT(reporter, RefCntIs(obj0, 2)); 64 REPORTER_ASSERT(reporter, 2 == obj0.getRefCnt());
66 REPORTER_ASSERT(reporter, RefCntIs(obj1, 2)); 65 REPORTER_ASSERT(reporter, 2 == obj1.getRefCnt());
67 66
68 // test out reset with data in the array (and a new allocation) 67 // test out reset with data in the array (and a new allocation)
69 tmp.reset(0); 68 tmp.reset(0);
70 REPORTER_ASSERT(reporter, 0 == tmp.count()); 69 REPORTER_ASSERT(reporter, 0 == tmp.count());
71 REPORTER_ASSERT(reporter, RefCntIs(obj0, 1)); 70 REPORTER_ASSERT(reporter, 1 == obj0.getRefCnt());
72 REPORTER_ASSERT(reporter, RefCntIs(obj1, 1)); 71 REPORTER_ASSERT(reporter, 1 == obj1.getRefCnt());
73 72
74 tmp.reset(2); // this should use the preexisting allocation 73 tmp.reset(2); // this should use the preexisting allocation
75 REPORTER_ASSERT(reporter, 2 == tmp.count()); 74 REPORTER_ASSERT(reporter, 2 == tmp.count());
76 tmp[0] = &obj0; 75 tmp[0] = &obj0;
77 tmp[1] = &obj1; 76 tmp[1] = &obj1;
78 } 77 }
79 78
80 // test out destructor with data in the array (and using existing allocation ) 79 // test out destructor with data in the array (and using existing allocation )
81 REPORTER_ASSERT(reporter, RefCntIs(obj0, 1)); 80 REPORTER_ASSERT(reporter, 1 == obj0.getRefCnt());
82 REPORTER_ASSERT(reporter, RefCntIs(obj1, 1)); 81 REPORTER_ASSERT(reporter, 1 == obj1.getRefCnt());
83 82
84 { 83 {
85 // test out allocating ctor (this should allocate new memory) 84 // test out allocating ctor (this should allocate new memory)
86 SkAutoSTArray<2, SkRefPtr<RefClass> > tmp(4); 85 SkAutoSTArray<2, SkRefPtr<RefClass> > tmp(4);
87 REPORTER_ASSERT(reporter, 4 == tmp.count()); 86 REPORTER_ASSERT(reporter, 4 == tmp.count());
88 87
89 tmp[0] = &obj0; 88 tmp[0] = &obj0;
90 tmp[1] = &obj1; 89 tmp[1] = &obj1;
91 REPORTER_ASSERT(reporter, RefCntIs(obj0, 2)); 90 REPORTER_ASSERT(reporter, 2 == obj0.getRefCnt());
92 REPORTER_ASSERT(reporter, RefCntIs(obj1, 2)); 91 REPORTER_ASSERT(reporter, 2 == obj1.getRefCnt());
93 92
94 // Test out resut with data in the array and malloced storage 93 // Test out resut with data in the array and malloced storage
95 tmp.reset(0); 94 tmp.reset(0);
96 REPORTER_ASSERT(reporter, RefCntIs(obj0, 1)); 95 REPORTER_ASSERT(reporter, 1 == obj0.getRefCnt());
97 REPORTER_ASSERT(reporter, RefCntIs(obj1, 1)); 96 REPORTER_ASSERT(reporter, 1 == obj1.getRefCnt());
98 97
99 tmp.reset(2); // this should use the preexisting storage 98 tmp.reset(2); // this should use the preexisting storage
100 tmp[0] = &obj0; 99 tmp[0] = &obj0;
101 tmp[1] = &obj1; 100 tmp[1] = &obj1;
102 REPORTER_ASSERT(reporter, RefCntIs(obj0, 2)); 101 REPORTER_ASSERT(reporter, 2 == obj0.getRefCnt());
103 REPORTER_ASSERT(reporter, RefCntIs(obj1, 2)); 102 REPORTER_ASSERT(reporter, 2 == obj1.getRefCnt());
104 103
105 tmp.reset(4); // this should force a new malloc 104 tmp.reset(4); // this should force a new malloc
106 REPORTER_ASSERT(reporter, RefCntIs(obj0, 1)); 105 REPORTER_ASSERT(reporter, 1 == obj0.getRefCnt());
107 REPORTER_ASSERT(reporter, RefCntIs(obj1, 1)); 106 REPORTER_ASSERT(reporter, 1 == obj1.getRefCnt());
108 107
109 tmp[0] = &obj0; 108 tmp[0] = &obj0;
110 tmp[1] = &obj1; 109 tmp[1] = &obj1;
111 REPORTER_ASSERT(reporter, RefCntIs(obj0, 2)); 110 REPORTER_ASSERT(reporter, 2 == obj0.getRefCnt());
112 REPORTER_ASSERT(reporter, RefCntIs(obj1, 2)); 111 REPORTER_ASSERT(reporter, 2 == obj1.getRefCnt());
113 } 112 }
114 113
115 REPORTER_ASSERT(reporter, RefCntIs(obj0, 1)); 114 REPORTER_ASSERT(reporter, 1 == obj0.getRefCnt());
116 REPORTER_ASSERT(reporter, RefCntIs(obj1, 1)); 115 REPORTER_ASSERT(reporter, 1 == obj1.getRefCnt());
117 } 116 }
118 117
119 ///////////////////////////////////////////////////////////////////////////// 118 /////////////////////////////////////////////////////////////////////////////
120 119
121 #define kSEARCH_COUNT 91 120 #define kSEARCH_COUNT 91
122 121
123 static void test_search(skiatest::Reporter* reporter) { 122 static void test_search(skiatest::Reporter* reporter) {
124 int i, array[kSEARCH_COUNT]; 123 int i, array[kSEARCH_COUNT];
125 SkRandom rand; 124 SkRandom rand;
126 125
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 REPORTER_ASSERT(reporter, u0 == gTest[i].fUni); 212 REPORTER_ASSERT(reporter, u0 == gTest[i].fUni);
214 REPORTER_ASSERT(reporter, 213 REPORTER_ASSERT(reporter,
215 p - gTest[i].fUtf8 == (int)strlen(gTest[i].fUtf8)); 214 p - gTest[i].fUtf8 == (int)strlen(gTest[i].fUtf8));
216 } 215 }
217 216
218 test_utf16(reporter); 217 test_utf16(reporter);
219 test_search(reporter); 218 test_search(reporter);
220 test_autounref(reporter); 219 test_autounref(reporter);
221 test_autostarray(reporter); 220 test_autostarray(reporter);
222 } 221 }
OLDNEW
« no previous file with comments | « tests/SurfaceTest.cpp ('k') | tools/RefCntIs.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698