• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <dlfcn.h>
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include "functionalext.h"
20 
21 typedef void (*TEST_FUN)();
22 
23 /**
24  * @tc.name      : asprintf_0100
25  * @tc.desc      : The parameters are valid and the data can be output according to the format
26  * @tc.level     : Level 0
27  */
asprintf_0100(void)28 void asprintf_0100(void)
29 {
30     char *buf = "d";
31     char *testStr = NULL;
32     int n;
33     n = asprintf(&testStr, "%s", buf);
34     free(testStr);
35     testStr = NULL;
36     EXPECT_TRUE("asprintf_0100", n > 0);
37 }
38 
39 /**
40  * @tc.name      : asprintf_0200
41  * @tc.desc      : The parameters are valid and the data can be output according to the format
42  * @tc.level     : Level 0
43  */
asprintf_0200(void)44 void asprintf_0200(void)
45 {
46     char *buf = "o";
47     char *testStr = NULL;
48     int n;
49     n = asprintf(&testStr, "%s", buf);
50     free(testStr);
51     testStr = NULL;
52     EXPECT_TRUE("asprintf_0200", n > 0);
53 }
54 
55 /**
56  * @tc.name      : asprintf_0300
57  * @tc.desc      : The parameters are valid and the data can be output according to the format
58  * @tc.level     : Level 0
59  */
asprintf_0300(void)60 void asprintf_0300(void)
61 {
62     char *buf = "x,X";
63     char *testStr = NULL;
64     int n;
65     n = asprintf(&testStr, "%s", buf);
66     free(testStr);
67     testStr = NULL;
68     EXPECT_TRUE("asprintf_0300", n > 0);
69 }
70 
71 /**
72  * @tc.name      : asprintf_0400
73  * @tc.desc      : The parameters are valid and the data can be output according to the format
74  * @tc.level     : Level 0
75  */
asprintf_0400(void)76 void asprintf_0400(void)
77 {
78     char *buf = "u";
79     char *testStr = NULL;
80     int n;
81     n = asprintf(&testStr, "%s", buf);
82     free(testStr);
83     testStr = NULL;
84     EXPECT_TRUE("asprintf_0400", n > 0);
85 }
86 
87 /**
88  * @tc.name      : asprintf_0500
89  * @tc.desc      : The parameters are valid and the data can be output according to the format
90  * @tc.level     : Level 0
91  */
asprintf_0500(void)92 void asprintf_0500(void)
93 {
94     char *buf = "f";
95     char *testStr = NULL;
96     int n;
97     n = asprintf(&testStr, "%s", buf);
98     free(testStr);
99     testStr = NULL;
100     EXPECT_TRUE("asprintf_0500", n > 0);
101 }
102 
103 /**
104  * @tc.name      : asprintf_0600
105  * @tc.desc      : The parameters are valid and the data can be output according to the format
106  * @tc.level     : Level 0
107  */
asprintf_0600(void)108 void asprintf_0600(void)
109 {
110     char *buf = "e,E";
111     char *testStr = NULL;
112     int n;
113     n = asprintf(&testStr, "%s", buf);
114     free(testStr);
115     testStr = NULL;
116     EXPECT_TRUE("asprintf_0600", n > 0);
117 }
118 
119 /**
120  * @tc.name      : asprintf_0700
121  * @tc.desc      : The parameters are valid and the data can be output according to the format
122  * @tc.level     : Level 0
123  */
asprintf_0700(void)124 void asprintf_0700(void)
125 {
126     char *buf = "g,G";
127     char *testStr = NULL;
128     int n;
129     n = asprintf(&testStr, "%s", buf);
130     free(testStr);
131     testStr = NULL;
132     EXPECT_TRUE("asprintf_0700", n > 0);
133 }
134 
135 /**
136  * @tc.name      : asprintf_0800
137  * @tc.desc      : The parameters are valid and the data can be output according to the format
138  * @tc.level     : Level 0
139  */
asprintf_0800(void)140 void asprintf_0800(void)
141 {
142     char *buf = "c";
143     char *testStr = NULL;
144     int n;
145     n = asprintf(&testStr, "%s", buf);
146     free(testStr);
147     testStr = NULL;
148     EXPECT_TRUE("asprintf_0800", n > 0);
149 }
150 
151 /**
152  * @tc.name      : asprintf_0900
153  * @tc.desc      : The parameters are valid and the data can be output according to the format
154  * @tc.level     : Level 0
155  */
asprintf_0900(void)156 void asprintf_0900(void)
157 {
158     char *buf = "s";
159     char *testStr = NULL;
160     int n;
161     n = asprintf(&testStr, "%s", buf);
162     free(testStr);
163     testStr = NULL;
164     EXPECT_TRUE("asprintf_0900", n > 0);
165 }
166 
167 TEST_FUN G_Fun_Array[] = {
168     asprintf_0100,
169     asprintf_0200,
170     asprintf_0300,
171     asprintf_0400,
172     asprintf_0500,
173     asprintf_0600,
174     asprintf_0700,
175     asprintf_0800,
176     asprintf_0900,
177 };
178 
main(int argc,char * argv[])179 int main(int argc, char *argv[])
180 {
181     int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN);
182     for (int pos = 0; pos < num; ++pos) {
183         G_Fun_Array[pos]();
184     }
185 
186     return t_status;
187 }