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 | |
15 namespace { | 11 namespace { |
16 | 12 |
17 TEST(ScopedNSObjectTest, EnableARCTests) { | |
18 ScopedNSObjectUnittestArcLinkerWorkaround(); | |
19 } | |
20 | |
21 TEST(ScopedNSObjectTest, ScopedNSObject) { | 13 TEST(ScopedNSObjectTest, ScopedNSObject) { |
22 base::scoped_nsobject<NSObject> p1([[NSObject alloc] init]); | 14 base::scoped_nsobject<NSObject> p1([[NSObject alloc] init]); |
23 ASSERT_TRUE(p1.get()); | 15 ASSERT_TRUE(p1.get()); |
24 ASSERT_EQ(1u, [p1 retainCount]); | 16 ASSERT_EQ(1u, [p1 retainCount]); |
25 base::scoped_nsobject<NSObject> p2(p1); | 17 base::scoped_nsobject<NSObject> p2(p1); |
26 ASSERT_EQ(p1.get(), p2.get()); | 18 ASSERT_EQ(p1.get(), p2.get()); |
27 ASSERT_EQ(2u, [p1 retainCount]); | 19 ASSERT_EQ(2u, [p1 retainCount]); |
28 p2.reset(); | 20 p2.reset(); |
29 ASSERT_EQ(nil, p2.get()); | 21 ASSERT_EQ(nil, p2.get()); |
30 ASSERT_EQ(1u, [p1 retainCount]); | 22 ASSERT_EQ(1u, [p1 retainCount]); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 base::scoped_nsobject<id> p2([[NSObject alloc] init]); | 93 base::scoped_nsobject<id> p2([[NSObject alloc] init]); |
102 ASSERT_TRUE(o1 != p2); | 94 ASSERT_TRUE(o1 != p2); |
103 ASSERT_FALSE(o1 == p2); | 95 ASSERT_FALSE(o1 == p2); |
104 id o2 = p2.get(); | 96 id o2 = p2.get(); |
105 swap(p1, p2); | 97 swap(p1, p2); |
106 ASSERT_EQ(o2, p1.get()); | 98 ASSERT_EQ(o2, p1.get()); |
107 ASSERT_EQ(o1, p2.get()); | 99 ASSERT_EQ(o1, p2.get()); |
108 } | 100 } |
109 | 101 |
110 } // namespace | 102 } // namespace |
OLD | NEW |