diff options
author | Christian Kandeler <christian.kandeler@qt.io> | 2018-01-31 16:04:56 +0100 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@qt.io> | 2018-02-01 08:14:32 +0000 |
commit | 8b99628dc3bb125366f8b5c99ca57c78b96c1e54 (patch) | |
tree | 472378f185788ec83c2f83c2a9b2d6f874fb0d69 /tests/auto/shared.h | |
parent | bf18a35838e67fc790e5fd043dbd7a76518de28f (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.h | 12 |
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; |