From 6792dd4035070eb340f3acd3417c3d441c1c1385 Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Tue, 21 Jan 2025 14:38:16 +0100 Subject: [PATCH] Add file/dir name normalization test --- test/testlocaldiscovery.cpp | 61 +++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/test/testlocaldiscovery.cpp b/test/testlocaldiscovery.cpp index 58e0b32878a..24a88057ea5 100644 --- a/test/testlocaldiscovery.cpp +++ b/test/testlocaldiscovery.cpp @@ -238,6 +238,67 @@ private Q_SLOTS: QVERIFY(!fakeFolder.currentRemoteState().find(QStringLiteral("C/.foo"))); QVERIFY(!fakeFolder.currentRemoteState().find(QStringLiteral("C/bar"))); } + + void testDirNameEncoding() + { + QFETCH_GLOBAL(Vfs::Mode, vfsMode); + QFETCH_GLOBAL(bool, filesAreDehydrated); + + const unsigned char a_umlaut_composed_bytes[] = {0xc3, 0xa4, 0x00}; + const QString a_umlaut_composed = QString::fromUtf8(reinterpret_cast(a_umlaut_composed_bytes)); + const QString a_umlaut_decomposed = a_umlaut_composed.normalized(QString::NormalizationForm_D); + + FakeFolder fakeFolder({FileInfo{}}, vfsMode, filesAreDehydrated); + fakeFolder.remoteModifier().mkdir(QStringLiteral("P")); + fakeFolder.remoteModifier().mkdir(QStringLiteral("P/A")); + fakeFolder.remoteModifier().insert(QStringLiteral("P/A/") + a_umlaut_decomposed); + fakeFolder.remoteModifier().mkdir(QStringLiteral("P/B") + a_umlaut_decomposed); + fakeFolder.remoteModifier().insert(QStringLiteral("P/B") + a_umlaut_decomposed + QStringLiteral("/b")); + + LocalDiscoveryTracker tracker; + connect(&fakeFolder.syncEngine(), &SyncEngine::itemCompleted, &tracker, &LocalDiscoveryTracker::slotItemCompleted); + connect(&fakeFolder.syncEngine(), &SyncEngine::finished, &tracker, &LocalDiscoveryTracker::slotSyncFinished); + + QVERIFY(fakeFolder.applyLocalModificationsAndSync()); + + { + auto localState = fakeFolder.currentLocalState(); + FileInfo *localFile = localState.find(QStringLiteral("P/A/") + a_umlaut_composed); + QVERIFY(localFile != nullptr); // check if the file exists + } + { + auto localState = fakeFolder.currentLocalState(); + FileInfo *localFile = localState.find(QStringLiteral("P/B") + a_umlaut_composed + QStringLiteral("/b")); + QVERIFY(localFile != nullptr); // check if the file exists + } + + qDebug() << "*** MARK"; + + fakeFolder.syncEngine().setLocalDiscoveryOptions(LocalDiscoveryStyle::DatabaseAndFilesystem, {QStringLiteral("P")}); + tracker.startSyncFullDiscovery(); + QVERIFY(fakeFolder.applyLocalModificationsAndSync()); + + { + auto remoteState = fakeFolder.currentRemoteState(); + FileInfo *remoteFile = remoteState.find(QStringLiteral("P/A/") + a_umlaut_composed); + QVERIFY(remoteFile == nullptr); // check if the file exists + } + { + auto remoteState = fakeFolder.currentRemoteState(); + FileInfo *remoteFile = remoteState.find(QStringLiteral("P/A/") + a_umlaut_decomposed); + QVERIFY(remoteFile != nullptr); // check if the file exists + } + { + auto remoteState = fakeFolder.currentRemoteState(); + FileInfo *remoteFile = remoteState.find(QStringLiteral("P/B") + a_umlaut_composed + QStringLiteral("/b")); + QVERIFY(remoteFile != nullptr); // check if the file exists + } + { + auto remoteState = fakeFolder.currentRemoteState(); + FileInfo *remoteFile = remoteState.find(QStringLiteral("P/B") + a_umlaut_decomposed + QStringLiteral("/b")); + QVERIFY(remoteFile != nullptr); // check if the file exists + } + } }; QTEST_GUILESS_MAIN(TestLocalDiscovery)