From d06ac5688c5494fb3392c8d07489e568bc6418db Mon Sep 17 00:00:00 2001 From: wujianlin Date: Wed, 27 Aug 2025 19:48:41 +0800 Subject: [PATCH] Supplement the libc_test test case Issue:https://gitee.com/openharmony/third_party_musl/issues/ICV4BE?from=project-issue Signed-off-by: wujianlin --- .../functionalext/supplement/ctype/isalpha.c | 43 ++++++++++ .../functionalext/supplement/ctype/isascii.c | 14 ++++ .../functionalext/supplement/ctype/tolower.c | 79 +++++++++++++++++++ .../functionalext/supplement/ctype/toupper.c | 79 +++++++++++++++++++ 4 files changed, 215 insertions(+) diff --git a/libc-test/src/functionalext/supplement/ctype/isalpha.c b/libc-test/src/functionalext/supplement/ctype/isalpha.c index 5f17e99f1..74043fecf 100644 --- a/libc-test/src/functionalext/supplement/ctype/isalpha.c +++ b/libc-test/src/functionalext/supplement/ctype/isalpha.c @@ -79,6 +79,47 @@ void isalpha_0500(void) EXPECT_EQ("isalpha_0500", total, 52); } +/** + * @tc.name : isalpha_0600 + * @tc.desc : Verify all the letters in the ASCII code table + * @tc.level : Level 1 + */ +void isalpha_0600(void) +{ + for (int i = 65; i < 91; i++) { + int ret = isalpha((char)i); + EXPECT_NE("isalpha_0600", ret, COUNT_ZERO); + } + + for (int i = 97; i < 123; i++) { + int ret = isalpha((char)i); + EXPECT_NE("isalpha_0600", ret, COUNT_ZERO); + } +} + +/** + * @tc.name : isalpha_0700 + * @tc.desc : Verify all non-alphabetic characters in the ASCII code table + * @tc.level : Level 1 + */ +void isalpha_0700(void) +{ + for (int i = 0; i < 65; i++) { + int ret = isalpha((char)i); + EXPECT_EQ("isalpha_0700", ret, COUNT_ZERO); + } + + for (int i = 91; i < 97; i++) { + int ret = isalpha((char)i); + EXPECT_EQ("isalpha_0700", ret, COUNT_ZERO); + } + + for (int i = 123; i < 128; i++) { + int ret = isalpha((char)i); + EXPECT_EQ("isalpha_0700", ret, COUNT_ZERO); + } +} + int main(void) { isalpha_0100(); @@ -86,5 +127,7 @@ int main(void) isalpha_0300(); isalpha_0400(); isalpha_0500(); + isalpha_0600(); + isalpha_0700(); return t_status; } \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/ctype/isascii.c b/libc-test/src/functionalext/supplement/ctype/isascii.c index d918ac008..5ae8c4571 100755 --- a/libc-test/src/functionalext/supplement/ctype/isascii.c +++ b/libc-test/src/functionalext/supplement/ctype/isascii.c @@ -37,8 +37,22 @@ void isascii_0100(void) } } +/** + * @tc.name : isascii_0200 + * @tc.desc : Test all ASCII code characters + * @tc.level : Level 1 + */ +void isascii_0200(void) +{ + for (int i = 0; i < 128; i++) { + int ret = isascii((char)i); + EXPECT_EQ("isascii_0200", ret, ONREXPECT); + } +} + int main(void) { isascii_0100(); + isascii_0200(); return t_status; } \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/ctype/tolower.c b/libc-test/src/functionalext/supplement/ctype/tolower.c index ee77d943c..2594eb80e 100644 --- a/libc-test/src/functionalext/supplement/ctype/tolower.c +++ b/libc-test/src/functionalext/supplement/ctype/tolower.c @@ -14,6 +14,7 @@ */ #include +#include #include #include "test.h" @@ -73,11 +74,89 @@ void tolower_0400(void) } } +/** + * @tc.name : tolower_0500 + * @tc.desc : Test the result of passing whitespace character into tolower + * @tc.level : Level 2 + */ +void tolower_0500(void) +{ + char ch = ' '; + char result = tolower(ch); + if (result != ch) { + t_error("%s tolower get result is %c but want get value %c ", __func__, result, ch); + } +} + +/** + * @tc.name : tolower_0600 + * @tc.desc : Test the result of passing all lowercase characters into tolower + * @tc.level : Level 2 + */ +void tolower_0600(void) +{ + char str1[] = "helloworld"; + size_t sizeStr = sizeof(str1); + char str2[sizeStr]; + for (int i = 0; str1[i]; i++) { + str2[i] = tolower(str1[i]); + } + char wantStr[] = "helloworld"; + int result = strcmp(wantStr, str2); + if (result != 0) { + t_error("%s tolower get str2 is %s but want get value %s ", __func__, str2, wantStr); + } +} + +/** + * @tc.name : tolower_0700 + * @tc.desc : Test the result of passing all uppercase characters into tolower + * @tc.level : Level 2 + */ +void tolower_0700(void) +{ + char str1[] = "HELLOWORLD"; + size_t sizeStr = sizeof(str1); + char str2[sizeStr]; + for (int i = 0; str1[i]; i++) { + str2[i] = tolower(str1[i]); + } + char wantStr[] = "helloworld"; + int result = strcmp(wantStr, str2); + if (result != 0) { + t_error("%s tolower get str2 is %s but want get value %s ", __func__, str2, wantStr); + } +} + +/** + * @tc.name : tolower_0800 + * @tc.desc : Test the result of passing Uncertain characters into tolower + * @tc.level : Level 2 + */ +void tolower_0800(void) +{ + char str1[] = "Hello world!"; + size_t sizeStr = sizeof(str1); + char str2[sizeStr]; + for (int i = 0; str1[i]; i++) { + str2[i] = tolower(str1[i]); + } + char wantStr[] = "hello world!"; + int result = strcmp(wantStr, str2); + if (result != 0) { + t_error("%s tolower get str2 is %s but want get value %s ", __func__, str2, wantStr); + } +} + int main(int argc, char *argv[]) { tolower_0100(); tolower_0200(); tolower_0300(); tolower_0400(); + tolower_0500(); + tolower_0600(); + tolower_0700(); + tolower_0800(); return t_status; } \ No newline at end of file diff --git a/libc-test/src/functionalext/supplement/ctype/toupper.c b/libc-test/src/functionalext/supplement/ctype/toupper.c index 556088078..72638da46 100644 --- a/libc-test/src/functionalext/supplement/ctype/toupper.c +++ b/libc-test/src/functionalext/supplement/ctype/toupper.c @@ -14,6 +14,7 @@ */ #include +#include #include #include "test.h" @@ -73,11 +74,89 @@ void toupper_0400(void) } } +/** + * @tc.name : toupper_0500 + * @tc.desc : Test the result of passing whitespace character into toupper + * @tc.level : Level 2 + */ +void toupper_0500(void) +{ + char ch = ' '; + char result = toupper(ch); + if (result != ch) { + t_error("%s toupper get result is %c but want get value %c ", __func__, result, ch); + } +} + +/** + * @tc.name : toupper_0600 + * @tc.desc : Test the result of passing all lowercase characters into toupper + * @tc.level : Level 2 + */ +void toupper_0600(void) +{ + char str1[] = "helloworld"; + size_t sizeStr = sizeof(str1); + char str2[sizeStr]; + for (int i = 0; str1[i]; i++) { + str2[i] = toupper(str1[i]); + } + char wantStr[] = "HELLOWORLD"; + int result = strcmp(wantStr, str2); + if (result != 0) { + t_error("%s toupper get str2 is %s but want get value %s ", __func__, str2, wantStr); + } +} + +/** + * @tc.name : toupper_0700 + * @tc.desc : Test the result of passing all uppercase characters into toupper + * @tc.level : Level 2 + */ +void toupper_0700(void) +{ + char str1[] = "HELLOWORLD"; + size_t sizeStr = sizeof(str1); + char str2[sizeStr]; + for (int i = 0; str1[i]; i++) { + str2[i] = toupper(str1[i]); + } + char wantStr[] = "HELLOWORLD"; + int result = strcmp(wantStr, str2); + if (result != 0) { + t_error("%s toupper get str2 is %s but want get value %s ", __func__, str2, wantStr); + } +} + +/** + * @tc.name : toupper_0800 + * @tc.desc : Test the result of passing Uncertain characters into toupper + * @tc.level : Level 2 + */ +void toupper_0800(void) +{ + char str1[] = "Hello world!"; + size_t sizeStr = sizeof(str1); + char str2[sizeStr]; + for (int i = 0; str1[i]; i++) { + str2[i] = toupper(str1[i]); + } + char wantStr[] = "HELLO WORLD!"; + int result = strcmp(wantStr, str2); + if (result != 0) { + t_error("%s toupper get str2 is %s but want get value %s ", __func__, str2, wantStr); + } +} + int main(int argc, char *argv[]) { toupper_0100(); toupper_0200(); toupper_0300(); toupper_0400(); + toupper_0500(); + toupper_0600(); + toupper_0700(); + toupper_0800(); return t_status; } \ No newline at end of file -- Gitee