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
3 // found in the LICENSE file.
5 #import "base/mac/bind_objc_block.h"
9 #include "base/callback.h"
10 #include "base/bind.h"
11 #include "base/callback_helpers.h"
12 #include "testing/gtest/include/gtest/gtest.h"
16 TEST(BindObjcBlockTest, TestScopedClosureRunnerExitScope) {
18 int* ptr = &run_count;
20 base::ScopedClosureRunner runner(base::BindBlock(^{
23 EXPECT_EQ(0, run_count);
25 EXPECT_EQ(1, run_count);
28 TEST(BindObjcBlockTest, TestScopedClosureRunnerRelease) {
30 int* ptr = &run_count;
33 base::ScopedClosureRunner runner(base::BindBlock(^{
37 EXPECT_EQ(0, run_count);
39 EXPECT_EQ(0, run_count);
41 EXPECT_EQ(1, run_count);
44 TEST(BindObjcBlockTest, TestReturnValue) {
45 const int kReturnValue = 42;
46 base::Callback<int(void)> c = base::BindBlock(^{return kReturnValue;});
47 EXPECT_EQ(kReturnValue, c.Run());
50 TEST(BindObjcBlockTest, TestArgument) {
51 const int kArgument = 42;
52 base::Callback<int(int)> c = base::BindBlock(^(int a){return a + 1;});
53 EXPECT_EQ(kArgument + 1, c.Run(kArgument));
56 TEST(BindObjcBlockTest, TestTwoArguments) {
58 std::string* ptr = &result;
59 base::Callback<void(const std::string&, const std::string&)> c =
60 base::BindBlock(^(const std::string& a, const std::string& b) {
63 c.Run("forty", "two");
64 EXPECT_EQ(result, "fortytwo");