diff options
author | Denis Shienkov <denis.shienkov@gmail.com> | 2013-11-22 15:29:34 +0400 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-05-21 02:15:10 +0200 |
commit | aefa611f0ceac2a945cc7df15683c5072e21153f (patch) | |
tree | 730d63ff3c1c7801155f2009f41f8eb87f1925bc /tests | |
parent | 0ab9188ad7ff019747cea7800a7455e709f3bf43 (diff) |
QWinOverlappedIoNotifier: Add an extended waitForAnyNotified() method
The existing waitForNotified method has the design limitation that it
doesn't allow the tracking of multiple I/O operations on a single
file handle.
Therefore we introduce an additional method waitForAnyNotified that
returns a pointer to the triggered OVERLAPPED object.
Change-Id: I536ed7f6828daa2b0ce03f2d662eeb10aa89ca99
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
Reviewed-by: Joerg Bornemann <joerg.bornemann@digia.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/corelib/io/qwinoverlappedionotifier/tst_qwinoverlappedionotifier.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/auto/corelib/io/qwinoverlappedionotifier/tst_qwinoverlappedionotifier.cpp b/tests/auto/corelib/io/qwinoverlappedionotifier/tst_qwinoverlappedionotifier.cpp index 8321f76bec..16f94e7c5d 100644 --- a/tests/auto/corelib/io/qwinoverlappedionotifier/tst_qwinoverlappedionotifier.cpp +++ b/tests/auto/corelib/io/qwinoverlappedionotifier/tst_qwinoverlappedionotifier.cpp @@ -58,6 +58,7 @@ private slots: void readFile(); void waitForNotified_data(); void waitForNotified(); + void waitForAnyNotified(); void brokenPipe(); void multipleOperations(); @@ -195,6 +196,45 @@ void tst_QWinOverlappedIoNotifier::waitForNotified() QCOMPARE(notifier.waitForNotified(100, &overlapped), false); } +void tst_QWinOverlappedIoNotifier::waitForAnyNotified() +{ + const QString fileName = QDir::toNativeSeparators(sourceFileInfo.absoluteFilePath()); + const int readBufferSize = sourceFileInfo.size(); + + QWinOverlappedIoNotifier notifier; + HANDLE hFile = CreateFile(reinterpret_cast<const wchar_t*>(fileName.utf16()), + GENERIC_READ, FILE_SHARE_READ, + NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); + notifier.setHandle(hFile); + notifier.setEnabled(true); + QVERIFY(notifier.waitForAnyNotified(100) == 0); + + OVERLAPPED overlapped1; + ZeroMemory(&overlapped1, sizeof(OVERLAPPED)); + QByteArray buffer1(readBufferSize, 0); + BOOL readSuccess = ReadFile(hFile, buffer1.data(), buffer1.size(), NULL, &overlapped1); + QVERIFY(readSuccess || GetLastError() == ERROR_IO_PENDING); + + OVERLAPPED overlapped2; + ZeroMemory(&overlapped2, sizeof(OVERLAPPED)); + QByteArray buffer2(readBufferSize, 0); + readSuccess = ReadFile(hFile, buffer2.data(), buffer2.size(), NULL, &overlapped2); + QVERIFY(readSuccess || GetLastError() == ERROR_IO_PENDING); + + QSet<OVERLAPPED *> overlappedObjects; + overlappedObjects << &overlapped1 << &overlapped2; + + for (int i = 1; i <= 2; ++i) { + OVERLAPPED *notifiedOverlapped = notifier.waitForAnyNotified(3000); + QVERIFY(overlappedObjects.contains(notifiedOverlapped)); + overlappedObjects.remove(notifiedOverlapped); + } + + CloseHandle(hFile); + QVERIFY(overlappedObjects.isEmpty()); + QVERIFY(notifier.waitForAnyNotified(100) == 0); +} + void tst_QWinOverlappedIoNotifier::brokenPipe() { QWinOverlappedIoNotifier notifier; |