Changeset View
Changeset View
Standalone View
Standalone View
autotests/jobtest.cpp
Show All 36 Lines | |||||
37 | 37 | | |||
38 | #include <kmountpoint.h> | 38 | #include <kmountpoint.h> | ||
39 | #include <kprotocolinfo.h> | 39 | #include <kprotocolinfo.h> | ||
40 | #include <kio/scheduler.h> | 40 | #include <kio/scheduler.h> | ||
41 | #include <kio/directorysizejob.h> | 41 | #include <kio/directorysizejob.h> | ||
42 | #include <kio/copyjob.h> | 42 | #include <kio/copyjob.h> | ||
43 | #include <kio/deletejob.h> | 43 | #include <kio/deletejob.h> | ||
44 | #include <kio/chmodjob.h> | 44 | #include <kio/chmodjob.h> | ||
45 | #include <kio/statjob.h> | ||||
45 | #include "kiotesthelper.h" // createTestFile etc. | 46 | #include "kiotesthelper.h" // createTestFile etc. | ||
46 | #ifndef Q_OS_WIN | 47 | #ifndef Q_OS_WIN | ||
47 | #include <unistd.h> // for readlink | 48 | #include <unistd.h> // for readlink | ||
48 | #endif | 49 | #endif | ||
49 | 50 | | |||
50 | QTEST_MAIN(JobTest) | 51 | QTEST_MAIN(JobTest) | ||
51 | 52 | | |||
52 | // The code comes partly from kdebase/kioslave/trash/testtrash.cpp | 53 | // The code comes partly from kdebase/kioslave/trash/testtrash.cpp | ||
▲ Show 20 Lines • Show All 1355 Lines • ▼ Show 20 Line(s) | 1404 | #else | |||
1408 | // TODO set setSide, setDetails | 1409 | // TODO set setSide, setDetails | ||
1409 | const KIO::UDSEntry &entry = job->statResult(); | 1410 | const KIO::UDSEntry &entry = job->statResult(); | ||
1410 | QVERIFY(!entry.isDir()); | 1411 | QVERIFY(!entry.isDir()); | ||
1411 | QVERIFY(!entry.isLink()); | 1412 | QVERIFY(!entry.isLink()); | ||
1412 | QCOMPARE(entry.stringValue(KIO::UDSEntry::UDS_NAME), QString()); | 1413 | QCOMPARE(entry.stringValue(KIO::UDSEntry::UDS_NAME), QString()); | ||
1413 | #endif | 1414 | #endif | ||
1414 | } | 1415 | } | ||
1415 | 1416 | | |||
1417 | void JobTest::statDetailsBasic() | ||||
1418 | { | ||||
1419 | const QString filePath = homeTmpDir() + "fileFromHome"; | ||||
1420 | createTestFile(filePath); | ||||
1421 | const QUrl url(QUrl::fromLocalFile(filePath)); | ||||
1422 | KIO::StatJob *job = KIO::statDetails(url, KIO::StatJob::StatSide::SourceSide, KIO::StatDetail::Basic, KIO::HideProgressInfo); | ||||
1423 | QVERIFY(job); | ||||
1424 | QVERIFY2(job->exec(), qPrintable(job->errorString())); | ||||
1425 | // TODO set setSide | ||||
1426 | const KIO::UDSEntry &entry = job->statResult(); | ||||
1427 | | ||||
1428 | // we only get filename, access, type, size, (no linkdest) | ||||
1429 | QCOMPARE(entry.count(), 4); | ||||
1430 | | ||||
1431 | QVERIFY(!entry.isDir()); | ||||
1432 | QVERIFY(!entry.isLink()); | ||||
1433 | QVERIFY(entry.numberValue(KIO::UDSEntry::UDS_ACCESS) > 0); | ||||
1434 | QCOMPARE(entry.stringValue(KIO::UDSEntry::UDS_NAME), QStringLiteral("fileFromHome")); | ||||
1435 | | ||||
1436 | // Compare what we get via kio_file and what we get when KFileItem stat()s directly | ||||
1437 | // for the requested fields | ||||
1438 | const KFileItem kioItem(entry, url); | ||||
1439 | const KFileItem fileItem(url); | ||||
1440 | QCOMPARE(kioItem.name(), fileItem.name()); | ||||
1441 | QCOMPARE(kioItem.url(), fileItem.url()); | ||||
1442 | QCOMPARE(kioItem.size(), fileItem.size()); | ||||
1443 | QCOMPARE(kioItem.user(), ""); | ||||
1444 | QCOMPARE(kioItem.group(), ""); | ||||
1445 | QCOMPARE(kioItem.mimetype(), "application/octet-stream"); | ||||
1446 | QCOMPARE(kioItem.permissions(), 438); | ||||
1447 | QCOMPARE(kioItem.time(KFileItem::ModificationTime), QDateTime()); | ||||
1448 | QCOMPARE(kioItem.time(KFileItem::AccessTime), QDateTime()); | ||||
1449 | } | ||||
1450 | | ||||
1451 | void JobTest::statDetailsBasicSetDetails() | ||||
1452 | { | ||||
1453 | const QString filePath = homeTmpDir() + "fileFromHome"; | ||||
1454 | createTestFile(filePath); | ||||
1455 | const QUrl url(QUrl::fromLocalFile(filePath)); | ||||
1456 | KIO::StatJob *job = KIO::stat(url); | ||||
1457 | job->setDetails(KIO::StatDetail::Basic); | ||||
1458 | QVERIFY(job); | ||||
1459 | QVERIFY2(job->exec(), qPrintable(job->errorString())); | ||||
1460 | // TODO set setSide | ||||
1461 | const KIO::UDSEntry &entry = job->statResult(); | ||||
1462 | | ||||
1463 | // we only get filename, access, type, size, (no linkdest) | ||||
1464 | QCOMPARE(entry.count(), 4); | ||||
1465 | | ||||
1466 | QVERIFY(!entry.isDir()); | ||||
1467 | QVERIFY(!entry.isLink()); | ||||
1468 | QVERIFY(entry.numberValue(KIO::UDSEntry::UDS_ACCESS) > 0); | ||||
1469 | QCOMPARE(entry.stringValue(KIO::UDSEntry::UDS_NAME), QStringLiteral("fileFromHome")); | ||||
1470 | | ||||
1471 | // Compare what we get via kio_file and what we get when KFileItem stat()s directly | ||||
1472 | // for the requested fields | ||||
1473 | const KFileItem kioItem(entry, url); | ||||
1474 | const KFileItem fileItem(url); | ||||
1475 | QCOMPARE(kioItem.name(), fileItem.name()); | ||||
1476 | QCOMPARE(kioItem.url(), fileItem.url()); | ||||
1477 | QCOMPARE(kioItem.size(), fileItem.size()); | ||||
1478 | QCOMPARE(kioItem.user(), ""); | ||||
1479 | QCOMPARE(kioItem.group(), ""); | ||||
1480 | QCOMPARE(kioItem.mimetype(), "application/octet-stream"); | ||||
1481 | QCOMPARE(kioItem.permissions(), 438); | ||||
1482 | QCOMPARE(kioItem.time(KFileItem::ModificationTime), QDateTime()); | ||||
1483 | QCOMPARE(kioItem.time(KFileItem::AccessTime), QDateTime()); | ||||
1484 | } | ||||
1485 | | ||||
1416 | #ifndef Q_OS_WIN | 1486 | #ifndef Q_OS_WIN | ||
1417 | void JobTest::statSymlink() | 1487 | void JobTest::statSymlink() | ||
1418 | { | 1488 | { | ||
1419 | const QString filePath = homeTmpDir() + "fileFromHome"; | 1489 | const QString filePath = homeTmpDir() + "fileFromHome"; | ||
1420 | createTestFile(filePath); | 1490 | createTestFile(filePath); | ||
1421 | const QString symlink = otherTmpDir() + "link"; | 1491 | const QString symlink = otherTmpDir() + "link"; | ||
1422 | QVERIFY(QFile(filePath).link(symlink)); | 1492 | QVERIFY(QFile(filePath).link(symlink)); | ||
1423 | QVERIFY(QFile::exists(symlink)); | 1493 | QVERIFY(QFile::exists(symlink)); | ||
1424 | setTimeStamp(symlink, QDateTime::currentDateTime().addSecs(-20)); // differentiate link time and source file time | 1494 | setTimeStamp(symlink, QDateTime::currentDateTime().addSecs(-20)); // differentiate link time and source file time | ||
1425 | 1495 | | |||
1426 | const QUrl url(QUrl::fromLocalFile(symlink)); | 1496 | const QUrl url(QUrl::fromLocalFile(symlink)); | ||
1427 | KIO::StatJob *job = KIO::stat(url, KIO::HideProgressInfo); | 1497 | KIO::StatJob *job = KIO::statDetails(url, KIO::StatJob::StatSide::SourceSide, | ||
1498 | KIO::StatDetail::Basic | KIO::StatDetail::ResolveSymlink | KIO::StatDetail::User | KIO::StatDetail::Time, | ||||
1499 | KIO::HideProgressInfo); | ||||
1428 | QVERIFY(job); | 1500 | QVERIFY(job); | ||
1429 | QVERIFY2(job->exec(), qPrintable(job->errorString())); | 1501 | QVERIFY2(job->exec(), qPrintable(job->errorString())); | ||
1430 | // TODO set setSide, setDetails | 1502 | // TODO set setSide, setDetails | ||
1431 | const KIO::UDSEntry &entry = job->statResult(); | 1503 | const KIO::UDSEntry &entry = job->statResult(); | ||
1504 | | ||||
1505 | // we only get filename, access, type, size, linkdest, uid, gid, btime, mtime, atime | ||||
1506 | QCOMPARE(entry.count(), 10); | ||||
1507 | | ||||
1432 | QVERIFY(!entry.isDir()); | 1508 | QVERIFY(!entry.isDir()); | ||
1433 | QVERIFY(entry.isLink()); | 1509 | QVERIFY(entry.isLink()); | ||
1510 | QVERIFY(entry.numberValue(KIO::UDSEntry::UDS_ACCESS) > 0); | ||||
1434 | QCOMPARE(entry.stringValue(KIO::UDSEntry::UDS_NAME), QStringLiteral("link")); | 1511 | QCOMPARE(entry.stringValue(KIO::UDSEntry::UDS_NAME), QStringLiteral("link")); | ||
1435 | 1512 | | |||
1436 | // Compare what we get via kio_file and what we get when KFileItem stat()s directly | 1513 | // Compare what we get via kio_file and what we get when KFileItem stat()s directly | ||
1437 | const KFileItem kioItem(entry, url); | 1514 | const KFileItem kioItem(entry, url); | ||
1438 | const KFileItem fileItem(url); | 1515 | const KFileItem fileItem(url); | ||
1439 | QCOMPARE(kioItem.name(), fileItem.name()); | 1516 | QCOMPARE(kioItem.name(), fileItem.name()); | ||
1440 | QCOMPARE(kioItem.url(), fileItem.url()); | 1517 | QCOMPARE(kioItem.url(), fileItem.url()); | ||
1441 | QVERIFY(kioItem.isLink()); | 1518 | QVERIFY(kioItem.isLink()); | ||
▲ Show 20 Lines • Show All 688 Lines • Show Last 20 Lines |