1- // ===-- Unittests for utimes -----------------------------------------------===//
1+ // ===-- Unittests for utimes
2+ // -----------------------------------------------===//
23//
34// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
45// See https://llvm.org/LICENSE.txt for license information.
56// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
67//
78// ===-----------------------------------------------------------------------===//
89
9- #include " src/fcntl/open.h"
10- #include " src/unistd/close.h"
10+ #include " hdr/fcntl_macros.h"
11+ #include " hdr/types/struct_timeval.h"
12+ #include " src/errno/libc_errno.h"
13+ #include " src/fcntl/open.h"
1114#include " src/stdio/remove.h"
12- #include " src/sys/stat/stat.h"
13- #include " src/unistd/unlink .h"
14- #include " test/UnitTest/Test .h"
15- #include " src/errno/libc_errno .h"
15+ #include " src/sys/stat/stat.h"
16+ #include " src/sys/time/utimes .h"
17+ #include " src/unistd/close .h"
18+ #include " src/unistd/unlink .h"
1619#include " test/UnitTest/ErrnoSetterMatcher.h"
17- #include " hdr/types/struct_timeval.h"
18- #include " hdr/fcntl_macros.h"
19- #include " src/sys/time/utimes.h"
20+ #include " test/UnitTest/Test.h"
2021#include < fcntl.h>
21- constexpr const char * FILE_PATH = " utimes.test" ;
22+ constexpr const char * FILE_PATH = " utimes.test" ;
2223
2324// SUCCESS: Takes a file and successfully updates
2425// its last access and modified times.
2526TEST (LlvmLibcUtimesTest, ChangeTimesSpecific){
2627 using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
27-
28+
2829 // const char* FILE_PATH = "testdata/__utimes_changetimes.test";
29-
30+
3031 auto TEST_FILE = libc_make_test_file_path (FILE_PATH);
3132 int fd = LIBC_NAMESPACE::open (TEST_FILE, O_WRONLY | O_CREAT);
3233 ASSERT_GT (fd, 0 );
3334 ASSERT_THAT (LIBC_NAMESPACE::close (fd), Succeeds (0 ));
34-
35+
3536 // make a dummy timeval struct
3637 struct timeval times[2 ];
3738 times[0 ].tv_sec = 54321 ;
@@ -45,31 +46,31 @@ TEST(LlvmLibcUtimesTest, ChangeTimesSpecific){
4546 // verify the times values against stat of the TEST_FILE
4647 struct stat statbuf;
4748 ASSERT_EQ (LIBC_NAMESPACE::stat (FILE_PATH, &statbuf), 0 );
48-
49+
4950 // seconds
5051 ASSERT_EQ (statbuf.st_atim .tv_sec , times[0 ].tv_sec );
5152 ASSERT_EQ (statbuf.st_mtim .tv_sec , times[1 ].tv_sec );
5253
5354 // microseconds
5455 ASSERT_EQ (statbuf.st_atim .tv_nsec , times[0 ].tv_usec * 1000 );
5556 ASSERT_EQ (statbuf.st_mtim .tv_nsec , times[1 ].tv_usec * 1000 );
56-
57- ASSERT_THAT (LIBC_NAMESPACE::remove (TEST_FILE), Succeeds (0 ));
57+
58+ ASSERT_THAT (LIBC_NAMESPACE::remove (TEST_FILE), Succeeds (0 ));
5859}
5960
6061// FAILURE: Invalid values in the timeval struct
6162// to check that utimes rejects it.
6263TEST (LlvmLibcUtimesTest, InvalidMicroseconds){
63- using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails;
64- using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
64+ using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails;
65+ using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
6566
6667 // const char* FILE_PATH = "testdata/__utimes_invalidmicroseconds.test";
67-
68+
6869 auto TEST_FILE = libc_make_test_file_path (FILE_PATH);
6970 int fd = LIBC_NAMESPACE::open (TEST_FILE, O_WRONLY | O_CREAT);
7071 ASSERT_GT (fd, 0 );
7172 ASSERT_THAT (LIBC_NAMESPACE::close (fd), Succeeds (0 ));
72-
73+
7374 // make a dummy timeval struct
7475 // populated with bad usec values
7576 struct timeval times[2 ];
@@ -80,7 +81,7 @@ TEST(LlvmLibcUtimesTest, InvalidMicroseconds){
8081
8182 // ensure utimes fails
8283 ASSERT_THAT (LIBC_NAMESPACE::utimes (FILE_PATH, times), Fails (EINVAL));
83-
84+
8485 // check for failure on
8586 // the other possible bad values
8687
@@ -90,6 +91,6 @@ TEST(LlvmLibcUtimesTest, InvalidMicroseconds){
9091 times[1 ].tv_usec = 1000 ;
9192
9293 // ensure utimes fails once more
93- ASSERT_THAT (LIBC_NAMESPACE::utimes (FILE_PATH, times), Fails (EINVAL));
94- ASSERT_THAT (LIBC_NAMESPACE::remove (TEST_FILE), Succeeds (0 ));
94+ ASSERT_THAT (LIBC_NAMESPACE::utimes (FILE_PATH, times), Fails (EINVAL));
95+ ASSERT_THAT (LIBC_NAMESPACE::remove (TEST_FILE), Succeeds (0 ));
9596}
0 commit comments