• 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 <stdio.h>
17 #include <string.h>
18 #include <unistd.h>
19 #include <fcntl.h>
20 #include "filepath_util.h"
21 
22 /**
23  * @tc.name      : unlink_0100
24  * @tc.desc      : Test the timegm result when tm exceeds the limit
25  * @tc.level     : Level 0
26  */
unlink_0100(void)27 void unlink_0100(void)
28 {
29     char path[PATH_MAX] = {0};
30     FILE_ABSOLUTE_PATH("test_unlink.txt", path);
31     int fd = open(path, O_CREAT, TEST_MODE);
32     int error_code = -1;
33     if (fd == error_code) {
34         t_error("%s unlink create file error", __func__);
35         return;
36     }
37     close(fd);
38     int result = unlink(path);
39     if (result != 0) {
40         t_error("%s unlink get result is %d not want 0", __func__, result);
41     }
42 }
43 
44 /**
45  * @tc.name      : unlink_0200
46  * @tc.desc      : Test the timegm result when tm exceeds the limit
47  * @tc.level     : Level 1
48  */
unlink_0200(void)49 void unlink_0200(void)
50 {
51     char path[PATH_MAX] = {0};
52     FILE_ABSOLUTE_PATH("unexist_test_unlink.txt", path);
53     int result = unlink(path);
54     int error_code = -1;
55     if (result != error_code) {
56         t_error("%s unlink get result is %d not want -1", __func__, result);
57     }
58 }
59 
main(int argc,char * argv[])60 int main(int argc, char *argv[])
61 {
62     unlink_0100();
63     unlink_0200();
64     return t_status;
65 }