| Index: base/mac/bind_objc_block_unittest_arc.mm
|
| diff --git a/base/mac/bind_objc_block_unittest_arc.mm b/base/mac/bind_objc_block_unittest_arc.mm
|
| index ded1c338e47d29b159038f9c5821dfa2139017c4..c4c268e78c504c9c5a885010d8c8978f16a24537 100644
|
| --- a/base/mac/bind_objc_block_unittest_arc.mm
|
| +++ b/base/mac/bind_objc_block_unittest_arc.mm
|
| @@ -9,26 +9,22 @@
|
| #include "base/bind.h"
|
| #include "base/callback.h"
|
| #include "base/callback_helpers.h"
|
| +#include "build/build_config.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| +#include "testing/gtest_mac.h"
|
|
|
| #if !defined(__has_feature) || !__has_feature(objc_arc)
|
| #error "This file requires ARC support."
|
| #endif
|
|
|
| -// This free-function is there to ensure that the object file in not discarded
|
| -// at link time when building with gyp (it is required because targets is built
|
| -// as a static library with gyp and not source set which cause the object file
|
| -// to be discarded if no symbol is used). Remove once gyp support is dropped.
|
| -void BindObjcBlockUnittestArcLinkerWorkaround() {}
|
| -
|
| namespace {
|
|
|
| TEST(BindObjcBlockTestARC, TestScopedClosureRunnerExitScope) {
|
| int run_count = 0;
|
| int* ptr = &run_count;
|
| {
|
| - base::ScopedClosureRunner runner(base::BindBlock(^{
|
| - (*ptr)++;
|
| + base::ScopedClosureRunner runner(base::BindBlockArc(^{
|
| + (*ptr)++;
|
| }));
|
| EXPECT_EQ(0, run_count);
|
| }
|
| @@ -40,8 +36,8 @@ TEST(BindObjcBlockTestARC, TestScopedClosureRunnerRelease) {
|
| int* ptr = &run_count;
|
| base::Closure c;
|
| {
|
| - base::ScopedClosureRunner runner(base::BindBlock(^{
|
| - (*ptr)++;
|
| + base::ScopedClosureRunner runner(base::BindBlockArc(^{
|
| + (*ptr)++;
|
| }));
|
| c = runner.Release();
|
| EXPECT_EQ(0, run_count);
|
| @@ -53,13 +49,17 @@ TEST(BindObjcBlockTestARC, TestScopedClosureRunnerRelease) {
|
|
|
| TEST(BindObjcBlockTestARC, TestReturnValue) {
|
| const int kReturnValue = 42;
|
| - base::Callback<int(void)> c = base::BindBlock(^{return kReturnValue;});
|
| + base::Callback<int(void)> c = base::BindBlockArc(^{
|
| + return kReturnValue;
|
| + });
|
| EXPECT_EQ(kReturnValue, c.Run());
|
| }
|
|
|
| TEST(BindObjcBlockTestARC, TestArgument) {
|
| const int kArgument = 42;
|
| - base::Callback<int(int)> c = base::BindBlock(^(int a){return a + 1;});
|
| + base::Callback<int(int)> c = base::BindBlockArc(^(int a) {
|
| + return a + 1;
|
| + });
|
| EXPECT_EQ(kArgument + 1, c.Run(kArgument));
|
| }
|
|
|
| @@ -67,8 +67,8 @@ TEST(BindObjcBlockTestARC, TestTwoArguments) {
|
| std::string result;
|
| std::string* ptr = &result;
|
| base::Callback<void(const std::string&, const std::string&)> c =
|
| - base::BindBlock(^(const std::string& a, const std::string& b) {
|
| - *ptr = a + b;
|
| + base::BindBlockArc(^(const std::string& a, const std::string& b) {
|
| + *ptr = a + b;
|
| });
|
| c.Run("forty", "two");
|
| EXPECT_EQ(result, "fortytwo");
|
| @@ -77,14 +77,12 @@ TEST(BindObjcBlockTestARC, TestTwoArguments) {
|
| TEST(BindObjcBlockTestARC, TestThreeArguments) {
|
| std::string result;
|
| std::string* ptr = &result;
|
| - base::Callback<void(const std::string&,
|
| - const std::string&,
|
| - const std::string&)> c =
|
| - base::BindBlock(^(const std::string& a,
|
| - const std::string& b,
|
| - const std::string& c) {
|
| - *ptr = a + b + c;
|
| - });
|
| + base::Callback<void(const std::string&, const std::string&,
|
| + const std::string&)>
|
| + c = base::BindBlockArc(
|
| + ^(const std::string& a, const std::string& b, const std::string& c) {
|
| + *ptr = a + b + c;
|
| + });
|
| c.Run("six", "times", "nine");
|
| EXPECT_EQ(result, "sixtimesnine");
|
| }
|
| @@ -94,16 +92,34 @@ TEST(BindObjcBlockTestARC, TestSixArguments) {
|
| std::string* ptr = &result1;
|
| int result2;
|
| int* ptr2 = &result2;
|
| - base::Callback<void(int, int, const std::string&, const std::string&,
|
| - int, const std::string&)> c =
|
| - base::BindBlock(^(int a, int b, const std::string& c,
|
| - const std::string& d, int e, const std::string& f) {
|
| - *ptr = c + d + f;
|
| - *ptr2 = a + b + e;
|
| + base::Callback<void(int, int, const std::string&, const std::string&, int,
|
| + const std::string&)>
|
| + c = base::BindBlockArc(^(int a, int b, const std::string& c,
|
| + const std::string& d, int e,
|
| + const std::string& f) {
|
| + *ptr = c + d + f;
|
| + *ptr2 = a + b + e;
|
| });
|
| c.Run(1, 2, "infinite", "improbability", 3, "drive");
|
| EXPECT_EQ(result1, "infiniteimprobabilitydrive");
|
| EXPECT_EQ(result2, 6);
|
| }
|
|
|
| +#if defined(OS_IOS)
|
| +
|
| +TEST(BindObjcBlockTestARC, TestBlockReleased) {
|
| + __weak NSObject* weak_nsobject;
|
| + @autoreleasepool {
|
| + NSObject* nsobject = [[NSObject alloc] init];
|
| + weak_nsobject = nsobject;
|
| +
|
| + auto callback = base::BindBlockArc(^{
|
| + [nsobject description];
|
| + });
|
| + }
|
| + EXPECT_NSEQ(nil, weak_nsobject);
|
| +}
|
| +
|
| +#endif
|
| +
|
| } // namespace
|
|
|