| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 | 54 |
| 55 base::scoped_nsobject<NSObject> p6 = p1; | 55 base::scoped_nsobject<NSObject> p6 = p1; |
| 56 ASSERT_EQ(3u, [p6 retainCount]); | 56 ASSERT_EQ(3u, [p6 retainCount]); |
| 57 { | 57 { |
| 58 base::mac::ScopedNSAutoreleasePool pool; | 58 base::mac::ScopedNSAutoreleasePool pool; |
| 59 p6.autorelease(); | 59 p6.autorelease(); |
| 60 ASSERT_EQ(nil, p6.get()); | 60 ASSERT_EQ(nil, p6.get()); |
| 61 ASSERT_EQ(3u, [p1 retainCount]); | 61 ASSERT_EQ(3u, [p1 retainCount]); |
| 62 } | 62 } |
| 63 ASSERT_EQ(2u, [p1 retainCount]); | 63 ASSERT_EQ(2u, [p1 retainCount]); |
| 64 |
| 65 base::scoped_nsobject<NSObject> p7([NSObject new]); |
| 66 base::scoped_nsobject<NSObject> p8(std::move(p7)); |
| 67 ASSERT_TRUE(p8); |
| 68 ASSERT_EQ(1u, [p8 retainCount]); |
| 69 ASSERT_FALSE(p7.get()); |
| 64 } | 70 } |
| 65 | 71 |
| 66 // Instantiating scoped_nsobject<> with T=NSAutoreleasePool should trip a | 72 // Instantiating scoped_nsobject<> with T=NSAutoreleasePool should trip a |
| 67 // static_assert. | 73 // static_assert. |
| 68 #if 0 | 74 #if 0 |
| 69 TEST(ScopedNSObjectTest, FailToCreateScopedNSObjectAutoreleasePool) { | 75 TEST(ScopedNSObjectTest, FailToCreateScopedNSObjectAutoreleasePool) { |
| 70 base::scoped_nsobject<NSAutoreleasePool> pool; | 76 base::scoped_nsobject<NSAutoreleasePool> pool; |
| 71 } | 77 } |
| 72 #endif | 78 #endif |
| 73 | 79 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 95 base::scoped_nsobject<id> p2([[NSObject alloc] init]); | 101 base::scoped_nsobject<id> p2([[NSObject alloc] init]); |
| 96 ASSERT_TRUE(o1 != p2); | 102 ASSERT_TRUE(o1 != p2); |
| 97 ASSERT_FALSE(o1 == p2); | 103 ASSERT_FALSE(o1 == p2); |
| 98 id o2 = p2.get(); | 104 id o2 = p2.get(); |
| 99 swap(p1, p2); | 105 swap(p1, p2); |
| 100 ASSERT_EQ(o2, p1.get()); | 106 ASSERT_EQ(o2, p1.get()); |
| 101 ASSERT_EQ(o1, p2.get()); | 107 ASSERT_EQ(o1, p2.get()); |
| 102 } | 108 } |
| 103 | 109 |
| 104 } // namespace | 110 } // namespace |
| OLD | NEW |