aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/api
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/api
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/api')
-rw-r--r--tests/auto/api/tst_api.cpp37
1 files changed, 6 insertions, 31 deletions
diff --git a/tests/auto/api/tst_api.cpp b/tests/auto/api/tst_api.cpp
index 36ea39b97..dad9eb82c 100644
--- a/tests/auto/api/tst_api.cpp
+++ b/tests/auto/api/tst_api.cpp
@@ -178,13 +178,7 @@ void TestApi::addQObjectMacroToCppFile()
receiver.descriptions.clear();
WAIT_FOR_NEW_TIMESTAMP();
- QFile cppFile("object.cpp");
- QVERIFY2(cppFile.open(QIODevice::ReadWrite), qPrintable(cppFile.errorString()));
- QByteArray contents = cppFile.readAll();
- contents.replace("// ", "");
- cppFile.resize(0);
- cppFile.write(contents);
- cppFile.close();
+ REPLACE_IN_FILE("object.cpp", "// ", "");
errorInfo = doBuildProject("add-qobject-macro-to-cpp-file", &receiver);
VERIFY_NO_ERROR(errorInfo);
QVERIFY2(receiver.descriptions.contains("moc"), qPrintable(receiver.descriptions));
@@ -209,14 +203,7 @@ void TestApi::addedFilePersistent()
// Add a file. qbs must schedule it for rule application on the next build.
WAIT_FOR_NEW_TIMESTAMP();
const qbs::SetupProjectParameters params = defaultSetupParameters(relProjectFilePath);
- QFile projectFile(params.projectFilePath());
- QVERIFY2(projectFile.open(QIODevice::ReadWrite), qPrintable(projectFile.errorString()));
- const QByteArray originalContent = projectFile.readAll();
- QByteArray addedFileContent = originalContent;
- addedFileContent.replace("/* 'file.cpp' */", "'file.cpp'");
- projectFile.resize(0);
- projectFile.write(addedFileContent);
- projectFile.flush();
+ REPLACE_IN_FILE(params.projectFilePath(), "/* 'file.cpp' */", "'file.cpp'");
std::unique_ptr<qbs::SetupProjectJob> setupJob(qbs::Project().setupProject(params, m_logSink,
0));
waitForFinished(setupJob.get());
@@ -226,18 +213,14 @@ void TestApi::addedFilePersistent()
// Remove the file again. qbs must unschedule the rule application again.
// Consequently, the linking step must fail as in the initial run.
WAIT_FOR_NEW_TIMESTAMP();
- projectFile.resize(0);
- projectFile.write(originalContent);
- projectFile.flush();
+ REPLACE_IN_FILE(params.projectFilePath(), "'file.cpp'", "/* 'file.cpp' */");
errorInfo = doBuildProject(relProjectFilePath, 0, &receiver);
QVERIFY(errorInfo.hasError());
QVERIFY2(isAboutUndefinedSymbols(receiver.output), qPrintable((receiver.output)));
// Add the file again. qbs must schedule it for rule application on the next build.
WAIT_FOR_NEW_TIMESTAMP();
- projectFile.resize(0);
- projectFile.write(addedFileContent);
- projectFile.close();
+ REPLACE_IN_FILE(params.projectFilePath(), "/* 'file.cpp' */", "'file.cpp'");
setupJob.reset(qbs::Project().setupProject(params, m_logSink, 0));
waitForFinished(setupJob.get());
QVERIFY2(!setupJob->error().hasError(), qPrintable(setupJob->error().toString()));
@@ -988,16 +971,8 @@ void TestApi::changeDependentLib()
VERIFY_NO_ERROR(errorInfo);
WAIT_FOR_NEW_TIMESTAMP();
- const QString qbsFileName("change-dependent-lib.qbs");
- QFile qbsFile(qbsFileName);
- QVERIFY(qbsFile.open(QIODevice::ReadWrite));
- const QByteArray content1 = qbsFile.readAll();
- QByteArray content2 = content1;
- content2.replace("cpp.defines: [\"XXXX\"]", "cpp.defines: [\"ABCD\"]");
- QVERIFY(content1 != content2);
- qbsFile.seek(0);
- qbsFile.write(content2);
- qbsFile.close();
+ REPLACE_IN_FILE("change-dependent-lib.qbs", "cpp.defines: [\"XXXX\"]",
+ "cpp.defines: [\"ABCD\"]");
errorInfo = doBuildProject("change-dependent-lib");
VERIFY_NO_ERROR(errorInfo);
}