Remove custom AssertStartsWith and AssertStringContains matchers
in favor of stock StartsWith and HasSubstr matchers provided by gmock. BUG=None Change-Id: Ib7e9a0ac73d506c349b8ec102dd4236767077d61 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/334460 Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Commit-Queue: Philipp Hancke <phancke@microsoft.com> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Cr-Commit-Position: refs/heads/main@{#41531}
This commit is contained in:
parent
3b7afb284f
commit
5aaa9ed41e
@ -25,11 +25,9 @@
|
|||||||
#include "rtc_base/gunit.h"
|
#include "rtc_base/gunit.h"
|
||||||
#include "rtc_base/synchronization/mutex.h"
|
#include "rtc_base/synchronization/mutex.h"
|
||||||
#include "rtc_base/time_utils.h"
|
#include "rtc_base/time_utils.h"
|
||||||
#include "system_wrappers/include/sleep.h"
|
|
||||||
#include "test/frame_utils.h"
|
#include "test/frame_utils.h"
|
||||||
#include "test/gtest.h"
|
#include "test/gtest.h"
|
||||||
|
|
||||||
using webrtc::SleepMs;
|
|
||||||
using webrtc::VideoCaptureCapability;
|
using webrtc::VideoCaptureCapability;
|
||||||
using webrtc::VideoCaptureFactory;
|
using webrtc::VideoCaptureFactory;
|
||||||
using webrtc::VideoCaptureModule;
|
using webrtc::VideoCaptureModule;
|
||||||
|
|||||||
@ -55,6 +55,7 @@
|
|||||||
#include "rtc_base/rtc_certificate_generator.h"
|
#include "rtc_base/rtc_certificate_generator.h"
|
||||||
#include "rtc_base/ssl_fingerprint.h"
|
#include "rtc_base/ssl_fingerprint.h"
|
||||||
#include "rtc_base/thread.h"
|
#include "rtc_base/thread.h"
|
||||||
|
#include "test/gmock.h"
|
||||||
#include "test/gtest.h"
|
#include "test/gtest.h"
|
||||||
#include "test/scoped_key_value_config.h"
|
#include "test/scoped_key_value_config.h"
|
||||||
#ifdef WEBRTC_ANDROID
|
#ifdef WEBRTC_ANDROID
|
||||||
@ -70,6 +71,7 @@ namespace webrtc {
|
|||||||
using RTCConfiguration = PeerConnectionInterface::RTCConfiguration;
|
using RTCConfiguration = PeerConnectionInterface::RTCConfiguration;
|
||||||
using RTCOfferAnswerOptions = PeerConnectionInterface::RTCOfferAnswerOptions;
|
using RTCOfferAnswerOptions = PeerConnectionInterface::RTCOfferAnswerOptions;
|
||||||
using ::testing::Combine;
|
using ::testing::Combine;
|
||||||
|
using ::testing::HasSubstr;
|
||||||
using ::testing::Values;
|
using ::testing::Values;
|
||||||
|
|
||||||
constexpr int kGenerateCertTimeout = 1000;
|
constexpr int kGenerateCertTimeout = 1000;
|
||||||
@ -789,16 +791,13 @@ TEST_P(PeerConnectionCryptoTest, SessionErrorIfFingerprintInvalid) {
|
|||||||
// Set the invalid answer and expect a fingerprint error.
|
// Set the invalid answer and expect a fingerprint error.
|
||||||
std::string error;
|
std::string error;
|
||||||
ASSERT_FALSE(callee->SetLocalDescription(std::move(invalid_answer), &error));
|
ASSERT_FALSE(callee->SetLocalDescription(std::move(invalid_answer), &error));
|
||||||
EXPECT_PRED_FORMAT2(AssertStringContains, error,
|
EXPECT_THAT(error, HasSubstr("Local fingerprint does not match identity."));
|
||||||
"Local fingerprint does not match identity.");
|
|
||||||
|
|
||||||
// Make sure that setting a valid remote offer or local answer also fails now.
|
// Make sure that setting a valid remote offer or local answer also fails now.
|
||||||
ASSERT_FALSE(callee->SetRemoteDescription(caller->CreateOffer(), &error));
|
ASSERT_FALSE(callee->SetRemoteDescription(caller->CreateOffer(), &error));
|
||||||
EXPECT_PRED_FORMAT2(AssertStringContains, error,
|
EXPECT_THAT(error, HasSubstr("Session error code: ERROR_CONTENT."));
|
||||||
"Session error code: ERROR_CONTENT.");
|
|
||||||
ASSERT_FALSE(callee->SetLocalDescription(std::move(valid_answer), &error));
|
ASSERT_FALSE(callee->SetLocalDescription(std::move(valid_answer), &error));
|
||||||
EXPECT_PRED_FORMAT2(AssertStringContains, error,
|
EXPECT_THAT(error, HasSubstr("Session error code: ERROR_CONTENT."));
|
||||||
"Session error code: ERROR_CONTENT.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
INSTANTIATE_TEST_SUITE_P(PeerConnectionCryptoTest,
|
INSTANTIATE_TEST_SUITE_P(PeerConnectionCryptoTest,
|
||||||
|
|||||||
@ -66,7 +66,6 @@
|
|||||||
#ifdef WEBRTC_ANDROID
|
#ifdef WEBRTC_ANDROID
|
||||||
#include "pc/test/android_test_initializer.h"
|
#include "pc/test/android_test_initializer.h"
|
||||||
#endif
|
#endif
|
||||||
#include "rtc_base/gunit.h"
|
|
||||||
#include "rtc_base/virtual_socket_server.h"
|
#include "rtc_base/virtual_socket_server.h"
|
||||||
#include "test/gmock.h"
|
#include "test/gmock.h"
|
||||||
|
|
||||||
@ -78,6 +77,7 @@ using RTCOfferAnswerOptions = PeerConnectionInterface::RTCOfferAnswerOptions;
|
|||||||
using ::testing::Bool;
|
using ::testing::Bool;
|
||||||
using ::testing::Combine;
|
using ::testing::Combine;
|
||||||
using ::testing::ElementsAre;
|
using ::testing::ElementsAre;
|
||||||
|
using ::testing::HasSubstr;
|
||||||
using ::testing::NotNull;
|
using ::testing::NotNull;
|
||||||
using ::testing::Values;
|
using ::testing::Values;
|
||||||
|
|
||||||
@ -286,8 +286,8 @@ TEST_P(PeerConnectionMediaTest,
|
|||||||
|
|
||||||
std::string error;
|
std::string error;
|
||||||
ASSERT_FALSE(callee->SetRemoteDescription(caller->CreateOffer(), &error));
|
ASSERT_FALSE(callee->SetRemoteDescription(caller->CreateOffer(), &error));
|
||||||
EXPECT_PRED_FORMAT2(AssertStartsWith, error,
|
EXPECT_THAT(error,
|
||||||
"Failed to set remote offer sdp: Failed to create");
|
HasSubstr("Failed to set remote offer sdp: Failed to create"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_P(PeerConnectionMediaTest,
|
TEST_P(PeerConnectionMediaTest,
|
||||||
@ -297,8 +297,8 @@ TEST_P(PeerConnectionMediaTest,
|
|||||||
|
|
||||||
std::string error;
|
std::string error;
|
||||||
ASSERT_FALSE(caller->SetLocalDescription(caller->CreateOffer(), &error));
|
ASSERT_FALSE(caller->SetLocalDescription(caller->CreateOffer(), &error));
|
||||||
EXPECT_PRED_FORMAT2(AssertStartsWith, error,
|
EXPECT_THAT(error,
|
||||||
"Failed to set local offer sdp: Failed to create");
|
HasSubstr("Failed to set local offer sdp: Failed to create"));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> GetIds(
|
std::vector<std::string> GetIds(
|
||||||
|
|||||||
@ -64,6 +64,7 @@
|
|||||||
#include "rtc_base/rtc_certificate_generator.h"
|
#include "rtc_base/rtc_certificate_generator.h"
|
||||||
#include "rtc_base/string_encode.h"
|
#include "rtc_base/string_encode.h"
|
||||||
#include "rtc_base/thread.h"
|
#include "rtc_base/thread.h"
|
||||||
|
#include "test/gmock.h"
|
||||||
#include "test/gtest.h"
|
#include "test/gtest.h"
|
||||||
#ifdef WEBRTC_ANDROID
|
#ifdef WEBRTC_ANDROID
|
||||||
#include "pc/test/android_test_initializer.h"
|
#include "pc/test/android_test_initializer.h"
|
||||||
@ -80,6 +81,7 @@ using RTCConfiguration = PeerConnectionInterface::RTCConfiguration;
|
|||||||
using RTCOfferAnswerOptions = PeerConnectionInterface::RTCOfferAnswerOptions;
|
using RTCOfferAnswerOptions = PeerConnectionInterface::RTCOfferAnswerOptions;
|
||||||
using ::testing::Bool;
|
using ::testing::Bool;
|
||||||
using ::testing::Combine;
|
using ::testing::Combine;
|
||||||
|
using ::testing::StartsWith;
|
||||||
using ::testing::Values;
|
using ::testing::Values;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@ -343,8 +345,7 @@ TEST_P(PeerConnectionSignalingStateTest, CreateOffer) {
|
|||||||
} else {
|
} else {
|
||||||
std::string error;
|
std::string error;
|
||||||
ASSERT_FALSE(wrapper->CreateOffer(RTCOfferAnswerOptions(), &error));
|
ASSERT_FALSE(wrapper->CreateOffer(RTCOfferAnswerOptions(), &error));
|
||||||
EXPECT_PRED_FORMAT2(AssertStartsWith, error,
|
EXPECT_EQ(error, "CreateOffer called when PeerConnection is closed.");
|
||||||
"CreateOffer called when PeerConnection is closed.");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -379,9 +380,9 @@ TEST_P(PeerConnectionSignalingStateTest, SetLocalOffer) {
|
|||||||
|
|
||||||
std::string error;
|
std::string error;
|
||||||
ASSERT_FALSE(wrapper->SetLocalDescription(std::move(offer), &error));
|
ASSERT_FALSE(wrapper->SetLocalDescription(std::move(offer), &error));
|
||||||
EXPECT_PRED_FORMAT2(
|
EXPECT_THAT(
|
||||||
AssertStartsWith, error,
|
error,
|
||||||
"Failed to set local offer sdp: Called in wrong state:");
|
StartsWith("Failed to set local offer sdp: Called in wrong state:"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -398,9 +399,9 @@ TEST_P(PeerConnectionSignalingStateTest, SetLocalPrAnswer) {
|
|||||||
} else {
|
} else {
|
||||||
std::string error;
|
std::string error;
|
||||||
ASSERT_FALSE(wrapper->SetLocalDescription(std::move(pranswer), &error));
|
ASSERT_FALSE(wrapper->SetLocalDescription(std::move(pranswer), &error));
|
||||||
EXPECT_PRED_FORMAT2(
|
EXPECT_THAT(
|
||||||
AssertStartsWith, error,
|
error,
|
||||||
"Failed to set local pranswer sdp: Called in wrong state:");
|
StartsWith("Failed to set local pranswer sdp: Called in wrong state:"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -416,9 +417,9 @@ TEST_P(PeerConnectionSignalingStateTest, SetLocalAnswer) {
|
|||||||
} else {
|
} else {
|
||||||
std::string error;
|
std::string error;
|
||||||
ASSERT_FALSE(wrapper->SetLocalDescription(std::move(answer), &error));
|
ASSERT_FALSE(wrapper->SetLocalDescription(std::move(answer), &error));
|
||||||
EXPECT_PRED_FORMAT2(
|
EXPECT_THAT(
|
||||||
AssertStartsWith, error,
|
error,
|
||||||
"Failed to set local answer sdp: Called in wrong state:");
|
StartsWith("Failed to set local answer sdp: Called in wrong state:"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -435,9 +436,9 @@ TEST_P(PeerConnectionSignalingStateTest, SetRemoteOffer) {
|
|||||||
} else {
|
} else {
|
||||||
std::string error;
|
std::string error;
|
||||||
ASSERT_FALSE(wrapper->SetRemoteDescription(std::move(offer), &error));
|
ASSERT_FALSE(wrapper->SetRemoteDescription(std::move(offer), &error));
|
||||||
EXPECT_PRED_FORMAT2(
|
EXPECT_THAT(
|
||||||
AssertStartsWith, error,
|
error,
|
||||||
"Failed to set remote offer sdp: Called in wrong state:");
|
StartsWith("Failed to set remote offer sdp: Called in wrong state:"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -454,9 +455,10 @@ TEST_P(PeerConnectionSignalingStateTest, SetRemotePrAnswer) {
|
|||||||
} else {
|
} else {
|
||||||
std::string error;
|
std::string error;
|
||||||
ASSERT_FALSE(wrapper->SetRemoteDescription(std::move(pranswer), &error));
|
ASSERT_FALSE(wrapper->SetRemoteDescription(std::move(pranswer), &error));
|
||||||
EXPECT_PRED_FORMAT2(
|
EXPECT_THAT(
|
||||||
AssertStartsWith, error,
|
error,
|
||||||
"Failed to set remote pranswer sdp: Called in wrong state:");
|
StartsWith(
|
||||||
|
"Failed to set remote pranswer sdp: Called in wrong state:"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -472,9 +474,9 @@ TEST_P(PeerConnectionSignalingStateTest, SetRemoteAnswer) {
|
|||||||
} else {
|
} else {
|
||||||
std::string error;
|
std::string error;
|
||||||
ASSERT_FALSE(wrapper->SetRemoteDescription(std::move(answer), &error));
|
ASSERT_FALSE(wrapper->SetRemoteDescription(std::move(answer), &error));
|
||||||
EXPECT_PRED_FORMAT2(
|
EXPECT_THAT(
|
||||||
AssertStartsWith, error,
|
error,
|
||||||
"Failed to set remote answer sdp: Called in wrong state:");
|
StartsWith("Failed to set remote answer sdp: Called in wrong state:"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1632,10 +1632,7 @@ rtc_source_set("gtest_prod") {
|
|||||||
|
|
||||||
rtc_library("gunit_helpers") {
|
rtc_library("gunit_helpers") {
|
||||||
testonly = true
|
testonly = true
|
||||||
sources = [
|
sources = [ "gunit.h" ]
|
||||||
"gunit.cc",
|
|
||||||
"gunit.h",
|
|
||||||
]
|
|
||||||
deps = [
|
deps = [
|
||||||
":logging",
|
":logging",
|
||||||
":rtc_base_tests_utils",
|
":rtc_base_tests_utils",
|
||||||
|
|||||||
@ -1,43 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2018 The WebRTC Project Authors. All rights reserved.
|
|
||||||
*
|
|
||||||
* Use of this source code is governed by a BSD-style license
|
|
||||||
* that can be found in the LICENSE file in the root of the source
|
|
||||||
* tree. An additional intellectual property rights grant can be found
|
|
||||||
* in the file PATENTS. All contributing project authors may
|
|
||||||
* be found in the AUTHORS file in the root of the source tree.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "rtc_base/gunit.h"
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include "absl/strings/match.h"
|
|
||||||
#include "absl/strings/string_view.h"
|
|
||||||
|
|
||||||
::testing::AssertionResult AssertStartsWith(const char* text_expr,
|
|
||||||
const char* prefix_expr,
|
|
||||||
absl::string_view text,
|
|
||||||
absl::string_view prefix) {
|
|
||||||
if (absl::StartsWith(text, prefix)) {
|
|
||||||
return ::testing::AssertionSuccess();
|
|
||||||
} else {
|
|
||||||
return ::testing::AssertionFailure()
|
|
||||||
<< text_expr << "\nwhich is\n\"" << text
|
|
||||||
<< "\"\ndoes not start with\n"
|
|
||||||
<< prefix_expr << "\nwhich is\n\"" << prefix << "\"";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
::testing::AssertionResult AssertStringContains(const char* str_expr,
|
|
||||||
const char* substr_expr,
|
|
||||||
absl::string_view str,
|
|
||||||
absl::string_view substr) {
|
|
||||||
if (str.find(substr) != absl::string_view::npos) {
|
|
||||||
return ::testing::AssertionSuccess();
|
|
||||||
} else {
|
|
||||||
return ::testing::AssertionFailure()
|
|
||||||
<< str_expr << "\nwhich is\n\"" << str << "\"\ndoes not contain\n"
|
|
||||||
<< substr_expr << "\nwhich is\n\"" << substr << "\"";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -154,16 +154,4 @@
|
|||||||
} else \
|
} else \
|
||||||
GTEST_CONCAT_TOKEN_(gunit_label_, __LINE__) : ASSERT_EQ(v1, v2)
|
GTEST_CONCAT_TOKEN_(gunit_label_, __LINE__) : ASSERT_EQ(v1, v2)
|
||||||
|
|
||||||
// Usage: EXPECT_PRED_FORMAT2(AssertStartsWith, text, "prefix");
|
|
||||||
testing::AssertionResult AssertStartsWith(const char* text_expr,
|
|
||||||
const char* prefix_expr,
|
|
||||||
absl::string_view text,
|
|
||||||
absl::string_view prefix);
|
|
||||||
|
|
||||||
// Usage: EXPECT_PRED_FORMAT2(AssertStringContains, str, "substring");
|
|
||||||
testing::AssertionResult AssertStringContains(const char* str_expr,
|
|
||||||
const char* substr_expr,
|
|
||||||
absl::string_view str,
|
|
||||||
absl::string_view substr);
|
|
||||||
|
|
||||||
#endif // RTC_BASE_GUNIT_H_
|
#endif // RTC_BASE_GUNIT_H_
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user