Tests: add tests for strchr() and strrchr()

This commit is contained in:
apio 2022-10-22 17:58:54 +02:00
parent 503a04f0e9
commit c3828dd357
2 changed files with 46 additions and 0 deletions

View File

@ -4,6 +4,8 @@ DEFINE_TEST(strlen);
DEFINE_TEST(strnlen); DEFINE_TEST(strnlen);
DEFINE_TEST(strcspn); DEFINE_TEST(strcspn);
DEFINE_TEST(strspn); DEFINE_TEST(strspn);
DEFINE_TEST(strchr);
DEFINE_TEST(strrchr);
DEFINE_TEST(atoi); DEFINE_TEST(atoi);
DEFINE_TEST(atol); DEFINE_TEST(atol);
@ -17,6 +19,8 @@ int main()
RUN_TEST(strnlen); RUN_TEST(strnlen);
RUN_TEST(strcspn); RUN_TEST(strcspn);
RUN_TEST(strspn); RUN_TEST(strspn);
RUN_TEST(strchr);
RUN_TEST(strrchr);
START_TEST_CASE(stdlib.h); START_TEST_CASE(stdlib.h);
RUN_TEST(atoi); RUN_TEST(atoi);

View File

@ -83,5 +83,47 @@ DEFINE_TEST(strspn)
EXPECT_EQ(len, 10); EXPECT_EQ(len, 10);
TEST_SUCCESS();
}
DEFINE_TEST(strchr)
{
START_TEST(strchr);
const char* str = "Hello, world!";
char* ptr = strchr(str, 'l');
EXPECT_EQ(ptr, str + 2);
ptr = strchr(str, 'u');
EXPECT_EQ(ptr, NULL);
ptr = strchr(str, '!');
EXPECT_EQ(ptr, str + 12);
TEST_SUCCESS();
}
DEFINE_TEST(strrchr)
{
START_TEST(strrchr);
const char* str = "Hello, world!";
char* ptr = strrchr(str, 'l');
EXPECT_EQ(ptr, str + 10);
ptr = strrchr(str, 'u');
EXPECT_EQ(ptr, NULL);
ptr = strrchr(str, '!');
EXPECT_EQ(ptr, str + 12);
TEST_SUCCESS(); TEST_SUCCESS();
} }