summaryrefslogtreecommitdiff
path: root/tests/auto/shared.h
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@digia.com>2014-08-01 09:49:30 +0200
committerJoerg Bornemann <joerg.bornemann@digia.com>2014-08-01 10:57:39 +0200
commit702068a6ab4a8e5cbd66d6e40b742d1f11c2361c (patch)
treeff93accb9c44aed841d4338ff0b1c7d8fa2d5ab6 /tests/auto/shared.h
parentb07742b80d3d1727d60df9b68b07bb79c4caabf1 (diff)
downloadqbs-702068a6ab4a8e5cbd66d6e40b742d1f11c2361c.tar.gz
Autotests: Make "copy and touch" operation atomic.
On Windows, QFile::copy does not update the timestamp on the target file. This fixes the "projectInvalidation" API test on that OS. Change-Id: I01c232de0f4e5e9bc5d2d28c24d5fb5516a58ca3 Reviewed-by: Joerg Bornemann <joerg.bornemann@digia.com>
Diffstat (limited to 'tests/auto/shared.h')
-rw-r--r--tests/auto/shared.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/auto/shared.h b/tests/auto/shared.h
index 2b9974110..e0920363f 100644
--- a/tests/auto/shared.h
+++ b/tests/auto/shared.h
@@ -31,6 +31,7 @@
#include <tools/hostosinfo.h>
+#include <QFile>
#include <QtTest>
#if QT_VERSION >= 0x050000
@@ -48,4 +49,22 @@ inline void waitForNewTimestamp()
QTest::qWait(1000);
}
+inline void touch(const QString &fn)
+{
+ QFile f(fn);
+ int s = f.size();
+ if (!f.open(QFile::ReadWrite))
+ qFatal("cannot open file %s", qPrintable(fn));
+ f.resize(s+1);
+ f.resize(s);
+}
+
+inline void copyFileAndUpdateTimestamp(const QString &source, const QString &target)
+{
+ QFile::remove(target);
+ if (!QFile::copy(source, target))
+ qFatal("Failed to copy '%s' to '%s'", qPrintable(source), qPrintable(target));
+ touch(target);
+}
+
#endif // Include guard.