You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.6 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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. #include "rtc_base/gunit.h"
  11. #include <string>
  12. #include "absl/strings/match.h"
  13. ::testing::AssertionResult AssertStartsWith(const char* text_expr,
  14. const char* prefix_expr,
  15. absl::string_view text,
  16. absl::string_view prefix) {
  17. if (absl::StartsWith(text, prefix)) {
  18. return ::testing::AssertionSuccess();
  19. } else {
  20. return ::testing::AssertionFailure()
  21. << text_expr << "\nwhich is\n\"" << text
  22. << "\"\ndoes not start with\n"
  23. << prefix_expr << "\nwhich is\n\"" << prefix << "\"";
  24. }
  25. }
  26. ::testing::AssertionResult AssertStringContains(const char* str_expr,
  27. const char* substr_expr,
  28. const std::string& str,
  29. const std::string& substr) {
  30. if (str.find(substr) != std::string::npos) {
  31. return ::testing::AssertionSuccess();
  32. } else {
  33. return ::testing::AssertionFailure()
  34. << str_expr << "\nwhich is\n\"" << str << "\"\ndoes not contain\n"
  35. << substr_expr << "\nwhich is\n\"" << substr << "\"";
  36. }
  37. }