| 419 | } |
| 420 | |
| 421 | void TestJlCompress::extractFile() |
| 422 | { |
| 423 | QFETCH(QString, zipName); |
| 424 | QFETCH(QStringList, fileNames); |
| 425 | QFETCH(QString, fileToExtract); |
| 426 | QFETCH(QString, destName); |
| 427 | QFETCH(QByteArray, encoding); |
| 428 | QDir curDir; |
| 429 | if (!curDir.mkpath("jlext/jlfile")) { |
| 430 | QFAIL("Couldn't mkpath jlext/jlfile"); |
| 431 | } |
| 432 | if (!createTestFiles(fileNames)) { |
| 433 | QFAIL("Couldn't create test files"); |
| 434 | } |
| 435 | QFile srcFile("tmp/" + fileToExtract); |
| 436 | QFile::Permissions srcPerm = srcFile.permissions(); |
| 437 | // Invert the "write other" flag so permissions |
| 438 | // are NOT default any more. Otherwise it's impossible |
| 439 | // to figure out whether the permissions were set correctly |
| 440 | // or JlCompress failed to set them completely, |
| 441 | // thus leaving them at the default setting. |
| 442 | srcPerm ^= QFile::WriteOther; |
| 443 | QVERIFY(srcFile.setPermissions(srcPerm)); |
| 444 | if (!createTestArchive(zipName, fileNames, |
| 445 | QTextCodec::codecForName(encoding))) { |
| 446 | QFAIL("Can't create test archive"); |
| 447 | } |
| 448 | QuaZip::setDefaultFileNameCodec(encoding); |
| 449 | QVERIFY(!JlCompress::extractFile(zipName, fileToExtract, |
| 450 | "jlext/jlfile/" + destName).isEmpty()); |
| 451 | QFileInfo destInfo("jlext/jlfile/" + destName), srcInfo("tmp/" + |
| 452 | fileToExtract); |
| 453 | QCOMPARE(destInfo.size(), srcInfo.size()); |
| 454 | QCOMPARE(destInfo.permissions(), srcInfo.permissions()); |
| 455 | curDir.remove("jlext/jlfile/" + destName); |
| 456 | // now test the QIODevice* overload |
| 457 | QFile zipFile(zipName); |
| 458 | QVERIFY(zipFile.open(QIODevice::ReadOnly)); |
| 459 | QVERIFY(!JlCompress::extractFile(&zipFile, fileToExtract, |
| 460 | "jlext/jlfile/" + destName).isEmpty()); |
| 461 | destInfo = QFileInfo("jlext/jlfile/" + destName); |
| 462 | QCOMPARE(destInfo.size(), srcInfo.size()); |
| 463 | QCOMPARE(destInfo.permissions(), srcInfo.permissions()); |
| 464 | curDir.remove("jlext/jlfile/" + destName); |
| 465 | if (!fileToExtract.endsWith("/")) { |
| 466 | // If we aren't extracting a directory, we need to check |
| 467 | // that extractFile() fails if there is a directory |
| 468 | // with the same name as the file being extracted. |
| 469 | curDir.mkdir("jlext/jlfile/" + destName); |
| 470 | QVERIFY(JlCompress::extractFile(zipName, fileToExtract, |
| 471 | "jlext/jlfile/" + destName).isEmpty()); |
| 472 | } |
| 473 | zipFile.close(); |
| 474 | // Here we either delete the target dir or the dir created in the |
| 475 | // test above. |
| 476 | curDir.rmpath("jlext/jlfile/" + destName); |
| 477 | removeTestFiles(fileNames); |
| 478 | curDir.remove(zipName); |
nothing calls this directly
no test coverage detected