OLD | NEW |
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 "SkThreadUtils.h" | 9 #include "SkThreadUtils.h" |
10 #include "SkTypes.h" | 10 #include "SkTypes.h" |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 | 157 |
158 Paint paint; | 158 Paint paint; |
159 REPORTER_ASSERT(reporter, paint.fEffect.get() == nullptr); | 159 REPORTER_ASSERT(reporter, paint.fEffect.get() == nullptr); |
160 REPORTER_ASSERT(reporter, !paint.get()); | 160 REPORTER_ASSERT(reporter, !paint.get()); |
161 check(reporter, 0, 0, 0, 0); | 161 check(reporter, 0, 0, 0, 0); |
162 | 162 |
163 paint.set(Create()); | 163 paint.set(Create()); |
164 check(reporter, 0, 0, 1, 0); | 164 check(reporter, 0, 0, 1, 0); |
165 REPORTER_ASSERT(reporter, paint.fEffect.get()->fRefCnt == 1); | 165 REPORTER_ASSERT(reporter, paint.fEffect.get()->fRefCnt == 1); |
166 | 166 |
| 167 if (paint.get()) { |
| 168 REPORTER_ASSERT(reporter, true); |
| 169 } else { |
| 170 REPORTER_ASSERT(reporter, false); |
| 171 } |
| 172 if (!paint.get()) { |
| 173 REPORTER_ASSERT(reporter, false); |
| 174 } else { |
| 175 REPORTER_ASSERT(reporter, true); |
| 176 } |
| 177 |
167 paint.set(nullptr); | 178 paint.set(nullptr); |
168 check(reporter, 0, 1, 1, 1); | 179 check(reporter, 0, 1, 1, 1); |
169 | 180 |
| 181 if (paint.get()) { |
| 182 REPORTER_ASSERT(reporter, false); |
| 183 } else { |
| 184 REPORTER_ASSERT(reporter, true); |
| 185 } |
| 186 if (!paint.get()) { |
| 187 REPORTER_ASSERT(reporter, true); |
| 188 } else { |
| 189 REPORTER_ASSERT(reporter, false); |
| 190 } |
| 191 |
170 auto e = Create(); | 192 auto e = Create(); |
171 REPORTER_ASSERT(reporter, sizeof(e) == sizeof(void*)); | 193 REPORTER_ASSERT(reporter, sizeof(e) == sizeof(void*)); |
172 | 194 |
173 check(reporter, 0, 1, 2, 1); | 195 check(reporter, 0, 1, 2, 1); |
174 paint.set(e); | 196 paint.set(e); |
175 check(reporter, 1, 1, 2, 1); | 197 check(reporter, 1, 1, 2, 1); |
176 REPORTER_ASSERT(reporter, paint.fEffect.get()->fRefCnt == 2); | 198 REPORTER_ASSERT(reporter, paint.fEffect.get()->fRefCnt == 2); |
177 | 199 |
178 Paint paint2; | 200 Paint paint2; |
179 paint2.set(paint.get()); | 201 paint2.set(paint.get()); |
180 check(reporter, 2, 1, 2, 1); | 202 check(reporter, 2, 1, 2, 1); |
181 REPORTER_ASSERT(reporter, paint.fEffect.get()->fRefCnt == 3); | 203 REPORTER_ASSERT(reporter, paint.fEffect.get()->fRefCnt == 3); |
182 | 204 |
| 205 // Test sk_sp::operator-> |
183 delete paint.get()->method(); | 206 delete paint.get()->method(); |
184 check(reporter, 2, 1, 2, 1); | 207 check(reporter, 2, 1, 2, 1); |
185 | 208 |
| 209 // Test sk_sp::operator* |
| 210 delete (*paint.get()).method(); |
| 211 check(reporter, 2, 1, 2, 1); |
| 212 |
186 paint.set(nullptr); | 213 paint.set(nullptr); |
187 e = nullptr; | 214 e = nullptr; |
188 paint2.set(nullptr); | 215 paint2.set(nullptr); |
189 check(reporter, 2, 4, 2, 2); | 216 check(reporter, 2, 4, 2, 2); |
190 | 217 |
191 reset_counters(); | 218 reset_counters(); |
192 { | 219 { |
193 // Test convertible sk_sp assignment. | 220 // Test convertible sk_sp assignment. |
194 check(reporter, 0, 0, 0, 0); | 221 check(reporter, 0, 0, 0, 0); |
195 sk_sp<Effect> foo(nullptr); | 222 sk_sp<Effect> foo(nullptr); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 baz = EffectImpl::Create(); | 267 baz = EffectImpl::Create(); |
241 check(reporter, 0, 0, 1, 0); | 268 check(reporter, 0, 0, 1, 0); |
242 paint.set(baz); | 269 paint.set(baz); |
243 check(reporter, 1, 0, 1, 0); | 270 check(reporter, 1, 0, 1, 0); |
244 baz = nullptr; | 271 baz = nullptr; |
245 check(reporter, 1, 1, 1, 0); | 272 check(reporter, 1, 1, 1, 0); |
246 paint.set(nullptr); | 273 paint.set(nullptr); |
247 check(reporter, 1, 2, 1, 1); | 274 check(reporter, 1, 2, 1, 1); |
248 } | 275 } |
249 | 276 |
OLD | NEW |