1 Star 0 Fork 145

溜达的板凳/BRPC

forked from 百度开源/BRPC 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
callback_helpers_unittest.cc 1.42 KB
一键复制 编辑 原始数据 按行查看 历史
// Copyright 2013 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 "butil/callback_helpers.h"
#include "butil/bind.h"
#include "butil/callback.h"
#include <gtest/gtest.h>
namespace {
void Increment(int* value) {
(*value)++;
}
TEST(BindHelpersTest, TestScopedClosureRunnerExitScope) {
int run_count = 0;
{
butil::ScopedClosureRunner runner(butil::Bind(&Increment, &run_count));
EXPECT_EQ(0, run_count);
}
EXPECT_EQ(1, run_count);
}
TEST(BindHelpersTest, TestScopedClosureRunnerRelease) {
int run_count = 0;
butil::Closure c;
{
butil::ScopedClosureRunner runner(butil::Bind(&Increment, &run_count));
c = runner.Release();
EXPECT_EQ(0, run_count);
}
EXPECT_EQ(0, run_count);
c.Run();
EXPECT_EQ(1, run_count);
}
TEST(BindHelpersTest, TestScopedClosureRunnerReset) {
int run_count_1 = 0;
int run_count_2 = 0;
{
butil::ScopedClosureRunner runner;
runner.Reset(butil::Bind(&Increment, &run_count_1));
runner.Reset(butil::Bind(&Increment, &run_count_2));
EXPECT_EQ(1, run_count_1);
EXPECT_EQ(0, run_count_2);
}
EXPECT_EQ(1, run_count_2);
int run_count_3 = 0;
{
butil::ScopedClosureRunner runner(butil::Bind(&Increment, &run_count_3));
EXPECT_EQ(0, run_count_3);
runner.Reset();
EXPECT_EQ(1, run_count_3);
}
EXPECT_EQ(1, run_count_3);
}
} // namespace
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C/C++
1
https://gitee.com/strolling-benches/BRPC.git
git@gitee.com:strolling-benches/BRPC.git
strolling-benches
BRPC
BRPC
master

搜索帮助