aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/shared.h
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@qt.io>2018-01-31 16:04:56 +0100
committerChristian Kandeler <christian.kandeler@qt.io>2018-02-01 08:14:32 +0000
commit8b99628dc3bb125366f8b5c99ca57c78b96c1e54 (patch)
tree472378f185788ec83c2f83c2a9b2d6f874fb0d69 /tests/auto/shared.h
parentbf18a35838e67fc790e5fd043dbd7a76518de28f (diff)
Autotests: Add convenience function for changing file contents
We do that in a lot of test functions. Change-Id: I8629e8bf936bc8f45d6a42b3bfc89a6a078cd023 Reviewed-by: Jake Petroules <jake.petroules@qt.io> Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Diffstat (limited to 'tests/auto/shared.h')
-rw-r--r--tests/auto/shared.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/tests/auto/shared.h b/tests/auto/shared.h
index b0ce6f942..f16ca4bde 100644
--- a/tests/auto/shared.h
+++ b/tests/auto/shared.h
@@ -44,6 +44,18 @@
#include <memory>
+#define REPLACE_IN_FILE(filePath, oldContent, newContent) \
+ do { \
+ QFile f((filePath)); \
+ QVERIFY2(f.open(QIODevice::ReadWrite), qPrintable(f.errorString())); \
+ QByteArray content = f.readAll(); \
+ const QByteArray savedContent = content; \
+ content.replace((oldContent), (newContent)); \
+ QVERIFY(content != savedContent); \
+ f.resize(0); \
+ f.write(content); \
+ } while (false)
+
inline int testTimeoutInMsecs()
{
bool ok;