Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(115)

Side by Side Diff: base/mac/scoped_nsobject_unittest.mm

Issue 2485463002: Fix scoped_nsobject move constructor. (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/mac/scoped_nsobject.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
OLDNEW
« no previous file with comments | « base/mac/scoped_nsobject.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698