Changeset View
Changeset View
Standalone View
Standalone View
autotests/jobtest.cpp
Show First 20 Lines • Show All 2038 Lines • ▼ Show 20 Line(s) | 2036 | for (int i = 0; i < numFiles; ++i) { | |||
---|---|---|---|---|---|
2039 | QCOMPARE(spyMimeType.at(i).at(1).toString(), QStringLiteral("text/plain")); | 2039 | QCOMPARE(spyMimeType.at(i).at(1).toString(), QStringLiteral("text/plain")); | ||
2040 | QCOMPARE(spyData.at(i * 2).at(0).toInt(), i); | 2040 | QCOMPARE(spyData.at(i * 2).at(0).toInt(), i); | ||
2041 | QCOMPARE(QString(spyData.at(i * 2).at(1).toByteArray()), QStringLiteral("Hello")); | 2041 | QCOMPARE(QString(spyData.at(i * 2).at(1).toByteArray()), QStringLiteral("Hello")); | ||
2042 | QCOMPARE(spyData.at(i * 2 + 1).at(0).toInt(), i); | 2042 | QCOMPARE(spyData.at(i * 2 + 1).at(0).toInt(), i); | ||
2043 | QCOMPARE(QString(spyData.at(i * 2 + 1).at(1).toByteArray()), QLatin1String("")); | 2043 | QCOMPARE(QString(spyData.at(i * 2 + 1).at(1).toByteArray()), QLatin1String("")); | ||
2044 | } | 2044 | } | ||
2045 | } | 2045 | } | ||
2046 | 2046 | | |||
2047 | void JobTest::cancelCopyAndCleanDest_data() | ||||
2048 | { | ||||
2049 | QTest::addColumn<bool>("suspend"); | ||||
2050 | QTest::addColumn<bool>("overwrite"); | ||||
2051 | | ||||
2052 | QTest::newRow("suspend job (without overwrite flag)") << true << false; | ||||
2053 | QTest::newRow("don't suspend job (without overwrite flag)") << false << false; | ||||
2054 | | ||||
2055 | #ifndef Q_OS_WIN | ||||
2056 | QTest::newRow("suspend job (with overwrite flag)") << true << true; | ||||
2057 | QTest::newRow("don't suspend job (with overwrite flag)") << false << true; | ||||
2058 | #endif | ||||
2059 | } | ||||
2060 | | ||||
2061 | void JobTest::cancelCopyAndCleanDest() | ||||
2062 | { | ||||
2063 | QFETCH(bool, suspend); | ||||
2064 | QFETCH(bool, overwrite); | ||||
2065 | | ||||
2066 | const QString baseDir = homeTmpDir(); | ||||
dfaure: no space after `connect` | |||||
2067 | const QString srcTemplate = baseDir + QStringLiteral("testfile_XXXXXX"); | ||||
2068 | const QString destFile = baseDir + QStringLiteral("testfile_copy"); | ||||
2069 | | ||||
I'm curious, why this signal, just to call another lambda? Can't you move the code of the second lambda into this one? It's not like the signal is queued right now, it's a direct call. dfaure: I'm curious, why this signal, just to call another lambda? Can't you move the code of the… | |||||
2070 | | ||||
2071 | QTemporaryFile f(srcTemplate); | ||||
2072 | if (!f.open()) { | ||||
2073 | qFatal("Couldn't open %s", qPrintable(f.fileName())); | ||||
2074 | } | ||||
2075 | f.seek(9999999); | ||||
2076 | f.write("0"); | ||||
2077 | f.close(); | ||||
2078 | QCOMPARE(f.size(), 10000000); //~10MB | ||||
2079 | | ||||
2080 | if (overwrite) { | ||||
Add f.remove() here, to avoid leaving a 10MB file around... (The alternative would be to use QTemporaryFile) dfaure: Add `f.remove()` here, to avoid leaving a 10MB file around...
(The alternative would be to use… | |||||
2081 | createTestFile(destFile); | ||||
2082 | } | ||||
2083 | | ||||
2084 | KIO::JobFlag m_overwriteFlag = overwrite ? KIO::Overwrite : KIO::DefaultFlags; | ||||
2085 | KIO::FileCopyJob *copyJob = KIO::file_copy(QUrl::fromLocalFile(f.fileName()), QUrl::fromLocalFile(destFile), -1, KIO::HideProgressInfo | m_overwriteFlag); | ||||
2086 | copyJob->setUiDelegate(nullptr); | ||||
2087 | QSignalSpy spyProcessedSize(copyJob, &KIO::Job::processedSize); | ||||
2088 | connect(copyJob, &KIO::Job::processedSize, this, [destFile, suspend, overwrite](KJob *job, qulonglong processedSize) { | ||||
2089 | if (processedSize > 0) { | ||||
2090 | const QString destToCheck = (!overwrite) ? destFile : destFile + QStringLiteral(".part"); | ||||
2091 | QVERIFY(QFile::exists(destToCheck)); | ||||
2092 | if (suspend) { | ||||
2093 | job->suspend(); | ||||
2094 | } | ||||
2095 | job->kill(); | ||||
2096 | QVERIFY(!QFile::exists(destToCheck)); | ||||
2097 | } | ||||
2098 | }); | ||||
2099 | QVERIFY(!copyJob->exec()); | ||||
2100 | QCOMPARE(spyProcessedSize.count(), 1); | ||||
2101 | } | ||||
2102 | |
no space after connect