• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2013 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <gtest/gtest.h>
18 
19 #include <errno.h>
20 #include <stdlib.h>
21 #include <sys/stat.h>
22 
TEST(sys_stat,futimens)23 TEST(sys_stat, futimens) {
24   FILE* fp = tmpfile();
25   ASSERT_TRUE(fp != NULL);
26 
27   int fd = fileno(fp);
28   ASSERT_NE(fd, -1);
29 
30   timespec times[2];
31   times[0].tv_sec = 123;
32   times[0].tv_nsec = 0;
33   times[1].tv_sec = 456;
34   times[1].tv_nsec = 0;
35   ASSERT_EQ(0, futimens(fd, times)) << strerror(errno);
36 
37   struct stat sb;
38   ASSERT_EQ(0, fstat(fd, &sb));
39   ASSERT_EQ(times[0].tv_sec, static_cast<long>(sb.st_atime));
40   ASSERT_EQ(times[1].tv_sec, static_cast<long>(sb.st_mtime));
41 
42   fclose(fp);
43 }
44 
TEST(sys_stat,futimens_EBADF)45 TEST(sys_stat, futimens_EBADF) {
46   timespec times[2];
47   times[0].tv_sec = 123;
48   times[0].tv_nsec = 0;
49   times[1].tv_sec = 456;
50   times[1].tv_nsec = 0;
51   ASSERT_EQ(-1, futimens(-1, times));
52   ASSERT_EQ(EBADF, errno);
53 }
54