diff options
author | Liang Qi <liang.qi@qt.io> | 2017-10-30 08:43:14 +0100 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2017-10-30 08:54:05 +0100 |
commit | 17d51411132edef53e79dcbaf1046f06f79bed5d (patch) | |
tree | 38398d448b30313f91960c70a3a28cce91293da9 /tests/auto/corelib | |
parent | ea0e868c4881944207e9b3a77011e05a505ff3b7 (diff) | |
parent | 9f0dda29d5d070f63b7f098139f01f07ec91ffdf (diff) |
Merge remote-tracking branch 'origin/5.9' into 5.10
Conflicts:
src/plugins/platforms/windows/qwindowswindow.cpp
tests/auto/widgets/kernel/qaction/tst_qaction.cpp
Change-Id: Ia017a825ed2ca2d53ac586f4ae48df6f65818d40
Diffstat (limited to 'tests/auto/corelib')
7 files changed, 109 insertions, 23 deletions
diff --git a/tests/auto/corelib/io/qfile/tst_qfile.cpp b/tests/auto/corelib/io/qfile/tst_qfile.cpp index 7bf45be58c..9026864b12 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); } { @@ -1592,12 +1615,34 @@ 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); 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. @@ -1605,31 +1650,36 @@ 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. + FILE *fhF = nullptr; + // Retry in case of sharing violation + QTRY_VERIFY(fOpen(largeFileEncoded, "rb", &fhF)); + StdioFileGuard fh(fhF); 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"); + 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)); QCOMPARE(file.size(), size); QVERIFY(file.seek(dataOffset)); QCOMPARE(file.read(knownData.size()), knownData); - fclose(fh); } } #endif @@ -1670,7 +1720,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 +1735,6 @@ void tst_QFile::bufferedRead() QCOMPARE(c, 'b'); QCOMPARE(file.pos(), qlonglong(2)); } - - fclose(stdFile); } #ifdef Q_OS_UNIX @@ -1815,7 +1863,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 +1898,7 @@ void tst_QFile::FILEReadWrite() } file.close(); - fclose(fp); + fp.close(); // check modified file { @@ -2436,11 +2484,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"); @@ -2449,7 +2496,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()); @@ -2705,11 +2752,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 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 --- /dev/null +++ b/tests/auto/corelib/io/qfileselector/platforms/+qnx/test 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 --- /dev/null +++ b/tests/auto/corelib/io/qfileselector/platforms/+qnx/test2 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 --- /dev/null +++ b/tests/auto/corelib/io/qfileselector/platforms/+unix/+qnx/test 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 @@ <file>platforms/+unix/+darwin/test</file> <file>platforms/+unix/+haiku/test</file> <file>platforms/+unix/+linux/test</file> + <file>platforms/+unix/+qnx/test</file> <file>platforms/+unix/test</file> <file>platforms/+windows/+wince/test</file> <file>platforms/+windows/+winnt/test</file> @@ -34,6 +35,7 @@ <file>platforms/+mac/test</file> <file>platforms/+haiku/test</file> <file>platforms/+linux/test</file> + <file>platforms/+qnx/test</file> <file>platforms/+wince/test</file> <file>platforms/+winrt/test</file> @@ -44,6 +46,7 @@ <file>platforms/+macos/test2</file> <file>platforms/+haiku/test2</file> <file>platforms/+linux/test2</file> + <file>platforms/+qnx/test2</file> <file>platforms/+wince/test2</file> <file>platforms/+winnt/test2</file> <file>platforms/+winrt/test2</file> 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 diff --git a/tests/auto/corelib/io/qurl/tst_qurl.cpp b/tests/auto/corelib/io/qurl/tst_qurl.cpp index 400a89c03f..20282068cb 100644 --- a/tests/auto/corelib/io/qurl/tst_qurl.cpp +++ b/tests/auto/corelib/io/qurl/tst_qurl.cpp @@ -2063,6 +2063,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")); } { @@ -2071,6 +2076,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")); } { @@ -2810,6 +2822,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() |