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 #import "base/mac/bind_objc_block.h" | 5 #import "base/mac/bind_objc_block.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/callback_helpers.h" | 11 #include "base/callback_helpers.h" |
| 12 #include "build/build_config.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "testing/gtest_mac.h" |
13 | 15 |
14 // See bind_objc_block_unittest_arc.mm for why this is necessary. Remove once | 16 #if defined(OS_IOS) |
15 // gyp support is dropped. | 17 #include "base/ios/weak_nsobject.h" |
16 void BindObjcBlockUnittestArcLinkerWorkaround(); | 18 #include "base/mac/scoped_nsautorelease_pool.h" |
| 19 #endif |
17 | 20 |
18 namespace { | 21 namespace { |
19 | 22 |
20 TEST(BindObjcBlockTest, EnableARCTests) { | |
21 BindObjcBlockUnittestArcLinkerWorkaround(); | |
22 } | |
23 | |
24 TEST(BindObjcBlockTest, TestScopedClosureRunnerExitScope) { | 23 TEST(BindObjcBlockTest, TestScopedClosureRunnerExitScope) { |
25 int run_count = 0; | 24 int run_count = 0; |
26 int* ptr = &run_count; | 25 int* ptr = &run_count; |
27 { | 26 { |
28 base::ScopedClosureRunner runner(base::BindBlock(^{ | 27 base::ScopedClosureRunner runner(base::BindBlock(^{ |
29 (*ptr)++; | 28 (*ptr)++; |
30 })); | 29 })); |
31 EXPECT_EQ(0, run_count); | 30 EXPECT_EQ(0, run_count); |
32 } | 31 } |
33 EXPECT_EQ(1, run_count); | 32 EXPECT_EQ(1, run_count); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 base::BindBlock(^(int a, int b, const std::string& c, | 96 base::BindBlock(^(int a, int b, const std::string& c, |
98 const std::string& d, int e, const std::string& f) { | 97 const std::string& d, int e, const std::string& f) { |
99 *ptr = c + d + f; | 98 *ptr = c + d + f; |
100 *ptr2 = a + b + e; | 99 *ptr2 = a + b + e; |
101 }); | 100 }); |
102 c.Run(1, 2, "infinite", "improbability", 3, "drive"); | 101 c.Run(1, 2, "infinite", "improbability", 3, "drive"); |
103 EXPECT_EQ(result1, "infiniteimprobabilitydrive"); | 102 EXPECT_EQ(result1, "infiniteimprobabilitydrive"); |
104 EXPECT_EQ(result2, 6); | 103 EXPECT_EQ(result2, 6); |
105 } | 104 } |
106 | 105 |
| 106 #if defined(OS_IOS) |
| 107 |
| 108 TEST(BindObjcBlockTest, TestBlockReleased) { |
| 109 base::WeakNSObject<NSObject> weak_nsobject; |
| 110 { |
| 111 base::mac::ScopedNSAutoreleasePool autorelease_pool; |
| 112 NSObject* nsobject = [[[NSObject alloc] init] autorelease]; |
| 113 weak_nsobject.reset(nsobject); |
| 114 |
| 115 auto callback = base::BindBlock(^{ |
| 116 [nsobject description]; |
| 117 }); |
| 118 } |
| 119 EXPECT_NSEQ(nil, weak_nsobject); |
| 120 } |
| 121 |
| 122 #endif |
| 123 |
107 } // namespace | 124 } // namespace |
OLD | NEW |