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 #import <CoreFoundation/CoreFoundation.h> | 7 #import <CoreFoundation/CoreFoundation.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #import "base/mac/scoped_nsobject.h" | 10 #import "base/mac/scoped_nsobject.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 | 12 |
13 #if !defined(__has_feature) || !__has_feature(objc_arc) | 13 #if !defined(__has_feature) || !__has_feature(objc_arc) |
14 #error "This file requires ARC support." | 14 #error "This file requires ARC support." |
15 #endif | 15 #endif |
16 | 16 |
17 // This free-function is there to ensure that the object file in not discarded | |
18 // at link time when building with gyp (it is required because targets is built | |
19 // as a static library with gyp and not source set which cause the object file | |
20 // to be discarded if no symbol is used). Remove once gyp support is dropped. | |
21 void ScopedNSObjectUnittestArcLinkerWorkaround() {} | |
22 | |
23 namespace { | 17 namespace { |
24 | 18 |
25 template <typename NST> | 19 template <typename NST> |
26 CFIndex GetRetainCount(const base::scoped_nsobject<NST>& nst) { | 20 CFIndex GetRetainCount(const base::scoped_nsobject<NST>& nst) { |
27 @autoreleasepool { | 21 @autoreleasepool { |
28 return CFGetRetainCount((__bridge CFTypeRef)nst.get()) - 1; | 22 return CFGetRetainCount((__bridge CFTypeRef)nst.get()) - 1; |
29 } | 23 } |
30 } | 24 } |
31 | 25 |
32 #if __has_feature(objc_arc_weak) | 26 #if __has_feature(objc_arc_weak) |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 base::scoped_nsobject<id> p2([[NSObject alloc] init]); | 122 base::scoped_nsobject<id> p2([[NSObject alloc] init]); |
129 EXPECT_TRUE(o1 != p2); | 123 EXPECT_TRUE(o1 != p2); |
130 EXPECT_FALSE(o1 == p2); | 124 EXPECT_FALSE(o1 == p2); |
131 id o2 = p2.get(); | 125 id o2 = p2.get(); |
132 swap(p1, p2); | 126 swap(p1, p2); |
133 EXPECT_EQ(o2, p1.get()); | 127 EXPECT_EQ(o2, p1.get()); |
134 EXPECT_EQ(o1, p2.get()); | 128 EXPECT_EQ(o1, p2.get()); |
135 } | 129 } |
136 | 130 |
137 } // namespace | 131 } // namespace |
OLD | NEW |