2022-10-16 13:31:58 +00:00
|
|
|
#include "Test.h"
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
DEFINE_TEST(strlen)
|
|
|
|
{
|
|
|
|
START_TEST(strlen);
|
|
|
|
|
|
|
|
const char* str = "Hello, World!";
|
|
|
|
|
|
|
|
size_t len = strlen(str);
|
|
|
|
|
|
|
|
EXPECT_EQ(len, 13);
|
|
|
|
|
|
|
|
char null[] = {'\0'};
|
|
|
|
|
|
|
|
len = strlen(null);
|
|
|
|
|
|
|
|
EXPECT_EQ(len, 0);
|
|
|
|
|
2022-10-16 14:00:14 +00:00
|
|
|
TEST_SUCCESS();
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFINE_TEST(strnlen)
|
|
|
|
{
|
|
|
|
START_TEST(strnlen);
|
|
|
|
|
|
|
|
const char* str = "What is going on?";
|
|
|
|
|
|
|
|
size_t len = strnlen(str, 20);
|
|
|
|
|
|
|
|
EXPECT_EQ(len, 17);
|
|
|
|
|
|
|
|
len = strnlen(str, 15);
|
|
|
|
|
|
|
|
EXPECT_EQ(len, 15);
|
|
|
|
|
|
|
|
char buf[] = {'H', 'e', 'l', 'l', 'o'};
|
|
|
|
|
|
|
|
len = strnlen(buf, sizeof(buf));
|
|
|
|
|
|
|
|
EXPECT_EQ(len, sizeof(buf));
|
|
|
|
|
2022-10-22 09:57:25 +00:00
|
|
|
TEST_SUCCESS();
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFINE_TEST(strcspn)
|
|
|
|
{
|
|
|
|
START_TEST(strcspn);
|
|
|
|
|
|
|
|
const char* str = "This string has vowels";
|
|
|
|
const char* vowels = "aeiou";
|
|
|
|
|
|
|
|
size_t len = strcspn(str, vowels);
|
|
|
|
|
|
|
|
EXPECT_EQ(len, 2);
|
|
|
|
|
|
|
|
str = "WWWWW";
|
|
|
|
len = strcspn(str, vowels);
|
|
|
|
|
|
|
|
EXPECT_EQ(len, 5);
|
|
|
|
|
2022-10-22 10:36:31 +00:00
|
|
|
TEST_SUCCESS();
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFINE_TEST(strspn)
|
|
|
|
{
|
|
|
|
START_TEST(strspn);
|
|
|
|
|
|
|
|
const char* str = "This is a test string";
|
|
|
|
const char* accept = "This ";
|
|
|
|
|
|
|
|
size_t len = strspn(str, accept);
|
|
|
|
|
|
|
|
EXPECT_EQ(len, 8);
|
|
|
|
|
|
|
|
str = "WWWWW";
|
|
|
|
len = strspn(str, accept);
|
|
|
|
|
|
|
|
EXPECT_EQ(len, 0);
|
|
|
|
|
|
|
|
str = "This is hi";
|
|
|
|
len = strspn(str, accept);
|
|
|
|
|
|
|
|
EXPECT_EQ(len, 10);
|
|
|
|
|
2022-10-16 13:31:58 +00:00
|
|
|
TEST_SUCCESS();
|
|
|
|
}
|