Commit 779e830d authored by danakj's avatar danakj Committed by Commit Bot

Add tests for IgnoreResult() receiving a callback.

Also test that it can IgnoreResult a callback with arguments and the
resulting callback will still accept those arguments.

R=dcheng@chromium.org

Bug: 1140582
Change-Id: If01cd5442f1ef0185fce74f6952cbdf54aaef07a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2503769Reviewed-by: default avatarGabriel Charette <gab@chromium.org>
Commit-Queue: danakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#821355}
parent 5d255cb4
......@@ -13,6 +13,7 @@
#include "base/memory/ptr_util.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "base/strings/string_number_conversions.h"
#include "base/test/bind_test_util.h"
#include "base/test/gtest_util.h"
#include "build/build_config.h"
......@@ -513,6 +514,32 @@ TEST_F(BindTest, IgnoreResultForOnce) {
std::move(non_void_weak_method_cb).Run();
}
TEST_F(BindTest, IgnoreResultForRepeatingCallback) {
std::string s;
RepeatingCallback<int(int)> cb = BindRepeating(
[](std::string* s, int i) {
*s += "Run" + base::NumberToString(i);
return 5;
},
&s);
RepeatingCallback<void(int)> noreturn = BindRepeating(IgnoreResult(cb));
noreturn.Run(2);
EXPECT_EQ(s, "Run2");
}
TEST_F(BindTest, IgnoreResultForOnceCallback) {
std::string s;
OnceCallback<int(int)> cb = BindOnce(
[](std::string* s, int i) {
*s += "Run" + base::NumberToString(i);
return 5;
},
&s);
OnceCallback<void(int)> noreturn = BindOnce(IgnoreResult(std::move(cb)));
std::move(noreturn).Run(2);
EXPECT_EQ(s, "Run2");
}
// Functions that take reference parameters.
// - Forced reference parameter type still stores a copy.
// - Forced const reference parameter type still stores a copy.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment