• 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 <stdlib.h>
17 #include "functionalext.h"
18 
19 /**
20  * @tc.name      : mkstemps_0100
21  * @tc.desc      : Provide the correct template, create a temporary file
22  * @tc.level     : Level 0
23  */
mkstemps_0100(void)24 void mkstemps_0100(void)
25 {
26     char tmpfile[] = "/tmp/mkstemps_0100_XXXXXX.dat";
27     int fd = mkstemps(tmpfile, strlen(".dat"));
28     EXPECT_TRUE("mkstemps_0100", fd != -1);
29     if (fd != -1) {
30         int cnt = write(fd, tmpfile, strlen(tmpfile));
31         EXPECT_TRUE("mkstemps_0100", cnt == strlen(tmpfile));
32         close(fd);
33         char rmfile[128];
34         int len = sprintf(rmfile, "rm %s", tmpfile);
35         if (len > 0) {
36             system(rmfile);
37         }
38     }
39 }
40 
41 /**
42  * @tc.name      : mkstemps_0200
43  * @tc.desc      : Provide the correct template and no fixed suffix, create a temporary file
44  * @tc.level     : Level 0
45  */
mkstemps_0200(void)46 void mkstemps_0200(void)
47 {
48     char tmpfile[] = "/tmp/mkstemps_0200_XXXXXX";
49     int fd = mkstemps(tmpfile, 0);
50     EXPECT_TRUE("mkstemps_0200", fd != -1);
51     if (fd != -1) {
52         int cnt = write(fd, tmpfile, strlen(tmpfile));
53         EXPECT_TRUE("mkstemps_0200", cnt == strlen(tmpfile));
54         close(fd);
55         char rmfile[128];
56         int len = sprintf(rmfile, "rm %s", tmpfile);
57         if (len > 0) {
58             system(rmfile);
59         }
60     }
61 }
62 
63 /**
64  * @tc.name      : mkstemps_0300
65  * @tc.desc      : Provide error template, create temp file
66  * @tc.level     : Level 2
67  */
mkstemps_0300(void)68 void mkstemps_0300(void)
69 {
70     char tmpfile[] = "/tmp/mkstemps_0300.dat";
71     int fd = mkstemps(tmpfile, strlen(".dat"));
72     EXPECT_TRUE("mkstemps_0300", fd == -1);
73     if (fd != -1) {
74         int cnt = write(fd, tmpfile, strlen(tmpfile));
75         EXPECT_TRUE("mkstemps_0300", cnt == strlen(tmpfile));
76         close(fd);
77         char rmfile[128];
78         int len = sprintf(rmfile, "rm %s", tmpfile);
79         if (len > 0) {
80             system(rmfile);
81         }
82     }
83 }
84 
main(void)85 int main(void)
86 {
87     mkstemps_0100();
88     mkstemps_0200();
89     mkstemps_0300();
90     return t_status;
91 }