add testsuites

Change-Id: Ice1193d1ae7f2e0d12a2a38a306a6399407f5037
This commit is contained in:
lnlan
2021-04-25 12:37:35 +08:00
parent dc90400456
commit 778c5e17c3
2720 changed files with 335022 additions and 0 deletions
@@ -0,0 +1,63 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "It_test_IO.h"
static UINT32 Testcase(VOID)
{
INT32 i = 0;
wchar_t str[] = L"ABCDEFG";
wchar_t str2[] = L"abcdefg";
wchar_t c[20];
wctype_t check = wctype("upper");
wctrans_t trans = wctrans("tolower");
while (str[i]) {
c[i] = str[i];
if (iswctype(c[i], check)) {
c[i] = towctrans(c[i], trans);
}
if (c[i] != str2[i]) {
goto EXIT;
}
i++;
}
return 0;
EXIT:
return -1;
}
VOID ItTestIo005(void)
{
TEST_ADD_CASE(__FUNCTION__, Testcase, TEST_LIB, TEST_LIBC, TEST_LEVEL1, TEST_FUNCTION);
}
@@ -0,0 +1,85 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "It_test_IO.h"
static INT32 Vdpfunc(int fd, char *format, ...)
{
va_list aptr;
INT32 ret;
va_start(aptr, format);
ret = vdprintf(fd, format, aptr);
va_end(aptr);
return ret;
}
static UINT32 Testcase(VOID)
{
CHAR file[30] = "/jffs0/vdprintf";
CHAR *str1 = "123456789";
CHAR buffer[20];
INT32 ret, fd;
CHAR str[20] = "789";
const int testBufLen = 20;
fd = open(file, O_CREAT | O_RDWR | O_TRUNC);
ICUNIT_GOTO_NOT_EQUAL(fd, -1, fd, EXIT);
ret = Vdpfunc(fd, "%s%s", "123456", str);
if (ret < 0) {
goto EXIT1;
}
ret = close(fd);
fd = open(file, O_RDWR);
ICUNIT_GOTO_NOT_EQUAL(fd, -1, fd, EXIT1);
read(fd, buffer, testBufLen);
close(fd);
ICUNIT_GOTO_STRING_EQUAL(buffer, str1, buffer, EXIT2);
unlink(file);
return (0);
EXIT1:
close(fd);
EXIT2:
unlink(file);
EXIT:
return -1;
}
VOID ItTestIo008(void)
{
TEST_ADD_CASE(__FUNCTION__, Testcase, TEST_LIB, TEST_LIBC, TEST_LEVEL1, TEST_FUNCTION);
}
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "It_test_IO.h"
static VOID GetWideMatches(const wchar_t *str, const wchar_t *format, ...)
{
va_list args;
va_start(args, format);
vswscanf(str, format, args);
va_end(args);
}
static UINT32 Testcase(VOID)
{
INT32 val, ret;
wchar_t buf[100]; // 100, buffer size
wchar_t *str = L"bottles";
GetWideMatches(L"99 bottles of beer on the wall", L" %d %ls ", &val, buf);
ret = wcscmp(buf, str);
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
return 0;
EXIT:
return -1;
}
VOID ItTestIo010(void)
{
TEST_ADD_CASE(__FUNCTION__, Testcase, TEST_LIB, TEST_LIBC, TEST_LEVEL1, TEST_FUNCTION);
}
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "It_test_IO.h"
static UINT32 Testcase(VOID)
{
INT32 val, ret, result;
wchar_t buf[200];
wchar_t *str = L"helloworld";
swscanf(str, L"%ls", buf);
ret = wcscmp(buf, str);
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
return 0;
EXIT:
return -1;
}
VOID ItTestIo013(void)
{
TEST_ADD_CASE(__FUNCTION__, Testcase, TEST_LIB, TEST_LIBC, TEST_LEVEL1, TEST_FUNCTION);
}
@@ -0,0 +1,83 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "It_test_IO.h"
static UINT32 testcase(VOID)
{
char *pathbuf = nullptr;
char *gun_libpthread_version_buf = nullptr;
char *gun_libc_version_buf = nullptr;
size_t n = 0;
n = confstr(_CS_PATH, NULL, (size_t) 0);
ICUNIT_ASSERT_WITHIN_EQUAL(n, 0, UINT_MAX, n);
pathbuf = (char *)malloc(n);
if (pathbuf == NULL) {
return LOS_NOK;
}
confstr(_CS_PATH, pathbuf, n);
ICUNIT_ASSERT_NOT_EQUAL_NULL(pathbuf, NULL, -1);
free(pathbuf);
pathbuf = NULL;
n = confstr(_CS_GNU_LIBPTHREAD_VERSION, NULL, (size_t) 0);
ICUNIT_ASSERT_WITHIN_EQUAL(n, 0, UINT_MAX, n);
if (n > 0) {
gun_libpthread_version_buf = (char *)malloc(n);
}
if (gun_libpthread_version_buf == NULL) {
return LOS_NOK;
}
confstr(_CS_GNU_LIBPTHREAD_VERSION, gun_libpthread_version_buf, n);
ICUNIT_ASSERT_NOT_EQUAL_NULL(gun_libpthread_version_buf, NULL, -1);
free(gun_libpthread_version_buf);
gun_libpthread_version_buf = NULL;
n = confstr(_CS_GNU_LIBC_VERSION, NULL, (size_t) 0);
ICUNIT_ASSERT_WITHIN_EQUAL(n, 0, UINT_MAX, n);
if (n > 0) {
gun_libc_version_buf = (char *)malloc(n);
}
if (gun_libc_version_buf == NULL) {
return LOS_NOK;
}
confstr(_CS_GNU_LIBC_VERSION, gun_libc_version_buf, n);
ICUNIT_ASSERT_NOT_EQUAL_NULL(gun_libc_version_buf, NULL, -1);
free(gun_libc_version_buf);
gun_libc_version_buf = NULL;
return LOS_OK;
}
VOID IO_TEST_CONFSTR_001(void)
{
TEST_ADD_CASE(__FUNCTION__, testcase, TEST_LIB, TEST_LIBC, TEST_LEVEL1, TEST_FUNCTION);
}
@@ -0,0 +1,56 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "It_test_IO.h"
#include <libintl.h>
#include <locale.h>
static UINT32 testcase(VOID)
{
char *s = "";
setlocale(LC_ALL, "");
textdomain("gettext_demo");
bindtextdomain("gettext_demo", ".");
bind_textdomain_codeset("gettext_demo", "UTF-8");
printf(dcgettext("www.huawei.com", "TestString1\n", LC_MESSAGES));
s = dcgettext("www.huawei.com", "TestString1\n", LC_MESSAGES);
printf("[INFO]%s:%d,%s,s=%s\n", __FILE__, __LINE__, __func__, s);
ICUNIT_ASSERT_STRING_EQUAL(s, "TestString1\n", s);
return LOS_OK;
}
VOID IO_TEST_DCGETTEXT_001(VOID)
{
TEST_ADD_CASE(__FUNCTION__, testcase, TEST_LIB, TEST_LIBC, TEST_LEVEL1, TEST_FUNCTION);
}
@@ -0,0 +1,137 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "It_test_IO.h"
#include <libintl.h>
#include <locale.h>
static UINT32 testcase1(VOID)
{
char *s = "";
setlocale(LC_ALL, "");
textdomain("gettext_demo");
bindtextdomain("gettext_demo", ".");
bind_textdomain_codeset("gettext_demo", "UTF-8");
errno = 0;
s = dcgettext("www.huawei.com", "TestString1\n", LC_MESSAGES);
TEST_PRINT("[INFO]%s:%d,%s,s=%s\n", __FILE__, __LINE__, __func__, s);
TEST_PRINT("[INFO]%s:%d,%s,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, errno, strerror(errno));
ICUNIT_GOTO_STRING_EQUAL(s, "TestString1\n", -1, OUT);
return LOS_OK;
OUT:
return LOS_NOK;
}
static UINT32 testcase2(VOID)
{
char *s = "";
setlocale(LC_ALL, "");
textdomain("gettext_demo");
bindtextdomain("gettext_demo", ".");
bind_textdomain_codeset("gettext_demo", "UTF-8");
errno = 0;
s = dcgettext(nullptr, "Hello World!\n", LC_MESSAGES);
TEST_PRINT("[INFO]%s:%d,%s,s=%s\n", __FILE__, __LINE__, __func__, s);
TEST_PRINT("[INFO]%s:%d,%s,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, errno, strerror(errno));
ICUNIT_GOTO_STRING_EQUAL(s, "Hello World!\n", -1, OUT);
return LOS_OK;
OUT:
return LOS_NOK;
}
static UINT32 testcase3(VOID)
{
char *s = "";
char *domain = "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890\
1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890\
12345678901234567890123456789012345678901234567890123456";
char *string = "Domain is NAME_MAX+1 256 characters long!\n";
setlocale(LC_ALL, "");
textdomain("gettext_demo");
bindtextdomain("gettext_demo", ".");
bind_textdomain_codeset("gettext_demo", "UTF-8");
errno = 0;
s = dcgettext(domain, string, LC_MESSAGES);
TEST_PRINT("[INFO]%s:%d,%s,s=%s\n", __FILE__, __LINE__, __func__, s);
TEST_PRINT("[INFO]%s:%d,%s,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, errno, strerror(errno));
ICUNIT_GOTO_STRING_EQUAL(s, string, -1, OUT);
return LOS_OK;
OUT:
return LOS_NOK;
}
static UINT32 testcase4(VOID)
{
char *s = "";
char *domain = "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890\
1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890\
123456789012345678901234567890123456789012345678901234567";
char *string = "Domain is more than NAME_MAX+1(256) 257 characters long!\n";
setlocale(LC_ALL, "");
textdomain("gettext_demo");
bindtextdomain("gettext_demo", ".");
bind_textdomain_codeset("gettext_demo", "UTF-8");
errno = 0;
s = dcgettext(domain, string, LC_MESSAGES);
TEST_PRINT("[INFO]%s:%d,%s,s=%s\n", __FILE__, __LINE__, __func__, s);
TEST_PRINT("[INFO]%s:%d,%s,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, errno, strerror(errno));
ICUNIT_GOTO_STRING_EQUAL(s, string, -1, OUT);
return LOS_OK;
OUT:
return LOS_NOK;
}
static UINT32 testcase(VOID)
{
errno = 0;
testcase1();
testcase2();
testcase3();
testcase4();
return LOS_OK;
}
VOID IO_TEST_DCGETTEXT_002(VOID)
{
TEST_ADD_CASE(__FUNCTION__, testcase, TEST_LIB, TEST_LIBC, TEST_LEVEL1, TEST_FUNCTION);
}
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "It_test_IO.h"
#include <libintl.h>
#include <locale.h>
static UINT32 testcase(VOID)
{
char *s = "";
setlocale(LC_ALL, "");
textdomain("gettext_demo");
bindtextdomain("gettext_demo", ".");
bind_textdomain_codeset("gettext_demo", "UTF-8");
printf(dcngettext("www.huawei.com", "TestString1\n", "TestString2\n", 1, LC_MESSAGES));
printf(dcngettext("www.huawei.com", "TestString1\n", "TestString2\n", 2, LC_MESSAGES));
s = dcngettext("www.huawei.com", "TestString1\n", "TestString2\n", 1, LC_MESSAGES);
printf("[INFO]%s:%d,%s,s=%s\n", __FILE__, __LINE__, __func__, s);
ICUNIT_ASSERT_STRING_EQUAL(s, "TestString1\n", s);
s = dcngettext("www.huawei.com", "TestString1\n", "TestString2\n", 2, LC_MESSAGES);
printf("[INFO]%s:%d,%s,s=%s\n", __FILE__, __LINE__, __func__, s);
ICUNIT_ASSERT_STRING_EQUAL(s, "TestString2\n", s);
return LOS_OK;
}
VOID IO_TEST_DCNGETTEXT_001(VOID)
{
TEST_ADD_CASE(__FUNCTION__, testcase, TEST_LIB, TEST_LIBC, TEST_LEVEL1, TEST_FUNCTION);
}
@@ -0,0 +1,102 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "It_test_IO.h"
#include <libintl.h>
#include <locale.h>
static UINT32 testcase1(VOID)
{
char *s = "";
setlocale(LC_ALL, "zh_CN.UTF-8");
textdomain("gettext_demo");
bindtextdomain("gettext_demo", ".");
bind_textdomain_codeset("gettext_demo", "UTF-8");
errno = 0;
s = dcngettext("", "TestString1:Hello world!\n", "TestString2\n", 1, LC_MESSAGES);
TEST_PRINT("[INFO]%s:%d,%s,s=%s\n", __FILE__, __LINE__, __func__, s);
TEST_PRINT("[INFO]%s:%d,%s,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, errno, strerror(errno));
ICUNIT_ASSERT_STRING_EQUAL(s, "TestString1:Hello world!\n", s);
ICUNIT_GOTO_EQUAL(errno, 0, errno, OUT);
errno = 0;
s = dcngettext("", "TestString1\n", "TestString2:Hello world!\n", 2, LC_MESSAGES);
TEST_PRINT("[INFO]%s:%d,%s,s=%s\n", __FILE__, __LINE__, __func__, s);
TEST_PRINT("[INFO]%s:%d,%s,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, errno, strerror(errno));
ICUNIT_ASSERT_STRING_EQUAL(s, "TestString2:Hello world!\n", s);
ICUNIT_GOTO_EQUAL(errno, 0, errno, OUT);
return LOS_OK;
OUT:
return LOS_NOK;
}
static UINT32 testcase2(VOID)
{
char *s = "";
setlocale(LC_ALL, "zh_CN.UTF-8");
textdomain("gettext_demo");
bindtextdomain("gettext_demo", ".");
bind_textdomain_codeset("gettext_demo", "UTF-8");
errno = 0;
s = dcngettext("en_US.UTF-8", "TestString1:Hello world!\n", "TestString2:Hello world!\n", 1, LC_MESSAGES);
TEST_PRINT("[INFO]%s:%d,%s,s=%s\n", __FILE__, __LINE__, __func__, s);
TEST_PRINT("[INFO]%s:%d,%s,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, errno, strerror(errno));
ICUNIT_ASSERT_STRING_EQUAL(s, "TestString1:Hello world!\n", s);
ICUNIT_GOTO_EQUAL(errno, 0, errno, OUT);
errno = 0;
s = dcngettext("en_US.UTF-8", "TestString1\n", "TestString2:Hello world!\n", 2, LC_MESSAGES);
TEST_PRINT("[INFO]%s:%d,%s,s=%s\n", __FILE__, __LINE__, __func__, s);
TEST_PRINT("[INFO]%s:%d,%s,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, errno, strerror(errno));
ICUNIT_ASSERT_STRING_EQUAL(s, "TestString2:Hello world!\n", s);
ICUNIT_GOTO_EQUAL(errno, 0, errno, OUT);
return LOS_OK;
OUT:
return LOS_NOK;
}
static UINT32 testcase(VOID)
{
testcase1();
testcase2();
return LOS_OK;
}
VOID IO_TEST_DCNGETTEXT_002(VOID)
{
TEST_ADD_CASE(__FUNCTION__, testcase, TEST_LIB, TEST_LIBC, TEST_LEVEL1, TEST_FUNCTION);
}
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "It_test_IO.h"
#include <libintl.h>
#include <locale.h>
static UINT32 testcase(VOID)
{
char *s = "";
setlocale(LC_ALL, "");
textdomain("gettext_demo");
bindtextdomain("gettext_demo", ".");
bind_textdomain_codeset("gettext_demo", "UTF-8");
printf(dngettext("www.huawei.com", "TestString1\n", "TestString2\n", 1));
printf(dngettext("www.huawei.com", "TestString1\n", "TestString2\n", 2));
s = dngettext("www.huawei.com", "TestString1\n", "TestString2\n", 1);
printf("[INFO]%s:%d,%s,s=%s\n", __FILE__, __LINE__, __func__, s);
ICUNIT_ASSERT_STRING_EQUAL(s, "TestString1\n", s);
s = dngettext("www.huawei.com", "TestString1\n", "TestString2\n", 2);
printf("[INFO]%s:%d,%s,s=%s\n", __FILE__, __LINE__, __func__, s);
ICUNIT_ASSERT_STRING_EQUAL(s, "TestString2\n", s);
return LOS_OK;
}
VOID IO_TEST_DNGETTEXT_001(VOID)
{
TEST_ADD_CASE(__FUNCTION__, testcase, TEST_LIB, TEST_LIBC, TEST_LEVEL1, TEST_FUNCTION);
}
@@ -0,0 +1,131 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "It_test_IO.h"
#include <libintl.h>
#include <locale.h>
static UINT32 testcase1(VOID)
{
char *s = "";
setlocale(LC_ALL, "zh_CN.UTF-8");
textdomain("gettext_demo");
bindtextdomain("gettext_demo", ".");
bind_textdomain_codeset("gettext_demo", "UTF-8");
errno = 0;
s = dngettext("", "TestString1:Hello world!\n", "TestString2\n", 1);
TEST_PRINT("[INFO]%s:%d,%s,s=%s\n", __FILE__, __LINE__, __func__, s);
TEST_PRINT("[INFO]%s:%d,%s,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, errno, strerror(errno));
ICUNIT_ASSERT_STRING_EQUAL(s, "TestString1:Hello world!\n", s);
ICUNIT_GOTO_EQUAL(errno, 0, errno, OUT);
errno = 0;
s = dngettext("", "TestString1\n", "TestString2:Hello world!\n", 2);
TEST_PRINT("[INFO]%s:%d,%s,s=%s\n", __FILE__, __LINE__, __func__, s);
TEST_PRINT("[INFO]%s:%d,%s,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, errno, strerror(errno));
ICUNIT_ASSERT_STRING_EQUAL(s, "TestString2:Hello world!\n", s);
ICUNIT_GOTO_EQUAL(errno, 0, errno, OUT);
return LOS_OK;
OUT:
return LOS_NOK;
}
static UINT32 testcase2(VOID)
{
char *s = "";
setlocale(LC_ALL, "zh_CN.UTF-8");
textdomain("gettext_demo");
bindtextdomain("gettext_demo", ".");
bind_textdomain_codeset("gettext_demo", "UTF-8");
errno = 0;
s = dngettext("en_US.UTF-8", "TestString1:Hello world!\n", "TestString2\n", 1);
TEST_PRINT("[INFO]%s:%d,%s,s=%s\n", __FILE__, __LINE__, __func__, s);
TEST_PRINT("[INFO]%s:%d,%s,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, errno, strerror(errno));
ICUNIT_ASSERT_STRING_EQUAL(s, "TestString1:Hello world!\n", s);
ICUNIT_GOTO_EQUAL(errno, 0, errno, OUT);
errno = 0;
s = dngettext("en_US.UTF-8", "TestString1\n", "TestString2:Hello world!\n", 2);
TEST_PRINT("[INFO]%s:%d,%s,s=%s\n", __FILE__, __LINE__, __func__, s);
TEST_PRINT("[INFO]%s:%d,%s,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, errno, strerror(errno));
ICUNIT_ASSERT_STRING_EQUAL(s, "TestString2:Hello world!\n", s);
ICUNIT_GOTO_EQUAL(errno, 0, errno, OUT);
return LOS_OK;
OUT:
return LOS_NOK;
}
static UINT32 testcase3(VOID)
{
char *s = "";
setlocale(LC_ALL, "zh_CN.UTF-8");
textdomain("gettext_demo");
bindtextdomain("gettext_demo", ".");
bind_textdomain_codeset("gettext_demo", "UTF-8");
errno = 0;
s = dngettext("en_US.UTF-8", "TestString1:Hello world!\n", "TestString2!\n", 5);
TEST_PRINT("[INFO]%s:%d,%s,s=%s\n", __FILE__, __LINE__, __func__, s);
TEST_PRINT("[INFO]%s:%d,%s,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, errno, strerror(errno));
ICUNIT_GOTO_STRING_EQUAL(s, "TestString2!\n", -1, OUT);
ICUNIT_GOTO_EQUAL(errno, 0, errno, OUT);
errno = 0;
s = dngettext("en_US.UTF-8", "TestString1\n", "TestString2:Hello world!\n", 3);
TEST_PRINT("[INFO]%s:%d,%s,s=%s\n", __FILE__, __LINE__, __func__, s);
TEST_PRINT("[INFO]%s:%d,%s,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, errno, strerror(errno));
ICUNIT_GOTO_STRING_EQUAL(s, "TestString2:Hello world!\n", -1, OUT);
ICUNIT_GOTO_EQUAL(errno, 0, errno, OUT);
return LOS_OK;
OUT:
return LOS_NOK;
}
static UINT32 testcase(VOID)
{
testcase1(); /* test the domain is NULL */
testcase2(); /* test the domain is different with the setlocale */
testcase3(); /* if n != 1,then dngettext will choose msgid2's string */
return LOS_OK;
}
VOID IO_TEST_DNGETTEXT_002(VOID)
{
TEST_ADD_CASE(__FUNCTION__, testcase, TEST_LIB, TEST_LIBC, TEST_LEVEL1, TEST_FUNCTION);
}
@@ -0,0 +1,93 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "It_test_IO.h"
#include <time.h>
#include <locale.h>
static UINT32 testcase(VOID)
{
time_t currtime;
struct tm *timer = {nullptr};
char buffer[80];
locale_t oldloc = LC_GLOBAL_LOCALE;
locale_t newloc = nullptr;
printf("[INFO]newloc=0x%x,oldloc=0x%x\n", (int)newloc, (int)oldloc);
newloc = duplocale(oldloc);
printf("[INFO]newloc=0x%x,oldloc=0x%x\n", (int)newloc, (int)oldloc);
ICUNIT_ASSERT_NOT_EQUAL_NULL(newloc, nullptr, -1);
time(&currtime);
timer = localtime(&currtime);
/* set timer as 'Thu Jan 1 23:48:56 1970'" */
timer->tm_sec = 32;
timer->tm_min = 3;
timer->tm_hour = 1;
timer->tm_mday = 2;
timer->tm_mon = 0;
timer->tm_year = 70;
timer->tm_wday = 5;
timer->tm_yday = 1;
timer->tm_isdst = 0;
timer->__tm_gmtoff = 0;
timer->__tm_zone = nullptr;
setenv("MUSL_LOCPATH", "/storage", 1);
printf("[INFO]getenv MUSL_LOCPATH=%s\n", getenv("MUSL_LOCPATH"));
ICUNIT_GOTO_STRING_EQUAL(getenv("MUSL_LOCPATH"), "/storage", getenv("MUSL_LOCPATH"), OUT);
printf("[INFO]Locale is: %s\n", setlocale(LC_TIME, "en_US.UTF-8"));
strftime(buffer, 80, "%c", timer);
printf("[INFO]Date is: %s\n", buffer);
ICUNIT_GOTO_STRING_EQUAL(buffer, "星期五 一月 2 01:03:32 1970", -1, OUT);
printf("[INFO]Locale is: %s\n", setlocale(LC_TIME, "zh_CN.UTF-8"));
strftime(buffer, 80, "%c", timer);
printf("[INFO]Date is: %s\n", buffer);
ICUNIT_GOTO_STRING_EQUAL(buffer, "星期五 一月 2 01:03:32 1970", -1, OUT);
printf("[INFO]Locale is: %s\n", setlocale(LC_TIME, ""));
strftime(buffer, 80, "%c", timer);
printf("[INFO]Date is: %s\n", buffer);
ICUNIT_GOTO_STRING_EQUAL(buffer, "Fri Jan 2 01:03:32 1970", -1, OUT);
free(newloc);
return LOS_OK;
OUT:
free(newloc);
return LOS_NOK;
}
VOID IO_TEST_DUPLOCALE_001(void)
{
TEST_ADD_CASE(__FUNCTION__, testcase, TEST_LIB, TEST_LIBC, TEST_LEVEL1, TEST_FUNCTION);
}
@@ -0,0 +1,75 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "It_test_IO.h"
#include <libintl.h>
#include <locale.h>
static UINT32 testcase1(VOID)
{
char *s = nullptr;
char *tmp = nullptr;
/* set the locale. */
setlocale(LC_ALL, "zh_CN.UTF-8");
setenv("MUSL_LOCPATH", "/storage", 1);
TEST_PRINT("[INFO]%s:%d,%s,getenv MUSL_LOCPATH=%s\n", __FILE__, __LINE__, __func__, getenv("MUSL_LOCPATH"));
tmp = setlocale(LC_TIME, "zh_CN.UTF-8");
TEST_PRINT("[INFO]%s:%d,%s,Locale is: %s\n", __FILE__, __LINE__, __func__, tmp);
ICUNIT_GOTO_STRING_EQUAL(tmp, "zh_CN.UTF-8", -1, OUT);
/* choose a domain for your program. */
tmp = textdomain("messages");
/* bind a directory,use PWD here. */
bindtextdomain("messages", ".");
/* set the output codeset.It is not needed usually */
bind_textdomain_codeset("messages", "UTF-8");
/* test gettext. */
s = gettext("Monday/n\n");
ICUNIT_ASSERT_STRING_EQUAL(s, "Monday/n\n", s);
return LOS_OK;
OUT:
return LOS_NOK;
}
static UINT32 testcase(VOID)
{
testcase1();
return LOS_OK;
}
VOID IO_TEST_GETTEXT_001(VOID)
{
TEST_ADD_CASE(__FUNCTION__, testcase, TEST_LIB, TEST_LIBC, TEST_LEVEL1, TEST_FUNCTION);
}
@@ -0,0 +1,68 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "It_test_IO.h"
#include <time.h>
#include <locale.h>
static UINT32 testcase(VOID)
{
time_t currtime;
struct tm *timer = {nullptr};
char buffer[80];
time(&currtime);
timer = localtime(&currtime);
setenv("MUSL_LOCPATH", "/storage", 1);
printf("getenv MUSL_LOCPATH=%s\n", getenv("MUSL_LOCPATH"));
printf("Locale is: %s\n", setlocale(LC_TIME, "en_US.UTF-8"));
strftime(buffer, 80, "%c", timer);
printf("Date is: %s\n", buffer);
ICUNIT_ASSERT_NOT_EQUAL_NULL(buffer, NULL, -1);
printf("Locale is: %s\n", setlocale(LC_TIME, "zh_CN.UTF-8"));
strftime(buffer, 80, "%c", timer);
printf("Date is: %s\n", buffer);
ICUNIT_ASSERT_NOT_EQUAL_NULL(buffer, NULL, -1);
printf("Locale is: %s\n", setlocale(LC_TIME, ""));
strftime(buffer, 80, "%c", timer);
printf("Date is: %s\n", buffer);
ICUNIT_ASSERT_NOT_EQUAL_NULL(buffer, NULL, -1);
return LOS_OK;
}
VOID IO_TEST_LOCALE_001(void)
{
TEST_ADD_CASE(__FUNCTION__, testcase, TEST_LIB, TEST_LIBC, TEST_LEVEL1, TEST_FUNCTION);
}
@@ -0,0 +1,69 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "It_test_IO.h"
#include <time.h>
#include <locale.h>
static UINT32 testcase(VOID)
{
time_t currtime;
struct tm *timer = {nullptr};
char buffer[80];
//locale_t loc = malloc(sizeof(locale_t);
time(&currtime);
timer = localtime(&currtime);
setenv("MUSL_LOCPATH", "/storage", 1);
printf("getenv MUSL_LOCPATH=%s\n", getenv("MUSL_LOCPATH"));
printf("Locale is: %s\n", setlocale(LC_TIME, "en_US.UTF-8"));
strftime(buffer, 80, "%c", timer);
printf("Date is: %s\n", buffer);
ICUNIT_ASSERT_NOT_EQUAL_NULL(buffer, NULL, -1);
printf("Locale is: %s\n", setlocale(LC_TIME, "zh_CN.UTF-8"));
strftime(buffer, 80, "%c", timer);
printf("Date is: %s\n", buffer);
ICUNIT_ASSERT_NOT_EQUAL_NULL(buffer, NULL, -1);
printf("Locale is: %s\n", setlocale(LC_TIME, ""));
strftime(buffer, 80, "%c", timer);
printf("Date is: %s\n", buffer);
ICUNIT_ASSERT_NOT_EQUAL_NULL(buffer, NULL, -1);
return LOS_OK;
}
VOID IO_TEST_LOCALE_002(void)
{
TEST_ADD_CASE(__FUNCTION__, testcase, TEST_LIB, TEST_LIBC, TEST_LEVEL1, TEST_FUNCTION);
}
@@ -0,0 +1,56 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "It_test_IO.h"
#include <libintl.h>
#include <locale.h>
static UINT32 testcase(VOID)
{
char *s = "";
setlocale(LC_ALL, "");
textdomain("gettext_demo");
bindtextdomain("gettext_demo", ".");
bind_textdomain_codeset("gettext_demo", "UTF-8");
printf(ngettext("Delete the selected file?\n", "Delete the selected files?\n", 1));
printf(ngettext("Delete the selected file?\n", "Delete the selected files?\n", 2));
s = ngettext("0123456789", "0123456789", 2);
ICUNIT_ASSERT_STRING_EQUAL(s, "0123456789", s);
return LOS_OK;
}
VOID IO_TEST_NGETTEXT_001(VOID)
{
TEST_ADD_CASE(__FUNCTION__, testcase, TEST_LIB, TEST_LIBC, TEST_LEVEL1, TEST_FUNCTION);
}
@@ -0,0 +1,100 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "It_test_IO.h"
#include <langinfo.h>
#include <locale.h>
static UINT32 testcase(VOID)
{
/* set the locale info */
setenv("MUSL_LOCPATH", "/storage", 1);
printf("getenv MUSL_LOCPATH=%s\n", getenv("MUSL_LOCPATH"));
printf("Locale is: %s\n", setlocale(LC_TIME, "zh_CN.UTF-8"));
setlocale(LC_CTYPE, "");
setlocale(LC_NUMERIC, "");
/* echo the nl_langinfo */
printf("%s\n", nl_langinfo(CODESET));
printf("%s\n", nl_langinfo(RADIXCHAR));
printf("%s\n", nl_langinfo(D_T_FMT));
printf("%s\n", nl_langinfo(D_FMT));
printf("%s\n", nl_langinfo(T_FMT));
printf("%s\n", nl_langinfo(DAY_1));
printf("%s\n", nl_langinfo(DAY_7));
printf("%s\n", nl_langinfo(ABDAY_1));
printf("%s\n", nl_langinfo(ABDAY_7));
printf("%s\n", nl_langinfo(MON_1));
printf("%s\n", nl_langinfo(MON_12));
printf("%s\n", nl_langinfo(ABMON_1));
printf("%s\n", nl_langinfo(ABMON_12));
printf("%s\n", nl_langinfo(THOUSEP));
printf("%s\n", nl_langinfo(YESEXPR));
printf("%s\n", nl_langinfo(NOEXPR));
printf("%s\n", nl_langinfo(CRNCYSTR));
/* set the locale info */
setenv("MUSL_LOCPATH", "/storage", 1);
printf("getenv MUSL_LOCPATH=%s\n", getenv("MUSL_LOCPATH"));
printf("Locale is: %s\n", setlocale(LC_TIME, "en_US.UTF-8"));
setlocale(LC_CTYPE, "");
setlocale(LC_NUMERIC, "");
/* echo the nl_langinfo */
printf("%s\n", nl_langinfo(CODESET));
printf("%s\n", nl_langinfo(RADIXCHAR));
printf("%s\n", nl_langinfo(D_T_FMT));
printf("%s\n", nl_langinfo(D_FMT));
printf("%s\n", nl_langinfo(T_FMT));
printf("%s\n", nl_langinfo(DAY_1));
printf("%s\n", nl_langinfo(DAY_7));
printf("%s\n", nl_langinfo(ABDAY_1));
printf("%s\n", nl_langinfo(ABDAY_7));
printf("%s\n", nl_langinfo(MON_1));
printf("%s\n", nl_langinfo(MON_12));
printf("%s\n", nl_langinfo(ABMON_1));
printf("%s\n", nl_langinfo(ABMON_12));
printf("%s\n", nl_langinfo(THOUSEP));
printf("%s\n", nl_langinfo(YESEXPR));
printf("%s\n", nl_langinfo(NOEXPR));
printf("%s\n", nl_langinfo(CRNCYSTR));
char *string = nl_langinfo(CRNCYSTR);
ICUNIT_ASSERT_NOT_EQUAL_NULL(string, NULL, string);
return LOS_OK;
}
VOID IO_TEST_NL_LANGINFO_001(VOID)
{
TEST_ADD_CASE(__FUNCTION__, testcase, TEST_LIB, TEST_LIBC, TEST_LEVEL1, TEST_FUNCTION);
}
@@ -0,0 +1,68 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "It_test_IO.h"
#include <langinfo.h>
#include <locale.h>
static UINT32 testcase(VOID) {
/* set the locale info */
setenv("MUSL_LOCPATH", "/storage", 1);
printf("getenv MUSL_LOCPATH=%s\n", getenv("MUSL_LOCPATH"));
printf("Locale is: %s\n", setlocale(LC_TIME, "en_US.UTF-8"));
setlocale(LC_CTYPE, "");
setlocale(LC_NUMERIC, "");
/* echo the nl_langinfo_l */
printf("%s\n", nl_langinfo_l(CODESET, (locale_t)"en_US.UTF-8"));
printf("%s\n", nl_langinfo_l(RADIXCHAR, (locale_t)"en_US.UTF-8"));
/* set the locale info */
setenv("MUSL_LOCPATH", "/storage", 1);
printf("getenv MUSL_LOCPATH=%s\n", getenv("MUSL_LOCPATH"));
printf("Locale is: %s\n", setlocale(LC_TIME, "zh_CN.UTF-8"));
setlocale(LC_CTYPE, "");
setlocale(LC_NUMERIC, "");
/* echo the nl_langinfo */
printf("%s\n", nl_langinfo_l(CODESET, (locale_t)"zh_CN.UTF-8"));
printf("%s\n", nl_langinfo_l(RADIXCHAR, (locale_t)"zh_CN.UTF-8"));
char *string = nl_langinfo_l(CRNCYSTR, (locale_t)"zh_CN.UTF-8");
ICUNIT_ASSERT_NOT_EQUAL_NULL(string, NULL, string);
return LOS_OK;
}
VOID IO_TEST_NL_LANGINFO_l_001(VOID)
{
TEST_ADD_CASE(__FUNCTION__, testcase, TEST_LIB, TEST_LIBC, TEST_LEVEL1, TEST_FUNCTION);
}
@@ -0,0 +1,171 @@
/*
* Copyright (c) 2021-2021, Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2021-2021, Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "It_test_IO.h"
#include <poll.h>
#include "signal.h"
#include "pthread.h"
#define LISTEN_FD_NUM 10
#define POLL_EVENTS 1
int pipeFdPpoll[LISTEN_FD_NUM][2];
static pthread_t g_tid = -1;
extern int ppoll(struct pollfd *fds, nfds_t nfds, const struct timespec *tmo_p, const sigset_t *sigmask);
static void *pthread_01(void)
{
static int count = 0;
int total_num = 0;
int times = 3;
int i, ret;
struct pollfd fds[LISTEN_FD_NUM] = {0};
char buffer[20];
struct timespec t = { 3,0 };
sigset_t sigset;
TEST_PRINT("[INFO]%s:%d,%s,Create thread %d\n", __FILE__, __LINE__, __func__, count);
count++;
sigemptyset(&sigset);
sigaddset(&sigset, SIGALRM); //把SIGALRM 信号添加到sigset 信号集中
sigaddset(&sigset, SIGUSR1);
for (i = 0; i < LISTEN_FD_NUM; i++) {
fds[i].fd = pipeFdPpoll[i][0];
fds[i].events = POLL_EVENTS;
}
while (times--) {
ret = ppoll(fds, LISTEN_FD_NUM, &t, &sigset);
total_num += ((ret > 0) ? ret : 0);
if (ret <= 0) {
continue;
}
for (i = 0; i < LISTEN_FD_NUM; i++) {
if (fds[i].revents & POLL_EVENTS) {
ret = read(fds[i].fd, buffer, 12);
ICUNIT_GOTO_EQUAL(ret, 12, ret, EXIT);
ret = strcmp(buffer, "hello world");
TEST_PRINT("[EVENT]%s:%d,%s,buffer=%s\n", __FILE__, __LINE__, __func__, buffer);
}
}
if (total_num == LISTEN_FD_NUM) {
break;
}
}
/* ICUNIT_GOTO_EQUAL(total_num, 10, -1, EXIT); */
TEST_PRINT("[INFO]%s:%d,%s,total_num=%d\n", __FILE__, __LINE__, __func__, total_num);
EXIT:
return nullptr;
}
static UINT32 testcase1(VOID)
{
int i;
int ret;
int count = 0;
for (i = 0; i < LISTEN_FD_NUM; i++) {
ret = pipe(pipeFdPpoll[i]);
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
TEST_PRINT("[INFO]%s:%d,%s,ret=%d,pipeFdPpoll[%d][0]=%d\n", __FILE__, __LINE__, __func__, ret, i, pipeFdPpoll[i][0]);
TEST_PRINT("[INFO]%s:%d,%s,ret=%d,pipeFdPpoll[%d][0]=%d\n", __FILE__, __LINE__, __func__, ret, i, pipeFdPpoll[i][1]);
}
errno = 0;
ret = pthread_create(&g_tid, nullptr, pthread_01(nullptr), nullptr);
TEST_PRINT("[INFO]%s:%d,%s,ret=%d,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, ret, errno, strerror(errno));
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
errno = 0;
for (i = 0; i < LISTEN_FD_NUM; i++) {
if ((pipeFdPpoll[i][1] != 9) && (pipeFdPpoll[i][1] != 10) && (pipeFdPpoll[i][1] != 11)) {
ret = write(pipeFdPpoll[i][1], "hello world!", 12); /* 12, "hello world" length and '\0' */
}
ICUNIT_GOTO_EQUAL(ret, 12, ret, EXIT);
TEST_PRINT("[INFO]%s:%d,%s,ret=%d,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, ret, errno, strerror(errno));
}
#if 1 /* write looply */
while(1) {
if (count++ > 3) {
break;
}
sleep(1);
for (i = 0; i < LISTEN_FD_NUM; i++) {
errno = 0;
ret = pthread_create(&g_tid, nullptr, pthread_01(nullptr), nullptr);
TEST_PRINT("[INFO]%s:%d,%s,ret=%d,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, ret, errno, strerror(errno));
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
if ((pipeFdPpoll[i][1] == 13) || (pipeFdPpoll[i][1] == 14) || (pipeFdPpoll[i][1] == 15)) {
errno = 0;
ret = write(pipeFdPpoll[i][1], "World HELLO!", 12); /* 12, "hello world" length and '\0' */
TEST_PRINT("[INFO]%s:%d,%s,ret=%d,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, ret, errno, strerror(errno));
TEST_PRINT("[INFO]%s:%d,%s,ret=%d,pipeFdPpoll[%d][1]=%d,count=%d\n", __FILE__, __LINE__, __func__, ret,i, pipeFdPpoll[i][1], count);
}
/* ICUNIT_GOTO_EQUAL(ret, 12, ret, EXIT); */
}
}
#endif
pthread_join(g_tid, nullptr);
for (i = 0; i < LISTEN_FD_NUM; i++) {
close(pipeFdPpoll[i][0]);
close(pipeFdPpoll[i][1]);
}
return LOS_OK;
EXIT:
for (i = 0; i < LISTEN_FD_NUM; i++) {
close(pipeFdPpoll[i][0]);
close(pipeFdPpoll[i][1]);
}
return LOS_NOK;
}
static UINT32 testcase(VOID)
{
testcase1();
return LOS_OK;
}
VOID IO_TEST_PPOLL_001(VOID)
{
TEST_ADD_CASE(__FUNCTION__, testcase, TEST_LIB, TEST_LIBC, TEST_LEVEL1, TEST_FUNCTION);
}
@@ -0,0 +1,111 @@
/*
* Copyright (c) 2021-2021, Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2021-2021, Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "It_test_IO.h"
#include "time.h"
#include "signal.h"
#include <poll.h>
#include <fcntl.h>
#include <unistd.h>
#include <strings.h>
#define BUF_LEN 20
#define MAX_SCAN_FDSET 10 /* define poll's listened FD set's size */
#define POLL_WAIT_TIMEOUT 10*1000 /* ms */
extern int ppoll(struct pollfd *fds, nfds_t nfds, const struct timespec *timeout, const sigset_t *sigmask);
void work_ppoll(int fd)
{
int ret = 0;
int i = 0;
char recv_buf[BUF_LEN];
sigset_t sigset;
struct timespec t;
struct pollfd scan_fdset[MAX_SCAN_FDSET];
int scan_fdset_num = 10;
int count = 5;
bzero(recv_buf, BUF_LEN);
sigemptyset(&sigset);
sigaddset(&sigset, SIGALRM); /* add SIGALRM to sigset */
sigaddset(&sigset, SIGUSR1); /* add SIGUSR1 to sigset */
bzero(&t, sizeof(struct timespec));
t.tv_sec = 10;
t.tv_nsec = 0;
bzero(scan_fdset, sizeof(struct pollfd) * MAX_SCAN_FDSET);
scan_fdset[0].fd = fd;
/* attention:in the book《UNIX网络编程第一卷》P162 metions:POLLERR,POLLHUP,POLLNVAL\
those error signals can not be set in events. */
/* they will return in revents,while the proper condition happens. */
scan_fdset[0].events = POLLOUT; /* set the signal needed to be listened:POLLOUT/POLLIN */
/* set other elements in the array as invalid. */
for (i = 1; i < MAX_SCAN_FDSET; i++) {
/* scan_fdset[i].fd = -1; */
scan_fdset[i].fd = fd;
scan_fdset[i].events = POLLOUT; /* set the signal needed to be listened. */
}
/* scan_fdset_num = 1; */ /* 表示当前的scan_fdset[] 数组中只使用前面1 个元素存放需要监听的扫描符 */
while (count--) {
ret = ppoll(scan_fdset, scan_fdset_num, &t, &sigset);
for (i = 0; i < MAX_SCAN_FDSET; i++) {
if (scan_fdset[i].revents & POLLOUT) {
TEST_PRINT("[INFO]%s:%d,%s,fd have signal!\n", __FILE__, __LINE__, __func__);
ret = read(fd, recv_buf, BUF_LEN);
if (-1 == ret) {
TEST_PRINT("[INFO]%s:%d,%s,read error!\n", __FILE__, __LINE__, __func__);
continue;
}
TEST_PRINT("[INFO]%s:%d,%s,recv_buf=%s\n", __FILE__, __LINE__, __func__, recv_buf);
}
TEST_PRINT("[INFO]%s:%d,%s,scan_fdset[i].revents=%d\n", __FILE__, __LINE__, __func__, scan_fdset[i].revents);
}
}
}
static UINT32 testcase(VOID)
{
int fd;
char *filename = FILEPATH_775;
fd = open(filename, O_RDWR);
TEST_PRINT("[INFO]%s:%d,%s,fd=%d\n", __FILE__, __LINE__, __func__, fd);
work_ppoll(fd);
return LOS_OK;
}
VOID IO_TEST_PPOLL_002(VOID)
{
TEST_ADD_CASE(__FUNCTION__, testcase, TEST_LIB, TEST_LIBC, TEST_LEVEL1, TEST_FUNCTION);
}
@@ -0,0 +1,71 @@
/*
* Copyright (c) 2021-2021, Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2021-2021, Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "It_test_IO.h"
#include <stdlib.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include "sys/select.h"
static UINT32 testcase(VOID)
{
fd_set rfds;
//struct timeval tv;
struct timespec tv;
int retval;
/* Watch stdin (fd 0) to see when it has input. */
FD_ZERO(&rfds);
FD_SET(0, &rfds);
/* Wait up to three seconds. */
//tv.tv_sec = 3;
//tv.tv_usec = 0;
tv.tv_sec = 3;
tv.tv_nsec = 0;
retval = pselect(1, &rfds, nullptr, nullptr, &tv, ((long[]){ 0, _NSIG/8 }));
if (retval == -1) {
perror("select()");
} else if (retval) {
printf("Data is available now.\n");
} else { /* FD_ISSET(0, &rfds) will be true. */
printf("No data within three seconds.\n");
}
return LOS_OK;
}
VOID IO_TEST_PSELECT_001(VOID)
{
TEST_ADD_CASE(__FUNCTION__, testcase, TEST_LIB, TEST_LIBC, TEST_LEVEL1, TEST_FUNCTION);
}
@@ -0,0 +1,53 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "It_test_IO.h"
#include <string.h>
#include "locale.h"
static UINT32 testcase(VOID)
{
char *a = "aBcDeF";
char *b = "AbCdEf";
locale_t loc;
printf("Strings:a=%s,b=%s,doing if(!strcasecmp(a, b))printf(\"\%s=\%s\\n\", a, b);", a, b, a, b);
if (!strcasecmp_l(a, b, loc)) {
printf("%s=%s\n", a, b);
}
ICUNIT_ASSERT_EQUAL(strcasecmp_l(a, b, loc), 0, strcasecmp_l(a, b, loc));
return LOS_OK;
}
VOID IO_TEST_STRCASECMP_L_001(VOID)
{
TEST_ADD_CASE(__FUNCTION__, testcase, TEST_LIB, TEST_LIBC, TEST_LEVEL1, TEST_FUNCTION);
}
@@ -0,0 +1,81 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "It_test_IO.h"
#include <string.h>
static UINT32 testcase1(VOID)
{
char *a = "aBcDeF";
char *b = "AbCEf";
int ret = 0;
locale_t loc;
errno = 0;
ret = strcasecmp_l(a, b, loc);
TEST_PRINT("[INFO]%s:%d,%s,ret=%d,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, ret, errno, strerror(errno));
ICUNIT_GOTO_NOT_EQUAL(ret, 0, ret, OUT);
ICUNIT_GOTO_EQUAL(errno, 0, errno, OUT);
return LOS_OK;
OUT:
return LOS_NOK;
}
static UINT32 testcase2(VOID)
{
char *a = "aBcDfF";
char *b = "AbCEe";
int ret = 0;
locale_t loc;
errno = 0;
ret = strcasecmp_l(a, b, loc);
TEST_PRINT("[INFO]%s:%d,%s,ret=%d,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, ret, errno, strerror(errno));
ICUNIT_GOTO_NOT_EQUAL(ret, 0, ret, OUT);
ICUNIT_GOTO_EQUAL(errno, 0, errno, OUT);
return LOS_OK;
OUT:
return LOS_NOK;
}
static UINT32 testcase(VOID)
{
testcase1();
testcase2();
return LOS_OK;
}
VOID IO_TEST_STRCASECMP_L_002(VOID)
{
TEST_ADD_CASE(__FUNCTION__, testcase, TEST_LIB, TEST_LIBC, TEST_LEVEL1, TEST_FUNCTION);
}
@@ -0,0 +1,56 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "It_test_IO.h"
#include <monetary.h>
#include "locale.h"
static UINT32 testcase(VOID)
{
char buf[100] = {0};
int ret = 0;
locale_t loc;
ret = strfmon_l(buf, sizeof(buf), loc, "[%^=*#6n] [%=*#6i]", 1234.567, 1234.567);
ICUNIT_ASSERT_EQUAL(ret, 23, ret);
ret = strfmon_l(buf, sizeof(buf), loc, "[%^=*#6n] [%=*#6i]", 134.567, 1234.567);
ICUNIT_ASSERT_EQUAL(ret, 23, ret);
ret = strfmon_l(buf, sizeof(buf), loc, "[%^=*#6n] [%=*#6i]", 1234.567, 134.567);
ICUNIT_ASSERT_EQUAL(ret, 23, ret);
return LOS_OK;
}
VOID IO_TEST_STRFMON_L_001(VOID)
{
TEST_ADD_CASE(__FUNCTION__, testcase, TEST_LIB, TEST_LIBC, TEST_LEVEL1, TEST_FUNCTION);
}
@@ -0,0 +1,88 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "It_test_IO.h"
#include <monetary.h>
#include "locale.h"
static UINT32 testcase1(VOID)
{
char buf[100] = {0};
int ret = 0;
locale_t loc;
errno = 0;
setenv("MUSL_LOCPATH", "/storage", 1);
TEST_PRINT("[INFO]%s:%d,%s,Locale is: %s\n", __FILE__, __LINE__, __func__,setlocale(LC_TIME, "zh_CN.UTF-8"));
errno = 0;
ret = strfmon_l(buf, 2, loc, "[%^=*#6n] [%=*#6i]", 1234.567, 1234.567);
TEST_PRINT("[INFO]%s:%d,%s,ret=%d,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, ret, errno, strerror(errno));
TEST_PRINT("[INFO]%s:%d,%s,ret=%d,buf=%s\n", __FILE__, __LINE__, __func__, ret, buf);
ICUNIT_GOTO_EQUAL(ret, -1, ret, OUT);
ICUNIT_GOTO_EQUAL(errno, E2BIG, errno, OUT);
errno = 0;
ret = strfmon_l(buf, 3, loc, "[%^=*#6n] [%=*#6i]", 134.567, 1234.567);
TEST_PRINT("[INFO]%s:%d,%s,ret=%d,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, ret, errno, strerror(errno));
TEST_PRINT("[INFO]%s:%d,%s,ret=%d,buf=%s\n", __FILE__, __LINE__, __func__, ret, buf);
ICUNIT_GOTO_EQUAL(ret, -1, ret, OUT);
ICUNIT_GOTO_EQUAL(errno, E2BIG, errno, OUT);
errno = 0;
ret = strfmon_l(buf, 22, loc, "[%^=*#6n] [%=*#6i]", 1234.567, 134.567);
TEST_PRINT("[INFO]%s:%d,%s,ret=%d,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, ret, errno, strerror(errno));
TEST_PRINT("[INFO]%s:%d,%s,ret=%d,buf=%s\n", __FILE__, __LINE__, __func__, ret, buf);
ICUNIT_GOTO_EQUAL(ret, -1, ret, OUT);
ICUNIT_GOTO_EQUAL(errno, E2BIG, errno, OUT);
errno = 0;
ret = strfmon_l(buf, 23, loc, "[%^=*#6n] [%=*#6i]", 1234.567, 134.567);
TEST_PRINT("[INFO]%s:%d,%s,ret=%d,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, ret, errno, strerror(errno));
TEST_PRINT("[INFO]%s:%d,%s,ret=%d,buf=%s\n", __FILE__, __LINE__, __func__, ret, buf);
ICUNIT_GOTO_EQUAL(ret, 23, ret, OUT);
ICUNIT_GOTO_EQUAL(errno, 0, errno, OUT);
return LOS_OK;
OUT:
return LOS_NOK;
}
static UINT32 testcase(VOID)
{
testcase1();
return LOS_OK;
}
VOID IO_TEST_STRFMON_L_002(VOID)
{
TEST_ADD_CASE(__FUNCTION__, testcase, TEST_LIB, TEST_LIBC, TEST_LEVEL1, TEST_FUNCTION);
}
@@ -0,0 +1,54 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "It_test_IO.h"
#include <string.h>
#include "locale.h"
static UINT32 testcase(VOID)
{
char *a = "aBcDeF";
char *b = "AbCdEf";
int n = 5;
locale_t loc;
printf("Strings:a=%s,b=%s,doing if(!strncasecmp(a, b, %d))printf(\"\%s=\%s\\n\", a, b);", a, b, n, a, b);
if (!strncasecmp_l(a, b, n, loc)) {
printf("%s=%s in first %d characters.\n", a, b, n);
}
ICUNIT_ASSERT_EQUAL(strncasecmp_l(a, b, n, loc), 0, strncasecmp_l(a, b, n, loc));
return LOS_OK;
}
VOID IO_TEST_STRNCASECMP_L_001(VOID)
{
TEST_ADD_CASE(__FUNCTION__, testcase, TEST_LIB, TEST_LIBC, TEST_LEVEL1, TEST_FUNCTION);
}
@@ -0,0 +1,139 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "It_test_IO.h"
#include <string.h>
static UINT32 testcase1(VOID)
{
char *a = "aBcDeF";
char *b = "AbCdEf";
int n = 600;
int ret = 0;
locale_t loc;
errno = 0;
setenv("MUSL_LOCPATH", "/storage", 1);
TEST_PRINT("[INFO]%s:%d,%s,Locale is: %s\n", __FILE__, __LINE__, __func__,setlocale(LC_TIME, "zh_CN.UTF-8"));
errno = 0;
ret = strncasecmp_l(a, b, n, loc);
TEST_PRINT("[INFO]%s:%d,%s,ret=%d,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, ret, errno, strerror(errno));
ICUNIT_GOTO_EQUAL(ret, 0, ret, OUT);
ICUNIT_GOTO_EQUAL(errno, 0, errno, OUT);
return LOS_OK;
OUT:
return LOS_NOK;
}
static UINT32 testcase2(VOID)
{
char *a = "aBcDeF";
char *b = "AbCdEi";
int n = -6;
int ret = 0;
locale_t loc;
errno = 0;
setenv("MUSL_LOCPATH", "/storage", 1);
TEST_PRINT("[INFO]%s:%d,%s,Locale is: %s\n", __FILE__, __LINE__, __func__,setlocale(LC_TIME, "zh_CN.UTF-8"));
errno = 0;
ret = strncasecmp_l(a, b, n, loc);
TEST_PRINT("[INFO]%s:%d,%s,ret=%d,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, ret, errno, strerror(errno));
ICUNIT_GOTO_EQUAL(ret, -3, ret, OUT);
ICUNIT_GOTO_EQUAL(errno, 0, errno, OUT);
return LOS_OK;
OUT:
return LOS_NOK;
}
static UINT32 testcase3(VOID)
{
char *a = "aBcDeF";
char *b = "AbCdAx";
int n = 0;
int ret = 0;
locale_t loc;
errno = 0;
setenv("MUSL_LOCPATH", "/storage", 1);
TEST_PRINT("[INFO]%s:%d,%s,Locale is: %s\n", __FILE__, __LINE__, __func__,setlocale(LC_TIME, "zh_CN.UTF-8"));
errno = 0;
ret = strncasecmp_l(a, b, n, loc);
TEST_PRINT("[INFO]%s:%d,%s,ret=%d,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, ret, errno, strerror(errno));
ICUNIT_GOTO_EQUAL(ret, 0, ret, OUT);
ICUNIT_GOTO_EQUAL(errno, 0, errno, OUT);
return LOS_OK;
OUT:
return LOS_NOK;
}
static UINT32 testcase4(VOID)
{
char *a = "34342aBcDeF";
char *b = "AbCdAx";
int n = 4;
int ret = 0;
locale_t loc;
errno = 0;
setenv("MUSL_LOCPATH", "/storage", 1);
TEST_PRINT("[INFO]%s:%d,%s,Locale is: %s\n", __FILE__, __LINE__, __func__,setlocale(LC_TIME, "zh_CN.UTF-8"));
errno = 0;
ret = strncasecmp_l(a, b, n, loc);
TEST_PRINT("[INFO]%s:%d,%s,ret=%d,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, ret, errno, strerror(errno));
ICUNIT_GOTO_EQUAL(ret, -46, ret, OUT);
ICUNIT_GOTO_EQUAL(errno, 0, errno, OUT);
return LOS_OK;
OUT:
return LOS_NOK;
}
static UINT32 testcase(VOID)
{
testcase1();
testcase2();
testcase3();
testcase4();
return LOS_OK;
}
VOID IO_TEST_STRNCASECMP_L_002(VOID)
{
TEST_ADD_CASE(__FUNCTION__, testcase, TEST_LIB, TEST_LIBC, TEST_LEVEL1, TEST_FUNCTION);
}
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "It_test_IO.h"
static UINT32 Testcase(VOID)
{
struct lconv *newloc = localeconv();
ICUNIT_ASSERT_NOT_EQUAL(newloc, NULL, newloc);
return LOS_OK;
}
VOID ItLocaleLocaleconv001(VOID)
{
TEST_ADD_CASE(__FUNCTION__, Testcase, TEST_LIB, TEST_LIBC, TEST_LEVEL1, TEST_FUNCTION);
}
@@ -0,0 +1,83 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "It_test_IO.h"
static UINT32 Testcase(VOID)
{
wchar_t *srcStr = L"hello";
wchar_t tarStr[20] = {0}; // 20, target buffer size
int nRet;
unsigned int nPos;
int nType;
char pathname[50]; // 50, path name buffer size
FILE *testFile;
strncpy(pathname, g_ioTestPath, 50); // 50, path name buffer size
char *filename = "/crtfputwstest1";
strcat(pathname, filename);
for (nType = 0; nType < 6; nType++) { // 6, test loop num
testFile = fopen(pathname, "a");
ICUNIT_GOTO_NOT_EQUAL(testFile, NULL, testFile, EXIT);
fseek(testFile, 0, SEEK_END);
nPos = (unsigned int)ftell(testFile);
nRet = fputws(srcStr, testFile);
ICUNIT_GOTO_NOT_EQUAL(nRet, -1, nRet, EXIT);
if ((nPos + 5) != (unsigned int)ftell(testFile)) { // 5, expect position offset
ICUNIT_GOTO_EQUAL(1, 0, 1, EXIT);
}
fclose(testFile);
testFile = fopen(pathname, "r");
ICUNIT_GOTO_NOT_EQUAL(testFile, NULL, testFile, EXIT);
wchar_t *p = fgetws(tarStr, 6, testFile); // 6, "hello" length and '\0'
ICUNIT_GOTO_EQUAL(p, tarStr, p, EXIT);
nRet = wcscmp(srcStr, tarStr);
ICUNIT_GOTO_EQUAL(nRet, 0, nRet, EXIT);
fclose(testFile);
}
remove(pathname);
return LOS_OK;
EXIT:
if (testFile != NULL) {
fclose(testFile);
remove(pathname);
}
return LOS_NOK;
}
VOID ItStdioFputws001(void)
{
TEST_ADD_CASE(__FUNCTION__, Testcase, TEST_LIB, TEST_LIBC, TEST_LEVEL1, TEST_FUNCTION);
}
@@ -0,0 +1,83 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "It_test_IO.h"
static UINT32 Testcase(VOID)
{
wchar_t tarStr[20] = {0}; // 20, buffer size
wchar_t *p;
int nRet;
unsigned int nPos;
int nType;
char pathname[50]; // 50, path name buffer size
strncpy(pathname, g_ioTestPath, 50); // 50, path name buffer size
char *filename = "/crtfwprintftest1";
FILE *testFile = NULL;
strcat(pathname, filename);
for (nType = 0; nType < 6; nType++) { // 6, loop test num
testFile = fopen(pathname, "w+");
ICUNIT_GOTO_NOT_EQUAL(testFile, NULL, testFile, EXIT);
nPos = (unsigned int)ftell(testFile);
nRet = fwprintf(testFile, L"hello world %d", 666); // 666, for test, print to testFile
ICUNIT_GOTO_EQUAL(nRet, 15, nRet, EXIT); // 15 total write size
if ((nPos + 15) != (unsigned int)ftell(testFile)) { // 15 total write size
ICUNIT_GOTO_EQUAL(1, 0, 1, EXIT);
}
fclose(testFile);
testFile = fopen(pathname, "r");
p = fgetws(tarStr, 16, testFile); // 16 read size,total write and '\0'
nRet = wcscmp(L"hello world 666", tarStr);
ICUNIT_GOTO_EQUAL(nRet, 0, nRet, EXIT);
fclose(testFile);
}
remove(pathname);
return LOS_OK;
EXIT:
if (testFile != NULL) {
fclose(testFile);
remove(pathname);
}
return LOS_NOK;
}
VOID ItStdioFwprintf001(void)
{
TEST_ADD_CASE(__FUNCTION__, Testcase, TEST_LIB, TEST_LIBC, TEST_LEVEL1, TEST_FUNCTION);
}
@@ -0,0 +1,77 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "It_test_IO.h"
static UINT32 Testcase(VOID)
{
char ch;
unsigned int nPos;
int ret;
char pathname[50]; // 50, enough space.
strncpy(pathname, g_ioTestPath, sizeof(pathname));
char *filename = "/crt_getc_unlocked_test1";
FILE *testFile = NULL;
strcat(pathname, filename);
testFile = fopen(pathname, "w+");
ICUNIT_ASSERT_NOT_EQUAL(testFile, NULL, LOS_NOK);
ret = fputs("0123456789abcdefghijklmnopqrstuvwxyz", testFile);
ICUNIT_GOTO_NOT_EQUAL(ret, EOF, ret, EXIT);
fclose(testFile);
testFile = fopen(pathname, "r");
ICUNIT_GOTO_NOT_EQUAL(testFile, NULL, testFile, EXIT);
nPos = ftell(testFile);
ch = getc_unlocked(testFile);
ICUNIT_GOTO_EQUAL(ch, '0', ch, EXIT);
if ((nPos + sizeof(char)) != (unsigned int)ftell(testFile)) {
ICUNIT_GOTO_EQUAL(1, 0, 1, EXIT);
}
fclose(testFile);
remove(pathname);
return LOS_OK;
EXIT:
if (testFile != NULL) {
fclose(testFile);
remove(pathname);
}
return LOS_NOK;
}
VOID ItStdioGetcUnlocked001(void)
{
TEST_ADD_CASE(__FUNCTION__, Testcase, TEST_LIB, TEST_LIBC, TEST_LEVEL1, TEST_FUNCTION);
}
@@ -0,0 +1,89 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "It_test_IO.h"
static UINT32 testcase(VOID)
{
struct mntent* mnt = nullptr;
struct mntent* mnt_new = nullptr;
FILE *fp = nullptr;
char *argv[2] = {nullptr};
argv[0] = "/etc/fstab";
argv[1] = "errors";
char *opt = argv[1];
char *ret = nullptr;
mnt_new = (struct mntent *)malloc(sizeof(struct mntent));
mnt_new->mnt_fsname = "UUID=c4992556-a86e-45e8-ba5f-190b16a9073x";
mnt_new->mnt_dir = "/usr1";
mnt_new->mnt_type = "ext3";
mnt_new->mnt_opts = "errors=remount-ro,nofail";
mnt_new->mnt_freq = 0;
mnt_new->mnt_passno = 1;
fp = setmntent("/etc/fstab", "r");
if (!fp) {
printf("fp=0x%x\n", fp);
return LOS_NOK;
}
mnt = getmntent(fp);
if (mnt && !(feof(fp) || ferror(fp))) {
ret = hasmntopt(mnt, opt);
printf("hasmntopt=%s\n", ret);
ICUNIT_ASSERT_NOT_EQUAL_NULL(ret, NULL, -1);
mnt = getmntent(fp);
}
if (fp != NULL) {
endmntent(fp);
}
/* test the addmntent below */
fp = setmntent(argv[0], "a");
if (fopen("/lib/libc.so", "r")) {
printf("aha I found you are OHOS!!!\n");
if (addmntent(fp, mnt_new)) {
printf("a new mnt is added to %s\n", argv[0]);
}
}
if (fp != NULL) {
endmntent(fp);
}
return LOS_OK;
}
VOID IT_STDIO_HASMNTOPT_001(void)
{
TEST_ADD_CASE(__FUNCTION__, testcase, TEST_LIB, TEST_LIBC, TEST_LEVEL1, TEST_FUNCTION);
}
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "It_test_IO.h"
static UINT32 Testcase(VOID)
{
setlocale(LC_ALL, "en_US.utf8");
size_t result = 0;
const char *str = "z\u00df\u6c34\U0001f34c";
const char *end = str + strlen(str);
mblen(NULL, 0);
while (str < end) {
int next = mblen(str, end - str);
if (next == -1) {
perror("strlen_mb");
break;
}
str += next;
++result;
}
ICUNIT_GOTO_EQUAL(result, 4, result, EXIT); // 4, except value
return LOS_OK;
EXIT:
return LOS_NOK;
}
VOID ItStdioMblen001(void)
{
TEST_ADD_CASE(__FUNCTION__, Testcase, TEST_LIB, TEST_LIBC, TEST_LEVEL1, TEST_FUNCTION);
}
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "It_test_IO.h"
static UINT32 Testcase(VOID)
{
// allow mbrlen() to work with UTF-8 multibyte encoding
setlocale(LC_ALL, "en_US.utf8");
const char *str = "";
size_t sz = strlen(str);
int len1, len2, len3;
mbstate_t mb;
memset(&mb, 0, sizeof(mb));
len1 = mbrlen(str, 1, &mb);
ICUNIT_GOTO_EQUAL(len1, -2, len1, EXIT); // -2, except return value
len2 = mbrlen(str + 1, sz - 1, &mb);
ICUNIT_GOTO_EQUAL(len2, 2, len2, EXIT); // 2, except return value
len3 = mbrlen(str + 1, sz - 1, &mb);
ICUNIT_GOTO_EQUAL(len3, -1, len3, EXIT);
return LOS_OK;
EXIT:
return LOS_NOK;
}
VOID ItStdioMbrlen001(void)
{
TEST_ADD_CASE(__FUNCTION__, Testcase, TEST_LIB, TEST_LIBC, TEST_LEVEL1, TEST_FUNCTION);
}
@@ -0,0 +1,81 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "It_test_IO.h"
static UINT32 Testcase(VOID)
{
wchar_t srcWc = L'H';
int tarWc, nRet;
long nPos;
int nType, i;
FILE *putwcFile = NULL;
char pathname[50]; // 50, pathname size
strncpy(pathname, g_ioTestPath, 50); // 50, pathname size
char *filename = "/crtputwctest1";
strcat(pathname, filename);
for (nType = 0; nType < 6; nType++) { // 6, loop test num
putwcFile = fopen(pathname, "w+");
ICUNIT_GOTO_NOT_EQUAL(putwcFile, NULL, putwcFile, EXIT);
nPos = ftell(putwcFile);
nRet = putwc(srcWc, putwcFile);
ICUNIT_GOTO_EQUAL(nRet, L'H', nRet, EXIT);
fclose(putwcFile);
putwcFile = fopen(pathname, "r");
tarWc = getwc(putwcFile);
ICUNIT_GOTO_EQUAL(tarWc, L'H', tarWc, EXIT);
if ((nPos + 1) != ftell(putwcFile)) {
ICUNIT_GOTO_EQUAL(1, 0, 1, EXIT);
}
fclose(putwcFile);
}
remove(pathname);
return LOS_OK;
EXIT:
if (putwcFile != NULL) {
fclose(putwcFile);
remove(pathname);
}
return LOS_NOK;
}
VOID ItStdioPutwc001(void)
{
TEST_ADD_CASE(__FUNCTION__, Testcase, TEST_LIB, TEST_LIBC, TEST_LEVEL1, TEST_FUNCTION);
}
@@ -0,0 +1,83 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "It_test_IO.h"
static UINT32 Testcase(VOID)
{
char *srcStr = "helloworld";
int nRet, fd;
char pathname[50]; // 50, path name size
char *filename = "/crtreadvtest1";
char buf1[6] = { 0 };
char buf2[6] = { 0 };
struct iovec iov[2]; // 2, read 2 block
ssize_t nread;
const int testStrLen = 10;
iov[0].iov_base = buf1;
iov[0].iov_len = sizeof(buf1) - 1;
iov[1].iov_base = buf2;
iov[1].iov_len = sizeof(buf2) - 1;
strncpy(pathname, g_ioTestPath, 50); // 50, path name size
strcat(pathname, filename);
fd = open(pathname, O_CREAT | O_RDWR | O_TRUNC, 0666); // 0666, file authority
if (fd < 0) {
printf("error: can`t open file\n");
}
nRet = write(fd, srcStr, testStrLen);
ICUNIT_GOTO_EQUAL(nRet, testStrLen, nRet, EXIT);
close(fd);
fd = open(pathname, O_RDWR);
if (fd < 0) {
printf("error: can`t open file\n");
}
nread = readv(fd, iov, 2); // 2, read 2 block
ICUNIT_GOTO_EQUAL(nread, testStrLen, nread, EXIT);
nRet = strcmp(buf2, "world");
ICUNIT_GOTO_EQUAL(nRet, 0, nRet, EXIT);
nRet = strcmp(buf1, "hello");
ICUNIT_GOTO_EQUAL(nRet, 0, nRet, EXIT);
close(fd);
remove(pathname);
return LOS_OK;
EXIT:
close(fd);
remove(pathname);
return LOS_NOK;
}
VOID ItStdioReadv001(void)
{
TEST_ADD_CASE(__FUNCTION__, Testcase, TEST_LIB, TEST_LIBC, TEST_LEVEL1, TEST_FUNCTION);
}
@@ -0,0 +1,51 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "It_test_IO.h"
static UINT32 Testcase(VOID)
{
int ret;
char *s = "abcdef123456abcdef";
char *p = NULL;
p = rindex(s, 'b');
ret = strcmp(p, "bcdef");
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
return LOS_OK;
EXIT:
return LOS_NOK;
}
VOID ItStdioRindex001(void)
{
TEST_ADD_CASE(__FUNCTION__, Testcase, TEST_LIB, TEST_LIBC, TEST_LEVEL1, TEST_FUNCTION);
}
@@ -0,0 +1,48 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "It_test_IO.h"
static UINT32 Testcase(VOID)
{
int oldmask;
int newmask = 0xff;
oldmask = setlogmask(newmask);
newmask = setlogmask(oldmask);
ICUNIT_ASSERT_EQUAL(newmask, 0xff, newmask);
return LOS_OK;
}
VOID ItStdioSetlogmask001(void)
{
TEST_ADD_CASE(__FUNCTION__, Testcase, TEST_LIB, TEST_LIBC, TEST_LEVEL1, TEST_FUNCTION);
}
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "It_test_IO.h"
static UINT32 Testcase(VOID)
{
double a = 12345678.12549;
double b = 0.1234567;
char ptr[128] = {0}; // 128, target buffer size
int ret;
gcvt(a, 10, ptr); // 10, convert significant value setting
ret = strcmp(ptr, "12345678.13");
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
gcvt(b, 6, ptr); // 6, convert significant value setting
ret = strcmp(ptr, "0.123457");
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
return 0;
}
VOID ItStdlibGcvt001(void)
{
TEST_ADD_CASE(__FUNCTION__, Testcase, TEST_LIB, TEST_LIBC, TEST_LEVEL1, TEST_FUNCTION);
}
@@ -0,0 +1,117 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "It_test_IO.h"
int g_pipeFd[10][2]; // 2, read and write; 10, listen fd number.
static pthread_t g_tid = -1;
static const int LISTEN_FD_NUM = 10;
static void *Pthread01(void *arg)
{
int totalNum = 0;
int times = 3; // 3, loop number for test.
int i, ret;
struct pollfd fds[LISTEN_FD_NUM] = {0};
char buffer[20]; // 20, enough space for test.
const int pollEvents = 1;
for (i = 0; i < LISTEN_FD_NUM; i++) {
fds[i].fd = g_pipeFd[i][0];
fds[i].events = pollEvents;
}
while (times--) {
ret = poll(fds, LISTEN_FD_NUM, 1000); // 1000, wait time.
totalNum += ((ret > 0) ? ret : 0);
if (ret <= 0) {
continue;
}
for (i = 0; i < LISTEN_FD_NUM; i++) {
if (fds[i].revents & pollEvents) {
ret = read(fds[i].fd, buffer, 12); // 12, "hello world" length and '\0'
ICUNIT_GOTO_EQUAL(ret, 12, ret, EXIT); // 12, "hello world" length and '\0'
ret = strcmp(buffer, "hello world");
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
}
}
if (totalNum == LISTEN_FD_NUM) {
break;
}
}
ICUNIT_GOTO_EQUAL(totalNum, LISTEN_FD_NUM, -1, EXIT);
EXIT:
return NULL;
}
static UINT32 Testcase(VOID)
{
int i;
int ret;
for (i = 0; i < LISTEN_FD_NUM; i++) {
ret = pipe(g_pipeFd[i]);
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
}
ret = pthread_create(&g_tid, NULL, Pthread01, NULL);
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
for (i = 0; i < LISTEN_FD_NUM; i++) {
ret = write(g_pipeFd[i][1], "hello world", 12); // 12, "hello world" length and '\0'
ICUNIT_GOTO_EQUAL(ret, 12, ret, EXIT); // 12, "hello world" length and '\0'
}
pthread_join(g_tid, NULL);
for (i = 0; i < LISTEN_FD_NUM; i++) {
close(g_pipeFd[i][0]);
close(g_pipeFd[i][1]);
}
return LOS_OK;
EXIT:
for (i = 0; i < LISTEN_FD_NUM; i++) {
close(g_pipeFd[i][0]);
close(g_pipeFd[i][1]);
}
return LOS_NOK;
}
VOID ItStdlibPoll002(void)
{
TEST_ADD_CASE(__FUNCTION__, Testcase, TEST_LIB, TEST_LIBC, TEST_LEVEL1, TEST_FUNCTION);
}
@@ -0,0 +1,86 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "It_test_IO.h"
struct PollParam {
int nfds;
int timeout;
int ret;
int err;
};
static UINT32 Testcase(VOID)
{
const int TEST_STR_LEN = 12;
int pipeFd[2], ret, err; // 2, pipe return 2 file descirpter
struct pollfd pollFd;
struct PollParam pollParam[4] = { /* nfds timeout ret err */
{ 0, 100, -1, EINVAL},
{ 4096, 10, -1, EINVAL},
{ 4095, 10, -1, EFAULT},
{ 1, -1, 1, 0}
};
ret = pipe(pipeFd);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ret = write(pipeFd[1], "hello world", TEST_STR_LEN);
printf("write first status: %d\n", ret);
ICUNIT_GOTO_EQUAL(ret, TEST_STR_LEN, ret, EXIT);
pollFd.fd = pipeFd[0];
pollFd.events = POLLIN;
for (int i = 0; i < sizeof(pollParam) / sizeof(pollParam[0]); i++) {
ret = poll(&pollFd, pollParam[i].nfds, pollParam[i].timeout);
ICUNIT_GOTO_EQUAL(ret, pollParam[i].ret, ret, EXIT);
if (ret == -1) {
printf("i = %d\n", i);
if (i == 2) { // 2, pollParam[2].
ICUNIT_GOTO_TWO_EQUAL(errno, EFAULT, EBADF, errno, EXIT);
} else {
ICUNIT_GOTO_EQUAL(errno, pollParam[i].err, errno, EXIT);
}
}
}
close(pipeFd[0]);
close(pipeFd[1]);
return LOS_OK;
EXIT:
close(pipeFd[0]);
close(pipeFd[1]);
return LOS_NOK;
}
VOID ItStdlibPoll003(void)
{
TEST_ADD_CASE(__FUNCTION__, Testcase, TEST_LIB, TEST_LIBC, TEST_LEVEL1, TEST_FUNCTION);
}