1 /*
2 * Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification,
5 * are permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15 * to endorse or promote products derived from this software without specific prior written
16 * permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #include "xts_io.h"
32
33 LITE_TEST_SUIT(IO, IoStdio, IoStdioTestSuite);
34
IoStdioTestSuiteSetUp(void)35 static BOOL IoStdioTestSuiteSetUp(void)
36 {
37 return TRUE;
38 }
39
IoStdioTestSuiteTearDown(void)40 static BOOL IoStdioTestSuiteTearDown(void)
41 {
42 return TRUE;
43 }
44
FormatVsnptf(char * format,...)45 int FormatVsnptf(char *format, ...)
46 {
47 va_list vArgList;
48 va_start(vArgList, format);
49 char str[50] = {0}; /* 50 common data for test, no special meaning */
50 int ret = vsnprintf_s(str, sizeof(str), sizeof(str), format, vArgList);
51 va_end(vArgList);
52 return ret;
53 }
54
55 /**
56 * @tc.number SUB_KERNEL_IO_STDIO_2100
57 * @tc.name vsnprintf basic function test
58 * @tc.desc [C- SOFTWARE -0200]
59 */
60 LITE_TEST_CASE(IoStdioTestSuite, testVsnprintf, Function | MediumTest | Level1)
61 {
62 int ret = FormatVsnptf((char *)"%s has %d words", "hello world", 11); /* 11 common data for test, no special meaning */
63 ICUNIT_ASSERT_EQUAL(ret, 24, ret); /* 24 common data for test, no special meaning */
64
65 ret = FormatVsnptf((char *)"%f and %c as well as %ld\n", 2.2, 'c', 6); /* 2.2, 6 common data for test, no special meaning */
66 ICUNIT_ASSERT_EQUAL(ret, 28, ret); /* 28 common data for test, no special meaning */
67 return 0;
68 }
69
70 RUN_TEST_SUITE(IoStdioTestSuite);
71
XtsIoStdioFuncTest(void)72 void XtsIoStdioFuncTest(void)
73 {
74 RUN_ONE_TESTCASE(testVsnprintf);
75 }
76