File: TestFileTime.cxx

package info (click to toggle)
mpd 0.24.6-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,736 kB
  • sloc: cpp: 75,014; python: 1,408; xml: 628; perl: 469; java: 289; sh: 286; ansic: 235; makefile: 105
file content (27 lines) | stat: -rw-r--r-- 712 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// SPDX-License-Identifier: BSD-2-Clause
// author: Max Kellermann <max.kellermann@gmail.com>

#include "time/FileTime.hxx"

#include <gtest/gtest.h>

#include <sys/stat.h>
#include <tchar.h>

TEST(Time, FileTimeToChrono)
{
	WIN32_FILE_ATTRIBUTE_DATA data;

	ASSERT_TRUE(GetFileAttributesEx(_T("."), GetFileExInfoStandard,
					&data));
	const auto tp = FileTimeToChrono(data.ftLastWriteTime);

	struct stat st;
	ASSERT_EQ(stat(".", &st), 0);

	ASSERT_EQ(std::chrono::system_clock::to_time_t(tp), st.st_mtime);

	const auto ft2 = ChronoToFileTime(std::chrono::system_clock::from_time_t(st.st_mtime));
	const auto tp2 = FileTimeToChrono(ft2);
	ASSERT_EQ(std::chrono::system_clock::to_time_t(tp2), st.st_mtime);
}