• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
3  * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice, this list of
9  *    conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice, this list
12  *    of conditions and the following disclaimer in the documentation and/or other materials
13  *    provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its contributors may be used
16  *    to endorse or promote products derived from this software without specific prior written
17  *    permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #include "ohos_types.h"
33 #include "posix_test.h"
34 #include "los_config.h"
35 #include "kernel_test.h"
36 #include <string.h>
37 #include <stdarg.h>
38 #include "log.h"
39 
40 #define RET_OK 1
41 #define MAX_ARG_NUM 2
42 #define MAX_STRING_LEN 6
43 /* *
44  * @tc.desc      : register a test suite, this suite is used to test basic flow and interface dependency
45  * @param        : subsystem name is utils
46  * @param        : module name is utilsFile
47  * @param        : test suit name is CmsisTaskFuncTestSuite
48  */
49 LITE_TEST_SUIT(Posix, Posixtimer, PosixStdargFuncTestSuite);
50 
51 /* *
52  * @tc.setup     : setup for all testcases
53  * @return       : setup result, TRUE is success, FALSE is fail
54  */
PosixStdargFuncTestSuiteSetUp(void)55 static BOOL PosixStdargFuncTestSuiteSetUp(void)
56 {
57     return TRUE;
58 }
59 
60 /* *
61  * @tc.teardown  : teardown for all testcases
62  * @return       : teardown result, TRUE is success, FALSE is fail
63  */
PosixStdargFuncTestSuiteTearDown(void)64 static BOOL PosixStdargFuncTestSuiteTearDown(void)
65 {
66     printf("==== [ Stdarg TEST ] ====\n\n");
67     return TRUE;
68 }
69 
70 
VaFunc(int argsNum,...)71 int VaFunc(int argsNum, ...)
72 {
73     va_list vaP1;
74     (void)va_start(vaP1, argsNum);
75 
76     va_list vaP2;
77     (void)va_copy(vaP2, vaP1);
78 
79     for (int i = 0; i < argsNum; i++) {
80         if (i < 1) {
81             TEST_ASSERT_EQUAL_INT(10, va_arg(vaP2, int));
82         }
83 
84         if (i == 1) {
85             TEST_ASSERT_EQUAL_INT(65, va_arg(vaP2, int));
86         }
87 
88         if (i > 1) {
89             TEST_ASSERT_EQUAL_STRING("hello world", va_arg(vaP2, char *));
90         }
91     }
92 
93     (void)va_end(vaP1);
94     (void)va_end(vaP2);
95 
96     return RET_OK;
97 }
98 
99 /* *
100  * @tc.number STDARG_API_TEST_001
101  * @tc.name   stdarg api test with not exist pid
102  * @tc.desc   [C- SOFTWARE -0200]
103  */
104 LITE_TEST_CASE(PosixStdargFuncTestSuite, testStdarg001, Function | MediumTest | Level1)
105 {
106     int ret = VaFunc(1, 10);
107     TEST_ASSERT_EQUAL_INT(RET_OK, ret);
108     return 0;
109 }
110 
111 /* *
112  * @tc.number STDARG_API_TEST_002
113  * @tc.name   stdarg api test with not exist pid
114  * @tc.desc   [C- SOFTWARE -0200]
115  */
116 LITE_TEST_CASE(PosixStdargFuncTestSuite, testStdarg002, Function | MediumTest | Level1)
117 {
118     int ret = VaFunc(2, 10, 'A');
119     TEST_ASSERT_EQUAL_INT(RET_OK, ret);
120     return 0;
121 }
122 
123 /* *
124  * @tc.number STDARG_API_TEST_003
125  * @tc.name   stdarg api test with not exist pid
126  * @tc.desc   [C- SOFTWARE -0200]
127  */
128 LITE_TEST_CASE(PosixStdargFuncTestSuite, testStdarg003, Function | MediumTest | Level1)
129 {
130     int ret = VaFunc(3, 10, 'A', "hello world");
131     TEST_ASSERT_EQUAL_INT(RET_OK, ret);
132     return 0;
133 }
134 
135 /* *
136  * @tc.number STDARG_API_TEST_003
137  * @tc.name   stdarg api test with not exist pid
138  * @tc.desc   [C- SOFTWARE -0200]
139  */
140 LITE_TEST_CASE(PosixStdargFuncTestSuite, testStdarg004, Function | MediumTest | Level1)
141 {
142     int ret = VaFunc(3, 10, 'A', "hello world", '\0');
143     TEST_ASSERT_EQUAL_INT(RET_OK, ret);
144     return 0;
145 }
146 
147 RUN_TEST_SUITE(PosixStdargFuncTestSuite);
148 
149 
PosixStdargFuncTest()150 void PosixStdargFuncTest()
151 {
152     LOG("begin PosixStdargFuncTest....");
153     RUN_ONE_TESTCASE(testStdarg001);
154     RUN_ONE_TESTCASE(testStdarg002);
155     RUN_ONE_TESTCASE(testStdarg003);
156     RUN_ONE_TESTCASE(testStdarg004);
157 
158     return;
159 }