1 /*
2 * Copyright 2018 The WebRTC Project Authors. All rights reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include "rtc_base/gunit.h"
12
13 #include <string>
14
15 #include "absl/strings/match.h"
16 #include "absl/strings/string_view.h"
17
AssertStartsWith(const char * text_expr,const char * prefix_expr,absl::string_view text,absl::string_view prefix)18 ::testing::AssertionResult AssertStartsWith(const char* text_expr,
19 const char* prefix_expr,
20 absl::string_view text,
21 absl::string_view prefix) {
22 if (absl::StartsWith(text, prefix)) {
23 return ::testing::AssertionSuccess();
24 } else {
25 return ::testing::AssertionFailure()
26 << text_expr << "\nwhich is\n\"" << text
27 << "\"\ndoes not start with\n"
28 << prefix_expr << "\nwhich is\n\"" << prefix << "\"";
29 }
30 }
31
AssertStringContains(const char * str_expr,const char * substr_expr,absl::string_view str,absl::string_view substr)32 ::testing::AssertionResult AssertStringContains(const char* str_expr,
33 const char* substr_expr,
34 absl::string_view str,
35 absl::string_view substr) {
36 if (str.find(substr) != absl::string_view::npos) {
37 return ::testing::AssertionSuccess();
38 } else {
39 return ::testing::AssertionFailure()
40 << str_expr << "\nwhich is\n\"" << str << "\"\ndoes not contain\n"
41 << substr_expr << "\nwhich is\n\"" << substr << "\"";
42 }
43 }
44