Skip to content

Commit

Permalink
Reproduce created() behavior in 5.10+ for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Bionus committed Aug 4, 2018
1 parent 8afe9c4 commit 9d5e694
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions tests/src/functions-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@
#include "functions-test.h"


QDateTime fileCreationDate(const QString &path)
{
QFileInfo fi(path);
#if (QT_VERSION < QT_VERSION_CHECK(5, 10, 0))
return fi.created();
#else
QDateTime d = fi.birthTime();
if (d.isValid())
return d;
return fi.metadataChangeTime();
#endif
}


void FunctionsTest::testCopyRecursively()
{
QString from = QDir::toNativeSeparators("tests/resources/recurse/");
Expand Down Expand Up @@ -255,13 +269,7 @@ void FunctionsTest::testSetFileCreationDate()

setFileCreationDate(path, date);

QDateTime created;
#if (QT_VERSION < QT_VERSION_CHECK(5, 10, 0))
created = QFileInfo(path).created();
#else
created = QFileInfo(path).birthTime();
#endif

QDateTime created = fileCreationDate(path);
QCOMPARE(created.toTime_t(), date.toTime_t());
}
void FunctionsTest::testSetFileCreationDateUtf8()
Expand All @@ -271,13 +279,7 @@ void FunctionsTest::testSetFileCreationDateUtf8()

setFileCreationDate(path, date);

QDateTime created;
#if (QT_VERSION < QT_VERSION_CHECK(5, 10, 0))
created = QFileInfo(path).created();
#else
created = QFileInfo(path).birthTime();
#endif

QDateTime created = fileCreationDate(path);
QCOMPARE(created.toTime_t(), date.toTime_t());
}

Expand Down

0 comments on commit 9d5e694

Please sign in to comment.