Return from the loop if a port name is found

The function devicePortName() search in the Registry the names of ports
by names of registry keys. At first looks for value of a key of "PortName",
and then of "PortNumber" key.

Thus, the first found value shall stop search and do not try to continue.

Tested on Windows 7/8 using Qt4 and then Qt5.

Change-Id: I98b00ff043a3b08476fec0a57b0d36ce65fc8d63
Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
Doc: Edited example documentation.

-added information about how to run the example by including a file
 from qtbase/doc/global
-edited summary sections
-added \brief.
-removed image captions. Our Qt 5 CSS files don't handle them.

Task-number: QTBUG-33597
Change-Id: If3293aa9d98b662f20af2af7030b0ab0fb1e8401
Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@digia.com>
Add the synchronous loopback data verification test

Good reason to check of data correctness at transferring and receiving.
In this test are used two serial ports, connected in a null-modem mode:
http://en.wikipedia.org/wiki/Null_modem .

The sender port transfers data to the receiver port. After data are
received is carried out check of equivalence of the transferred and
received data.

Before run of testing it is necessary to set two variable environments
QTEST_SERIALPORT_SENDER and QTEST_SERIALPORT_RECEIVER to specify names
of used serial ports.

This test can reveal errors related with the internal data processing
and also errors of synchronous I/O inside of QSerialPort.

This test is placed in separate "benchmarks" category not to mix-up
with "manual" and "auto" categories, because this test is closer to
"benchmarks" by own functionality.

Tested on Windows 7/8 with the virtual com0com serial ports, using
Qt4 and then Qt5.

Change-Id: Ie6f87b50784bce211cf68c16cf75f79d12a8564f
Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>
Fix events handling in waitForBytesWritten() method on Windows

In case of communication event is triggered in the
waitForBytesWritten() method then necessary to process it with
the _q_completeAsyncCommunication() method, but not with the
_q_completeAsyncRead() method.

Otherwise it leads to false filling of the readBuffer with the
data that were read earlier (or with garbage) which remained in
readChunkBuffer.

The synchronous loopback autotest reproduces a bug without of
this patch.

Tested on Windows 7/8 with the on-board and USB serial ports,
using Qt5.

Task-number: QTBUG-40344
Change-Id: I679109b60f4058c4c6f7e5f02c1f70ba6039d8d8
Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
Fix leak of a descriptor after unsuccessful opening

In case of unsuccessful initialization of a device at the opening, a
valid descriptor has to be closed before return from the open() method.

Task-number: QTBUG-40414
Change-Id: I45568f176e003d9be1fe8c3017da29f39908efb0
Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
Pass a length of string to QString::fromWCharArray

Using of the QString::fromWCharArray() we didn't pass length of a string,
hoping that all WCHAR strings are terminated by the null-character.

But it can lead to the wrong results if the initial WCHAR string has no
null character. Therefore it is reasonable to pass length of a string to
exclude an error.

Besides, to do not break of the algorithm of string comparison it is
necessary to return not null-terminated strings. Also now there is no need
to initialize of some allocated arrays by zero values.

Tested on Windows 7/8 with the on-board, the virtual com0com, the USB FTDI
and the PL2303 serial ports, using Qt4 and then Qt5.

Change-Id: I382cf8eacf4ab4d21c54de17fcdd6b9fcfa3d02c
Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>
Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
Make the QSerialPort::flush() non-blocking

According to documentation, the flush() method shall be non-blocking.

Tested on Linux 64-bit with auto-tests with the on-board and the USB
serial ports for Qt4 and then Qt5.

Note: On Windows the flush() method still does not work.

Change-Id: Iaee80361e59e0c281206ca24c817a446cdbf6ed1
Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
Move the synchronous loopback test from benchmarks to auto tests

Previous commit 76f293bfb0fd7bab391f96ac822eacc40e4c5176 with adding of
this test to the benchmarks were hasty.

After all it makes sense to place it to auto tests to have opportunity to
run with others together.

Besides, this test is renamed since it is not a loopback, it is an I/O
test with the synchronous approach.

Change-Id: I043a6e0075561167bb29a59a384554ef98dbbd4a
Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
Fix compilation of apps with QT_DISABLE_DEPRECATED_BEFORE=0x050300

The enum is already marked as deprecated leading to this error:
qserialport.h:267:46: error: no type named 'DataErrorPolicy' in 'QSerialPort'
    void dataErrorPolicyChanged(QSerialPort::DataErrorPolicy policy);
                                ~~~~~~~~~~~~~^

Change-Id: I8d178f0d0921b8f5308183e1f09a4c8388448e26
Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
Merge remote-tracking branch 'origin/5.3' into 5.4

Conflicts:
	examples/serialport/examples.qdoc

Change-Id: If79f2f140e72f0a499f8e61e3897848f454a5042