From 87aac3caca30f9f9ac9efbe895ec0f9fafab8155 Mon Sep 17 00:00:00 2001 From: Ahmad Samir Date: Sat, 24 Jun 2023 01:51:57 +0300 Subject: [PATCH] QFile: add decodeName() unittests And extend the encodeName() unittest. Change-Id: Id5cd8a1f7ffbdb0d810bdc80b28aab9eb5cfbcdb Reviewed-by: Thiago Macieira --- tests/auto/corelib/io/qfile/tst_qfile.cpp | 37 ++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/tests/auto/corelib/io/qfile/tst_qfile.cpp b/tests/auto/corelib/io/qfile/tst_qfile.cpp index 4048faf4e1..bd83aff141 100644 --- a/tests/auto/corelib/io/qfile/tst_qfile.cpp +++ b/tests/auto/corelib/io/qfile/tst_qfile.cpp @@ -201,6 +201,9 @@ private slots: #ifdef Q_OS_UNIX void isSequential(); #endif + void decodeName_data(); + void decodeName(); + void encodeName_data() { decodeName_data(); } void encodeName(); void truncate(); void seekToPos(); @@ -1914,9 +1917,41 @@ void tst_QFile::isSequential() } #endif +void tst_QFile::decodeName_data() +{ + QTest::addColumn("bytearray"); + QTest::addColumn("qstring"); + + QTest::newRow("null") << QByteArray() << QString(); + QTest::newRow("simple") << "/path/to/file"_ba << u"/path/to/file"_s; + +#ifndef Q_OS_WIN +# ifdef Q_OS_DARWIN + // Mac always expects filenames in UTF-8... and decomposed... + QTest::newRow("filé") << "/path/to/file\xCC\x81"_ba << u"/path/to/filé"_s; +# else + QTest::newRow("filé") << "/path/to/fil\xC3\xA9"_ba << u"/path/to/filé"_s; +# endif + QTest::newRow("fraction-slash") + << "/path\342\201\204to\342\201\204file"_ba << u"/path⁄to⁄file"_s; + QTest::newRow("fraction-slash-u16") << "/path\u2044to\u2044file"_ba << u"/path⁄to⁄file"_s; +#endif // !Q_OS_WIN +} + +void tst_QFile::decodeName() +{ + QFETCH(QByteArray, bytearray); + QFETCH(QString, qstring); + + QCOMPARE(QFile::decodeName(bytearray), qstring); +} + void tst_QFile::encodeName() { - QCOMPARE(QFile::encodeName(QString()), QByteArray()); + QFETCH(QString, qstring); + QFETCH(QByteArray, bytearray); + + QCOMPARE(QFile::encodeName(qstring), bytearray); } void tst_QFile::truncate()