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 : mkstemp_0100
21 * @tc.desc : Verify mkstemp process success. Provide the correct template and no fixed suffix, create a
22 * temporary file
23 * @tc.level : Level 0
24 */
mkstemp_0100(void)25 void mkstemp_0100(void)
26 {
27 char tmpfile[] = "/data/mkstemp_0100_XXXXXX";
28 int fd = mkstemp(tmpfile);
29 EXPECT_TRUE("mkstemp_0100", fd != -1);
30 if (fd != -1) {
31 int cnt = write(fd, tmpfile, strlen(tmpfile));
32 EXPECT_TRUE("mkstemp_0100", cnt == strlen(tmpfile));
33 close(fd);
34 char rmfile[128];
35 int len = sprintf(rmfile, "rm %s", tmpfile);
36 if (len > 0) {
37 system(rmfile);
38 }
39 }
40 }
41
42 /**
43 * @tc.name : mkstemp_0200
44 * @tc.desc : Verify mkstemp process fail. Provide error template, create temp file fail
45 * @tc.level : Level 2
46 */
mkstemp_0200(void)47 void mkstemp_0200(void)
48 {
49 char tmpfile[] = "/data/mkstemp_0200.dat";
50 int fd = mkstemp(tmpfile);
51 EXPECT_TRUE("mkstemp_0200", fd == -1);
52 if (fd != -1) {
53 int cnt = write(fd, tmpfile, strlen(tmpfile));
54 EXPECT_TRUE("mkstemp_0200", cnt == strlen(tmpfile));
55 close(fd);
56 char rmfile[128];
57 int len = sprintf(rmfile, "rm %s", tmpfile);
58 if (len > 0) {
59 system(rmfile);
60 }
61 }
62 }
63
main(void)64 int main(void)
65 {
66 mkstemp_0100();
67 mkstemp_0200();
68 return t_status;
69 }