diff options
Diffstat (limited to 'tests/auto/installer/deleteoperation/tst_deleteoperation.cpp')
-rw-r--r-- | tests/auto/installer/deleteoperation/tst_deleteoperation.cpp | 49 |
1 files changed, 30 insertions, 19 deletions
diff --git a/tests/auto/installer/deleteoperation/tst_deleteoperation.cpp b/tests/auto/installer/deleteoperation/tst_deleteoperation.cpp index 807d03498..43ea52407 100644 --- a/tests/auto/installer/deleteoperation/tst_deleteoperation.cpp +++ b/tests/auto/installer/deleteoperation/tst_deleteoperation.cpp @@ -75,8 +75,7 @@ private slots: QVERIFY(!op.performOperation()); QCOMPARE(UpdateOperation::Error(op.error()), UpdateOperation::InvalidArguments); - QCOMPARE(op.errorString(), QString("Invalid arguments in Delete: " - "0 arguments given, exactly 1 arguments expected.")); + QCOMPARE(op.errorString(), QString("Invalid arguments in Delete: 0 arguments given, 1 to 3 arguments expected in the form: <file to remove> [UNDOOPERATION, \"\"].")); op.setArguments(QStringList() << ""); QTest::ignoreMessage(QtWarningMsg, "QFile::copy: Empty or null file name"); @@ -92,13 +91,16 @@ private slots: void testDeleteRestore_data() { QTest::addColumn<QString>("path"); - QTest::newRow("relative") << "test"; - QTest::newRow("absolute") << qApp->applicationDirPath() + QDir::toNativeSeparators("/test"); + QTest::addColumn<bool>("overrideUndo"); + QTest::newRow("relative") << "test" << false; + QTest::newRow("absolute") << qApp->applicationDirPath() + QDir::toNativeSeparators("/test") << false; + QTest::newRow("no undo") << "test" << true; } void testDeleteRestore() { QFETCH(QString, path); + QFETCH(bool, overrideUndo); QByteArray testString("Generated by QTest\n"); QFile testFile(path); @@ -107,23 +109,32 @@ private slots: out << testString; testFile.close(); - QVERIFY(QFileInfo(path).exists()); + QVERIFY(QFileInfo::exists(path)); QByteArray testFileHash = QInstaller::calculateHash(path, QCryptographicHash::Sha1); - DeleteOperation op; - op.setArguments(QStringList() << path); - - op.backup(); - QVERIFY(QFileInfo(op.value("backupOfExistingFile").toString()).exists()); - - QVERIFY2(op.performOperation(), op.errorString().toLatin1()); - QVERIFY(!QFileInfo(path).exists()); - - QVERIFY2(op.undoOperation(), op.errorString().toLatin1()); - QByteArray restoredFileHash = QInstaller::calculateHash(path, QCryptographicHash::Sha1); - QVERIFY(testFileHash == restoredFileHash); - - QVERIFY(QFile(path).remove()); + DeleteOperation *op = new DeleteOperation(); + op->setArguments(QStringList() << path); + if (overrideUndo) + op->setArguments(op->arguments() << QLatin1String("UNDOOPERATION")); + + op->backup(); + QVERIFY(QFileInfo::exists(op->value("backupOfExistingFile").toString())); + + QVERIFY2(op->performOperation(), op->errorString().toLatin1()); + QVERIFY(!QFileInfo::exists(path)); + + QVERIFY2(op->undoOperation(), op->errorString().toLatin1()); + if (!overrideUndo) { + QByteArray restoredFileHash = QInstaller::calculateHash(path, QCryptographicHash::Sha1); + QVERIFY(testFileHash == restoredFileHash); + } else { + QVERIFY(!QFileInfo::exists(path)); + } + + QString backupFileName = op->value("backupOfExistingFile").toString(); + delete op; + QVERIFY(!QFileInfo::exists(backupFileName)); + QCOMPARE(QFile(path).remove(), !overrideUndo); } void testDeleteFromScript() |