13d8536b4Sopenharmony_ci/*
23d8536b4Sopenharmony_ci * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
33d8536b4Sopenharmony_ci * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
43d8536b4Sopenharmony_ci *
53d8536b4Sopenharmony_ci * Redistribution and use in source and binary forms, with or without modification,
63d8536b4Sopenharmony_ci * are permitted provided that the following conditions are met:
73d8536b4Sopenharmony_ci *
83d8536b4Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright notice, this list of
93d8536b4Sopenharmony_ci *    conditions and the following disclaimer.
103d8536b4Sopenharmony_ci *
113d8536b4Sopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright notice, this list
123d8536b4Sopenharmony_ci *    of conditions and the following disclaimer in the documentation and/or other materials
133d8536b4Sopenharmony_ci *    provided with the distribution.
143d8536b4Sopenharmony_ci *
153d8536b4Sopenharmony_ci * 3. Neither the name of the copyright holder nor the names of its contributors may be used
163d8536b4Sopenharmony_ci *    to endorse or promote products derived from this software without specific prior written
173d8536b4Sopenharmony_ci *    permission.
183d8536b4Sopenharmony_ci *
193d8536b4Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
203d8536b4Sopenharmony_ci * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
213d8536b4Sopenharmony_ci * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
223d8536b4Sopenharmony_ci * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
233d8536b4Sopenharmony_ci * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
243d8536b4Sopenharmony_ci * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
253d8536b4Sopenharmony_ci * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
263d8536b4Sopenharmony_ci * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
273d8536b4Sopenharmony_ci * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
283d8536b4Sopenharmony_ci * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
293d8536b4Sopenharmony_ci * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
303d8536b4Sopenharmony_ci */
313d8536b4Sopenharmony_ci
323d8536b4Sopenharmony_ci#include "ohos_types.h"
333d8536b4Sopenharmony_ci#include "posix_test.h"
343d8536b4Sopenharmony_ci#include "los_config.h"
353d8536b4Sopenharmony_ci#include "kernel_test.h"
363d8536b4Sopenharmony_ci#include "ctype.h"
373d8536b4Sopenharmony_ci#include "stdlib.h"
383d8536b4Sopenharmony_ci#include "string.h"
393d8536b4Sopenharmony_ci#include "log.h"
403d8536b4Sopenharmony_ci
413d8536b4Sopenharmony_ci/* *
423d8536b4Sopenharmony_ci * @tc.desc      : register a test suite, this suite is used to test basic flow and interface dependency
433d8536b4Sopenharmony_ci * @param        : subsystem name is utils
443d8536b4Sopenharmony_ci * @param        : module name is utilsFile
453d8536b4Sopenharmony_ci * @param        : test suit name is CmsisTaskFuncTestSuite
463d8536b4Sopenharmony_ci */
473d8536b4Sopenharmony_ciLITE_TEST_SUIT(Posix, Posixtimer, PosixStdlibStrtolTest);
483d8536b4Sopenharmony_ci
493d8536b4Sopenharmony_ci/* *
503d8536b4Sopenharmony_ci * @tc.setup     : setup for all testcases
513d8536b4Sopenharmony_ci * @return       : setup result, TRUE is success, FALSE is fail
523d8536b4Sopenharmony_ci */
533d8536b4Sopenharmony_cistatic BOOL PosixStdlibStrtolTestSetUp(void)
543d8536b4Sopenharmony_ci{
553d8536b4Sopenharmony_ci    return TRUE;
563d8536b4Sopenharmony_ci}
573d8536b4Sopenharmony_ci
583d8536b4Sopenharmony_ci/* *
593d8536b4Sopenharmony_ci * @tc.teardown  : teardown for all testcases
603d8536b4Sopenharmony_ci * @return       : teardown result, TRUE is success, FALSE is fail
613d8536b4Sopenharmony_ci */
623d8536b4Sopenharmony_cistatic BOOL PosixStdlibStrtolTestTearDown(void)
633d8536b4Sopenharmony_ci{
643d8536b4Sopenharmony_ci    LOG("+-------------------------------------------+\n");
653d8536b4Sopenharmony_ci    return TRUE;
663d8536b4Sopenharmony_ci}
673d8536b4Sopenharmony_ci
683d8536b4Sopenharmony_ci/* *
693d8536b4Sopenharmony_ci * @tc.number    : TEST_STDLIB_STRTOL_001
703d8536b4Sopenharmony_ci * @tc.name      : convert string to long integer
713d8536b4Sopenharmony_ci * @tc.desc      : [C- SOFTWARE -0200]
723d8536b4Sopenharmony_ci */
733d8536b4Sopenharmony_ciLITE_TEST_CASE(PosixStdlibStrtolTest, testStdlibStrtol001, Function | MediumTest | Level1)
743d8536b4Sopenharmony_ci{
753d8536b4Sopenharmony_ci    char nPtr16[] = " 10";
763d8536b4Sopenharmony_ci    char *endPtr16 = NULL;
773d8536b4Sopenharmony_ci    long ret = strtol(nPtr16, &endPtr16, 16);
783d8536b4Sopenharmony_ci    if (ret == 16) {
793d8536b4Sopenharmony_ci        LOG("[DEMO] posix stdlib test case 1:strtol(base=16) ret:%ld,%s, endPtr:%s ok.\n", ret, nPtr16, endPtr16);
803d8536b4Sopenharmony_ci    } else {
813d8536b4Sopenharmony_ci        LOG("[DEMO] posix stdlib test case 1:strtol(base=16) ret:%ld,%s fail.\n", ret, nPtr16);
823d8536b4Sopenharmony_ci    }
833d8536b4Sopenharmony_ci    ICUNIT_ASSERT_EQUAL(ret, 16, ret);
843d8536b4Sopenharmony_ci    ICUNIT_ASSERT_STRING_EQUAL(endPtr16, "", 0);
853d8536b4Sopenharmony_ci    return 0;
863d8536b4Sopenharmony_ci}
873d8536b4Sopenharmony_ci
883d8536b4Sopenharmony_ci/* *
893d8536b4Sopenharmony_ci * @tc.number    : TEST_STDLIB_STRTOL_002
903d8536b4Sopenharmony_ci * @tc.name      : convert string to long integer
913d8536b4Sopenharmony_ci * @tc.desc      : [C- SOFTWARE -0200]
923d8536b4Sopenharmony_ci */
933d8536b4Sopenharmony_ciLITE_TEST_CASE(PosixStdlibStrtolTest, testStdlibStrtol002, Function | MediumTest | Level1)
943d8536b4Sopenharmony_ci{
953d8536b4Sopenharmony_ci    char nPtr16[] = "0x10";
963d8536b4Sopenharmony_ci    char *endPtr16 = NULL;
973d8536b4Sopenharmony_ci    long ret = strtol(nPtr16, &endPtr16, 0);
983d8536b4Sopenharmony_ci    if (ret == 16) {
993d8536b4Sopenharmony_ci        LOG("[DEMO] posix stdlib test case 2:strtol(base=16) ret:%ld,%s, endPtr:%s ok.\n", ret, nPtr16, endPtr16);
1003d8536b4Sopenharmony_ci    } else {
1013d8536b4Sopenharmony_ci        LOG("[DEMO] posix stdlib test case 2:strtol(base=16) ret:%ld,%s fail.\n", ret, nPtr16);
1023d8536b4Sopenharmony_ci    }
1033d8536b4Sopenharmony_ci    ICUNIT_ASSERT_EQUAL(ret, 16, ret);
1043d8536b4Sopenharmony_ci    ICUNIT_ASSERT_STRING_EQUAL(endPtr16, "", 0);
1053d8536b4Sopenharmony_ci    return 0;
1063d8536b4Sopenharmony_ci}
1073d8536b4Sopenharmony_ci
1083d8536b4Sopenharmony_ci/* *
1093d8536b4Sopenharmony_ci * @tc.number    : TEST_STDLIB_STRTOL_003
1103d8536b4Sopenharmony_ci * @tc.name      : convert string to long integer
1113d8536b4Sopenharmony_ci * @tc.desc      : [C- SOFTWARE -0200]
1123d8536b4Sopenharmony_ci */
1133d8536b4Sopenharmony_ciLITE_TEST_CASE(PosixStdlibStrtolTest, testStdlibStrtol003, Function | MediumTest | Level1)
1143d8536b4Sopenharmony_ci{
1153d8536b4Sopenharmony_ci    char nPtr10[] = "10";
1163d8536b4Sopenharmony_ci    char *endPtr10 = NULL;
1173d8536b4Sopenharmony_ci    long ret = strtol(nPtr10, &endPtr10, 10);
1183d8536b4Sopenharmony_ci    if (ret == 10) {
1193d8536b4Sopenharmony_ci        LOG("[DEMO] posix stdlib test case 3:strtol(base=10) ret:%ld,%s, endPtr:%s ok.\n", ret, nPtr10, endPtr10);
1203d8536b4Sopenharmony_ci    } else {
1213d8536b4Sopenharmony_ci        LOG("[DEMO] posix stdlib test case 3:strtol(base=10) ret:%ld,%s fail.\n", ret, nPtr10);
1223d8536b4Sopenharmony_ci    }
1233d8536b4Sopenharmony_ci    ICUNIT_ASSERT_EQUAL(ret, 10, ret);
1243d8536b4Sopenharmony_ci    ICUNIT_ASSERT_STRING_EQUAL(endPtr10, "", 0);
1253d8536b4Sopenharmony_ci    return 0;
1263d8536b4Sopenharmony_ci}
1273d8536b4Sopenharmony_ci
1283d8536b4Sopenharmony_ci/* *
1293d8536b4Sopenharmony_ci * @tc.number    : TEST_STDLIB_STRTOL_004
1303d8536b4Sopenharmony_ci * @tc.name      : convert string to long integer
1313d8536b4Sopenharmony_ci * @tc.desc      : [C- SOFTWARE -0200]
1323d8536b4Sopenharmony_ci */
1333d8536b4Sopenharmony_ciLITE_TEST_CASE(PosixStdlibStrtolTest, testStdlibStrtol004, Function | MediumTest | Level1)
1343d8536b4Sopenharmony_ci{
1353d8536b4Sopenharmony_ci    char nPtr10[] = "-10";
1363d8536b4Sopenharmony_ci    char *endPtr10 = NULL;
1373d8536b4Sopenharmony_ci    long ret = strtol(nPtr10, &endPtr10, 10);
1383d8536b4Sopenharmony_ci    if (ret == -10) {
1393d8536b4Sopenharmony_ci        LOG("[DEMO] posix stdlib test case 4:strtol(base=10) ret:%ld,%s, endPtr:%s ok.\n", ret, nPtr10, endPtr10);
1403d8536b4Sopenharmony_ci    } else {
1413d8536b4Sopenharmony_ci        LOG("[DEMO] posix stdlib test case 4:strtol(base=10) ret:%ld,%s fail.\n", ret, nPtr10);
1423d8536b4Sopenharmony_ci    }
1433d8536b4Sopenharmony_ci    ICUNIT_ASSERT_EQUAL(ret, -10, ret);
1443d8536b4Sopenharmony_ci    ICUNIT_ASSERT_STRING_EQUAL(endPtr10, "", 0);
1453d8536b4Sopenharmony_ci    return 0;
1463d8536b4Sopenharmony_ci}
1473d8536b4Sopenharmony_ci
1483d8536b4Sopenharmony_ci/* *
1493d8536b4Sopenharmony_ci * @tc.number    : TEST_STDLIB_STRTOL_005
1503d8536b4Sopenharmony_ci * @tc.name      : convert string to long integer
1513d8536b4Sopenharmony_ci * @tc.desc      : [C- SOFTWARE -0200]
1523d8536b4Sopenharmony_ci */
1533d8536b4Sopenharmony_ciLITE_TEST_CASE(PosixStdlibStrtolTest, testStdlibStrtol005, Function | MediumTest | Level1)
1543d8536b4Sopenharmony_ci{
1553d8536b4Sopenharmony_ci    char nPtr10_3[] = "10";
1563d8536b4Sopenharmony_ci    char *endPtr10_3 = NULL;
1573d8536b4Sopenharmony_ci    long ret = strtol(nPtr10_3, &endPtr10_3, 0);
1583d8536b4Sopenharmony_ci    if (ret == 10) {
1593d8536b4Sopenharmony_ci        LOG("[DEMO] posix stdlib test case 5:strtol(base=0) ret:%ld,%s, endPtr:%s ok.\n", ret, nPtr10_3, endPtr10_3);
1603d8536b4Sopenharmony_ci    } else {
1613d8536b4Sopenharmony_ci        LOG("[DEMO] posix stdlib test case 5:strtol(base=0) ret:%ld,%s fail.\n", ret, nPtr10_3);
1623d8536b4Sopenharmony_ci    }
1633d8536b4Sopenharmony_ci    ICUNIT_ASSERT_EQUAL(ret, 10, ret);
1643d8536b4Sopenharmony_ci    ICUNIT_ASSERT_STRING_EQUAL(endPtr10_3, "", 0);
1653d8536b4Sopenharmony_ci    return 0;
1663d8536b4Sopenharmony_ci}
1673d8536b4Sopenharmony_ci
1683d8536b4Sopenharmony_ci/* *
1693d8536b4Sopenharmony_ci * @tc.number    : TEST_STDLIB_STRTOL_006
1703d8536b4Sopenharmony_ci * @tc.name      : convert string to long integer
1713d8536b4Sopenharmony_ci * @tc.desc      : [C- SOFTWARE -0200]
1723d8536b4Sopenharmony_ci */
1733d8536b4Sopenharmony_ciLITE_TEST_CASE(PosixStdlibStrtolTest, testStdlibStrtol006, Function | MediumTest | Level1)
1743d8536b4Sopenharmony_ci{
1753d8536b4Sopenharmony_ci    char nPtr8[] = "10";
1763d8536b4Sopenharmony_ci    char *endPtr8 = NULL;
1773d8536b4Sopenharmony_ci    long ret = strtol(nPtr8, &endPtr8, 8);
1783d8536b4Sopenharmony_ci    if (ret == 8) {
1793d8536b4Sopenharmony_ci        LOG("[DEMO] posix stdlib test case 6:strtol(base=8) ret:%ld,%s, endPtr:%s ok.\n", ret, nPtr8, endPtr8);
1803d8536b4Sopenharmony_ci    } else {
1813d8536b4Sopenharmony_ci        LOG("[DEMO] posix stdlib test case 6:strtol(base=8) ret:%ld,%s fail.\n", ret, nPtr8);
1823d8536b4Sopenharmony_ci    }
1833d8536b4Sopenharmony_ci    ICUNIT_ASSERT_EQUAL(ret, 8, ret);
1843d8536b4Sopenharmony_ci    ICUNIT_ASSERT_STRING_EQUAL(endPtr8, "", 0);
1853d8536b4Sopenharmony_ci    return 0;
1863d8536b4Sopenharmony_ci}
1873d8536b4Sopenharmony_ci
1883d8536b4Sopenharmony_ci/* *
1893d8536b4Sopenharmony_ci * @tc.number    : TEST_STDLIB_STRTOL_007
1903d8536b4Sopenharmony_ci * @tc.name      : convert string to long integer
1913d8536b4Sopenharmony_ci * @tc.desc      : [C- SOFTWARE -0200]
1923d8536b4Sopenharmony_ci */
1933d8536b4Sopenharmony_ciLITE_TEST_CASE(PosixStdlibStrtolTest, testStdlibStrtol007, Function | MediumTest | Level1)
1943d8536b4Sopenharmony_ci{
1953d8536b4Sopenharmony_ci    char nPtr8_2[] = "010";
1963d8536b4Sopenharmony_ci    char *endPtr8_2 = NULL;
1973d8536b4Sopenharmony_ci    long ret = strtol(nPtr8_2, &endPtr8_2, 8);
1983d8536b4Sopenharmony_ci    if (ret == 8) {
1993d8536b4Sopenharmony_ci        LOG("[DEMO] posix stdlib test case 7:strtol(base=8) ret:%ld,%s, endPtr:%s ok.\n", ret, nPtr8_2, endPtr8_2);
2003d8536b4Sopenharmony_ci    } else {
2013d8536b4Sopenharmony_ci        LOG("[DEMO] posix stdlib test case 7:strtol(base=8) ret:%ld,%s fail.\n", ret, nPtr8_2);
2023d8536b4Sopenharmony_ci    }
2033d8536b4Sopenharmony_ci    ICUNIT_ASSERT_EQUAL(ret, 8, ret);
2043d8536b4Sopenharmony_ci    ICUNIT_ASSERT_STRING_EQUAL(endPtr8_2, "", 0);
2053d8536b4Sopenharmony_ci    return 0;
2063d8536b4Sopenharmony_ci}
2073d8536b4Sopenharmony_ci
2083d8536b4Sopenharmony_ci/* *
2093d8536b4Sopenharmony_ci * @tc.number    : TEST_STDLIB_STRTOL_008
2103d8536b4Sopenharmony_ci * @tc.name      : convert string to long integer
2113d8536b4Sopenharmony_ci * @tc.desc      : [C- SOFTWARE -0200]
2123d8536b4Sopenharmony_ci */
2133d8536b4Sopenharmony_ciLITE_TEST_CASE(PosixStdlibStrtolTest, testStdlibStrtol008, Function | MediumTest | Level1)
2143d8536b4Sopenharmony_ci{
2153d8536b4Sopenharmony_ci    char nPtr8_3[] = "010";
2163d8536b4Sopenharmony_ci    char *endPtr8_3 = NULL;
2173d8536b4Sopenharmony_ci    long ret = strtol(nPtr8_3, &endPtr8_3, 0);
2183d8536b4Sopenharmony_ci    if (ret == 8) {
2193d8536b4Sopenharmony_ci        LOG("[DEMO] posix stdlib test case 8:strtol(base=8) ret:%ld,%s, endPtr:%s ok.\n", ret, nPtr8_3, endPtr8_3);
2203d8536b4Sopenharmony_ci    } else {
2213d8536b4Sopenharmony_ci        LOG("[DEMO] posix stdlib test case 8:strtol(base=8) ret:%ld,%s fail.\n", ret, nPtr8_3);
2223d8536b4Sopenharmony_ci    }
2233d8536b4Sopenharmony_ci    ICUNIT_ASSERT_EQUAL(ret, 8, ret);
2243d8536b4Sopenharmony_ci    ICUNIT_ASSERT_STRING_EQUAL(endPtr8_3, "", 0);
2253d8536b4Sopenharmony_ci    return 0;
2263d8536b4Sopenharmony_ci}
2273d8536b4Sopenharmony_ci
2283d8536b4Sopenharmony_ci/* *
2293d8536b4Sopenharmony_ci * @tc.number    : TEST_STDLIB_STRTOL_009
2303d8536b4Sopenharmony_ci * @tc.name      : convert string to long integer
2313d8536b4Sopenharmony_ci * @tc.desc      : [C- SOFTWARE -0200]
2323d8536b4Sopenharmony_ci */
2333d8536b4Sopenharmony_ciLITE_TEST_CASE(PosixStdlibStrtolTest, testStdlibStrtol009, Function | MediumTest | Level1)
2343d8536b4Sopenharmony_ci{
2353d8536b4Sopenharmony_ci    char nPtr2[] = "10";
2363d8536b4Sopenharmony_ci    char *endPtr2 = NULL;
2373d8536b4Sopenharmony_ci    long ret = strtol(nPtr2, &endPtr2, 2);
2383d8536b4Sopenharmony_ci    if (ret == 2) {
2393d8536b4Sopenharmony_ci        LOG("[DEMO] posix stdlib test case 9:strtol(base=2) ret:%ld,%s, endPtr:%s ok.\n", ret, nPtr2, endPtr2);
2403d8536b4Sopenharmony_ci    } else {
2413d8536b4Sopenharmony_ci        LOG("[DEMO] posix stdlib test case 9:strtol(base=2) ret:%ld,%s fail.\n", ret, nPtr2);
2423d8536b4Sopenharmony_ci    }
2433d8536b4Sopenharmony_ci    ICUNIT_ASSERT_EQUAL(ret, 2, ret);
2443d8536b4Sopenharmony_ci    ICUNIT_ASSERT_STRING_EQUAL(endPtr2, "", 0);
2453d8536b4Sopenharmony_ci    return 0;
2463d8536b4Sopenharmony_ci}
2473d8536b4Sopenharmony_ci
2483d8536b4Sopenharmony_ci/* *
2493d8536b4Sopenharmony_ci * @tc.number    : TEST_STDLIB_STRTOL_010
2503d8536b4Sopenharmony_ci * @tc.name      : convert string to long integer
2513d8536b4Sopenharmony_ci * @tc.desc      : [C- SOFTWARE -0200]
2523d8536b4Sopenharmony_ci */
2533d8536b4Sopenharmony_ciLITE_TEST_CASE(PosixStdlibStrtolTest, testStdlibStrtol010, Function | MediumTest | Level1)
2543d8536b4Sopenharmony_ci{
2553d8536b4Sopenharmony_ci    char nPtr[] = "12 0110 0XDEFE 0666 -1.6";
2563d8536b4Sopenharmony_ci    char *endPtr = NULL;
2573d8536b4Sopenharmony_ci    long ret = strtol(nPtr, &endPtr, 10);
2583d8536b4Sopenharmony_ci    if (ret == 12) {
2593d8536b4Sopenharmony_ci        LOG("[DEMO] posix stdlib test case 10:strtol(base=10) ret:%ld, %s, endPtr:%s ok.\n", ret, endPtr, endPtr);
2603d8536b4Sopenharmony_ci    } else {
2613d8536b4Sopenharmony_ci        LOG("[DEMO] posix stdlib test case 10:strtol(base=10) ret:%ld, %s fail.\n", ret, endPtr);
2623d8536b4Sopenharmony_ci    }
2633d8536b4Sopenharmony_ci    ICUNIT_ASSERT_EQUAL(ret, 12, ret);
2643d8536b4Sopenharmony_ci    ICUNIT_ASSERT_STRING_EQUAL(endPtr, " 0110 0XDEFE 0666 -1.6", 0);
2653d8536b4Sopenharmony_ci    return 0;
2663d8536b4Sopenharmony_ci}
2673d8536b4Sopenharmony_ci
2683d8536b4Sopenharmony_ci#if (LOSCFG_LIBC_MUSL == 1)
2693d8536b4Sopenharmony_ci/* *
2703d8536b4Sopenharmony_ci * @tc.number    : TEST_STDLIB_STRTOL_011
2713d8536b4Sopenharmony_ci * @tc.name      : convert string to long integer
2723d8536b4Sopenharmony_ci * @tc.desc      : [C- SOFTWARE -0200]
2733d8536b4Sopenharmony_ci */
2743d8536b4Sopenharmony_ciLITE_TEST_CASE(PosixStdlibStrtolTest, testStdlibStrtol011, Function | MediumTest | Level1)
2753d8536b4Sopenharmony_ci{
2763d8536b4Sopenharmony_ci    char nPtr[] = "12 1.5";
2773d8536b4Sopenharmony_ci    char *endPtr = NULL;
2783d8536b4Sopenharmony_ci    long ret = strtol(nPtr, &endPtr, 65);
2793d8536b4Sopenharmony_ci    if (ret == 0) {
2803d8536b4Sopenharmony_ci        LOG("[DEMO] posix stdlib test case 11:strtol(base=65) ret:%ld, %s, endPtr:%s ok.\n", ret, endPtr, endPtr);
2813d8536b4Sopenharmony_ci    } else {
2823d8536b4Sopenharmony_ci        LOG("[DEMO] posix stdlib test case 11:strtol(base=65) ret:%ld, %s fail.\n", ret, endPtr);
2833d8536b4Sopenharmony_ci    }
2843d8536b4Sopenharmony_ci    ICUNIT_ASSERT_EQUAL(ret, 0, ret);
2853d8536b4Sopenharmony_ci    ICUNIT_ASSERT_STRING_EQUAL(endPtr, "12 1.5", 0);
2863d8536b4Sopenharmony_ci    return 0;
2873d8536b4Sopenharmony_ci}
2883d8536b4Sopenharmony_ci#endif
2893d8536b4Sopenharmony_ci
2903d8536b4Sopenharmony_ciLITE_TEST_CASE(PosixStdlibStrtolTest, testStdlibStrtol012, Function | MediumTest | Level1)
2913d8536b4Sopenharmony_ci{
2923d8536b4Sopenharmony_ci    char nPtr[] = "2147483647 -2147483648";
2933d8536b4Sopenharmony_ci    char *endPtr = NULL;
2943d8536b4Sopenharmony_ci    long ret = strtol(nPtr, &endPtr, 10);
2953d8536b4Sopenharmony_ci    if (ret == 2147483647) {
2963d8536b4Sopenharmony_ci        LOG("[DEMO] posix stdlib test case 12:strtol(base=10) ret:%ld, %s, endPtr:%s ok.\n", ret, endPtr, endPtr);
2973d8536b4Sopenharmony_ci    } else {
2983d8536b4Sopenharmony_ci        LOG("[DEMO] posix stdlib test case 12:strtol(base=10) ret:%ld, %s fail.\n", ret, endPtr);
2993d8536b4Sopenharmony_ci    }
3003d8536b4Sopenharmony_ci    ICUNIT_ASSERT_EQUAL(ret, 2147483647, ret);
3013d8536b4Sopenharmony_ci    ICUNIT_ASSERT_STRING_EQUAL(endPtr, " -2147483648", 0);
3023d8536b4Sopenharmony_ci    return 0;
3033d8536b4Sopenharmony_ci}
3043d8536b4Sopenharmony_ci
3053d8536b4Sopenharmony_ci/* *
3063d8536b4Sopenharmony_ci * @tc.number    : TEST_STDLIB_ATOL_002
3073d8536b4Sopenharmony_ci * @tc.name      : convert string to long integer
3083d8536b4Sopenharmony_ci * @tc.desc      : [C- SOFTWARE -0200]
3093d8536b4Sopenharmony_ci */
3103d8536b4Sopenharmony_ciLITE_TEST_CASE(PosixStdlibStrtolTest, testStdlibStrtol013, Function | MediumTest | Level1)
3113d8536b4Sopenharmony_ci{
3123d8536b4Sopenharmony_ci    char nPtr[] = " -2147483648";
3133d8536b4Sopenharmony_ci    char *endPtr = NULL;
3143d8536b4Sopenharmony_ci    long ret = strtol(nPtr, &endPtr, 10);
3153d8536b4Sopenharmony_ci    if (ret == -2147483648) {
3163d8536b4Sopenharmony_ci        LOG("[DEMO] posix stdlib test case 13:strtol(base=10) ret:%ld, %s, endPtr:%s ok.\n", ret, endPtr, endPtr);
3173d8536b4Sopenharmony_ci    } else {
3183d8536b4Sopenharmony_ci        LOG("[DEMO] posix stdlib test case 13:strtol(base=10) ret:%ld, %s fail.\n", ret, endPtr);
3193d8536b4Sopenharmony_ci    }
3203d8536b4Sopenharmony_ci    ICUNIT_ASSERT_EQUAL(ret, -2147483648, ret);
3213d8536b4Sopenharmony_ci    ICUNIT_ASSERT_STRING_EQUAL(endPtr, "", 0);
3223d8536b4Sopenharmony_ci    return 0;
3233d8536b4Sopenharmony_ci}
3243d8536b4Sopenharmony_ci
3253d8536b4Sopenharmony_ciRUN_TEST_SUITE(PosixStdlibStrtolTest);
3263d8536b4Sopenharmony_ci
3273d8536b4Sopenharmony_civoid PosixStdlibStrtolFuncTest()
3283d8536b4Sopenharmony_ci{
3293d8536b4Sopenharmony_ci    LOG("begin PosixStdlibStrtolFuncTest....");
3303d8536b4Sopenharmony_ci    RUN_ONE_TESTCASE(testStdlibStrtol001);
3313d8536b4Sopenharmony_ci    RUN_ONE_TESTCASE(testStdlibStrtol002);
3323d8536b4Sopenharmony_ci    RUN_ONE_TESTCASE(testStdlibStrtol003);
3333d8536b4Sopenharmony_ci    RUN_ONE_TESTCASE(testStdlibStrtol004);
3343d8536b4Sopenharmony_ci    RUN_ONE_TESTCASE(testStdlibStrtol005);
3353d8536b4Sopenharmony_ci    RUN_ONE_TESTCASE(testStdlibStrtol006);
3363d8536b4Sopenharmony_ci    RUN_ONE_TESTCASE(testStdlibStrtol007);
3373d8536b4Sopenharmony_ci    RUN_ONE_TESTCASE(testStdlibStrtol008);
3383d8536b4Sopenharmony_ci    RUN_ONE_TESTCASE(testStdlibStrtol009);
3393d8536b4Sopenharmony_ci    RUN_ONE_TESTCASE(testStdlibStrtol010);
3403d8536b4Sopenharmony_ci#if (LOSCFG_LIBC_MUSL == 1)
3413d8536b4Sopenharmony_ci    RUN_ONE_TESTCASE(testStdlibStrtol011);
3423d8536b4Sopenharmony_ci#endif
3433d8536b4Sopenharmony_ci    RUN_ONE_TESTCASE(testStdlibStrtol012);
3443d8536b4Sopenharmony_ci    RUN_ONE_TESTCASE(testStdlibStrtol013);
3453d8536b4Sopenharmony_ci
3463d8536b4Sopenharmony_ci    return;
3473d8536b4Sopenharmony_ci}