Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 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 | |
Steve Anton | 68586e8 | 2018-12-14 01:41:25 | [diff] [blame] | 15 | #include "absl/strings/match.h" |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 16 | |
Steve Anton | 68586e8 | 2018-12-14 01:41:25 | [diff] [blame] | 17 | ::testing::AssertionResult AssertStartsWith(const char* text_expr, |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 18 | const char* prefix_expr, |
Steve Anton | 68586e8 | 2018-12-14 01:41:25 | [diff] [blame] | 19 | absl::string_view text, |
| 20 | absl::string_view prefix) { |
| 21 | if (absl::StartsWith(text, prefix)) { |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 22 | return ::testing::AssertionSuccess(); |
| 23 | } else { |
| 24 | return ::testing::AssertionFailure() |
Steve Anton | 68586e8 | 2018-12-14 01:41:25 | [diff] [blame] | 25 | << text_expr << "\nwhich is\n\"" << text |
| 26 | << "\"\ndoes not start with\n" |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 27 | << prefix_expr << "\nwhich is\n\"" << prefix << "\""; |
| 28 | } |
| 29 | } |
Steve Anton | 80dd7b5 | 2018-02-17 01:08:42 | [diff] [blame] | 30 | |
| 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 | } |