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 <string.h>
18 #include "test.h"
19
20 /**
21 * @tc.name : tempnam_0100
22 * @tc.desc : Call the tempnam method to generate a temporary file
23 * @tc.level : Level 0
24 */
tempnam_0100(void)25 void tempnam_0100(void)
26 {
27 char *dir = "/data";
28 char *pte = "temp";
29 char *result = tempnam(dir, pte);
30 if (!result) {
31 t_error("%s tempnam error cannot create temp file\n", __func__);
32 }
33 if (!strstr(result, pte)) {
34 t_error("%s tempnam get result not contain %s\n", __func__, pte);
35 }
36 }
37
38 /**
39 * @tc.name : tempnam_0200
40 * @tc.desc : test tempnam is the result when pfx is empty
41 * @tc.level : Level 1
42 */
tempnam_0200(void)43 void tempnam_0200(void)
44 {
45 char *dir = "/data";
46 char *pte = NULL;
47 char *result = tempnam(dir, pte);
48 if (!result) {
49 t_error("%s tempnam error cannot create temp file\n", __func__);
50 }
51 }
52
53 /**
54 * @tc.name : tempnam_0300
55 * @tc.desc : Test tempnam results when the dir path does not exist
56 * @tc.level : Level 1
57 */
tempnam_0300(void)58 void tempnam_0300(void)
59 {
60 char *dir = "/file";
61 char *pte = "temp";
62 char *result = tempnam(dir, pte);
63 if (!result) {
64 t_error("%s tempnam error cannot create temp file\n", __func__);
65 }
66 if (!strstr(result, pte)) {
67 t_error("%s tempnam get result not contain %s\n", __func__, pte);
68 }
69 }
70
71 /**
72 * @tc.name : tempnam_0400
73 * @tc.desc : Test tempnam when the dir path is a file
74 * @tc.level : Level 1
75 */
tempnam_0400(void)76 void tempnam_0400(void)
77 {
78 char *dir = "/file/a.txt";
79 char *pte = "temp";
80 char *result = tempnam(dir, pte);
81 if (!result) {
82 t_error("%s tempnam error cannot create temp file\n", __func__);
83 }
84 if (!strstr(result, pte)) {
85 t_error("%s tempnam get result not contain %s\n", __func__, pte);
86 }
87 }
88
89 /**
90 * @tc.name : tempnam_0500
91 * @tc.desc : Test tempnam when dir path is empty string
92 * @tc.level : Level 1
93 */
tempnam_0500(void)94 void tempnam_0500(void)
95 {
96 char *dir = NULL;
97 char *pte = "temp";
98 char *result = tempnam(dir, pte);
99 if (!result) {
100 t_error("%s tempnam error cannot create temp file\n", __func__);
101 }
102 if (!strstr(result, pte)) {
103 t_error("%s tempnam get result not contain %s\n", __func__, pte);
104 }
105 }
106
main(int argc, char *argv[])107 int main(int argc, char *argv[])
108 {
109 // tempnam_0100();
110 // tempnam_0200();
111 // tempnam_0300();
112 // tempnam_0400();
113 // tempnam_0500();
114 return t_status;
115 }