IoTestWchar.cpp 16.7 KB
Newer Older
N
nanxiansen 已提交
1 2 3
/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
 */
M
mamingshuai 已提交
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
/*
 * Copyright (c) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <stdarg.h>

#include <wchar.h>

#include "IoTest.h"
#include <securec.h>

using namespace testing::ext;


int FormatVfwscanf(FILE *fp, const wchar_t *format, ...)
{
    va_list args;
    va_start(args, format);
    int ret = vfwscanf(fp, format, args);
    va_end(args);
    return ret;
}

int FormatVfwprintf(FILE *fp, const wchar_t *format, ...)
{
    va_list args;
    va_start(args, format);
    int ret = vfwprintf(fp, format, args);
    va_end(args);
    return ret;
}

/**
 * @tc.number SUB_KERNEL_IO_WCHAR_0100
 * @tc.name   vfwprintf basic function test
 * @tc.desc   [C- SOFTWARE -0200]
 */
HWTEST_F(IoTest, testVfwprintf, Function | MediumTest | Level1)
{
    FILE *fp = nullptr;
    FOPEN_WRITE(fp);
    int ret = FormatVfwprintf(fp, L"%s has %d words ", "helloworld", 10);
    EXPECT_EQ(ret, 24);
    ASSERT_NE(fclose(fp), -1) << "> fclose fail, errno = " << errno;

    FOPEN_READ(fp);
    wchar_t wStr[50] = {0};
    int i;
    ret = FormatVfwscanf(fp, L"%ls has %d words ", wStr, &i);
    EXPECT_EQ(ret, 2) << "> vfwscanf return fail, errno = " << errno;
    EXPECT_STREQ(wStr, L"helloworld");
    EXPECT_EQ(i, 10);

    ASSERT_NE(fclose(fp), -1) << "> fclose fail, errno = "<< errno;
}

/**
 * @tc.number SUB_KERNEL_IO_WCHAR_0200
 * @tc.name   fwprintf basic function test
 * @tc.desc   [C- SOFTWARE -0200]
 */
HWTEST_F(IoTest, testFwprintf, Function | MediumTest | Level1)
{
    FILE *fp = nullptr;
    FOPEN_WRITE(fp);
    int ret = fwprintf(fp, L"%s has %d words ", "helloworld", 10);
    EXPECT_EQ(ret, 24);
    ASSERT_NE(fclose(fp), -1) << "> fclose fail, errno = " << errno;

    FOPEN_READ(fp);
    wchar_t wStr[50] = {0};
    int i;
    ret = fwscanf(fp, L"%ls has %d words ", wStr, &i);
    EXPECT_EQ(ret, 2) << "> vfwscanf return fail, errno = " << errno;
    EXPECT_STREQ(wStr, L"helloworld");
    EXPECT_EQ(i, 10);

    ASSERT_NE(fclose(fp), -1) << "> fclose fail, errno = "<< errno;
}

/**
 * @tc.number SUB_KERNEL_IO_WCHAR_0300
 * @tc.name   fwide basic function test
 * @tc.desc   [C- SOFTWARE -0200]
 */
HWTEST_F(IoTest, testFwide, Function | MediumTest | Level1)
{
    FILE *fp = nullptr;
    INIT_TEST_FILE(fp);
    FOPEN_READ(fp);
    int ret = fwide(fp, -6);
    EXPECT_EQ(ret, -1);
    ASSERT_NE(fclose(fp), -1) << "> fclose fail, errno = "<< errno;

    FOPEN_READ(fp);
    ret = fwide(fp, 0);
    EXPECT_EQ(ret, 0);
    ASSERT_NE(fclose(fp), -1) << "> fclose fail, errno = "<< errno;

    FOPEN_READ(fp);
    ret = fwide(fp, 8);
    EXPECT_EQ(ret, 1);
    ASSERT_NE(fclose(fp), -1) << "> fclose fail, errno = "<< errno;
}

