summaryrefslogtreecommitdiffstats
path: root/googlemock/include/gmock/gmock-spec-builders.h
diff options
context:
space:
mode:
authorAbseil Team <absl-team@google.com>2022-04-09 01:39:39 (GMT)
committerCopybara-Service <copybara-worker@google.com>2022-04-09 01:40:07 (GMT)
commita1cc8c55195661a58ad60c3bb062a0b9c302710d (patch)
tree4a2dc2bc70e5cbcf086e8090796b4675958c518c /googlemock/include/gmock/gmock-spec-builders.h
parent5f467ec04df33024e3c6760fa403b5cd5d8e9ace (diff)
downloadgoogletest-a1cc8c55195661a58ad60c3bb062a0b9c302710d.zip
googletest-a1cc8c55195661a58ad60c3bb062a0b9c302710d.tar.gz
googletest-a1cc8c55195661a58ad60c3bb062a0b9c302710d.tar.bz2
Add support for move-only and &&-qualified actions in WillOnce.
This provides a type-safe way for an action to express that it wants to be called only once, or to capture move-only objects. It is a generalization of the type system-evading hack in ByMove, with the improvement that it works for _any_ action (including user-defined ones), and correctly expresses that the action can only be used with WillOnce. I'll make existing actions benefit in a future commit. PiperOrigin-RevId: 440496139 Change-Id: I4145d191cca5655995ef41360bb126c123cb41d3
Diffstat (limited to 'googlemock/include/gmock/gmock-spec-builders.h')
-rw-r--r--googlemock/include/gmock/gmock-spec-builders.h8
1 files changed, 5 insertions, 3 deletions
diff --git a/googlemock/include/gmock/gmock-spec-builders.h b/googlemock/include/gmock/gmock-spec-builders.h
index 8e4c5c6..917fa9a 100644
--- a/googlemock/include/gmock/gmock-spec-builders.h
+++ b/googlemock/include/gmock/gmock-spec-builders.h
@@ -992,14 +992,16 @@ class TypedExpectation : public ExpectationBase {
return After(s1, s2, s3, s4).After(s5);
}
- // Implements the .WillOnce() clause.
- TypedExpectation& WillOnce(const Action<F>& action) {
+ // Implements the .WillOnce() clause for copyable actions.
+ TypedExpectation& WillOnce(OnceAction<F> once_action) {
ExpectSpecProperty(last_clause_ <= kWillOnce,
".WillOnce() cannot appear after "
".WillRepeatedly() or .RetiresOnSaturation().");
last_clause_ = kWillOnce;
- untyped_actions_.push_back(new Action<F>(action));
+ untyped_actions_.push_back(
+ new Action<F>(std::move(once_action).ReleaseAction()));
+
if (!cardinality_specified()) {
set_cardinality(Exactly(static_cast<int>(untyped_actions_.size())));
}