diff --git a/modules/video_capture/test/video_capture_unittest.cc b/modules/video_capture/test/video_capture_unittest.cc index 002131ebc7..dec8de70cb 100644 --- a/modules/video_capture/test/video_capture_unittest.cc +++ b/modules/video_capture/test/video_capture_unittest.cc @@ -25,11 +25,9 @@ #include "rtc_base/gunit.h" #include "rtc_base/synchronization/mutex.h" #include "rtc_base/time_utils.h" -#include "system_wrappers/include/sleep.h" #include "test/frame_utils.h" #include "test/gtest.h" -using webrtc::SleepMs; using webrtc::VideoCaptureCapability; using webrtc::VideoCaptureFactory; using webrtc::VideoCaptureModule; diff --git a/pc/peer_connection_crypto_unittest.cc b/pc/peer_connection_crypto_unittest.cc index a65988ab05..3b3f502e1f 100644 --- a/pc/peer_connection_crypto_unittest.cc +++ b/pc/peer_connection_crypto_unittest.cc @@ -55,6 +55,7 @@ #include "rtc_base/rtc_certificate_generator.h" #include "rtc_base/ssl_fingerprint.h" #include "rtc_base/thread.h" +#include "test/gmock.h" #include "test/gtest.h" #include "test/scoped_key_value_config.h" #ifdef WEBRTC_ANDROID @@ -70,6 +71,7 @@ namespace webrtc { using RTCConfiguration = PeerConnectionInterface::RTCConfiguration; using RTCOfferAnswerOptions = PeerConnectionInterface::RTCOfferAnswerOptions; using ::testing::Combine; +using ::testing::HasSubstr; using ::testing::Values; constexpr int kGenerateCertTimeout = 1000; @@ -789,16 +791,13 @@ TEST_P(PeerConnectionCryptoTest, SessionErrorIfFingerprintInvalid) { // Set the invalid answer and expect a fingerprint error. std::string error; ASSERT_FALSE(callee->SetLocalDescription(std::move(invalid_answer), &error)); - EXPECT_PRED_FORMAT2(AssertStringContains, error, - "Local fingerprint does not match identity."); + EXPECT_THAT(error, HasSubstr("Local fingerprint does not match identity.")); // Make sure that setting a valid remote offer or local answer also fails now. ASSERT_FALSE(callee->SetRemoteDescription(caller->CreateOffer(), &error)); - EXPECT_PRED_FORMAT2(AssertStringContains, error, - "Session error code: ERROR_CONTENT."); + EXPECT_THAT(error, HasSubstr("Session error code: ERROR_CONTENT.")); ASSERT_FALSE(callee->SetLocalDescription(std::move(valid_answer), &error)); - EXPECT_PRED_FORMAT2(AssertStringContains, error, - "Session error code: ERROR_CONTENT."); + EXPECT_THAT(error, HasSubstr("Session error code: ERROR_CONTENT.")); } INSTANTIATE_TEST_SUITE_P(PeerConnectionCryptoTest, diff --git a/pc/peer_connection_media_unittest.cc b/pc/peer_connection_media_unittest.cc index 061c59a3b0..b892eacb78 100644 --- a/pc/peer_connection_media_unittest.cc +++ b/pc/peer_connection_media_unittest.cc @@ -66,7 +66,6 @@ #ifdef WEBRTC_ANDROID #include "pc/test/android_test_initializer.h" #endif -#include "rtc_base/gunit.h" #include "rtc_base/virtual_socket_server.h" #include "test/gmock.h" @@ -78,6 +77,7 @@ using RTCOfferAnswerOptions = PeerConnectionInterface::RTCOfferAnswerOptions; using ::testing::Bool; using ::testing::Combine; using ::testing::ElementsAre; +using ::testing::HasSubstr; using ::testing::NotNull; using ::testing::Values; @@ -286,8 +286,8 @@ TEST_P(PeerConnectionMediaTest, std::string error; ASSERT_FALSE(callee->SetRemoteDescription(caller->CreateOffer(), &error)); - EXPECT_PRED_FORMAT2(AssertStartsWith, error, - "Failed to set remote offer sdp: Failed to create"); + EXPECT_THAT(error, + HasSubstr("Failed to set remote offer sdp: Failed to create")); } TEST_P(PeerConnectionMediaTest, @@ -297,8 +297,8 @@ TEST_P(PeerConnectionMediaTest, std::string error; ASSERT_FALSE(caller->SetLocalDescription(caller->CreateOffer(), &error)); - EXPECT_PRED_FORMAT2(AssertStartsWith, error, - "Failed to set local offer sdp: Failed to create"); + EXPECT_THAT(error, + HasSubstr("Failed to set local offer sdp: Failed to create")); } std::vector GetIds( diff --git a/pc/peer_connection_signaling_unittest.cc b/pc/peer_connection_signaling_unittest.cc index 190fb38b43..7764be923d 100644 --- a/pc/peer_connection_signaling_unittest.cc +++ b/pc/peer_connection_signaling_unittest.cc @@ -64,6 +64,7 @@ #include "rtc_base/rtc_certificate_generator.h" #include "rtc_base/string_encode.h" #include "rtc_base/thread.h" +#include "test/gmock.h" #include "test/gtest.h" #ifdef WEBRTC_ANDROID #include "pc/test/android_test_initializer.h" @@ -80,6 +81,7 @@ using RTCConfiguration = PeerConnectionInterface::RTCConfiguration; using RTCOfferAnswerOptions = PeerConnectionInterface::RTCOfferAnswerOptions; using ::testing::Bool; using ::testing::Combine; +using ::testing::StartsWith; using ::testing::Values; namespace { @@ -343,8 +345,7 @@ TEST_P(PeerConnectionSignalingStateTest, CreateOffer) { } else { std::string error; ASSERT_FALSE(wrapper->CreateOffer(RTCOfferAnswerOptions(), &error)); - EXPECT_PRED_FORMAT2(AssertStartsWith, error, - "CreateOffer called when PeerConnection is closed."); + EXPECT_EQ(error, "CreateOffer called when PeerConnection is closed."); } } @@ -379,9 +380,9 @@ TEST_P(PeerConnectionSignalingStateTest, SetLocalOffer) { std::string error; ASSERT_FALSE(wrapper->SetLocalDescription(std::move(offer), &error)); - EXPECT_PRED_FORMAT2( - AssertStartsWith, error, - "Failed to set local offer sdp: Called in wrong state:"); + EXPECT_THAT( + error, + StartsWith("Failed to set local offer sdp: Called in wrong state:")); } } @@ -398,9 +399,9 @@ TEST_P(PeerConnectionSignalingStateTest, SetLocalPrAnswer) { } else { std::string error; ASSERT_FALSE(wrapper->SetLocalDescription(std::move(pranswer), &error)); - EXPECT_PRED_FORMAT2( - AssertStartsWith, error, - "Failed to set local pranswer sdp: Called in wrong state:"); + EXPECT_THAT( + error, + StartsWith("Failed to set local pranswer sdp: Called in wrong state:")); } } @@ -416,9 +417,9 @@ TEST_P(PeerConnectionSignalingStateTest, SetLocalAnswer) { } else { std::string error; ASSERT_FALSE(wrapper->SetLocalDescription(std::move(answer), &error)); - EXPECT_PRED_FORMAT2( - AssertStartsWith, error, - "Failed to set local answer sdp: Called in wrong state:"); + EXPECT_THAT( + error, + StartsWith("Failed to set local answer sdp: Called in wrong state:")); } } @@ -435,9 +436,9 @@ TEST_P(PeerConnectionSignalingStateTest, SetRemoteOffer) { } else { std::string error; ASSERT_FALSE(wrapper->SetRemoteDescription(std::move(offer), &error)); - EXPECT_PRED_FORMAT2( - AssertStartsWith, error, - "Failed to set remote offer sdp: Called in wrong state:"); + EXPECT_THAT( + error, + StartsWith("Failed to set remote offer sdp: Called in wrong state:")); } } @@ -454,9 +455,10 @@ TEST_P(PeerConnectionSignalingStateTest, SetRemotePrAnswer) { } else { std::string error; ASSERT_FALSE(wrapper->SetRemoteDescription(std::move(pranswer), &error)); - EXPECT_PRED_FORMAT2( - AssertStartsWith, error, - "Failed to set remote pranswer sdp: Called in wrong state:"); + EXPECT_THAT( + error, + StartsWith( + "Failed to set remote pranswer sdp: Called in wrong state:")); } } @@ -472,9 +474,9 @@ TEST_P(PeerConnectionSignalingStateTest, SetRemoteAnswer) { } else { std::string error; ASSERT_FALSE(wrapper->SetRemoteDescription(std::move(answer), &error)); - EXPECT_PRED_FORMAT2( - AssertStartsWith, error, - "Failed to set remote answer sdp: Called in wrong state:"); + EXPECT_THAT( + error, + StartsWith("Failed to set remote answer sdp: Called in wrong state:")); } } diff --git a/rtc_base/BUILD.gn b/rtc_base/BUILD.gn index 174f410699..9615374745 100644 --- a/rtc_base/BUILD.gn +++ b/rtc_base/BUILD.gn @@ -1632,10 +1632,7 @@ rtc_source_set("gtest_prod") { rtc_library("gunit_helpers") { testonly = true - sources = [ - "gunit.cc", - "gunit.h", - ] + sources = [ "gunit.h" ] deps = [ ":logging", ":rtc_base_tests_utils", diff --git a/rtc_base/gunit.cc b/rtc_base/gunit.cc deleted file mode 100644 index 7cd60fe9ee..0000000000 --- a/rtc_base/gunit.cc +++ /dev/null @@ -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 - -#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 << "\""; - } -} diff --git a/rtc_base/gunit.h b/rtc_base/gunit.h index 6bc1419729..759b377aa2 100644 --- a/rtc_base/gunit.h +++ b/rtc_base/gunit.h @@ -154,16 +154,4 @@ } else \ 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_