/**
 * @tc.number SUB_KERNEL_IO_WCHAR_0400
 * @tc.name   fgetws basic function test
 * @tc.desc   [C- SOFTWARE -0200]
 */
HWTEST_F(IoTest, testFgetws, Function | MediumTest | Level1)
{
    FILE *fp = nullptr;
    FOPEN_WRITE(fp);
    wchar_t wStr[50] = {0};
    wchar_t wStrT[50] = L"hello world";
    int ret = fputws(wStrT, fp);
    ASSERT_NE(ret, -1) << "> fputws fail, errno = " << errno;
    ASSERT_NE(fclose(fp), -1) << "> fclose fail, errno = "<< errno;

    FOPEN_READ(fp);
N
nanxiansen 已提交
136
    wchar_t *retW = fgetws(wStr, sizeof(wStr)/sizeof(wStr[0]), fp);
M
mamingshuai 已提交
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
    EXPECT_STREQ(retW, wStrT);
    ASSERT_NE(fclose(fp), -1) << "> fclose fail, errno = "<< errno;
}

/**
 * @tc.number SUB_KERNEL_IO_WCHAR_0500
 * @tc.name   putwc basic function test
 * @tc.desc   [C- SOFTWARE -0200]
 */
HWTEST_F(IoTest, testPutwc, Function | MediumTest | Level1)
{
    FILE *fp = nullptr;
    FOPEN_WRITE(fp);
    wint_t ret = putwc(L'A', fp);
    EXPECT_EQ(ret, L'A');
    ASSERT_NE(fclose(fp), -1) << "> fclose fail, errno = " << errno;

    FOPEN_READ(fp);
    ret = getwc(fp);
    EXPECT_EQ(ret, L'A');
    EXPECT_NE(fclose(fp), -1) << "> fclose fail, errno = " << errno;
}

/**
 * @tc.number SUB_KERNEL_IO_WCHAR_0600
 * @tc.name   ungetwc basic function test
 * @tc.desc   [C- SOFTWAret -0200]
 */
HWTEST_F(IoTest, testUngetwc, Function | MediumTest | Level1)
{
    FILE *fp = nullptr;
    INIT_TEST_FILE(fp);
    FOPEN_READ(fp);
    wint_t ret = getwc(fp);
    EXPECT_EQ(ret, 104U);
    ret = ungetc(ret, fp);
    EXPECT_EQ(ret, 104U);
    wchar_t str[50] = {0};
N
nanxiansen 已提交
175
    wchar_t *retS = fgetws(str, sizeof(str)/sizeof(str[0]), fp);
M
mamingshuai 已提交
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
    EXPECT_STREQ(retS, str);
    EXPECT_STREQ(str, L"hello world");
    EXPECT_NE(fclose(fp), -1) << "> fclose fail, errno = " << errno;
}

/**
 * @tc.number SUB_KERNEL_IO_WCHAR_0700
 * @tc.name   fputwc basic function test
 * @tc.desc   [C- SOFTWARE -0200]
 */
HWTEST_F(IoTest, testFputwc, Function | MediumTest | Level1)
{
    FILE *fp = nullptr;
    FOPEN_WRITE(fp);
    wint_t ret = fputwc(L'A', fp);
    EXPECT_EQ(ret, L'A');
    ASSERT_NE(fclose(fp), -1) << "> fclose fail, errno = " << errno;

    FOPEN_READ(fp);
    ret = fgetwc(fp);
    EXPECT_EQ(ret, L'A');
    ASSERT_NE(fclose(fp), -1) << "> fclose fail, errno = " << errno;
}

/**
 * @tc.number SUB_KERNEL_IO_WCHAR_0800
 * @tc.name   fwscanf basic function test
 * @tc.desc   [C- SOFTWARE -0200]
 */
