testlocaldiscovery.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * This software is in the public domain, furnished "as is", without technical
  3. * support, and with no warranty, express or implied, as to its usefulness for
  4. * any purpose.
  5. *
  6. */
  7. #include <QtTest>
  8. #include "syncenginetestutils.h"
  9. #include <syncengine.h>
  10. #include <localdiscoverytracker.h>
  11. using namespace OCC;
  12. class TestLocalDiscovery : public QObject
  13. {
  14. Q_OBJECT
  15. private slots:
  16. // Check correct behavior when local discovery is partially drawn from the db
  17. void testLocalDiscoveryStyle()
  18. {
  19. FakeFolder fakeFolder{ FileInfo::A12_B12_C12_S12() };
  20. LocalDiscoveryTracker tracker;
  21. connect(&fakeFolder.syncEngine(), &SyncEngine::itemCompleted, &tracker, &LocalDiscoveryTracker::slotItemCompleted);
  22. connect(&fakeFolder.syncEngine(), &SyncEngine::finished, &tracker, &LocalDiscoveryTracker::slotSyncFinished);
  23. // More subdirectories are useful for testing
  24. fakeFolder.localModifier().mkdir("A/X");
  25. fakeFolder.localModifier().mkdir("A/Y");
  26. fakeFolder.localModifier().insert("A/X/x1");
  27. fakeFolder.localModifier().insert("A/Y/y1");
  28. tracker.addTouchedPath("A/X");
  29. tracker.startSyncFullDiscovery();
  30. QVERIFY(fakeFolder.syncOnce());
  31. QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
  32. QVERIFY(tracker.localDiscoveryPaths().empty());
  33. // Test begins
  34. fakeFolder.localModifier().insert("A/a3");
  35. fakeFolder.localModifier().insert("A/X/x2");
  36. fakeFolder.localModifier().insert("A/Y/y2");
  37. fakeFolder.localModifier().insert("B/b3");
  38. fakeFolder.remoteModifier().insert("C/c3");
  39. tracker.addTouchedPath("A/X");
  40. fakeFolder.syncEngine().setLocalDiscoveryOptions(LocalDiscoveryStyle::DatabaseAndFilesystem, tracker.localDiscoveryPaths());
  41. tracker.startSyncPartialDiscovery();
  42. QVERIFY(fakeFolder.syncOnce());
  43. QVERIFY(fakeFolder.currentRemoteState().find("A/a3"));
  44. QVERIFY(fakeFolder.currentRemoteState().find("A/X/x2"));
  45. QVERIFY(!fakeFolder.currentRemoteState().find("A/Y/y2"));
  46. QVERIFY(!fakeFolder.currentRemoteState().find("B/b3"));
  47. QVERIFY(fakeFolder.currentLocalState().find("C/c3"));
  48. QCOMPARE(fakeFolder.syncEngine().lastLocalDiscoveryStyle(), LocalDiscoveryStyle::DatabaseAndFilesystem);
  49. QVERIFY(tracker.localDiscoveryPaths().empty());
  50. QVERIFY(fakeFolder.syncOnce());
  51. QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
  52. QCOMPARE(fakeFolder.syncEngine().lastLocalDiscoveryStyle(), LocalDiscoveryStyle::FilesystemOnly);
  53. QVERIFY(tracker.localDiscoveryPaths().empty());
  54. }
  55. void testLocalDiscoveryDecision()
  56. {
  57. FakeFolder fakeFolder{ FileInfo::A12_B12_C12_S12() };
  58. auto &engine = fakeFolder.syncEngine();
  59. QVERIFY(engine.shouldDiscoverLocally(""));
  60. QVERIFY(engine.shouldDiscoverLocally("A"));
  61. QVERIFY(engine.shouldDiscoverLocally("A/X"));
  62. fakeFolder.syncEngine().setLocalDiscoveryOptions(
  63. LocalDiscoveryStyle::DatabaseAndFilesystem,
  64. { "A/X", "foo bar space/touch", "foo/", "zzz" });
  65. QVERIFY(engine.shouldDiscoverLocally(""));
  66. QVERIFY(engine.shouldDiscoverLocally("A"));
  67. QVERIFY(engine.shouldDiscoverLocally("A/X"));
  68. QVERIFY(!engine.shouldDiscoverLocally("B"));
  69. QVERIFY(!engine.shouldDiscoverLocally("A B"));
  70. QVERIFY(!engine.shouldDiscoverLocally("B/X"));
  71. QVERIFY(!engine.shouldDiscoverLocally("A/X/Y"));
  72. QVERIFY(engine.shouldDiscoverLocally("foo bar space"));
  73. QVERIFY(engine.shouldDiscoverLocally("foo"));
  74. QVERIFY(!engine.shouldDiscoverLocally("foo bar"));
  75. QVERIFY(!engine.shouldDiscoverLocally("foo bar/touch"));
  76. fakeFolder.syncEngine().setLocalDiscoveryOptions(
  77. LocalDiscoveryStyle::DatabaseAndFilesystem,
  78. {});
  79. QVERIFY(!engine.shouldDiscoverLocally(""));
  80. }
  81. };
  82. QTEST_GUILESS_MAIN(TestLocalDiscovery)
  83. #include "testlocaldiscovery.moc"