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

Side by Side Diff: skia/ext/refptr_unittest.cc

Issue 2011713003: Roll skia to 8cc209111876b7c78b5ec577c9221d8ed5e21024 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 4 years, 6 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 | « skia/ext/refptr.h ('k') | skia/ext/skia_utils_base.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "skia/ext/refptr.h"
6
7 #include "testing/gtest/include/gtest/gtest.h"
8
9 namespace skia {
10 namespace {
11
12 TEST(RefPtrTest, ReferenceCounting) {
13 SkRefCnt* ref = new SkRefCnt();
14 EXPECT_TRUE(ref->unique());
15
16 {
17 // Adopt the reference from the caller on creation.
18 RefPtr<SkRefCnt> refptr1 = AdoptRef(ref);
19 EXPECT_TRUE(ref->unique());
20 EXPECT_TRUE(refptr1->unique());
21
22 EXPECT_EQ(ref, &*refptr1);
23 EXPECT_EQ(ref, refptr1.get());
24
25 {
26 // Take a second reference for the second instance.
27 RefPtr<SkRefCnt> refptr2(refptr1);
28 EXPECT_FALSE(ref->unique());
29
30 RefPtr<SkRefCnt> refptr3;
31 EXPECT_FALSE(refptr3);
32
33 // Take a third reference for the third instance.
34 refptr3 = refptr1;
35 EXPECT_FALSE(ref->unique());
36
37 // Same object, so should have the same refcount.
38 refptr2 = refptr3;
39 EXPECT_FALSE(ref->unique());
40
41 // Drop the object from refptr2, so it should lose its reference.
42 EXPECT_TRUE(refptr2);
43 refptr2.clear();
44 EXPECT_FALSE(ref->unique());
45
46 EXPECT_FALSE(refptr2);
47 EXPECT_EQ(NULL, refptr2.get());
48
49 EXPECT_TRUE(refptr3);
50 EXPECT_FALSE(refptr3->unique());
51 EXPECT_EQ(ref, &*refptr3);
52 EXPECT_EQ(ref, refptr3.get());
53 }
54
55 // Drop a reference when the third object is destroyed.
56 EXPECT_TRUE(ref->unique());
57 }
58 }
59
60 TEST(RefPtrTest, Construct) {
61 SkRefCnt* ref = new SkRefCnt();
62 EXPECT_TRUE(ref->unique());
63
64 // Adopt the reference from the caller on creation.
65 RefPtr<SkRefCnt> refptr1(AdoptRef(ref));
66 EXPECT_TRUE(ref->unique());
67 EXPECT_TRUE(refptr1->unique());
68
69 EXPECT_EQ(ref, &*refptr1);
70 EXPECT_EQ(ref, refptr1.get());
71
72 RefPtr<SkRefCnt> refptr2(refptr1);
73 EXPECT_FALSE(ref->unique());
74 }
75
76 TEST(RefPtrTest, DeclareAndAssign) {
77 SkRefCnt* ref = new SkRefCnt();
78 EXPECT_TRUE(ref->unique());
79
80 // Adopt the reference from the caller on creation.
81 RefPtr<SkRefCnt> refptr1 = AdoptRef(ref);
82 EXPECT_TRUE(ref->unique());
83 EXPECT_TRUE(refptr1->unique());
84
85 EXPECT_EQ(ref, &*refptr1);
86 EXPECT_EQ(ref, refptr1.get());
87
88 RefPtr<SkRefCnt> refptr2 = refptr1;
89 EXPECT_FALSE(ref->unique());
90 }
91
92 TEST(RefPtrTest, Assign) {
93 SkRefCnt* ref = new SkRefCnt();
94 EXPECT_TRUE(ref->unique());
95
96 // Adopt the reference from the caller on creation.
97 RefPtr<SkRefCnt> refptr1;
98 refptr1 = AdoptRef(ref);
99 EXPECT_TRUE(ref->unique());
100 EXPECT_TRUE(refptr1->unique());
101
102 EXPECT_EQ(ref, &*refptr1);
103 EXPECT_EQ(ref, refptr1.get());
104
105 RefPtr<SkRefCnt> refptr2;
106 refptr2 = refptr1;
107 EXPECT_FALSE(ref->unique());
108 }
109
110 class Subclass : public SkRefCnt {};
111
112 TEST(RefPtrTest, Upcast) {
113 RefPtr<Subclass> child = AdoptRef(new Subclass());
114 EXPECT_TRUE(child->unique());
115
116 RefPtr<SkRefCnt> parent = child;
117 EXPECT_TRUE(child);
118 EXPECT_TRUE(parent);
119
120 EXPECT_FALSE(child->unique());
121 EXPECT_FALSE(parent->unique());
122 }
123
124 } // namespace
125 } // namespace skia
OLDNEW
« no previous file with comments | « skia/ext/refptr.h ('k') | skia/ext/skia_utils_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698