From 7501a03db6f061d5044ff667debdb97ad8e43fc6 Mon Sep 17 00:00:00 2001 From: alex-z Date: Mon, 15 Apr 2024 06:44:06 +0200 Subject: [PATCH] Unit tests. Test .lnk file with a real shortcut file. Test will hang if QFileInfo is used on .lnk files. Signed-off-by: alex-z --- test/CMakeLists.txt | 1 + test/fakeshortcut.base64 | 1 + test/testsynccfapi.cpp | 29 +++++++++++++++++++++++++++++ 3 files changed, 31 insertions(+) create mode 100644 test/fakeshortcut.base64 diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index ca00593ac161b..75eaaf7049e26 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -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) diff --git a/test/fakeshortcut.base64 b/test/fakeshortcut.base64 new file mode 100644 index 0000000000000..d8238b664e110 --- /dev/null +++ b/test/fakeshortcut.base64 @@ -0,0 +1 @@ +TAAAAAEUAgAAAAAAwAAAAAAAAEbbQAAAIAAAAAAJorPzgNoB9zzzZuSO2gEACaKz84DaAdAmUQAAAAAAAQAAAAAAAAAAAAAAAAAAAH8BFAAfUOBP0CDqOmkQotgIACswMJ0ZAC9DOlwAAAAAAAAAAAAAAAAAAAAAAAAAjAAxAAAAAACPWAkbEQBQUk9HUkF+MQAAdAAJAAQA776nVBorj1gJGy4AAABnIwAAAABxAAAAAAAAAAAASgAAAAAAPAGZAFAAcgBvAGcAcgBhAG0A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AQAAAAAHwAAAAkAAABTAC0AMQAtADUALQAxADgAAAAAAAAAAAA5AAAAMVNQU7EWbUStjXBIp0hALqQ9eIwdAAAAaAAAAABIAAAAF1Nw2ThL+k6aiadcTJDozAAAAAAAAAAAAAAAAA== \ No newline at end of file diff --git a/test/testsynccfapi.cpp b/test/testsynccfapi.cpp index a3d84cbca8765..a306bc44e2b25 100644 --- a/test/testsynccfapi.cpp +++ b/test/testsynccfapi.cpp @@ -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"); @@ -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()