From aefa611f0ceac2a945cc7df15683c5072e21153f Mon Sep 17 00:00:00 2001 From: Denis Shienkov Date: Fri, 22 Nov 2013 15:29:34 +0400 Subject: 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 Reviewed-by: Joerg Bornemann --- .../tst_qwinoverlappedionotifier.cpp | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'tests') 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(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 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; -- cgit v1.2.3