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 <fcntl.h>
17 #include <sys/stat.h>
18 #include "functionalext.h"
19
20 /**
21 * @tc.name : creat_0100
22 * @tc.desc : Each parameter is valid and a new file can be created.
23 * @tc.level : Level 0
24 */
creat_0100(void)25 void creat_0100(void)
26 {
27 int fd = -1;
28 const char *ptr = "/data/creattest.txt";
29 fd = creat(ptr, O_RDWR | O_CREAT);
30 EXPECT_NE("creat_0100", fd, -1);
31 close(fd);
32 remove(ptr);
33 ptr = NULL;
34 }
35
36 /**
37 * @tc.name : creat_0200
38 * @tc.desc : The filename parameter is invalid, a new file cannot be created.
39 * @tc.level : Level 2
40 */
creat_0200(void)41 void creat_0200(void)
42 {
43 int fd = 0;
44 const char *ptr = "";
45 fd = open(ptr, O_RDONLY);
46 EXPECT_EQ("creat_0200", fd, -1);
47 close(fd);
48 remove(ptr);
49 ptr = NULL;
50 }
51
52 /**
53 * @tc.name : creat_0300
54 * @tc.desc : The mode parameter is invalid and a new file cannot be created.
55 * @tc.level : Level 0
56 */
creat_0300(void)57 void creat_0300(void)
58 {
59 int fd = 0;
60 const char *ptr = "/data/creattest.txt";
61 fd = open(ptr, O_WRONLY);
62 EXPECT_EQ("creat_0300", fd, -1);
63 close(fd);
64 remove(ptr);
65 ptr = NULL;
66 }
67
main(int argc,char * argv[])68 int main(int argc, char *argv[])
69 {
70 creat_0100();
71 creat_0200();
72 creat_0300();
73 return t_status;
74 }