2
* Copyright 2010 Google Inc.
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
17
// Author: jmarantz@google.com (Joshua Marantz)
20
#ifndef PAGESPEED_KERNEL_BASE_GTEST_H_
21
#define PAGESPEED_KERNEL_BASE_GTEST_H_
23
#include "pagespeed/kernel/base/string.h"
24
#include "pagespeed/kernel/base/string_util.h"
25
#include "testing/gtest/include/gtest/gtest.h"
27
namespace net_instaweb {
29
GoogleString GTestSrcDir();
30
GoogleString GTestTempDir();
32
} // namespace net_instaweb
37
// Allows EXPECT_STREQ to be used on StringPiece.
38
inline GTEST_API_ AssertionResult CmpHelperSTREQ(
39
const char* expected_expression,
40
const char* actual_expression,
41
const StringPiece& expected,
42
const StringPiece& actual) {
43
return CmpHelperSTREQ(expected_expression, actual_expression,
44
expected.as_string().c_str(),
45
actual.as_string().c_str());
48
// Allows EXPECT_STRNE to be used on StringPiece.
49
inline GTEST_API_ AssertionResult CmpHelperSTRNE(
50
const char* expected_expression,
51
const char* actual_expression,
52
const StringPiece& expected,
53
const StringPiece& actual) {
54
return CmpHelperSTRNE(expected_expression, actual_expression,
55
expected.as_string().c_str(),
56
actual.as_string().c_str());
59
// EXPECT_SUBSTR and EXPECT_SUBSTR_NE allows a simple way to search for a
60
// substring. Works on StringPiece, char* and GoogleString.
61
#define EXPECT_HAS_SUBSTR(needle, haystack) \
62
EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSUBSTR, needle, haystack)
64
#define EXPECT_HAS_SUBSTR_NE(needle, haystack) \
65
EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSUBSTRNE, needle, haystack)
67
template <typename StringType>
68
inline GTEST_API_ AssertionResult CmpHelperSUBSTR(
69
const char* haystack_expression,
70
const char* needle_expression,
71
const StringType haystack,
72
const StringPiece& needle) {
73
return ::testing::IsSubstring(haystack_expression, needle_expression,
74
haystack, needle.as_string());
77
template <typename StringType1, typename StringType2>
78
inline GTEST_API_ AssertionResult CmpHelperSUBSTR(
79
const char* haystack_expression,
80
const char* needle_expression,
81
const StringType1 haystack,
82
const StringType2 needle) {
83
return ::testing::IsSubstring(haystack_expression, needle_expression,
87
template <typename StringType>
88
inline GTEST_API_ AssertionResult CmpHelperSUBSTRNE(
89
const char* haystack_expression,
90
const char* needle_expression,
91
const StringType haystack,
92
const StringPiece& needle) {
93
return ::testing::IsNotSubstring(haystack_expression, needle_expression,
94
haystack, needle.as_string());
97
template <typename StringType1, typename StringType2>
98
inline GTEST_API_ AssertionResult CmpHelperSUBSTRNE(
99
const char* haystack_expression,
100
const char* needle_expression,
101
const StringType1 haystack,
102
const StringType2 needle) {
103
return ::testing::IsNotSubstring(haystack_expression, needle_expression,
107
} // namespace internal
108
} // namespace testing
110
#endif // PAGESPEED_KERNEL_BASE_GTEST_H_