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 <stdarg.h>
17 #include <stdio.h>
18 #include <string.h>
19 #include "test.h"
20
21 /**
22 * @tc.name : vprintf_0100
23 * @tc.desc : Send formatted output to standard output with %d
24 * @tc.level : Level 0
25 */
vprintf_0100(char * format,...)26 void vprintf_0100(char *format, ...)
27 {
28 va_list args;
29 va_start(args, format);
30 int result = vprintf(format, args);
31 va_end(args);
32 if (result < 0) {
33 t_error("%s vprintf get result is less than 0", __func__);
34 }
35 char *want = "This is the 1th test for vprintf";
36 int len = strlen(want);
37 if (result != len) {
38 t_error("%s vprintf get wrong result, want %s", __func__, want);
39 }
40 }
41
42 /**
43 * @tc.name : vprintf_0200
44 * @tc.desc : Send formatted output to standard output whit %s
45 * @tc.level : Level 1
46 */
vprintf_0200(char * format,...)47 void vprintf_0200(char *format, ...)
48 {
49 va_list args;
50 va_start(args, format);
51 int result = vprintf(format, args);
52 va_end(args);
53 if (result < 0) {
54 t_error("%s vprintf get result is less than 0", __func__);
55 }
56 char *want = "This is the 2th test for vprintf";
57 int len = strlen(want);
58 if (result != len) {
59 t_error("%s vprintf get wrong result, want %s", __func__, want);
60 }
61 }
62
main(int argc,char * argv[])63 int main(int argc, char *argv[])
64 {
65 vprintf_0100("This is the %dth test for vprintf", 1);
66 vprintf_0200("This is the 2th test for %s", "vprintf");
67 return t_status;
68 }