| 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 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 ASSERT_EQ(3u, [p6 retainCount]); | 45 ASSERT_EQ(3u, [p6 retainCount]); |
| 46 { | 46 { |
| 47 base::mac::ScopedNSAutoreleasePool pool; | 47 base::mac::ScopedNSAutoreleasePool pool; |
| 48 p6.autorelease(); | 48 p6.autorelease(); |
| 49 ASSERT_EQ(nil, p6.get()); | 49 ASSERT_EQ(nil, p6.get()); |
| 50 ASSERT_EQ(3u, [p1 retainCount]); | 50 ASSERT_EQ(3u, [p1 retainCount]); |
| 51 } | 51 } |
| 52 ASSERT_EQ(2u, [p1 retainCount]); | 52 ASSERT_EQ(2u, [p1 retainCount]); |
| 53 } | 53 } |
| 54 | 54 |
| 55 // Instantiating scoped_nsobject<> with T=NSAutoreleasePool should trip a |
| 56 // static_assert. |
| 55 #if 0 | 57 #if 0 |
| 56 TEST(ScopedNSObjectTest, FailToCreateScopedNSObjectAutoreleasePool) { | 58 TEST(ScopedNSObjectTest, FailToCreateScopedNSObjectAutoreleasePool) { |
| 57 base::scoped_nsobject<NSAutoreleasePool> pool; | 59 base::scoped_nsobject<NSAutoreleasePool> pool; |
| 58 } | 60 } |
| 59 #endif | 61 #endif |
| 60 | 62 |
| 61 TEST(ScopedNSObjectTest, ScopedNSObjectInContainer) { | 63 TEST(ScopedNSObjectTest, ScopedNSObjectInContainer) { |
| 62 base::scoped_nsobject<id> p([[NSObject alloc] init]); | 64 base::scoped_nsobject<id> p([[NSObject alloc] init]); |
| 63 ASSERT_TRUE(p.get()); | 65 ASSERT_TRUE(p.get()); |
| 64 ASSERT_EQ(1u, [p retainCount]); | 66 ASSERT_EQ(1u, [p retainCount]); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 82 base::scoped_nsobject<id> p2([[NSObject alloc] init]); | 84 base::scoped_nsobject<id> p2([[NSObject alloc] init]); |
| 83 ASSERT_TRUE(o1 != p2); | 85 ASSERT_TRUE(o1 != p2); |
| 84 ASSERT_FALSE(o1 == p2); | 86 ASSERT_FALSE(o1 == p2); |
| 85 id o2 = p2.get(); | 87 id o2 = p2.get(); |
| 86 swap(p1, p2); | 88 swap(p1, p2); |
| 87 ASSERT_EQ(o2, p1.get()); | 89 ASSERT_EQ(o2, p1.get()); |
| 88 ASSERT_EQ(o1, p2.get()); | 90 ASSERT_EQ(o1, p2.get()); |
| 89 } | 91 } |
| 90 | 92 |
| 91 } // namespace | 93 } // namespace |
| OLD | NEW |