| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "skia/ext/refptr.h" | 5 #include "skia/ext/refptr.h" |
| 6 | 6 |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 | 8 |
| 9 namespace skia { | 9 namespace skia { |
| 10 namespace { | 10 namespace { |
| 11 | 11 |
| 12 TEST(RefPtrTest, EmptyContruction) { |
| 13 RefPtr<SkRefCnt> refptr; |
| 14 EXPECT_FALSE(refptr); |
| 15 } |
| 16 |
| 12 TEST(RefPtrTest, ReferenceCounting) { | 17 TEST(RefPtrTest, ReferenceCounting) { |
| 13 SkRefCnt* ref = new SkRefCnt(); | 18 SkRefCnt* ref = new SkRefCnt(); |
| 14 EXPECT_EQ(1, ref->getRefCnt()); | 19 EXPECT_EQ(1, ref->getRefCnt()); |
| 15 | 20 |
| 16 { | 21 { |
| 17 // Adopt the reference from the caller on creation. | 22 // Adopt the reference from the caller on creation. |
| 18 RefPtr<SkRefCnt> refptr1 = AdoptRef(ref); | 23 RefPtr<SkRefCnt> refptr1 = AdoptRef(ref); |
| 19 EXPECT_EQ(1, ref->getRefCnt()); | 24 EXPECT_EQ(1, ref->getRefCnt()); |
| 20 EXPECT_EQ(1, refptr1->getRefCnt()); | 25 EXPECT_EQ(1, refptr1->getRefCnt()); |
| 21 | 26 |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 EXPECT_EQ(1, child->getRefCnt()); | 119 EXPECT_EQ(1, child->getRefCnt()); |
| 115 | 120 |
| 116 RefPtr<SkRefCnt> parent = child; | 121 RefPtr<SkRefCnt> parent = child; |
| 117 EXPECT_TRUE(child); | 122 EXPECT_TRUE(child); |
| 118 EXPECT_TRUE(parent); | 123 EXPECT_TRUE(parent); |
| 119 | 124 |
| 120 EXPECT_EQ(2, child->getRefCnt()); | 125 EXPECT_EQ(2, child->getRefCnt()); |
| 121 EXPECT_EQ(2, parent->getRefCnt()); | 126 EXPECT_EQ(2, parent->getRefCnt()); |
| 122 } | 127 } |
| 123 | 128 |
| 129 bool Factory(SkRefCnt** refcnt) { |
| 130 *refcnt = new SkRefCnt; |
| 131 return true; |
| 132 } |
| 133 |
| 134 TEST(RefPtrTest, Receive) { |
| 135 RefPtr<SkRefCnt> refptr; |
| 136 Factory(refptr.ReceiveAndAdoptRef()); |
| 137 EXPECT_EQ(1, refptr->getRefCnt()); |
| 138 } |
| 139 |
| 140 TEST(RefPtrTest, ReceiveAndUseInSameExpression) { |
| 141 // This should assert, but only in debug mode. |
| 142 #ifndef NDEBUG |
| 143 RefPtr<SkRefCnt> refptr; |
| 144 EXPECT_DEATH({ Factory(refptr.ReceiveAndAdoptRef()) && refptr.get(); }, ""); |
| 145 #endif |
| 146 } |
| 147 |
| 124 } // namespace | 148 } // namespace |
| 125 } // namespace skia | 149 } // namespace skia |
| OLD | NEW |