HWTEST_F(IoTest, testFwscanf, Function | MediumTest | Level1)
{
    FILE *fp = nullptr;
    FOPEN_WRITE(fp);
    int ret = fwprintf(fp, L"%ls has %d words", L"helloworld", 10);
    EXPECT_EQ(ret, 23);
    EXPECT_NE(fclose(fp), -1) << "> fclose fail, errno = "<< errno;

    FOPEN_READ(fp);
    wchar_t wStr[50] = {0};
    int i;
    ret = fwscanf(fp, L"%ls has %d words", wStr, &i);
    EXPECT_EQ(ret, 2);
    EXPECT_EQ(i, 10);
    EXPECT_STREQ(wStr, L"helloworld");
    ASSERT_NE(fclose(fp), -1) << "> fclose fail, errno = "<< errno;
}

/**
 * @tc.number SUB_KERNEL_IO_WCHAR_0900
 * @tc.name   wmemset  basic function test
 * @tc.desc   [C- SOFTWARE -0200]
 */
HWTEST_F(IoTest, testWmemset, Function | MediumTest | Level1)
{
    wchar_t dest[50] = {0};
    wchar_t *ret = wmemset(dest, L'=', 8);
    EXPECT_STREQ(ret, dest);
    EXPECT_STREQ(dest, L"========");

    ret = wmemset(dest, L' ', 8);
    EXPECT_STREQ(ret, dest);
    EXPECT_STREQ(dest, L"        ");

    ret = wmemset(dest, L'!', 0);
    EXPECT_STREQ(ret, dest);
    EXPECT_STREQ(dest, L"        ");
}

/**
 * @tc.number SUB_KERNEL_IO_WCHAR_1000
 * @tc.name   wmemchr basic function test
 * @tc.desc   [C- SOFTWARE -0200]
 */
HWTEST_F(IoTest, testWmemchr, Function | MediumTest | Level1)
{
    wchar_t src[] = L"hello world";
N
nanxiansen 已提交
252
    wchar_t *ret = wmemchr(src, L' ', sizeof(src)/sizeof(src[0]) - 1);
M
mamingshuai 已提交
253 254 255
    EXPECT_STREQ(ret, L" world");

    wchar_t srcT[] = L"this is string";
N
nanxiansen 已提交
256
    ret = wmemchr(srcT, L'?', sizeof(srcT)/sizeof(srcT[0]) - 1);
M
mamingshuai 已提交
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336
    EXPECT_STREQ(ret, nullptr);
}

/**
 * @tc.number SUB_KERNEL_IO_WCHAR_1100
 * @tc.name   wmemcpy basic function test
 * @tc.desc   [C- SOFTWARE -0200]
 */
HWTEST_F(IoTest, testWmemcpy, Function | MediumTest | Level1)
{
    wchar_t src[] = L"hello";
    wchar_t dest[] = L"world ! ! !";
    wchar_t *ret = wmemcpy(dest, src, 5);
    EXPECT_STREQ(ret, L"hello ! ! !");

    wchar_t srcT[] = L"this is";
    wchar_t destT[] = L"string";
    ret = wmemcpy(destT, srcT, 0);
    EXPECT_STREQ(ret, destT);
}

/**
 * @tc.number SUB_KERNEL_IO_WCHAR_1200
 * @tc.name   wmemmove basic function test
 * @tc.desc   [C- SOFTWARE -0200]
 */
HWTEST_F(IoTest, testWmemmove, Function | MediumTest | Level1)
{
    wchar_t src[] = L"hello";
    wchar_t dest[] = L"world ! ! !";
    wchar_t *ret = wmemmove(dest, src, 5);
    EXPECT_STREQ(ret, L"hello ! ! !");

    wchar_t srcT[] = L"this is";
    wchar_t destT[] = L"string";
    ret = wmemmove(destT, srcT, 0);
    EXPECT_STREQ(ret, destT);
}

/**
 * @tc.number SUB_KERNEL_IO_WCHAR_1300
 * @tc.name   putwchar basic function test
 * @tc.desc   [C- SOFTWARE -0200]
 */
HWTEST_F(IoTest, testPutwchar, Function | MediumTest | Level1)
{
    for (wchar_t wc = L'A'; wc <= L'Z'; ++wc) {
        wint_t ret = putwchar(wc);
        EXPECT_EQ(ret, wc);
    }
}

