teste2efiletransfer.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * Copyright (C) by Claudio Cambra <claudio.cambra@nextcloud.com>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  11. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. * for more details.
  13. */
  14. #include <QObject>
  15. #include <QTest>
  16. #include <QSignalSpy>
  17. #include "gui/accountstate.h"
  18. #include "gui/folderman.h"
  19. #include "common/utility.h"
  20. #include "endtoendtestutils.h"
  21. class E2eFileTransferTest : public QObject
  22. {
  23. Q_OBJECT
  24. public:
  25. E2eFileTransferTest() = default;
  26. private:
  27. private slots:
  28. void initTestCase()
  29. {
  30. qRegisterMetaType<OCC::SyncResult>("OCC::SyncResult");
  31. }
  32. void testSyncFolder()
  33. {
  34. {
  35. EndToEndTestHelper _helper;
  36. OCC::Folder *_testFolder = nullptr;
  37. QSignalSpy accountReady(&_helper, &EndToEndTestHelper::accountReady);
  38. _helper.startAccountConfig();
  39. QVERIFY(accountReady.wait(3000));
  40. const auto accountState = _helper.accountState();
  41. QSignalSpy accountConnected(accountState.data(), &OCC::AccountState::isConnectedChanged);
  42. QVERIFY(accountConnected.wait(30000));
  43. _testFolder = _helper.configureSyncFolder();
  44. QVERIFY(_testFolder);
  45. // Try the down-sync first
  46. QSignalSpy folderSyncFinished(_testFolder, &OCC::Folder::syncFinished);
  47. OCC::FolderMan::instance()->forceSyncForFolder(_testFolder);
  48. QVERIFY(folderSyncFinished.wait(3000));
  49. const auto testFolderPath = _testFolder->path();
  50. const QString expectedFilePath(testFolderPath + QStringLiteral("welcome.txt"));
  51. const QFile expectedFile(expectedFilePath);
  52. qDebug() << "Checking if expected file exists at:" << expectedFilePath;
  53. QVERIFY(expectedFile.exists());
  54. // Now write a file to test the upload
  55. const auto fileName = QStringLiteral("test_file.txt");
  56. const QString localFilePath(_testFolder->path() + fileName);
  57. QVERIFY(OCC::Utility::writeRandomFile(localFilePath));
  58. OCC::FolderMan::instance()->forceSyncForFolder(_testFolder);
  59. QVERIFY(folderSyncFinished.wait(3000));
  60. qDebug() << "First folder sync complete";
  61. const auto waitForServerToProcessTime = QTime::currentTime().addSecs(3);
  62. while (QTime::currentTime() < waitForServerToProcessTime) {
  63. QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
  64. }
  65. // Do a propfind to check for this file
  66. const QString remoteFilePath(_testFolder->remotePathTrailingSlash() + fileName);
  67. auto checkFileExistsJob = new OCC::PropfindJob(_helper.account(), remoteFilePath, this);
  68. QSignalSpy result(checkFileExistsJob, &OCC::PropfindJob::result);
  69. checkFileExistsJob->setProperties(QList<QByteArray>() << "getlastmodified");
  70. checkFileExistsJob->start();
  71. QVERIFY(result.wait(10000));
  72. // Now try to delete the file and check change is reflected
  73. QFile createdFile(localFilePath);
  74. QVERIFY(createdFile.exists());
  75. createdFile.remove();
  76. OCC::FolderMan::instance()->forceSyncForFolder(_testFolder);
  77. QVERIFY(folderSyncFinished.wait(3000));
  78. while (QTime::currentTime() < waitForServerToProcessTime) {
  79. QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
  80. }
  81. auto checkFileDeletedJob = new OCC::PropfindJob(_helper.account(), remoteFilePath, this);
  82. QSignalSpy error(checkFileDeletedJob, &OCC::PropfindJob::finishedWithError);
  83. checkFileDeletedJob->setProperties(QList<QByteArray>() << "getlastmodified");
  84. checkFileDeletedJob->start();
  85. QVERIFY(error.wait(10000));
  86. }
  87. QTest::qWait(10000);
  88. }
  89. };
  90. QTEST_MAIN(E2eFileTransferTest)
  91. #include "teste2efiletransfer.moc"