Skip to content

Commit

Permalink
libc: strchr tests: add test group for ASCII compare
Browse files Browse the repository at this point in the history
JIRA: CI-232
  • Loading branch information
maska989 committed May 22, 2023
1 parent 2af9212 commit 707605b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
3 changes: 2 additions & 1 deletion libc/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ void runner(void)
RUN_TEST_GROUP(test_pthread_cond);
RUN_TEST_GROUP(strtod_family);
RUN_TEST_GROUP(stdlib_alloc);
RUN_TEST_GROUP(string_len);
RUN_TEST_GROUP(stdlib_env);
RUN_TEST_GROUP(ctype);
RUN_TEST_GROUP(stdio_scanf_d);
Expand All @@ -54,6 +53,8 @@ void runner(void)
RUN_TEST_GROUP(stdio_scanf_squareBrackets);
RUN_TEST_GROUP(stdio_scanf_rest);
RUN_TEST_GROUP(string_chr);
RUN_TEST_GROUP(string_len);
RUN_TEST_GROUP(string_spn);
}


Expand Down
37 changes: 36 additions & 1 deletion libc/string_lenchr.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@
#include <limits.h>
#include <unity_fixture.h>

#define BUFF_SIZE 128


TEST_GROUP(string_len);
TEST_GROUP(string_chr);
TEST_GROUP(string_spn);


TEST_SETUP(string_len)
Expand All @@ -53,7 +56,7 @@ TEST(string_len, ascii)
doubleNul[] = "\0\0abc",
specials[] = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~",
whites[] = " \v\t\r\n";
char asciiSet[128] = { 0 };
char asciiSet[BUFF_SIZE] = { 0 };
int sz, i;

TEST_ASSERT_EQUAL_INT(0, strlen(""));
Expand Down Expand Up @@ -154,6 +157,33 @@ TEST(string_len, big)
}


TEST_SETUP(string_spn)
{
}


TEST_TEAR_DOWN(string_spn)
{
}

TEST(string_spn, ascii)
{
char asciiSet[BUFF_SIZE] = { 0 };
char supportAsciiSet[BUFF_SIZE] = { 0 };
int i;

for (i = 1; i < BUFF_SIZE; i++) {
asciiSet[i - 1] = i;
}

for (i = 1; i < BUFF_SIZE; i++) {
supportAsciiSet[i - 1] = i;
TEST_ASSERT_EQUAL_INT(i, strcspn(asciiSet, &asciiSet[i]));
TEST_ASSERT_EQUAL_INT(i, strspn(asciiSet, supportAsciiSet));
}
}


/*
////////////////////////////////////////////////////////////////////////////////////
*/
Expand Down Expand Up @@ -408,6 +438,11 @@ TEST_GROUP_RUNNER(string_len)
RUN_TEST_CASE(string_len, big);
}

TEST_GROUP_RUNNER(string_spn)
{
RUN_TEST_CASE(string_spn, ascii);
}


TEST_GROUP_RUNNER(string_chr)
{
Expand Down

0 comments on commit 707605b

Please sign in to comment.