diff options
Diffstat (limited to 'base/bind_helpers_unittest.cc')
-rw-r--r-- | base/bind_helpers_unittest.cc | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/base/bind_helpers_unittest.cc b/base/bind_helpers_unittest.cc new file mode 100644 index 0000000..3ef2d75 --- /dev/null +++ b/base/bind_helpers_unittest.cc @@ -0,0 +1,39 @@ +// 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. + +#include "base/bind_helpers.h" + +#include "base/callback.h" +#include "base/bind.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace { + +void Increment(int* value) { + (*value)++; +} + +TEST(BindHelpersTest, TestScopedClosureRunnerExitScope) { + int run_count = 0; + { + base::ScopedClosureRunner runner(base::Bind(&Increment, &run_count)); + EXPECT_EQ(0, run_count); + } + EXPECT_EQ(1, run_count); +} + +TEST(BindHelpersTest, TestScopedClosureRunnerRelease) { + int run_count = 0; + base::Closure c; + { + base::ScopedClosureRunner runner(base::Bind(&Increment, &run_count)); + c = runner.Release(); + EXPECT_EQ(0, run_count); + } + EXPECT_EQ(0, run_count); + c.Run(); + EXPECT_EQ(1, run_count); +} + +} // namespace |