/**
 * @tc.number SUB_KERNEL_IO_WCHAR_1400
 * @tc.name   wmemcmp basic function test
 * @tc.desc   [C- SOFTWARE -0200]
 */
HWTEST_F(IoTest, testWmemcmp, Function | MediumTest | Level1)
{
    wchar_t dest[] = L"BBCDEFG";
    wchar_t src[] = L"CBCDEFF";
    int ret = wmemcmp(dest, src, 7);
    EXPECT_LT(ret, 0);

    ret = wmemcmp(L"abcdefg", L"ABCDEFG", 2);
    EXPECT_GT(ret, 0);

    ret = wmemcmp(L"ABCDEFG", L"ABCDEFG", 6);
    EXPECT_EQ(ret, 0);
}

/**
 * @tc.number SUB_KERNEL_IO_WCHAR_1500
 * @tc.name   mbsinit basic function test
 * @tc.desc   [C- SOFTWARE -0200]
 */
HWTEST_F(IoTest, testMbsinit, Function | MediumTest | Level1)
{
    mbstate_t *ps = nullptr;
    int ret = mbsinit(ps);
L
limeng151 已提交
337
    int memRet = -1;
M
mamingshuai 已提交
338 339 340
    EXPECT_NE(ret, 0);

    mbstate_t psF;
L
limeng151 已提交
341 342
    memRet = memset_s(&psF, sizeof(psF), 0, sizeof(psF));
    EXPECT_EQ(0, memRet);
M
mamingshuai 已提交
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360
    ret = mbsinit(&psF);
    EXPECT_NE(ret, 0);
}

int FormatVswscanf(const wchar_t *str, const wchar_t *format, ...)
{
    va_list args;
    va_start(args, format);
    int ret = vswscanf(str, format, args);
    va_end(args);
    return ret;
}

int FormatVswprintf(const wchar_t *format, ...)
{
    va_list args;
    va_start(args, format);
    wchar_t str[50] = {0};
N
nanxiansen 已提交
361
    int ret = vswprintf(str, sizeof(str)/sizeof(str[0]), format, args);
M
mamingshuai 已提交
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393
    fputws(str, stdout);
    va_end(args);
    return ret;
}

/**
 * @tc.number SUB_KERNEL_IO_WCHAR_1600
 * @tc.name   vswprintf basic function test
 * @tc.desc   [C- SOFTWARE -0200]
 */
HWTEST_F(IoTest, testVswprintf, Function | MediumTest | Level1)
{
    int ret = FormatVswprintf(L"%ls has %d words", L"helloworld", 10);
    EXPECT_EQ(ret, 23);

    int i;
    wchar_t wBuf[50] = {0};
    wchar_t str[] = L"helloworld has 10 words";
    ret = FormatVswscanf(str, L"%ls has %d words", wBuf, &i);
    EXPECT_EQ(ret, 2) << "> vswcanf return fail, errno = " << errno;
    EXPECT_STREQ(wBuf, L"helloworld");
    EXPECT_EQ(i, 10);
}

/**
 * @tc.number SUB_KERNEL_IO_WCHAR_1700
 * @tc.name   swprintf basic function test
 * @tc.desc   [C- SOFTWARE -0200]
 */
HWTEST_F(IoTest, testSwprintf, Function | MediumTest | Level1)
{
    wchar_t wBuf[50] = {0};
N
nanxiansen 已提交
394
    int ret = swprintf(wBuf, sizeof(wBuf)/sizeof(wBuf[0]), L"%ls has %d words", L"helloworld", 10);
M
mamingshuai 已提交
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436
    EXPECT_EQ(ret, 23);
    EXPECT_STREQ(wBuf, L"helloworld has 10 words");

    wchar_t wStr[50] = {0};
    int i;
    ret = swscanf(wBuf, L"%ls has %d words", wStr, &i);
    EXPECT_EQ(ret, 2) << "> swscanf return fail, errno = " << errno;
    EXPECT_EQ(i, 10);
    EXPECT_STREQ(wStr, L"helloworld");
}

