using ::testing::_;
using ::testing::AllOf;
using ::testing::Eq;
using ::testing::Ge;
using ::testing::Gt;
using ::testing::Lt;
using ::testing::MatchesRegex;
using ::testing::Property;
int counter = 0;
RTCErrorOr<int> result = WaitUntil([&] { return ++counter; }, Eq(3));
EXPECT_THAT(result, IsRtcOkAndHolds(3));
}
TEST(WaitUntilTest, ReturnsErrorWhenTimeoutIsReached) {
test::RunLoop thread; int counter = 0;
RTCErrorOr<int> result =
WaitUntil([&] { return --counter; }, Eq(1),
{.timeout = TimeDelta::Millis(10), .result_name = "counter"}); // Only returns the last error. Note we only are checking that the error // message ends with a negative number rather than a specific number to avoid // flakiness.
EXPECT_THAT(
result,
IsRtcErrorOrWithMessage(
_, MatchesRegex( "Value of: counter\nExpected: is equal to 1\nActual: -\\d+")));
}
TEST(WaitUntilTest, ErrorContainsMatcherExplanation) {
test::RunLoop thread; int counter = 0; auto matcher = AllOf(Gt(0), Lt(10));
RTCErrorOr<int> result =
WaitUntil([&] { return --counter; }, matcher,
{.timeout = TimeDelta::Millis(10), .result_name = "counter"}); // Only returns the last error. Note we only are checking that the error // message ends with a negative number rather than a specific number to avoid // flakiness.
EXPECT_THAT(
result,
IsRtcErrorOrWithMessage(
_, MatchesRegex("Value of: counter\nExpected: \\(is > 0\\) and " "\\(is < 10\\)\nActual: -\\d+, which doesn't match " "\\(is > 0\\)")));
}
int counter = 0;
EXPECT_TRUE(WaitUntil(
[&] { return ++counter == 3; },
{.polling_interval = TimeDelta::Millis(10), .clock = &fake_clock})); // Check function wasn't called again after it become true.
EXPECT_EQ(counter, 3);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.