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 
AssertStartsWith(const char * text_expr,const char * prefix_expr,absl::string_view text,absl::string_view prefix)17 ::testing::AssertionResult AssertStartsWith(const char* text_expr,
18                                             const char* prefix_expr,
19                                             absl::string_view text,
20                                             absl::string_view prefix) {
21   if (absl::StartsWith(text, prefix)) {
22     return ::testing::AssertionSuccess();
23   } else {
24     return ::testing::AssertionFailure()
25            << text_expr << "\nwhich is\n\"" << text
26            << "\"\ndoes not start with\n"
27            << prefix_expr << "\nwhich is\n\"" << prefix << "\"";
28   }
29 }
30 
AssertStringContains(const char * str_expr,const char * substr_expr,const std::string & str,const std::string & substr)31 ::testing::AssertionResult AssertStringContains(const char* str_expr,
32                                                 const char* substr_expr,
33                                                 const std::string& str,
34                                                 const std::string& substr) {
35   if (str.find(substr) != std::string::npos) {
36     return ::testing::AssertionSuccess();
37   } else {
38     return ::testing::AssertionFailure()
39            << str_expr << "\nwhich is\n\"" << str << "\"\ndoes not contain\n"
40            << substr_expr << "\nwhich is\n\"" << substr << "\"";
41   }
42 }
43