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 <stdio.h>
17 #include <stdlib.h>
18 #include "functionalext.h"
19
20 const int32_t SPRINTF_0100_RESULT = 4;
21 const int32_t SPRINTF_0200_RESULT = 5;
22 const int32_t SPRINTF_0300_RESULT = 19;
23 const int32_t SECOND_PARAM = 2;
24 const int32_t THIRD_PARAM = 12345;
25
26 /**
27 * @tc.name : sprintf_0100
28 * @tc.desc : Verify sprintf process success with two params
29 * @tc.level : Level 0
30 */
sprintf_0100(void)31 void sprintf_0100(void)
32 {
33 char str[1024];
34 int ret = sprintf(str, "test");
35 EXPECT_EQ("sprintf_0100", ret, SPRINTF_0100_RESULT);
36 EXPECT_STREQ("sprintf_0100", str, "test");
37 }
38
39 /**
40 * @tc.name : sprintf_0200
41 * @tc.desc : Verify sprintf process success with three params(the thrid praram type is int_32)
42 * @tc.level : Level 0
43 */
sprintf_0200(void)44 void sprintf_0200(void)
45 {
46 char str[1024];
47 int ret = sprintf(str, "test%d", SECOND_PARAM);
48 EXPECT_EQ("sprintf_0200", ret, SPRINTF_0200_RESULT);
49 EXPECT_STREQ("sprintf_0200", str, "test2");
50 }
51
52 /**
53 * @tc.name : sprintf_0300
54 * @tc.desc : Verify sprintf process success with three params(the thrid praram type is string)
55 * @tc.level : Level 0
56 */
sprintf_0300(void)57 void sprintf_0300(void)
58 {
59 char str[1024];
60 int ret = sprintf(str, "testname:%s%d", "test3", THIRD_PARAM);
61 EXPECT_EQ("sprintf_0300", ret, SPRINTF_0300_RESULT);
62 EXPECT_STREQ("sprintf_0300", str, "testname:test312345");
63 }
64
main(void)65 int main(void)
66 {
67 sprintf_0100();
68 sprintf_0200();
69 sprintf_0300();
70 return t_status;
71 }
72