blob: 7cd60fe9ee8b218137cb0f5b5449b7ef2178e35b [file] [log] [blame]
Steve Antonad7bffc2018-01-22 10:21:56 -08001/*
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 Anton68586e82018-12-13 17:41:25 -080015#include "absl/strings/match.h"
Ali Tofigh7fa90572022-03-17 15:47:49 +010016#include "absl/strings/string_view.h"
Steve Antonad7bffc2018-01-22 10:21:56 -080017
Steve Anton68586e82018-12-13 17:41:25 -080018::testing::AssertionResult AssertStartsWith(const char* text_expr,
Steve Antonad7bffc2018-01-22 10:21:56 -080019 const char* prefix_expr,
Steve Anton68586e82018-12-13 17:41:25 -080020 absl::string_view text,
21 absl::string_view prefix) {
22 if (absl::StartsWith(text, prefix)) {
Steve Antonad7bffc2018-01-22 10:21:56 -080023 return ::testing::AssertionSuccess();
24 } else {
25 return ::testing::AssertionFailure()
Steve Anton68586e82018-12-13 17:41:25 -080026 << text_expr << "\nwhich is\n\"" << text
27 << "\"\ndoes not start with\n"
Steve Antonad7bffc2018-01-22 10:21:56 -080028 << prefix_expr << "\nwhich is\n\"" << prefix << "\"";
29 }
30}
Steve Anton80dd7b52018-02-16 17:08:42 -080031
32::testing::AssertionResult AssertStringContains(const char* str_expr,
33 const char* substr_expr,
Ali Tofigh7fa90572022-03-17 15:47:49 +010034 absl::string_view str,
35 absl::string_view substr) {
36 if (str.find(substr) != absl::string_view::npos) {
Steve Anton80dd7b52018-02-16 17:08:42 -080037 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}