From 4f9b2cb026e334eb24dd35b05422b9dad6d8a2f3 Mon Sep 17 00:00:00 2001 From: Liang Qi Date: Thu, 21 Sep 2017 13:14:40 +0200 Subject: Remove duplicate qnx from the platform file selector names Update the QFileSelector tests for QNX. Co-authored-by: James McDonnell Change-Id: I68a8fde86725596323b539433287ac1a18fac1eb Reviewed-by: Thiago Macieira --- tests/auto/corelib/io/qfileselector/platforms/+qnx/test | 0 tests/auto/corelib/io/qfileselector/platforms/+qnx/test2 | 0 tests/auto/corelib/io/qfileselector/platforms/+unix/+qnx/test | 0 tests/auto/corelib/io/qfileselector/qfileselector.qrc | 3 +++ tests/auto/corelib/io/qfileselector/tst_qfileselector.cpp | 2 +- 5 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 tests/auto/corelib/io/qfileselector/platforms/+qnx/test create mode 100644 tests/auto/corelib/io/qfileselector/platforms/+qnx/test2 create mode 100644 tests/auto/corelib/io/qfileselector/platforms/+unix/+qnx/test (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/io/qfileselector/platforms/+qnx/test b/tests/auto/corelib/io/qfileselector/platforms/+qnx/test new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/auto/corelib/io/qfileselector/platforms/+qnx/test2 b/tests/auto/corelib/io/qfileselector/platforms/+qnx/test2 new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/auto/corelib/io/qfileselector/platforms/+unix/+qnx/test b/tests/auto/corelib/io/qfileselector/platforms/+unix/+qnx/test new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/auto/corelib/io/qfileselector/qfileselector.qrc b/tests/auto/corelib/io/qfileselector/qfileselector.qrc index ea9b8270e0..54b2e0a0e2 100644 --- a/tests/auto/corelib/io/qfileselector/qfileselector.qrc +++ b/tests/auto/corelib/io/qfileselector/qfileselector.qrc @@ -21,6 +21,7 @@ platforms/+unix/+darwin/test platforms/+unix/+haiku/test platforms/+unix/+linux/test + platforms/+unix/+qnx/test platforms/+unix/test platforms/+windows/+wince/test platforms/+windows/+winnt/test @@ -34,6 +35,7 @@ platforms/+mac/test platforms/+haiku/test platforms/+linux/test + platforms/+qnx/test platforms/+wince/test platforms/+winrt/test @@ -44,6 +46,7 @@ platforms/+macos/test2 platforms/+haiku/test2 platforms/+linux/test2 + platforms/+qnx/test2 platforms/+wince/test2 platforms/+winnt/test2 platforms/+winrt/test2 diff --git a/tests/auto/corelib/io/qfileselector/tst_qfileselector.cpp b/tests/auto/corelib/io/qfileselector/tst_qfileselector.cpp index c537e43802..c9f1e3d9f6 100644 --- a/tests/auto/corelib/io/qfileselector/tst_qfileselector.cpp +++ b/tests/auto/corelib/io/qfileselector/tst_qfileselector.cpp @@ -86,7 +86,7 @@ void tst_QFileSelector::basicTest_data() QString expectedPlatform2File(""); //Only the last selector QString expectedPlatform3File; // Only the first selector (the family) #if defined(Q_OS_UNIX) && !defined(Q_OS_ANDROID) && \ - !defined(Q_OS_DARWIN) && !defined(Q_OS_LINUX) && !defined(Q_OS_HAIKU) + !defined(Q_OS_DARWIN) && !defined(Q_OS_LINUX) && !defined(Q_OS_HAIKU) && !defined(Q_OS_QNX) /* We are only aware of specific unixes, and do not have test files for any of the others. However those unixes can get a selector added from the result of a uname call, so this will lead to a case where we don't have that file so we can't expect the concatenation of platform -- cgit v1.2.3 From 9574436666c1806a69fdd5f7a83f41ad0f6152ac Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 21 Sep 2017 13:59:05 -0700 Subject: QUrl: make sure setPort(nonnegative) is taken as part of authority There were a couple of corner cases where doing setPort() would result in QUrl thinking that an authority was not present. Since the full URL parsing implies that a host is always present if the authority is present, then we also imply that setting the port number makes the host be present too. Change-Id: I69f37f9304f24709a823fffd14e67c12da18d69f Reviewed-by: David Faure --- tests/auto/corelib/io/qurl/tst_qurl.cpp | 35 +++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/io/qurl/tst_qurl.cpp b/tests/auto/corelib/io/qurl/tst_qurl.cpp index 1ff85fc6dc..0bbd1b9f15 100644 --- a/tests/auto/corelib/io/qurl/tst_qurl.cpp +++ b/tests/auto/corelib/io/qurl/tst_qurl.cpp @@ -2080,6 +2080,11 @@ void tst_QUrl::isValid() QVERIFY(!url.isValid()); QVERIFY(url.toString().isEmpty()); QVERIFY(url.errorString().contains("Path component starts with '//' and authority is absent")); + + // should disappear if we set a port + url.setPort(80); + QVERIFY(url.isValid()); + QCOMPARE(url.toString(), QString("http://:80//example.com")); } { @@ -2088,6 +2093,13 @@ void tst_QUrl::isValid() QVERIFY(!url.isValid()); QVERIFY(url.toString().isEmpty()); QVERIFY(url.errorString().contains("':' before any '/'")); + + // this specific error disappears if we set anything in the authority, + // but then we run into another error + url.setPort(80); + QVERIFY(!url.isValid()); + QVERIFY(url.toString().isEmpty()); + QVERIFY(url.errorString().contains("Path component is relative and authority is present")); } { @@ -2827,6 +2839,29 @@ void tst_QUrl::setPort() QCOMPARE(url.port(), -1); QVERIFY(url.errorString().contains("out of range")); } + + { + QUrl reference("//:80"); + QUrl piecewise; + piecewise.setPort(80); + QCOMPARE(piecewise, reference); + } + + { + // setAuthority must clear the port + QUrl url("http://example.com:80"); + url.setAuthority("example.org"); + QCOMPARE(url.port(), -1); + QCOMPARE(url.toString(), QString("http://example.org")); + } + + { + // setAuthority must clear the port + QUrl url("http://example.com:80"); + url.setAuthority(QString()); + QCOMPARE(url.port(), -1); + QCOMPARE(url.toString(), QString("http:")); + } } void tst_QUrl::port_data() -- cgit v1.2.3 From cd45d0f712f844d05b88801bc000550db0856043 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 25 Oct 2017 13:36:33 +0200 Subject: tst_QFile: Introduce StdioFileGuard MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Guard the FILE * obtained by fopen() by a RAI class ensuring the file is closed on destruction. Change-Id: I9297f91ca2120238f3a44bad92bca5f920e01aa8 Reviewed-by: Jędrzej Nowacki --- tests/auto/corelib/io/qfile/tst_qfile.cpp | 64 +++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 21 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/io/qfile/tst_qfile.cpp b/tests/auto/corelib/io/qfile/tst_qfile.cpp index 32165ad2b8..450229e01e 100644 --- a/tests/auto/corelib/io/qfile/tst_qfile.cpp +++ b/tests/auto/corelib/io/qfile/tst_qfile.cpp @@ -109,6 +109,30 @@ QT_END_NAMESPACE Q_DECLARE_METATYPE(QFile::FileError) + +class StdioFileGuard +{ + Q_DISABLE_COPY(StdioFileGuard) +public: + explicit StdioFileGuard(FILE *f = nullptr) : m_file(f) {} + ~StdioFileGuard() { close(); } + + operator FILE *() const { return m_file; } + + void close(); + +private: + FILE * m_file; +}; + +void StdioFileGuard::close() +{ + if (m_file != nullptr) { + fclose(m_file); + m_file = nullptr; + } +} + class tst_QFile : public QObject { Q_OBJECT @@ -660,14 +684,13 @@ void tst_QFile::size() } { - QFile f; - FILE* stream = QT_FOPEN(filename.toLocal8Bit().constData(), "rb"); + StdioFileGuard stream(QT_FOPEN(filename.toLocal8Bit().constData(), "rb")); QVERIFY( stream ); + QFile f; QVERIFY( f.open(stream, QIODevice::ReadOnly) ); QCOMPARE( f.size(), size ); f.close(); - fclose(stream); } { @@ -1598,6 +1621,7 @@ void tst_QFile::largeUncFileSupport() qint64 dataOffset = Q_INT64_C(8589914592); QByteArray knownData("LargeFile content at offset 8589914592"); QString largeFile("//" + QtNetworkSettings::winServerName() + "/testsharelargefile/file.bin"); + const QByteArray largeFileEncoded = QFile::encodeName(largeFile); { // 1) Native file handling. @@ -1612,24 +1636,24 @@ void tst_QFile::largeUncFileSupport() } { // 2) stdlib file handling. + StdioFileGuard fh(fopen(largeFileEncoded.constData(), "rb")); + QVERIFY(fh); QFile file; - FILE *fh = fopen(QFile::encodeName(largeFile).data(), "rb"); QVERIFY(file.open(fh, QIODevice::ReadOnly)); QCOMPARE(file.size(), size); QVERIFY(file.seek(dataOffset)); QCOMPARE(file.read(knownData.size()), knownData); - fclose(fh); } { // 3) stdio file handling. - QFile file; - FILE *fh = fopen(QFile::encodeName(largeFile).data(), "rb"); + StdioFileGuard fh(fopen(largeFileEncoded.constData(), "rb")); + QVERIFY(fh); int fd = int(_fileno(fh)); + QFile file; QVERIFY(file.open(fd, QIODevice::ReadOnly)); QCOMPARE(file.size(), size); QVERIFY(file.seek(dataOffset)); QCOMPARE(file.read(knownData.size()), knownData); - fclose(fh); } } #endif @@ -1670,7 +1694,7 @@ void tst_QFile::bufferedRead() file.write("abcdef"); file.close(); - FILE *stdFile = fopen("stdfile.txt", "r"); + StdioFileGuard stdFile(fopen("stdfile.txt", "r")); QVERIFY(stdFile); char c; QCOMPARE(int(fread(&c, 1, 1, stdFile)), 1); @@ -1685,8 +1709,6 @@ void tst_QFile::bufferedRead() QCOMPARE(c, 'b'); QCOMPARE(file.pos(), qlonglong(2)); } - - fclose(stdFile); } #ifdef Q_OS_UNIX @@ -1815,7 +1837,7 @@ void tst_QFile::FILEReadWrite() f.close(); } - FILE *fp = fopen("FILEReadWrite.txt", "r+b"); + StdioFileGuard fp(fopen("FILEReadWrite.txt", "r+b")); QVERIFY(fp); QFile file; QVERIFY2(file.open(fp, QFile::ReadWrite), msgOpenFailed(file).constData()); @@ -1850,7 +1872,7 @@ void tst_QFile::FILEReadWrite() } file.close(); - fclose(fp); + fp.close(); // check modified file { @@ -2435,11 +2457,10 @@ void tst_QFile::virtualFile() void tst_QFile::textFile() { -#if defined(Q_OS_WIN) - FILE *fs = ::fopen("writeabletextfile", "wt"); -#else - FILE *fs = ::fopen("writeabletextfile", "w"); -#endif + const char *openMode = QOperatingSystemVersion::current().type() != QOperatingSystemVersion::Windows + ? "w" : "wt"; + StdioFileGuard fs(fopen("writeabletextfile", openMode)); + QVERIFY(fs); QFile f; QByteArray part1("This\nis\na\nfile\nwith\nnewlines\n"); QByteArray part2("Add\nsome\nmore\nnewlines\n"); @@ -2448,7 +2469,7 @@ void tst_QFile::textFile() f.write(part1); f.write(part2); f.close(); - ::fclose(fs); + fs.close(); QFile file("writeabletextfile"); QVERIFY2(file.open(QIODevice::ReadOnly), msgOpenFailed(file).constData()); @@ -2704,11 +2725,12 @@ void tst_QFile::handle() //test round trip of adopted stdio file handle QFile file2; - FILE *fp = fopen(qPrintable(m_testSourceFile), "r"); + StdioFileGuard fp(fopen(qPrintable(m_testSourceFile), "r")); + QVERIFY(fp); file2.open(fp, QIODevice::ReadOnly); QCOMPARE(int(file2.handle()), int(fileno(fp))); QCOMPARE(int(file2.handle()), int(fileno(fp))); - fclose(fp); + fp.close(); //test round trip of adopted posix file handle #ifdef Q_OS_UNIX -- cgit v1.2.3 From 1c3dc8cfb8e72770d56f2fbe131adbfe542a51c7 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 25 Oct 2017 13:57:26 +0200 Subject: tst_QFile::largeUncFileSupport(): Use QTRY_VERIFY() to open the file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Open failures due to sharing violations have been observed in Coin. Change-Id: If7fbe01a454b3c343c0b87f73db50c28eae901c3 Reviewed-by: Edward Welbourne Reviewed-by: Jędrzej Nowacki --- tests/auto/corelib/io/qfile/tst_qfile.cpp | 36 ++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/io/qfile/tst_qfile.cpp b/tests/auto/corelib/io/qfile/tst_qfile.cpp index 450229e01e..5f3ebeadd7 100644 --- a/tests/auto/corelib/io/qfile/tst_qfile.cpp +++ b/tests/auto/corelib/io/qfile/tst_qfile.cpp @@ -1615,6 +1615,27 @@ void tst_QFile::writeTextFile() } #if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) +// Helper for executing QFile::open() with warning in QTRY_VERIFY(), which evaluates the condition +// multiple times +static bool qFileOpen(QFile &file, QIODevice::OpenMode ioFlags) +{ + const bool result = file.isOpen() || file.open(ioFlags); + if (!result) + qWarning() << "Cannot open" << file.fileName() << ':' << file.errorString(); + return result; +} + +// Helper for executing fopen() with warning in QTRY_VERIFY(), which evaluates the condition +// multiple times +static bool fOpen(const QByteArray &fileName, const char *mode, FILE **file) +{ + if (*file == nullptr) + *file = fopen(fileName.constData(), mode); + if (*file == nullptr) + qWarning("Cannot open %s: %s", fileName.constData(), strerror(errno)); + return *file != nullptr; +} + void tst_QFile::largeUncFileSupport() { qint64 size = Q_INT64_C(8589934592); @@ -1629,15 +1650,18 @@ void tst_QFile::largeUncFileSupport() QVERIFY2(file.exists(), msgFileDoesNotExist(largeFile)); QCOMPARE(file.size(), size); - QVERIFY2(file.open(QIODevice::ReadOnly), msgOpenFailed(file).constData()); + // Retry in case of sharing violation + QTRY_VERIFY2(qFileOpen(file, QIODevice::ReadOnly), msgOpenFailed(file).constData()); QCOMPARE(file.size(), size); QVERIFY(file.seek(dataOffset)); QCOMPARE(file.read(knownData.size()), knownData); } { // 2) stdlib file handling. - StdioFileGuard fh(fopen(largeFileEncoded.constData(), "rb")); - QVERIFY(fh); + FILE *fhF = nullptr; + // Retry in case of sharing violation + QTRY_VERIFY(fOpen(largeFileEncoded, "rb", &fhF)); + StdioFileGuard fh(fhF); QFile file; QVERIFY(file.open(fh, QIODevice::ReadOnly)); QCOMPARE(file.size(), size); @@ -1646,8 +1670,10 @@ void tst_QFile::largeUncFileSupport() } { // 3) stdio file handling. - StdioFileGuard fh(fopen(largeFileEncoded.constData(), "rb")); - QVERIFY(fh); + FILE *fhF = nullptr; + // Retry in case of sharing violation + QTRY_VERIFY(fOpen(largeFileEncoded, "rb", &fhF)); + StdioFileGuard fh(fhF); int fd = int(_fileno(fh)); QFile file; QVERIFY(file.open(fd, QIODevice::ReadOnly)); -- cgit v1.2.3