Skip to content

Commit

Permalink
Add file/dir name normalization test
Browse files Browse the repository at this point in the history
  • Loading branch information
erikjv committed Jan 21, 2025
1 parent d43a780 commit 6792dd4
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions test/testlocaldiscovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const char *>(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)
Expand Down

0 comments on commit 6792dd4

Please sign in to comment.