/**
 * @tc.number SUB_KERNEL_IO_WCHAR_1800
 * @tc.name   wprintf basic function test
 * @tc.desc   [C- SOFTWARE -0200]
 */
HWTEST_F(IoTest, testWprintf, Function | MediumTest | Level1)
{
    pid_t pid = fork();
    ASSERT_TRUE(pid >= 0) << "======== Fork Error! =========";
    if (pid == 0) { // child
        int rt = 0;
        FILE *fp = freopen(IOTEST_TEMPFILE, "w", stdout);
        if (fp == nullptr) {
            LOG("freopen fail, errno = %d", errno);
            rt = 1;
        }
        if (wprintf(L"%ls %d", L"helloworld", 10) != 13) {
            LOG("wprintf fail, errno = %d", errno);
            rt = 1;
        }
        if (fclose(fp) == -1) {
            LOG("fclose fail, errno = %d", errno);
            rt = 1;
        }
        exit(rt);
    } else { // parent
        WaitProcExitedOK(pid);

        FILE *fp1 = fopen(IOTEST_TEMPFILE, "r");
        ASSERT_NE(fp1, nullptr) << "fopen fail, errno = " << errno;
        wchar_t str[50] = {0};
N
nanxiansen 已提交
437
        wchar_t *gStr = fgetws(str, sizeof(str)/sizeof(str[0]), fp1);
M
mamingshuai 已提交
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519
        EXPECT_STREQ(gStr, str) << "fgetws fail, errno = " << errno;
        EXPECT_STREQ(str, L"helloworld 10") << "fgetws fail, errno = " << errno;
        EXPECT_NE(fclose(fp1), -1) << "> fclose fail, errno = " << errno;
    }
}

/**
 * @tc.number SUB_KERNEL_IO_WCHAR_1900
 * @tc.name   wscanf basic function test
 * @tc.desc   [C- SOFTWARE -0200]
 */
HWTEST_F(IoTest, testWscanf, Function | MediumTest | Level1)
{
    FILE  *fp = nullptr;
    INIT_TEST_FILE(fp);
    pid_t pid = fork();
    ASSERT_TRUE(pid >= 0) << "======== Fork Error! =========";
    if (pid == 0) { // child
        int rt = 0;
        FILE *fp1 = freopen(IOTEST_TEMPFILE, "r", stdin);
        if (fp1 == nullptr) {
            LOG("freopen fail, errno = %d", errno);
            rt = 1;
        }
        wchar_t str[50] = {0};
        if (wscanf(L"%ls", str) != 1) {
            LOG("wscanf fail, errno = %d", errno);
            rt = 1;
            if (wcscmp(str, L"hello world") != 0) {
                LOG("wscanf fail, errno = %d", errno);
                rt = 1;
            }
        }
        if (fclose(fp1) == -1) {
            LOG("fclose  fail, errno = %d", errno);
        }
        exit(rt);
    } else { // parent
        WaitProcExitedOK(pid);
    }
}

int FormatVwprintf(const wchar_t *format, ...)
{
    va_list argPtr;
    va_start(argPtr, format);
    int ret = vwprintf(format, argPtr);
    va_end(argPtr);
    return ret;
}

/**
 * @tc.number SUB_KERNEL_IO_WCHAR_2000
 * @tc.name   vwprintf basic function test
 * @tc.desc   [C- SOFTWARE -0200]
 */
