Skip to content

Commit

Permalink
[Test-linux] Add tests for troubleshooting failing tests on CI
Browse files Browse the repository at this point in the history
  • Loading branch information
rikyoz committed Jun 23, 2024
1 parent 76f254a commit a40b27c
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion tests/src/test_dateutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,27 @@

#include <catch2/catch.hpp>

#ifndef _WIN32
#include "utils/archive.hpp"
#include "utils/shared_lib.hpp"

#include <bit7z/bitarchivereader.hpp>
#endif

#include <internal/dateutil.hpp>

#ifndef _WIN32
#include <chrono>
#endif
#include <ctime> // 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. */
Expand Down Expand Up @@ -59,4 +74,32 @@ TEST_CASE( "fsutil: Date conversions", "[fsutil][date functions]" ) {
REQUIRE( output == testDate.dateTime );
}
}
}
}

#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

0 comments on commit a40b27c

Please sign in to comment.