// 功能:统计输入字符串长度
// ih: 输入字符串
// 返回字符个数
unsigned int _strlen(const char* s)
{
if (!s) return 0u;
const char *sc = s;
for (; *sc; ++sc);
return unsigned int(sc - s);
}
TEST_CASE("string function test", "好看的白盒测试哟")
{
SECTION("raw string length measure") {
const char* string1 = nullptr;
const char* string2 = "";
const char* string3 = "1";
const char* string4 = "123";
const char* string5 = "123456789abcdef0";
CHECK(_strlen(string1) == 0);
CHECK(_strlen(string2) == 0);
CHECK(_strlen(string3) == 1);
CHECK(_strlen(string4) == 3);
CHECK(_strlen(string5) == 16);
CHECK(_strnlen(string1, 3) == 0);
CHECK(_strnlen(string2, 3) == 0);
CHECK(_strnlen(string3, 3) == 1);
CHECK(_strnlen(string4, 3) == 3);
CHECK(_strnlen(string5, 3) == 3);
}
}