From a40b27cb91a65196f593dbcbbe7d670cb7326599 Mon Sep 17 00:00:00 2001 From: Oz Date: Sun, 23 Jun 2024 21:47:42 +0200 Subject: [PATCH] [Test-linux] Add tests for troubleshooting failing tests on CI --- tests/src/test_dateutil.cpp | 45 ++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/tests/src/test_dateutil.cpp b/tests/src/test_dateutil.cpp index 2375f865..532fdd2c 100644 --- a/tests/src/test_dateutil.cpp +++ b/tests/src/test_dateutil.cpp @@ -12,12 +12,27 @@ #include +#ifndef _WIN32 +#include "utils/archive.hpp" +#include "utils/shared_lib.hpp" + +#include +#endif + #include +#ifndef _WIN32 +#include +#endif #include // For std::time_t (on MSVC 2015). using namespace bit7z; +#ifndef _WIN32 +using namespace bit7z::test; +using namespace bit7z::test::filesystem; +#endif + /* Note: std::time_t is usually a UNIX timestamp, so we are using only dates after the UNIX epoch datetime. * We do not expect the conversion function to check whether the input is correct, * so we don't perform tests with wrong inputs. */ @@ -59,4 +74,32 @@ TEST_CASE( "fsutil: Date conversions", "[fsutil][date functions]" ) { REQUIRE( output == testDate.dateTime ); } } -} \ No newline at end of file +} + +#ifndef _WIN32 +TEMPLATE_TEST_CASE( "fsutil: Date conversion of last write time", "[fsutil][date functions]", + tstring, buffer_t, stream_t ) { + const TestDirectory testDir{ fs::path{ test_archives_dir } / "extraction" / "single_file" }; + + const auto arcFileName = fs::path{ clouds.name }.concat( ".7z" ); + + TestType inputArchive{}; + getInputArchive( arcFileName, inputArchive ); + BitArchiveReader info( test::sevenzip_lib(), inputArchive, BitFormat::SevenZip ); + + const auto item = info.itemAt( 0 ); + + const auto lastWriteTime = item.itemProperty( BitProperty::MTime ).getFileTime(); + INFO( "Last write time FILETIME: {" << lastWriteTime.dwHighDateTime << ", " << lastWriteTime.dwLowDateTime << "}") + const auto result = FILETIME_to_file_time_type( lastWriteTime ); + + namespace chrono = std::chrono; + const auto result_as_seconds = static_cast< std::uint64_t >( chrono::duration_cast< chrono::seconds >( result.time_since_epoch() ).count() ); + INFO( "Last write file time_point: " << result_as_seconds ) + + const auto result2 = item.lastWriteTime(); + const auto result2_as_seconds = static_cast< std::uint64_t >( chrono::duration_cast< chrono::seconds >( result2.time_since_epoch() ).count() ); + INFO( "Last write system time_point: " << result2_as_seconds ) + REQUIRE( result_as_seconds == result2_as_seconds ); +} +#endif \ No newline at end of file