blob: 83ee8075fb9c721ef1d3648b66f5c31adf5c5a00 [file] [log] [blame]
Steve Antonad7bffc2018-01-22 18:21:561/*
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-14 01:41:2515#include "absl/strings/match.h"
Steve Antonad7bffc2018-01-22 18:21:5616
Steve Anton68586e82018-12-14 01:41:2517::testing::AssertionResult AssertStartsWith(const char* text_expr,
Steve Antonad7bffc2018-01-22 18:21:5618 const char* prefix_expr,
Steve Anton68586e82018-12-14 01:41:2519 absl::string_view text,
20 absl::string_view prefix) {
21 if (absl::StartsWith(text, prefix)) {
Steve Antonad7bffc2018-01-22 18:21:5622 return ::testing::AssertionSuccess();
23 } else {
24 return ::testing::AssertionFailure()
Steve Anton68586e82018-12-14 01:41:2525 << text_expr << "\nwhich is\n\"" << text
26 << "\"\ndoes not start with\n"
Steve Antonad7bffc2018-01-22 18:21:5627 << prefix_expr << "\nwhich is\n\"" << prefix << "\"";
28 }
29}
Steve Anton80dd7b52018-02-17 01:08:4230
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}