Tests: Add tests for strcmp() and strncmp()

This commit is contained in:
apio 2022-11-06 19:51:56 +01:00
parent 5d94525c7a
commit 2e9348181d
2 changed files with 52 additions and 0 deletions

View File

@ -8,6 +8,8 @@ DEFINE_TEST(memcmp);
DEFINE_TEST(memmove);
DEFINE_TEST(strlen);
DEFINE_TEST(strnlen);
DEFINE_TEST(strcmp);
DEFINE_TEST(strncmp);
DEFINE_TEST(strcspn);
DEFINE_TEST(strspn);
DEFINE_TEST(strchr);
@ -38,6 +40,8 @@ int main()
RUN_TEST(memmove);
RUN_TEST(strlen);
RUN_TEST(strnlen);
RUN_TEST(strcmp);
RUN_TEST(strncmp);
RUN_TEST(strcspn);
RUN_TEST(strspn);
RUN_TEST(strchr);

View File

@ -166,6 +166,54 @@ DEFINE_TEST(strnlen)
TEST_SUCCESS();
}
DEFINE_TEST(strcmp)
{
START_TEST(strcmp);
const char* str1 = "Hello, World!";
const char* str2 = "Hello, Planet!";
int rc = strcmp(str1, str1);
EXPECT_EQ(rc, 0);
rc = strcmp(str1, str2);
EXPECT(rc > 0);
rc = strcmp(str2, str1);
EXPECT(rc < 0);
TEST_SUCCESS();
}
DEFINE_TEST(strncmp)
{
START_TEST(strncmp);
const char* str1 = "Hello, World!";
const char* str2 = "Hello, Planet!";
int rc = strncmp(str1, str1, 14);
EXPECT_EQ(rc, 0);
rc = strncmp(str1, str2, 14);
EXPECT(rc > 0);
rc = strncmp(str2, str1, 14);
EXPECT(rc < 0);
rc = strncmp(str1, str2, 6);
EXPECT_EQ(rc, 0);
TEST_SUCCESS();
}
DEFINE_TEST(strcspn)
{
START_TEST(strcspn);