| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "base/mac/scoped_nsautorelease_pool.h" | 7 #include "base/mac/scoped_nsautorelease_pool.h" |
| 8 #include "base/mac/scoped_nsobject.h" | 8 #include "base/mac/scoped_nsobject.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| 11 // See scoped_nsobject_unittest_arc.mm for why this is necessary. Remove once |
| 12 // gyp support is dropped. |
| 13 void ScopedNSObjectUnittestArcLinkerWorkaround(); |
| 14 |
| 11 namespace { | 15 namespace { |
| 12 | 16 |
| 17 TEST(ScopedNSObjectTest, EnableARCTests) { |
| 18 ScopedNSObjectUnittestArcLinkerWorkaround(); |
| 19 } |
| 20 |
| 13 TEST(ScopedNSObjectTest, ScopedNSObject) { | 21 TEST(ScopedNSObjectTest, ScopedNSObject) { |
| 14 base::scoped_nsobject<NSObject> p1([[NSObject alloc] init]); | 22 base::scoped_nsobject<NSObject> p1([[NSObject alloc] init]); |
| 15 ASSERT_TRUE(p1.get()); | 23 ASSERT_TRUE(p1.get()); |
| 16 ASSERT_EQ(1u, [p1 retainCount]); | 24 ASSERT_EQ(1u, [p1 retainCount]); |
| 17 base::scoped_nsobject<NSObject> p2(p1); | 25 base::scoped_nsobject<NSObject> p2(p1); |
| 18 ASSERT_EQ(p1.get(), p2.get()); | 26 ASSERT_EQ(p1.get(), p2.get()); |
| 19 ASSERT_EQ(2u, [p1 retainCount]); | 27 ASSERT_EQ(2u, [p1 retainCount]); |
| 20 p2.reset(); | 28 p2.reset(); |
| 21 ASSERT_EQ(nil, p2.get()); | 29 ASSERT_EQ(nil, p2.get()); |
| 22 ASSERT_EQ(1u, [p1 retainCount]); | 30 ASSERT_EQ(1u, [p1 retainCount]); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 base::scoped_nsobject<id> p2([[NSObject alloc] init]); | 92 base::scoped_nsobject<id> p2([[NSObject alloc] init]); |
| 85 ASSERT_TRUE(o1 != p2); | 93 ASSERT_TRUE(o1 != p2); |
| 86 ASSERT_FALSE(o1 == p2); | 94 ASSERT_FALSE(o1 == p2); |
| 87 id o2 = p2.get(); | 95 id o2 = p2.get(); |
| 88 swap(p1, p2); | 96 swap(p1, p2); |
| 89 ASSERT_EQ(o2, p1.get()); | 97 ASSERT_EQ(o2, p1.get()); |
| 90 ASSERT_EQ(o1, p2.get()); | 98 ASSERT_EQ(o1, p2.get()); |
| 91 } | 99 } |
| 92 | 100 |
| 93 } // namespace | 101 } // namespace |
| OLD | NEW |