• 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 <fcntl.h>
17 #include <sys/stat.h>
18 #include <sys/time.h>
19 #include "functionalext.h"
20 
21 #define TEST_FIFO_MODE 777
22 #define TEST_SIZE 2
23 
24 extern int __lutimes_time64(const char *, const struct timeval [2]);
25 
26 /**
27  * @tc.name      : lutimes_0100
28  * @tc.desc      : Verify inet_lnaofof process success. Lfutimes can modify the timestamp of the file.
29  * @tc.level     : Level 0
30  */
lutimes_0100(void)31 void lutimes_0100(void)
32 {
33     int ret;
34     struct stat s;
35     static struct timeval tv[TEST_SIZE] = {{0L, 0L}, {0L, 0L}};
36     tv[0].tv_sec = s.st_atime;
37     tv[0].tv_usec = 0;
38     tv[1].tv_sec = s.st_mtime;
39     tv[1].tv_usec = 0;
40     int fd = -1;
41     fd = creat("./lutimes_0100.txt", TEST_FIFO_MODE);
42     if (fd < 0) {
43         EXPECT_MT("lutimes_0100", fd, 0);
44         return;
45     } else {
46         close(fd);
47     }
48     ret = lutimes("./lutimes_0100.txt", tv);
49     EXPECT_EQ("lutimes_0100", ret, 0);
50     ret = remove("lutimes_0100.txt");
51     EXPECT_EQ("lutimes_0100", ret, 0);
52 }
53 
54 /**
55  * @tc.name      : lutimes_0200
56  * @tc.desc      : Verify inet_lnaofof process fail. Because the fd argument is invalid
57  *                 and the lutimes function cannot modify the timestamp of the file.
58  * @tc.level     : Level 2
59  */
lutimes_0200(void)60 void lutimes_0200(void)
61 {
62     int ret = -1;
63     static struct timeval tv[TEST_SIZE] = {{0L, 0L}, {0L, 0L}};
64     ret = lutimes("./lutimes_0200.txt", tv);
65     EXPECT_EQ("lutimes_0200", ret, -1);
66 }
67 
68 /**
69  * @tc.name      : lutimes_time64_0100
70  * @tc.desc      : Verify inet_lnaofof process success. Lfutimes can modify the timestamp of the file.
71  * @tc.level     : Level 0
72  */
lutimes_time64_0100(void)73 void lutimes_time64_0100(void)
74 {
75     int ret;
76     struct stat s;
77     static struct timeval tv[TEST_SIZE] = {{0L, 0L}, {0L, 0L}};
78     tv[0].tv_sec = s.st_atime;
79     tv[0].tv_usec = 0;
80     tv[1].tv_sec = s.st_mtime;
81     tv[1].tv_usec = 0;
82     int fd = -1;
83     fd = creat("./lutimes_time64_0100.txt", TEST_FIFO_MODE);
84     if (fd < 0) {
85         EXPECT_MT("lutimes_time64_0100", fd, 0);
86         return;
87     } else {
88         close(fd);
89     }
90     ret = __lutimes_time64("./lutimes_time64_0100.txt", tv);
91     EXPECT_EQ("lutimes_time64_0100", ret, 0);
92     ret = remove("lutimes_time64_0100.txt");
93     EXPECT_EQ("lutimes_time64_0100", ret, 0);
94 }
95 
main(void)96 int main(void)
97 {
98     lutimes_0100();
99     lutimes_0200();
100     lutimes_time64_0100();
101     return t_status;
102 }