Skip to content

Commit

Permalink
Unit tests. Test .lnk file with a real shortcut file. Test will hang …
Browse files Browse the repository at this point in the history
…if QFileInfo is used on .lnk files.

Signed-off-by: alex-z <[email protected]>
  • Loading branch information
allexzander authored and mgallien committed Jul 10, 2024
1 parent f70d1c1 commit 7501a03
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ configure_file(fakefiledrope2eefoldermetadata.json "${PROJECT_BINARY_DIR}/bin/fa
configure_file(e2etestsfakecert.pem "${PROJECT_BINARY_DIR}/bin/e2etestsfakecert.pem" COPYONLY)
configure_file(e2etestsfakecertprivatekey.pem "${PROJECT_BINARY_DIR}/bin/e2etestsfakecertprivatekey.pem" COPYONLY)
configure_file(e2etestsfakecertpublickey.pem "${PROJECT_BINARY_DIR}/bin/e2etestsfakecertpublickey.pem" COPYONLY)
configure_file(fake2eelocksucceeded.json "${PROJECT_BINARY_DIR}/bin/fakeshortcut.base64" COPYONLY)


if(ADD_E2E_TESTS)
Expand Down
1 change: 1 addition & 0 deletions test/fakeshortcut.base64
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TAAAAAEUAgAAAAAAwAAAAAAAAEbbQAAAIAAAAAAJorPzgNoB9zzzZuSO2gEACaKz84DaAdAmUQAAAAAAAQAAAAAAAAAAAAAAAAAAAH8BFAAfUOBP0CDqOmkQotgIACswMJ0ZAC9DOlwAAAAAAAAAAAAAAAAAAAAAAAAAjAAxAAAAAACPWAkbEQBQUk9HUkF+MQAAdAAJAAQA776nVBorj1gJGy4AAABnIwAAAABxAAAAAAAAAAAASgAAAAAAPAGZAFAAcgBvAGcAcgBhAG0AIABGAGkAbABlAHMAAABAAHMAaABlAGwAbAAzADIALgBkAGwAbAAsAC0AMgAxADcAOAAxAAAAGABcADEAAAAAAI9YChsQAE5FWFRDTH4xAABEAAkABADvvo9YCRuPWAobLgAAABjbAAAAA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AAAA==
29 changes: 29 additions & 0 deletions test/testsynccfapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1368,6 +1368,8 @@ private slots:
FakeFolder fakeFolder{FileInfo{}};
auto vfs = setupVfs(fakeFolder);

qInfo("Starting .lnk test. It might hand and will get killed after timeout...");

// Create a Windows shortcut (.lnk) file
fakeFolder.remoteModifier().insert("linkfile.lnk");

Expand All @@ -1379,6 +1381,33 @@ private slots:
triggerDownload(fakeFolder, "linkfile.lnk");
QVERIFY(fakeFolder.syncOnce());
QVERIFY(itemInstruction(completeSpy, "linkfile.lnk", CSYNC_INSTRUCTION_SYNC));

// a real .lnk file contents stored as base64 for tests
QFile fakeShortcutBase64(QStringLiteral("fakeshortcut.base64"));
QVERIFY(fakeShortcutBase64.open(QFile::ReadOnly));
const auto fakeShortcutBase64Binary = QByteArray::fromBase64(fakeShortcutBase64.readAll());
fakeShortcutBase64.close();

// fill the .lnk file with binary data from real shortcut and turn it into OnlineOnly file
const QString shortcutFilePathOnDisk = fakeFolder.localPath() + "linkfile.lnk";
QFile shorcutFileOnDisk(shortcutFilePathOnDisk);
QVERIFY(shorcutFileOnDisk.open(QFile::WriteOnly));
QVERIFY(shorcutFileOnDisk.write(fakeShortcutBase64Binary));
shorcutFileOnDisk.close();

// run tests on it
::setPinState(shortcutFilePathOnDisk, PinState::OnlineOnly, cfapi::NoRecurse);
QVERIFY(fakeFolder.syncOnce());
QVERIFY(vfs->pinState("linkfile.lnk").isValid());
QVERIFY(itemInstruction(completeSpy, "linkfile.lnk", CSYNC_INSTRUCTION_SYNC));

// trigget download of online only .lnk file
triggerDownload(fakeFolder, "linkfile.lnk");
QVERIFY(fakeFolder.syncOnce());
QVERIFY(vfs->pinState("linkfile.lnk").isValid());
QVERIFY(itemInstruction(completeSpy, "linkfile.lnk", CSYNC_INSTRUCTION_SYNC));

qInfo("Finishing .lnk test");
}

void testFolderDoesNotUpdatePlaceholderMetadata()
Expand Down

0 comments on commit 7501a03

Please sign in to comment.