diff options
author | noyau@chromium.org <noyau@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-25 17:47:58 +0000 |
---|---|---|
committer | noyau@chromium.org <noyau@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-25 17:47:58 +0000 |
commit | a5e2cd18bab74fb3fb35727f61c59e6d506f1467 (patch) | |
tree | 3eadc3e0e8e35e367d3c485a5b444ef6f572728e /base/mac/bind_objc_block_unittest.mm | |
parent | 8b79d54e48c014264f4d66a323f5fc0e5d498c15 (diff) | |
download | chromium_src-a5e2cd18bab74fb3fb35727f61c59e6d506f1467.zip chromium_src-a5e2cd18bab74fb3fb35727f61c59e6d506f1467.tar.gz chromium_src-a5e2cd18bab74fb3fb35727f61c59e6d506f1467.tar.bz2 |
Adding the possibility to build a closure from an ObjectiveC block.
This lead to more readeable ObjectiveC code as the bound code is right next to where it is scheduled as opposed to be outside the class–usually in a separate function in an anonymous namespace.
BUG=None
TEST=None
Review URL: https://chromiumcodereview.appspot.com/10818034
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@148357 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/mac/bind_objc_block_unittest.mm')
-rw-r--r-- | base/mac/bind_objc_block_unittest.mm | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/base/mac/bind_objc_block_unittest.mm b/base/mac/bind_objc_block_unittest.mm new file mode 100644 index 0000000..17fbe6e --- /dev/null +++ b/base/mac/bind_objc_block_unittest.mm @@ -0,0 +1,42 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#import "base/mac/bind_objc_block.h" + +#include "base/callback.h" +#include "base/bind.h" +#include "base/bind_helpers.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace { + +TEST(BindObjcBlockTest, TestScopedClosureRunnerExitScope) { + int run_count = 0; + int* ptr = &run_count; + { + base::ScopedClosureRunner runner(base::BindBlock(^{ + (*ptr)++; + })); + EXPECT_EQ(0, run_count); + } + EXPECT_EQ(1, run_count); +} + +TEST(BindObjcBlockTest, TestScopedClosureRunnerRelease) { + int run_count = 0; + int* ptr = &run_count; + base::Closure c; + { + base::ScopedClosureRunner runner(base::BindBlock(^{ + (*ptr)++; + })); + c = runner.Release(); + EXPECT_EQ(0, run_count); + } + EXPECT_EQ(0, run_count); + c.Run(); + EXPECT_EQ(1, run_count); +} + +} // namespace |