HWTEST_F(IoTest, testVwprintf, Function | MediumTest | Level1)
{
    pid_t pid = fork();
    ASSERT_TRUE(pid >= 0) << "======== Fork Error! =========";
    if (pid == 0) { // child
        int rt = 0;
        FILE *fp = freopen(IOTEST_TEMPFILE, "w", stdout);
        if (fp == nullptr) {
            LOG("freopen fail, errno = %d", errno);
            rt = 1;
        }
        if (FormatVwprintf(L"%ls %d", L"helloworld", 10) != 13) {
            LOG("vwprintf fail, errno = %d", errno);
            rt = 1;
        }
        if (fclose(fp) == -1) {
            LOG("fclose fail, errno = %d", errno);
            rt = 1;
        }
        exit(rt);
    } else { // parent
        WaitProcExitedOK(pid);

        FILE *fp1 = fopen(IOTEST_TEMPFILE, "r");
        ASSERT_NE(fp1, nullptr) << "fopen fail, errno = " << errno;
        wchar_t str[50] = {0};
N
nanxiansen 已提交
520
        wchar_t *gStr = fgetws(str, sizeof(str)/sizeof(str[0]), fp1);
M
mamingshuai 已提交
521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618
        EXPECT_STREQ(gStr, str) << "fgetws fail, errno = " << errno;
        EXPECT_STREQ(str, L"helloworld 10") << "fgetws fail, errno = " << errno;
        EXPECT_NE(fclose(fp1), -1) << "> fclose fail, errno = " << errno;
    }
}

int FormatVwscanf(const wchar_t *format, ...)
{
    va_list argPtr;
    va_start(argPtr, format);
    int ret = vwscanf(format, argPtr);
    va_end(argPtr);
    return ret;
}

/**
 * @tc.number SUB_KERNEL_IO_WCHAR_2100
 * @tc.name   vwscanf basic function test
 * @tc.desc   [C- SOFTWARE -0200]
 */
HWTEST_F(IoTest, testVwscanf, Function | MediumTest | Level1)
{
    FILE *fp = nullptr;
    INIT_TEST_FILE(fp);
    pid_t pid = fork();
    ASSERT_TRUE(pid >= 0) << "======== Fork Error! =========";
    if (pid == 0) { // child
        int rt = 0;
        FILE *fp1 = freopen(IOTEST_TEMPFILE, "r", stdin);
        if (fp1 == nullptr) {
            LOG("freopen fail, errno = %d", errno);
            rt = 1;
        }
        wchar_t str[50] = {0};
        if (FormatVwscanf(L"%ls", str) != 1) {
            LOG("vwscanf fail, errno = %d", errno);
            rt = 1;
            if (wcscmp(str, L"hello world") != 0) {
                LOG("vwscanf fail, errno = %d", errno);
                rt = 1;
            }
        }
        if (fclose(fp1) == -1) {
            LOG("fclose fail, errno = %d", errno);
        }
        exit(rt);
    } else { // parent
        WaitProcExitedOK(pid);
    }
}

/**
 * @tc.number SUB_KERNEL_IO_WCHAR_2200
 * @tc.name   getwchar basic function test
 * @tc.desc   [C- SOFTWARE -0200]
 */
HWTEST_F(IoTest, testGetwchar, Function | MediumTest | Level1)
{
    FILE *fp = nullptr;
    INIT_TEST_FILE(fp);
    pid_t pid = fork();
    ASSERT_TRUE(pid >= 0) << "======== Fork Error! =========";
    if (pid == 0) { // child
        int rt = 0;
        FILE *fp1 = freopen(IOTEST_TEMPFILE, "r", stdin);
        if (fp1 == nullptr) {
            LOG("freopen fail, errno = %d", errno);
            rt = 1;
        }
        if (getwchar() != 104) {
            LOG("getwchar fail, errno = %d", errno);
            rt = 1;
        }
        if (fclose(fp1) == -1) {
            LOG("fclose fail, errno = %d", errno);
            rt = 1;
        }
        exit(rt);
    } else { // parent
        WaitProcExitedOK(pid);
    }
}

/**
 * @tc.number SUB_KERNEL_IO_WCHAR_2300
 * @tc.name   btowc basic function test
 * @tc.desc   [C- SOFTWARE -0200]
 */
HWTEST_F(IoTest, testBtowc, Function | MediumTest | Level1)
{
    EXPECT_EQ(btowc('6'), L'6');

    EXPECT_EQ(btowc('A'), L'A');

    EXPECT_EQ(btowc('&'), L'&');

    EXPECT_EQ(btowc(EOF), WEOF);
}