strtok_r()/wcstok() tests: check the state pointer too.
This is a little bit odd since no specification says that the reason why "subsequent searches return null" is because the state pointer is null ... but that's the only existing (and only reasonable?) implementation, and _not_ checking that risks tests passing "by accident" because there happens to be another '\0' or L'\0' after the initial one.
An alternative would be to have a _loop_ checking that you can call the function a large number of times and keep getting null, so "why not both?".
Also use EXPECT_EQ() rather than EXPECT_STREQ() when we're expecting a null pointer.
Change-Id: I7f12eac78d2adda978abff6f88e1f62db59763d3
diff --git a/tests/string_test.cpp b/tests/string_test.cpp
index 9b88ae4..50f75b6 100644
--- a/tests/string_test.cpp
+++ b/tests/string_test.cpp
@@ -1751,9 +1751,11 @@
EXPECT_STREQ("hello", strtok(str, ":"));
EXPECT_STREQ("world", strtok(nullptr, ":"));
EXPECT_STREQ("foo", strtok(nullptr, ":"));
- EXPECT_STREQ(nullptr, strtok(nullptr, ":"));
+ EXPECT_EQ(nullptr, strtok(nullptr, ":"));
// Repeated calls after the first nullptr keep returning nullptr.
- EXPECT_STREQ(nullptr, strtok(nullptr, ":"));
+ for (size_t i = 0; i < 1024; ++i) {
+ EXPECT_EQ(nullptr, strtok(nullptr, ":"));
+ }
}
TEST(STRING_TEST, strtok_r) {
@@ -1770,7 +1772,10 @@
EXPECT_STREQ("hello", strtok_r(str, ":", &p));
EXPECT_STREQ("world", strtok_r(nullptr, ":", &p));
EXPECT_STREQ("foo", strtok_r(nullptr, ":", &p));
- EXPECT_STREQ(nullptr, strtok_r(nullptr, ":", &p));
+ EXPECT_EQ(nullptr, strtok_r(nullptr, ":", &p));
// Repeated calls after the first nullptr keep returning nullptr.
- EXPECT_STREQ(nullptr, strtok_r(nullptr, ":", &p));
+ for (size_t i = 0; i < 1024; ++i) {
+ EXPECT_EQ(nullptr, p);
+ EXPECT_EQ(nullptr, strtok_r(nullptr, ":", &p));
+ }
}