1- // ===-- Unittests for utimes
2- // -----------------------------------------------===//
1+ // ===-- Unittests for utimes ----------------------------------------------===//
32//
43// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
54// See https://llvm.org/LICENSE.txt for license information.
65// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
76//
8- // ===----------------------------------------------------------------------- ===//
7+ // ===----------------------------------------------------------------------===//
98
109#include " hdr/fcntl_macros.h"
1110#include " hdr/types/struct_timeval.h"
1514#include " src/sys/stat/stat.h"
1615#include " src/sys/time/utimes.h"
1716#include " src/unistd/close.h"
18- #include " src/unistd/unlink.h"
1917#include " test/UnitTest/ErrnoSetterMatcher.h"
2018#include " test/UnitTest/Test.h"
21- # include < fcntl.h >
19+
2220constexpr const char *FILE_PATH = " utimes.test" ;
2321
24- // SUCCESS: Takes a file and successfully updates
22+ // SUCCESS: Takes a file and successfully updates
2523// its last access and modified times.
26- TEST (LlvmLibcUtimesTest, ChangeTimesSpecific){
24+ TEST (LlvmLibcUtimesTest, ChangeTimesSpecific) {
2725 using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
2826
2927 // const char* FILE_PATH = "testdata/__utimes_changetimes.test";
@@ -39,7 +37,7 @@ TEST(LlvmLibcUtimesTest, ChangeTimesSpecific){
3937 times[0 ].tv_usec = 12345 ;
4038 times[1 ].tv_sec = 43210 ;
4139 times[1 ].tv_usec = 23456 ;
42-
40+
4341 // ensure utimes succeeds
4442 ASSERT_THAT (LIBC_NAMESPACE::utimes (FILE_PATH, times), Succeeds (0 ));
4543
@@ -51,7 +49,7 @@ TEST(LlvmLibcUtimesTest, ChangeTimesSpecific){
5149 ASSERT_EQ (statbuf.st_atim .tv_sec , times[0 ].tv_sec );
5250 ASSERT_EQ (statbuf.st_mtim .tv_sec , times[1 ].tv_sec );
5351
54- // microseconds
52+ // microseconds
5553 ASSERT_EQ (statbuf.st_atim .tv_nsec , times[0 ].tv_usec * 1000 );
5654 ASSERT_EQ (statbuf.st_mtim .tv_nsec , times[1 ].tv_usec * 1000 );
5755
@@ -60,7 +58,7 @@ TEST(LlvmLibcUtimesTest, ChangeTimesSpecific){
6058
6159// FAILURE: Invalid values in the timeval struct
6260// to check that utimes rejects it.
63- TEST (LlvmLibcUtimesTest, InvalidMicroseconds){
61+ TEST (LlvmLibcUtimesTest, InvalidMicroseconds) {
6462 using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails;
6563 using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
6664
@@ -71,25 +69,25 @@ TEST(LlvmLibcUtimesTest, InvalidMicroseconds){
7169 ASSERT_GT (fd, 0 );
7270 ASSERT_THAT (LIBC_NAMESPACE::close (fd), Succeeds (0 ));
7371
74- // make a dummy timeval struct
72+ // make a dummy timeval struct
7573 // populated with bad usec values
7674 struct timeval times[2 ];
7775 times[0 ].tv_sec = 54321 ;
7876 times[0 ].tv_usec = 4567 ;
7977 times[1 ].tv_sec = 43210 ;
80- times[1 ].tv_usec = 1000000 ; // invalid
81-
78+ times[1 ].tv_usec = 1000000 ; // invalid
79+
8280 // ensure utimes fails
8381 ASSERT_THAT (LIBC_NAMESPACE::utimes (FILE_PATH, times), Fails (EINVAL));
8482
85- // check for failure on
83+ // check for failure on
8684 // the other possible bad values
8785
8886 times[0 ].tv_sec = 54321 ;
89- times[0 ].tv_usec = -4567 ; // invalid
87+ times[0 ].tv_usec = -4567 ; // invalid
9088 times[1 ].tv_sec = 43210 ;
9189 times[1 ].tv_usec = 1000 ;
92-
90+
9391 // ensure utimes fails once more
9492 ASSERT_THAT (LIBC_NAMESPACE::utimes (FILE_PATH, times), Fails (EINVAL));
9593 ASSERT_THAT (LIBC_NAMESPACE::remove (TEST_FILE), Succeeds (0 ));
0 commit comments