@@ -40,14 +40,16 @@ template <auto Func> struct StrchrTest : public LIBC_NAMESPACE::testing::Test {
40
40
const char *src = " abcde" ;
41
41
42
42
// Should return null terminator.
43
- ASSERT_STREQ (Func (src, ' \0 ' ), " " );
43
+ const char *nul_terminator = Func (src, ' \0 ' );
44
+ ASSERT_NE (nul_terminator, nullptr );
45
+ ASSERT_STREQ (nul_terminator, " " );
44
46
// Source string should not change.
45
47
ASSERT_STREQ (src, " abcde" );
46
48
}
47
49
48
50
void characterNotWithinStringShouldReturnNullptr () {
49
51
// Since 'z' is not within the string, should return nullptr.
50
- ASSERT_STREQ (Func (" 123?" , ' z' ), nullptr );
52
+ ASSERT_EQ (Func (" 123?" , ' z' ), nullptr );
51
53
}
52
54
53
55
void theSourceShouldNotChange () {
@@ -74,11 +76,13 @@ template <auto Func> struct StrchrTest : public LIBC_NAMESPACE::testing::Test {
74
76
75
77
void emptyStringShouldOnlyMatchNullTerminator () {
76
78
// Null terminator should match.
77
- ASSERT_STREQ (Func (" " , ' \0 ' ), " " );
79
+ const char empty_string[] = " " ;
80
+ ASSERT_EQ (static_cast <const char *>(Func (empty_string, ' \0 ' )),
81
+ empty_string);
78
82
// All other characters should not match.
79
- ASSERT_STREQ (Func (" " , ' Z' ), nullptr );
80
- ASSERT_STREQ (Func (" " , ' 3' ), nullptr );
81
- ASSERT_STREQ (Func (" " , ' *' ), nullptr );
83
+ ASSERT_EQ (Func (" " , ' Z' ), nullptr );
84
+ ASSERT_EQ (Func (" " , ' 3' ), nullptr );
85
+ ASSERT_EQ (Func (" " , ' *' ), nullptr );
82
86
}
83
87
};
84
88
@@ -114,25 +118,27 @@ template <auto Func> struct StrrchrTest : public LIBC_NAMESPACE::testing::Test {
114
118
const char *src = " abcde" ;
115
119
116
120
// Should return null terminator.
117
- ASSERT_STREQ (Func (src, ' \0 ' ), " " );
121
+ const char *nul_terminator = Func (src, ' \0 ' );
122
+ ASSERT_NE (nul_terminator, nullptr );
123
+ ASSERT_STREQ (nul_terminator, " " );
118
124
// Source string should not change.
119
125
ASSERT_STREQ (src, " abcde" );
120
126
}
121
127
122
128
void findsLastBehindFirstNullTerminator () {
123
129
static const char src[6 ] = {' a' , ' a' , ' \0 ' , ' b' , ' \0 ' , ' c' };
124
130
// 'b' is behind a null terminator, so should not be found.
125
- ASSERT_STREQ (Func (src, ' b' ), nullptr );
131
+ ASSERT_EQ (Func (src, ' b' ), nullptr );
126
132
// Same goes for 'c'.
127
- ASSERT_STREQ (Func (src, ' c' ), nullptr );
133
+ ASSERT_EQ (Func (src, ' c' ), nullptr );
128
134
129
135
// Should find the second of the two a's.
130
136
ASSERT_STREQ (Func (src, ' a' ), " a" );
131
137
}
132
138
133
139
void characterNotWithinStringShouldReturnNullptr () {
134
140
// Since 'z' is not within the string, should return nullptr.
135
- ASSERT_STREQ (Func (" 123?" , ' z' ), nullptr );
141
+ ASSERT_EQ (Func (" 123?" , ' z' ), nullptr );
136
142
}
137
143
138
144
void shouldFindLastOfDuplicates () {
@@ -146,11 +152,13 @@ template <auto Func> struct StrrchrTest : public LIBC_NAMESPACE::testing::Test {
146
152
147
153
void emptyStringShouldOnlyMatchNullTerminator () {
148
154
// Null terminator should match.
149
- ASSERT_STREQ (Func (" " , ' \0 ' ), " " );
155
+ const char empty_string[] = " " ;
156
+ ASSERT_EQ (static_cast <const char *>(Func (empty_string, ' \0 ' )),
157
+ empty_string);
150
158
// All other characters should not match.
151
- ASSERT_STREQ (Func (" " , ' A' ), nullptr );
152
- ASSERT_STREQ (Func (" " , ' 2' ), nullptr );
153
- ASSERT_STREQ (Func (" " , ' *' ), nullptr );
159
+ ASSERT_EQ (Func (" " , ' A' ), nullptr );
160
+ ASSERT_EQ (Func (" " , ' 2' ), nullptr );
161
+ ASSERT_EQ (Func (" " , ' *' ), nullptr );
154
162
}
155
163
};
156
164
0 commit comments