From 7f8d17b6fe903e0603c8e8fea9bdd7eb7fe66f34 Mon Sep 17 00:00:00 2001 From: Denis Shienkov Date: Fri, 21 Nov 2014 16:01:30 +0300 Subject: Fix QSPI::isNull() The method QSPI::isNull() should return false when QSPI is empty. Tested on Winsows 8 and Linux with on-board, virtual and USB serial ports using Qt5 and then Qt4. Task-number: QTBUG-41262 Change-Id: Ic9e0afc5549311283aef7ec2ed841f5e418b7edf Reviewed-by: Sergey Belyashov --- src/serialport/qserialportinfo.cpp | 8 +- src/serialport/qserialportinfo.h | 1 + src/serialport/qserialportinfo_mac.cpp | 54 +++++----- src/serialport/qserialportinfo_unix.cpp | 60 +++++------ src/serialport/qserialportinfo_win.cpp | 22 ++-- src/serialport/qserialportinfo_wince.cpp | 12 +-- tests/auto/auto.pro | 2 +- tests/auto/qserialportinfo/qserialportinfo.pro | 11 ++ tests/auto/qserialportinfo/tst_qserialportinfo.cpp | 114 +++++++++++++++++++++ 9 files changed, 206 insertions(+), 78 deletions(-) create mode 100644 tests/auto/qserialportinfo/qserialportinfo.pro create mode 100644 tests/auto/qserialportinfo/tst_qserialportinfo.cpp diff --git a/src/serialport/qserialportinfo.cpp b/src/serialport/qserialportinfo.cpp index 23a4d1c..ced4361 100644 --- a/src/serialport/qserialportinfo.cpp +++ b/src/serialport/qserialportinfo.cpp @@ -65,7 +65,6 @@ QT_BEGIN_NAMESPACE \sa isNull() */ QSerialPortInfo::QSerialPortInfo() - : d_ptr(new QSerialPortInfoPrivate) { } @@ -81,7 +80,6 @@ QSerialPortInfo::QSerialPortInfo(const QSerialPortInfo &other) Constructs a QSerialPortInfo object from serial \a port. */ QSerialPortInfo::QSerialPortInfo(const QSerialPort &port) - : d_ptr(new QSerialPortInfoPrivate) { foreach (const QSerialPortInfo &serialPortInfo, availablePorts()) { if (port.portName() == serialPortInfo.portName()) { @@ -99,7 +97,6 @@ QSerialPortInfo::QSerialPortInfo(const QSerialPort &port) instance for that port. */ QSerialPortInfo::QSerialPortInfo(const QString &name) - : d_ptr(new QSerialPortInfoPrivate) { foreach (const QSerialPortInfo &serialPortInfo, availablePorts()) { if (name == serialPortInfo.portName()) { @@ -109,6 +106,11 @@ QSerialPortInfo::QSerialPortInfo(const QString &name) } } +QSerialPortInfo::QSerialPortInfo(const QSerialPortInfoPrivate &dd) + : d_ptr(new QSerialPortInfoPrivate(dd)) +{ +} + /*! Destroys the QSerialPortInfo object. References to the values in the object become invalid. diff --git a/src/serialport/qserialportinfo.h b/src/serialport/qserialportinfo.h index 262e54d..0c7a0f1 100644 --- a/src/serialport/qserialportinfo.h +++ b/src/serialport/qserialportinfo.h @@ -81,6 +81,7 @@ public: static QList availablePorts(); private: + QSerialPortInfo(const QSerialPortInfoPrivate &dd); friend QList availablePortsByUdev(); friend QList availablePortsBySysfs(); friend QList availablePortsByFiltersOfDevices(); diff --git a/src/serialport/qserialportinfo_mac.cpp b/src/serialport/qserialportinfo_mac.cpp index d400d68..3685d55 100644 --- a/src/serialport/qserialportinfo_mac.cpp +++ b/src/serialport/qserialportinfo_mac.cpp @@ -78,15 +78,15 @@ static quint16 searchShortIntProperty(io_registry_entry_t ioRegistryEntry, return value; } -static bool isCompleteInfo(const QSerialPortInfo &portInfo) +static bool isCompleteInfo(const QSerialPortInfoPrivate &priv) { - return !portInfo.portName().isEmpty() - && !portInfo.systemLocation().isEmpty() - && !portInfo.manufacturer().isEmpty() - && !portInfo.description().isEmpty() - && !portInfo.serialNumber().isEmpty() - && portInfo.hasProductIdentifier() - && portInfo.hasVendorIdentifier(); + return !priv.portName.isEmpty() + && !priv.device.isEmpty() + && !priv.manufacturer.isEmpty() + && !priv.description.isEmpty() + && !priv.serialNumber.isEmpty() + && priv.hasProductIdentifier + && priv.hasVendorIdentifier; } static QString devicePortName(io_registry_entry_t ioRegistryEntry) @@ -160,37 +160,37 @@ QList QSerialPortInfo::availablePorts() if (!serialPortService) break; - QSerialPortInfo serialPortInfo; + QSerialPortInfoPrivate priv; forever { - if (serialPortInfo.portName().isEmpty()) - serialPortInfo.d_ptr->portName = devicePortName(serialPortService); + if (priv.portName.isEmpty()) + priv.portName = devicePortName(serialPortService); - if (serialPortInfo.systemLocation().isEmpty()) - serialPortInfo.d_ptr->device = deviceSystemLocation(serialPortService); + if (priv.device.isEmpty()) + priv.device = deviceSystemLocation(serialPortService); - if (serialPortInfo.description().isEmpty()) - serialPortInfo.d_ptr->description = deviceDescription(serialPortService); + if (priv.description.isEmpty()) + priv.description = deviceDescription(serialPortService); - if (serialPortInfo.manufacturer().isEmpty()) - serialPortInfo.d_ptr->manufacturer = deviceManufacturer(serialPortService); + if (priv.manufacturer.isEmpty()) + priv.manufacturer = deviceManufacturer(serialPortService); - if (serialPortInfo.serialNumber().isEmpty()) - serialPortInfo.d_ptr->serialNumber = deviceSerialNumber(serialPortService); + if (priv.serialNumber.isEmpty()) + priv.serialNumber = deviceSerialNumber(serialPortService); - if (!serialPortInfo.hasVendorIdentifier()) { - serialPortInfo.d_ptr->vendorIdentifier = + if (!priv.hasVendorIdentifier) { + priv.vendorIdentifier = deviceVendorIdentifier(serialPortService, - serialPortInfo.d_ptr->hasVendorIdentifier); + priv.hasVendorIdentifier); } - if (!serialPortInfo.hasProductIdentifier()) { - serialPortInfo.d_ptr->productIdentifier = + if (!priv.hasProductIdentifier) { + priv.productIdentifier = deviceProductIdentifier(serialPortService, - serialPortInfo.d_ptr->hasProductIdentifier); + priv.hasProductIdentifier); } - if (isCompleteInfo(serialPortInfo)) { + if (isCompleteInfo(priv)) { ::IOObjectRelease(serialPortService); break; } @@ -200,7 +200,7 @@ QList QSerialPortInfo::availablePorts() break; } - serialPortInfoList.append(serialPortInfo); + serialPortInfoList.append(priv); } ::IOObjectRelease(serialPortIterator); diff --git a/src/serialport/qserialportinfo_unix.cpp b/src/serialport/qserialportinfo_unix.cpp index 4479e97..7322a3c 100644 --- a/src/serialport/qserialportinfo_unix.cpp +++ b/src/serialport/qserialportinfo_unix.cpp @@ -98,10 +98,10 @@ QList availablePortsByFiltersOfDevices() QList serialPortInfoList; foreach (const QString &deviceFilePath, filteredDeviceFilePaths()) { - QSerialPortInfo serialPortInfo; - serialPortInfo.d_ptr->device = deviceFilePath; - serialPortInfo.d_ptr->portName = QSerialPortPrivate::portNameFromSystemLocation(deviceFilePath); - serialPortInfoList.append(serialPortInfo); + QSerialPortInfoPrivate priv; + priv.device = deviceFilePath; + priv.portName = QSerialPortPrivate::portNameFromSystemLocation(deviceFilePath); + serialPortInfoList.append(priv); } return serialPortInfoList; @@ -125,7 +125,7 @@ QList availablePortsBySysfs() if (lastIndexOfSlash == -1) continue; - QSerialPortInfo serialPortInfo; + QSerialPortInfoPrivate priv; if (targetPath.contains(QStringLiteral("pnp"))) { // TODO: Obtain more information #ifndef Q_OS_ANDROID @@ -155,26 +155,26 @@ QList availablePortsBySysfs() QFile description(QFileInfo(targetDir, QStringLiteral("product")).absoluteFilePath()); if (description.open(QIODevice::ReadOnly | QIODevice::Text)) - serialPortInfo.d_ptr->description = QString::fromLatin1(description.readAll()).simplified(); + priv.description = QString::fromLatin1(description.readAll()).simplified(); QFile manufacturer(QFileInfo(targetDir, QStringLiteral("manufacturer")).absoluteFilePath()); if (manufacturer.open(QIODevice::ReadOnly | QIODevice::Text)) - serialPortInfo.d_ptr->manufacturer = QString::fromLatin1(manufacturer.readAll()).simplified(); + priv.manufacturer = QString::fromLatin1(manufacturer.readAll()).simplified(); QFile serialNumber(QFileInfo(targetDir, QStringLiteral("serial")).absoluteFilePath()); if (serialNumber.open(QIODevice::ReadOnly | QIODevice::Text)) - serialPortInfo.d_ptr->serialNumber = QString::fromLatin1(serialNumber.readAll()).simplified(); + priv.serialNumber = QString::fromLatin1(serialNumber.readAll()).simplified(); QFile vendorIdentifier(QFileInfo(targetDir, QStringLiteral("idVendor")).absoluteFilePath()); if (vendorIdentifier.open(QIODevice::ReadOnly | QIODevice::Text)) { - serialPortInfo.d_ptr->vendorIdentifier = QString::fromLatin1(vendorIdentifier.readAll()) - .toInt(&serialPortInfo.d_ptr->hasVendorIdentifier, 16); + priv.vendorIdentifier = QString::fromLatin1(vendorIdentifier.readAll()) + .toInt(&priv.hasVendorIdentifier, 16); } QFile productIdentifier(QFileInfo(targetDir, QStringLiteral("idProduct")).absoluteFilePath()); if (productIdentifier.open(QIODevice::ReadOnly | QIODevice::Text)) { - serialPortInfo.d_ptr->productIdentifier = QString::fromLatin1(productIdentifier.readAll()) - .toInt(&serialPortInfo.d_ptr->hasProductIdentifier, 16); + priv.productIdentifier = QString::fromLatin1(productIdentifier.readAll()) + .toInt(&priv.hasProductIdentifier, 16); } break; @@ -185,13 +185,13 @@ QList availablePortsBySysfs() QDir targetDir(targetPath + QStringLiteral("/device")); QFile vendorIdentifier(QFileInfo(targetDir, QStringLiteral("vendor")).absoluteFilePath()); if (vendorIdentifier.open(QIODevice::ReadOnly | QIODevice::Text)) { - serialPortInfo.d_ptr->vendorIdentifier = QString::fromLatin1(vendorIdentifier.readAll()) - .toInt(&serialPortInfo.d_ptr->hasVendorIdentifier, 16); + priv.vendorIdentifier = QString::fromLatin1(vendorIdentifier.readAll()) + .toInt(&priv.hasVendorIdentifier, 16); } QFile productIdentifier(QFileInfo(targetDir, QStringLiteral("device")).absoluteFilePath()); if (productIdentifier.open(QIODevice::ReadOnly | QIODevice::Text)) { - serialPortInfo.d_ptr->productIdentifier = QString::fromLatin1(productIdentifier.readAll()) - .toInt(&serialPortInfo.d_ptr->hasProductIdentifier, 16); + priv.productIdentifier = QString::fromLatin1(productIdentifier.readAll()) + .toInt(&priv.hasProductIdentifier, 16); } // TODO: Obtain more information about the device } else if (targetPath.contains(QStringLiteral(".serial/tty/tty"))) { @@ -201,9 +201,9 @@ QList availablePortsBySysfs() continue; } - serialPortInfo.d_ptr->portName = targetPath.mid(lastIndexOfSlash + 1); - serialPortInfo.d_ptr->device = QSerialPortPrivate::portNameToSystemLocation(serialPortInfo.d_ptr->portName); - serialPortInfoList.append(serialPortInfo); + priv.portName = targetPath.mid(lastIndexOfSlash + 1); + priv.device = QSerialPortPrivate::portNameToSystemLocation(priv.portName); + serialPortInfoList.append(priv); } return serialPortInfoList; @@ -318,25 +318,25 @@ QList availablePortsByUdev() if (!dev) return serialPortInfoList; - QSerialPortInfo serialPortInfo; + QSerialPortInfoPrivate priv; - serialPortInfo.d_ptr->device = QString::fromLatin1(::udev_device_get_devnode(dev.data())); - serialPortInfo.d_ptr->portName = QString::fromLatin1(::udev_device_get_sysname(dev.data())); + priv.device = QString::fromLatin1(::udev_device_get_devnode(dev.data())); + priv.portName = QString::fromLatin1(::udev_device_get_sysname(dev.data())); udev_device *parentdev = ::udev_device_get_parent(dev.data()); if (parentdev) { if (checkUdevForSerial8250Driver(parentdev)) continue; - serialPortInfo.d_ptr->description = getUdevModelName(dev.data()); - serialPortInfo.d_ptr->manufacturer = getUdevVendorName(dev.data()); - serialPortInfo.d_ptr->serialNumber = getUdevSerialNumber(dev.data()); - serialPortInfo.d_ptr->vendorIdentifier = getUdevVendorIdentifier(dev.data(), serialPortInfo.d_ptr->hasVendorIdentifier); - serialPortInfo.d_ptr->productIdentifier = getUdevModelIdentifier(dev.data(), serialPortInfo.d_ptr->hasProductIdentifier); + priv.description = getUdevModelName(dev.data()); + priv.manufacturer = getUdevVendorName(dev.data()); + priv.serialNumber = getUdevSerialNumber(dev.data()); + priv.vendorIdentifier = getUdevVendorIdentifier(dev.data(), priv.hasVendorIdentifier); + priv.productIdentifier = getUdevModelIdentifier(dev.data(), priv.hasProductIdentifier); } else { - if (serialPortInfo.d_ptr->portName.startsWith(rfcommDeviceName)) { + if (priv.portName.startsWith(rfcommDeviceName)) { bool ok; - int portNumber = serialPortInfo.d_ptr->portName.mid(rfcommDeviceName.length()).toInt(&ok); + int portNumber = priv.portName.mid(rfcommDeviceName.length()).toInt(&ok); if (!ok || (portNumber < 0) || (portNumber > 255)) continue; } else { @@ -344,7 +344,7 @@ QList availablePortsByUdev() } } - serialPortInfoList.append(serialPortInfo); + serialPortInfoList.append(priv); } return serialPortInfoList; diff --git a/src/serialport/qserialportinfo_win.cpp b/src/serialport/qserialportinfo_win.cpp index 0958617..d4dff94 100644 --- a/src/serialport/qserialportinfo_win.cpp +++ b/src/serialport/qserialportinfo_win.cpp @@ -312,23 +312,23 @@ QList QSerialPortInfo::availablePorts() continue; } - QSerialPortInfo serialPortInfo; + QSerialPortInfoPrivate priv; - serialPortInfo.d_ptr->portName = portName; - serialPortInfo.d_ptr->device = QSerialPortPrivate::portNameToSystemLocation(portName); - serialPortInfo.d_ptr->description = deviceDescription(deviceInfoSet, &deviceInfoData); - serialPortInfo.d_ptr->manufacturer = deviceManufacturer(deviceInfoSet, &deviceInfoData); + priv.portName = portName; + priv.device = QSerialPortPrivate::portNameToSystemLocation(portName); + priv.description = deviceDescription(deviceInfoSet, &deviceInfoData); + priv.manufacturer = deviceManufacturer(deviceInfoSet, &deviceInfoData); const QString instanceIdentifier = deviceInstanceIdentifier(deviceInfoData.DevInst); - serialPortInfo.d_ptr->serialNumber = + priv.serialNumber = deviceSerialNumber(instanceIdentifier, deviceInfoData.DevInst); - serialPortInfo.d_ptr->vendorIdentifier = - deviceVendorIdentifier(instanceIdentifier, serialPortInfo.d_ptr->hasVendorIdentifier); - serialPortInfo.d_ptr->productIdentifier = - deviceProductIdentifier(instanceIdentifier, serialPortInfo.d_ptr->hasProductIdentifier); + priv.vendorIdentifier = + deviceVendorIdentifier(instanceIdentifier, priv.hasVendorIdentifier); + priv.productIdentifier = + deviceProductIdentifier(instanceIdentifier, priv.hasProductIdentifier); - serialPortInfoList.append(serialPortInfo); + serialPortInfoList.append(priv); } ::SetupDiDestroyDeviceInfoList(deviceInfoSet); } diff --git a/src/serialport/qserialportinfo_wince.cpp b/src/serialport/qserialportinfo_wince.cpp index 15d2cf7..f39b5a2 100644 --- a/src/serialport/qserialportinfo_wince.cpp +++ b/src/serialport/qserialportinfo_wince.cpp @@ -105,13 +105,13 @@ QList QSerialPortInfo::availablePorts() &di); if (hSearch != INVALID_HANDLE_VALUE) { do { - QSerialPortInfo serialPortInfo; - serialPortInfo.d_ptr->device = QString::fromWCharArray(di.szLegacyName); - serialPortInfo.d_ptr->portName = QSerialPortPrivate::portNameFromSystemLocation(serialPortInfo.d_ptr->device); - serialPortInfo.d_ptr->description = findDescription(HKEY_LOCAL_MACHINE, - QString::fromWCharArray(di.szDeviceKey)); + QSerialPortInfoPrivate priv; + priv.device = QString::fromWCharArray(di.szLegacyName); + priv.portName = QSerialPortPrivate::portNameFromSystemLocation(priv.device); + priv.description = findDescription(HKEY_LOCAL_MACHINE, + QString::fromWCharArray(di.szDeviceKey)); - serialPortInfoList.append(serialPortInfo); + serialPortInfoList.append(priv); } while (::FindNextDevice(hSearch, &di)); ::FindClose(hSearch); diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index 14963a2..5e317d7 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -1,2 +1,2 @@ TEMPLATE = subdirs -SUBDIRS += qserialport cmake +SUBDIRS += qserialport qserialportinfo cmake diff --git a/tests/auto/qserialportinfo/qserialportinfo.pro b/tests/auto/qserialportinfo/qserialportinfo.pro new file mode 100644 index 0000000..b3e49bd --- /dev/null +++ b/tests/auto/qserialportinfo/qserialportinfo.pro @@ -0,0 +1,11 @@ +QT = core testlib +TARGET = tst_qserialportinfo +#CONFIG += testcase + +greaterThan(QT_MAJOR_VERSION, 4) { + QT += serialport +} else { + include($$QTSERIALPORT_PROJECT_ROOT/src/serialport/qt4support/serialport.prf) +} + +SOURCES = tst_qserialportinfo.cpp diff --git a/tests/auto/qserialportinfo/tst_qserialportinfo.cpp b/tests/auto/qserialportinfo/tst_qserialportinfo.cpp new file mode 100644 index 0000000..afbcf0b --- /dev/null +++ b/tests/auto/qserialportinfo/tst_qserialportinfo.cpp @@ -0,0 +1,114 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Denis Shienkov +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSerialPort module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include + +class tst_QSerialPortInfo : public QObject +{ + Q_OBJECT +public: + explicit tst_QSerialPortInfo(); + +private slots: + void initTestCase(); + + void constructors(); + void assignment(); + +private: + QString m_senderPortName; + QString m_receiverPortName; + QStringList m_availablePortNames; +}; + +tst_QSerialPortInfo::tst_QSerialPortInfo() +{ +} + +void tst_QSerialPortInfo::initTestCase() +{ + m_senderPortName = QString::fromLocal8Bit(qgetenv("QTEST_SERIALPORT_SENDER")); + m_receiverPortName = QString::fromLocal8Bit(qgetenv("QTEST_SERIALPORT_RECEIVER")); + if (m_senderPortName.isEmpty() || m_receiverPortName.isEmpty()) { +#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) + QSKIP("Test doesn't work because the names of serial ports aren't found in env."); +#else + QSKIP("Test doesn't work because the names of serial ports aren't set found env.", SkipAll); +#endif + } else { + m_availablePortNames << m_senderPortName << m_receiverPortName; + } +} + +void tst_QSerialPortInfo::constructors() +{ + QSerialPortInfo empty; + QVERIFY(empty.isNull()); + QSerialPortInfo empty2(QLatin1String("ABCD")); + QVERIFY(empty2.isNull()); + QSerialPortInfo empty3(empty); + QVERIFY(empty3.isNull()); + + QSerialPortInfo exist(m_senderPortName); + QVERIFY(!exist.isNull()); + QSerialPortInfo exist2(exist); + QVERIFY(!exist2.isNull()); +} + +void tst_QSerialPortInfo::assignment() +{ + QSerialPortInfo empty; + QVERIFY(empty.isNull()); + QSerialPortInfo empty2; + empty2 = empty; + QVERIFY(empty2.isNull()); + + QSerialPortInfo exist(m_senderPortName); + QVERIFY(!exist.isNull()); + QSerialPortInfo exist2; + exist2 = exist; + QVERIFY(!exist2.isNull()); +} + +QTEST_MAIN(tst_QSerialPortInfo) +#include "tst_qserialportinfo.moc" -- cgit v1.2.1 From a6a961317b50b306cbc0d5286dd3d1053b3754a4 Mon Sep 17 00:00:00 2001 From: Denis Shienkov Date: Fri, 21 Nov 2014 23:36:57 +0300 Subject: Declare QElapsedTimer closer to usage Change-Id: I74622eaf3a7f5179ff25fc815997d5e4cf3cc2c7 Reviewed-by: Sergey Belyashov --- src/serialport/qserialport_unix.cpp | 2 -- src/serialport/qserialport_win.cpp | 12 ++++++------ src/serialport/qserialport_wince.cpp | 2 -- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/serialport/qserialport_unix.cpp b/src/serialport/qserialport_unix.cpp index eb71e86..c836eb2 100644 --- a/src/serialport/qserialport_unix.cpp +++ b/src/serialport/qserialport_unix.cpp @@ -382,7 +382,6 @@ bool QSerialPortPrivate::waitForReadyRead(int msecs) Q_Q(QSerialPort); QElapsedTimer stopWatch; - stopWatch.start(); do { @@ -413,7 +412,6 @@ bool QSerialPortPrivate::waitForBytesWritten(int msecs) return false; QElapsedTimer stopWatch; - stopWatch.start(); forever { diff --git a/src/serialport/qserialport_win.cpp b/src/serialport/qserialport_win.cpp index 64ca00e..a43e620 100644 --- a/src/serialport/qserialport_win.cpp +++ b/src/serialport/qserialport_win.cpp @@ -330,15 +330,15 @@ bool QSerialPortPrivate::waitForReadyRead(int msecs) { Q_Q(QSerialPort); - QElapsedTimer stopWatch; - stopWatch.start(); - if (!writeStarted && !_q_startAsyncWrite()) return false; const qint64 initialReadBufferSize = readBuffer.size(); qint64 currentReadBufferSize = initialReadBufferSize; + QElapsedTimer stopWatch; + stopWatch.start(); + do { bool timedOut = false; HANDLE triggeredEvent = 0; @@ -384,12 +384,12 @@ bool QSerialPortPrivate::waitForBytesWritten(int msecs) if (writeBuffer.isEmpty()) return false; - QElapsedTimer stopWatch; - stopWatch.start(); - if (!writeStarted && !_q_startAsyncWrite()) return false; + QElapsedTimer stopWatch; + stopWatch.start(); + forever { bool timedOut = false; HANDLE triggeredEvent = 0; diff --git a/src/serialport/qserialport_wince.cpp b/src/serialport/qserialport_wince.cpp index a9c80b2..ee5d395 100644 --- a/src/serialport/qserialport_wince.cpp +++ b/src/serialport/qserialport_wince.cpp @@ -348,7 +348,6 @@ bool QSerialPortPrivate::waitForReadyRead(int msec) return true; QElapsedTimer stopWatch; - stopWatch.start(); forever { @@ -377,7 +376,6 @@ bool QSerialPortPrivate::waitForBytesWritten(int msec) return false; QElapsedTimer stopWatch; - stopWatch.start(); forever { -- cgit v1.2.1 From 1266e02a63f83c3a644e77fd07edb020602e6f50 Mon Sep 17 00:00:00 2001 From: Denis Shienkov Date: Sat, 22 Nov 2014 23:22:41 +0300 Subject: Simplify handling of overlapped result There is not necessary to pass direction to handleOverlappedResult(). Because it is passed already as a second argument (pointer to OVERLAPPED structure that defines a desired direction). Also this method is renamed to more simple and short name. Change-Id: I9c20cf97c1712aed8d3e9ea6d9b4687ce4487523 Reviewed-by: Sergey Belyashov --- src/serialport/qserialport_win.cpp | 12 ++++++------ src/serialport/qserialport_win_p.h | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/serialport/qserialport_win.cpp b/src/serialport/qserialport_win.cpp index a43e620..5a2cf8e 100644 --- a/src/serialport/qserialport_win.cpp +++ b/src/serialport/qserialport_win.cpp @@ -518,7 +518,7 @@ bool QSerialPortPrivate::setDataErrorPolicy(QSerialPort::DataErrorPolicy policy) bool QSerialPortPrivate::_q_completeAsyncCommunication() { - if (handleOverlappedResult(0, communicationOverlapped) == qint64(-1)) + if (overlappedResult(communicationOverlapped) == qint64(-1)) return false; if (EV_ERR & triggeredEventMask) handleLineStatusErrors(); @@ -528,7 +528,7 @@ bool QSerialPortPrivate::_q_completeAsyncCommunication() bool QSerialPortPrivate::_q_completeAsyncRead() { - const qint64 bytesTransferred = handleOverlappedResult(QSerialPort::Input, readCompletionOverlapped); + const qint64 bytesTransferred = overlappedResult(readCompletionOverlapped); if (bytesTransferred == qint64(-1)) { readStarted = false; return false; @@ -553,7 +553,7 @@ bool QSerialPortPrivate::_q_completeAsyncWrite() Q_Q(QSerialPort); if (writeStarted) { - const qint64 bytesTransferred = handleOverlappedResult(QSerialPort::Output, writeCompletionOverlapped); + const qint64 bytesTransferred = overlappedResult(writeCompletionOverlapped); if (bytesTransferred == qint64(-1)) { writeStarted = false; return false; @@ -809,7 +809,7 @@ bool QSerialPortPrivate::updateCommTimeouts() return true; } -qint64 QSerialPortPrivate::handleOverlappedResult(int direction, OVERLAPPED &overlapped) +qint64 QSerialPortPrivate::overlappedResult(OVERLAPPED &overlapped) { Q_Q(QSerialPort); @@ -819,9 +819,9 @@ qint64 QSerialPortPrivate::handleOverlappedResult(int direction, OVERLAPPED &ove if (error == QSerialPort::NoError) return qint64(0); if (error != QSerialPort::ResourceError) { - if (direction == QSerialPort::Input) + if (&overlapped == &readCompletionOverlapped) q->setError(QSerialPort::ReadError); - else if (direction == QSerialPort::Output) + else if (&overlapped == &writeCompletionOverlapped) q->setError(QSerialPort::WriteError); else q->setError(error); diff --git a/src/serialport/qserialport_win_p.h b/src/serialport/qserialport_win_p.h index 6b009fe..78529e8 100644 --- a/src/serialport/qserialport_win_p.h +++ b/src/serialport/qserialport_win_p.h @@ -141,7 +141,7 @@ private: bool initialize(QIODevice::OpenMode mode); bool updateDcb(); bool updateCommTimeouts(); - qint64 handleOverlappedResult(int direction, OVERLAPPED &overlapped); + qint64 overlappedResult(OVERLAPPED &overlapped); bool waitAnyEvent(int msecs, bool *timedOut, HANDLE *triggeredEvent); -- cgit v1.2.1 From 28d75608fe4920a4b0b57262b211d9990d636ea0 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Sun, 23 Nov 2014 07:09:19 -0800 Subject: Remove the 'register' keyword It doesn't do anything and has been deprecated in C++14. Clang even prints a warning. Change-Id: Ie803a206f02897f99358ed22bf9cb999ca457741 Reviewed-by: Denis Shienkov --- src/serialport/qt4support/include/private/qcore_unix_p.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/serialport/qt4support/include/private/qcore_unix_p.h b/src/serialport/qt4support/include/private/qcore_unix_p.h index 6a7fb72..640525a 100644 --- a/src/serialport/qt4support/include/private/qcore_unix_p.h +++ b/src/serialport/qt4support/include/private/qcore_unix_p.h @@ -72,7 +72,7 @@ static inline int qt_safe_open(const char *pathname, int flags, mode_t mode = 07 #ifdef O_CLOEXEC flags |= O_CLOEXEC; #endif - register int fd; + int fd; EINTR_LOOP(fd, QT_OPEN(pathname, flags, mode)); // unknown flags are ignored, so we have no way of verifying if @@ -104,7 +104,7 @@ static inline qint64 qt_safe_write(int fd, const void *data, qint64 len) static inline int qt_safe_close(int fd) { - register int ret; + int ret; EINTR_LOOP(ret, QT_CLOSE(fd)); return ret; } -- cgit v1.2.1 From a00cbfb7f336a56b9ae2235c44149ec63ced9ee5 Mon Sep 17 00:00:00 2001 From: Denis Shienkov Date: Sun, 23 Nov 2014 23:06:16 +0300 Subject: Remove Q_OS_WIN64 since Q_OS_WIN32 defines 64-bit too Change-Id: I32eaf132f19a3b6fcbd5fd55d0690c3bd62bb641 Reviewed-by: Sergey Belyashov --- src/serialport/qserialport.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/serialport/qserialport.h b/src/serialport/qserialport.h index a8f9a05..fa681ad 100644 --- a/src/serialport/qserialport.h +++ b/src/serialport/qserialport.h @@ -273,7 +273,7 @@ private: Q_DISABLE_COPY(QSerialPort) -#if defined (Q_OS_WIN32) || defined(Q_OS_WIN64) +#if defined (Q_OS_WIN32) Q_PRIVATE_SLOT(d_func(), bool _q_completeAsyncCommunication()) Q_PRIVATE_SLOT(d_func(), bool _q_completeAsyncRead()) Q_PRIVATE_SLOT(d_func(), bool _q_completeAsyncWrite()) -- cgit v1.2.1 From ab51ad6a5f4e533c31bd8e5b6f16a3bcd09a3ee6 Mon Sep 17 00:00:00 2001 From: Denis Shienkov Date: Mon, 24 Nov 2014 18:21:57 +0300 Subject: Allow to use custom devices paths QSP incorrectly transforms non-standard device names to their paths and vice-versa (for example, "/home/ttyS0", "//./COM1", and so on). Now this problem is solved: * The transformation code is moved to QSPP. * Added autotests auto/qserialportinfoprivate to testing of conversion algorithm. These tests are private and can be activated with building of QtSerialPort with: qmake "QT_CONFIG+=private_tests warnings_are_errors" \ DEFINES+=QT_BUILD_INTERNAL Tested on Windows 8, Linux, OSX with auto-tests, with on-board and virtual serial ports. Task-number: QTBUG-38639 Change-Id: I43757a7f1390f53ed2b1d70de59c6bfb71892a59 Reviewed-by: Sergey Belyashov --- src/serialport/qserialport.cpp | 18 ++-- src/serialport/qserialport_unix.cpp | 35 +------ src/serialport/qserialport_unix_p.h | 3 - src/serialport/qserialport_win.cpp | 18 ---- src/serialport/qserialport_win_p.h | 3 - src/serialport/qserialport_wince.cpp | 16 --- src/serialport/qserialport_wince_p.h | 3 - src/serialport/qserialportinfo_mac.cpp | 14 +++ src/serialport/qserialportinfo_p.h | 12 ++- src/serialport/qserialportinfo_unix.cpp | 18 +++- src/serialport/qserialportinfo_win.cpp | 23 ++++- src/serialport/qserialportinfo_wince.cpp | 14 ++- tests/auto/auto.pro | 5 +- .../qserialportinfoprivate.pro | 4 + .../tst_qserialportinfoprivate.cpp | 110 +++++++++++++++++++++ 15 files changed, 196 insertions(+), 100 deletions(-) create mode 100644 tests/auto/qserialportinfoprivate/qserialportinfoprivate.pro create mode 100644 tests/auto/qserialportinfoprivate/tst_qserialportinfoprivate.cpp diff --git a/src/serialport/qserialport.cpp b/src/serialport/qserialport.cpp index 82bcde3..2bd7c69 100644 --- a/src/serialport/qserialport.cpp +++ b/src/serialport/qserialport.cpp @@ -36,6 +36,7 @@ #include "qserialport.h" #include "qserialportinfo.h" +#include "qserialportinfo_p.h" #ifdef Q_OS_WINCE #include "qserialport_wince_p.h" @@ -435,7 +436,7 @@ QSerialPort::~QSerialPort() void QSerialPort::setPortName(const QString &name) { Q_D(QSerialPort); - d->systemLocation = QSerialPortPrivate::portNameToSystemLocation(name); + d->systemLocation = QSerialPortInfoPrivate::portNameToSystemLocation(name); } /*! @@ -446,7 +447,7 @@ void QSerialPort::setPortName(const QString &name) void QSerialPort::setPort(const QSerialPortInfo &serialPortInfo) { Q_D(QSerialPort); - d->systemLocation = QSerialPortPrivate::portNameToSystemLocation(serialPortInfo.systemLocation()); + d->systemLocation = serialPortInfo.systemLocation(); } /*! @@ -460,7 +461,7 @@ void QSerialPort::setPort(const QSerialPortInfo &serialPortInfo) \li Brief Description \row \li Windows - \li Removes the prefix "\\\\.\\" from the system location + \li Removes the prefix "\\\\.\\" or "//./" from the system location and returns the remainder of the string. \row \li Windows CE @@ -471,16 +472,9 @@ void QSerialPort::setPort(const QSerialPortInfo &serialPortInfo) \li Returns the system location as it is, as it is equivalent to the port name. \row - \li GNU/Linux + \li Unix, BSD \li Removes the prefix "/dev/" from the system location and returns the remainder of the string. - \row - \li Mac OSX - \li Removes the prefix "/dev/cu." and "/dev/tty." from the - system location and returns the remainder of the string. - \row - \li Other *nix - \li The same as for GNU/Linux. \endtable \sa setPort(), QSerialPortInfo::portName() @@ -488,7 +482,7 @@ void QSerialPort::setPort(const QSerialPortInfo &serialPortInfo) QString QSerialPort::portName() const { Q_D(const QSerialPort); - return QSerialPortPrivate::portNameFromSystemLocation(d->systemLocation); + return QSerialPortInfoPrivate::portNameFromSystemLocation(d->systemLocation); } /*! diff --git a/src/serialport/qserialport_unix.cpp b/src/serialport/qserialport_unix.cpp index c836eb2..599f151 100644 --- a/src/serialport/qserialport_unix.cpp +++ b/src/serialport/qserialport_unix.cpp @@ -34,6 +34,7 @@ ****************************************************************************/ #include "qserialport_unix_p.h" +#include "qserialportinfo_p.h" #include #include @@ -163,7 +164,7 @@ bool QSerialPortPrivate::open(QIODevice::OpenMode mode) { Q_Q(QSerialPort); - QString lockFilePath = serialPortLockFilePath(portNameFromSystemLocation(systemLocation)); + QString lockFilePath = serialPortLockFilePath(QSerialPortInfoPrivate::portNameFromSystemLocation(systemLocation)); bool isLockFileEmpty = lockFilePath.isEmpty(); if (isLockFileEmpty) { qWarning("Failed to create a lock file for opening the device"); @@ -1156,38 +1157,6 @@ qint64 QSerialPortPrivate::readPerChar(char *data, qint64 maxSize) return ret; } -#ifdef Q_OS_MAC -static const QString defaultFilePathPrefix = QStringLiteral("/dev/cu."); -static const QString unusedFilePathPrefix = QStringLiteral("/dev/tty."); -#else -static const QString defaultFilePathPrefix = QStringLiteral("/dev/"); -#endif - -QString QSerialPortPrivate::portNameToSystemLocation(const QString &port) -{ - QString ret = port; - -#ifdef Q_OS_MAC - ret.remove(unusedFilePathPrefix); -#endif - - if (!ret.contains(defaultFilePathPrefix)) - ret.prepend(defaultFilePathPrefix); - return ret; -} - -QString QSerialPortPrivate::portNameFromSystemLocation(const QString &location) -{ - QString ret = location; - -#ifdef Q_OS_MAC - ret.remove(unusedFilePathPrefix); -#endif - - ret.remove(defaultFilePathPrefix); - return ret; -} - typedef QMap BaudRateMap; // The OS specific defines can be found in termios.h diff --git a/src/serialport/qserialport_unix_p.h b/src/serialport/qserialport_unix_p.h index 1cc767d..f1821ea 100644 --- a/src/serialport/qserialport_unix_p.h +++ b/src/serialport/qserialport_unix_p.h @@ -131,9 +131,6 @@ public: qint64 bytesToWrite() const; qint64 writeData(const char *data, qint64 maxSize); - static QString portNameToSystemLocation(const QString &port); - static QString portNameFromSystemLocation(const QString &location); - static qint32 baudRateFromSetting(qint32 setting); static qint32 settingFromBaudRate(qint32 baudRate); diff --git a/src/serialport/qserialport_win.cpp b/src/serialport/qserialport_win.cpp index 5a2cf8e..7b7405e 100644 --- a/src/serialport/qserialport_win.cpp +++ b/src/serialport/qserialport_win.cpp @@ -900,24 +900,6 @@ bool QSerialPortPrivate::waitAnyEvent(int msecs, bool *timedOut, HANDLE *trigger return true; } -static const QString defaultPathPrefix = QStringLiteral("\\\\.\\"); - -QString QSerialPortPrivate::portNameToSystemLocation(const QString &port) -{ - QString ret = port; - if (!ret.contains(defaultPathPrefix)) - ret.prepend(defaultPathPrefix); - return ret; -} - -QString QSerialPortPrivate::portNameFromSystemLocation(const QString &location) -{ - QString ret = location; - if (ret.contains(defaultPathPrefix)) - ret.remove(defaultPathPrefix); - return ret; -} - // This table contains standard values of baud rates that // are defined in MSDN and/or in Win SDK file winbase.h diff --git a/src/serialport/qserialport_win_p.h b/src/serialport/qserialport_win_p.h index 78529e8..1e941a0 100644 --- a/src/serialport/qserialport_win_p.h +++ b/src/serialport/qserialport_win_p.h @@ -108,9 +108,6 @@ public: qint64 bytesToWrite() const; qint64 writeData(const char *data, qint64 maxSize); - static QString portNameToSystemLocation(const QString &port); - static QString portNameFromSystemLocation(const QString &location); - static qint32 baudRateFromSetting(qint32 setting); static qint32 settingFromBaudRate(qint32 baudRate); diff --git a/src/serialport/qserialport_wince.cpp b/src/serialport/qserialport_wince.cpp index ee5d395..04c09b1 100644 --- a/src/serialport/qserialport_wince.cpp +++ b/src/serialport/qserialport_wince.cpp @@ -766,22 +766,6 @@ bool QSerialPortPrivate::waitForReadOrWrite(bool *selectForRead, bool *selectFor return false; } -QString QSerialPortPrivate::portNameToSystemLocation(const QString &port) -{ - QString ret = port; - if (!ret.contains(QLatin1Char(':'))) - ret.append(QLatin1Char(':')); - return ret; -} - -QString QSerialPortPrivate::portNameFromSystemLocation(const QString &location) -{ - QString ret = location; - if (ret.contains(QLatin1Char(':'))) - ret.remove(QLatin1Char(':')); - return ret; -} - static const QList standardBaudRatePairList() { diff --git a/src/serialport/qserialport_wince_p.h b/src/serialport/qserialport_wince_p.h index dedd4b1..3fc4e23 100644 --- a/src/serialport/qserialport_wince_p.h +++ b/src/serialport/qserialport_wince_p.h @@ -99,9 +99,6 @@ public: qint64 bytesToWrite() const; qint64 writeData(const char *data, qint64 maxSize); - static QString portNameToSystemLocation(const QString &port); - static QString portNameFromSystemLocation(const QString &location); - static qint32 baudRateFromSetting(qint32 setting); static qint32 settingFromBaudRate(qint32 baudRate); diff --git a/src/serialport/qserialportinfo_mac.cpp b/src/serialport/qserialportinfo_mac.cpp index 3685d55..54abe21 100644 --- a/src/serialport/qserialportinfo_mac.cpp +++ b/src/serialport/qserialportinfo_mac.cpp @@ -242,4 +242,18 @@ bool QSerialPortInfo::isValid() const return f.exists(); } +QString QSerialPortInfoPrivate::portNameToSystemLocation(const QString &source) +{ + return (source.startsWith(QLatin1Char('/')) + || source.startsWith(QStringLiteral("./")) + || source.startsWith(QStringLiteral("../"))) + ? source : (QStringLiteral("/dev/") + source); +} + +QString QSerialPortInfoPrivate::portNameFromSystemLocation(const QString &source) +{ + return source.startsWith(QStringLiteral("/dev/")) + ? source.mid(5) : source; +} + QT_END_NAMESPACE diff --git a/src/serialport/qserialportinfo_p.h b/src/serialport/qserialportinfo_p.h index 6ab4117..c9f1086 100644 --- a/src/serialport/qserialportinfo_p.h +++ b/src/serialport/qserialportinfo_p.h @@ -51,7 +51,7 @@ QT_BEGIN_NAMESPACE -class QSerialPortInfoPrivate +class Q_AUTOTEST_EXPORT QSerialPortInfoPrivate { public: QSerialPortInfoPrivate() @@ -59,9 +59,15 @@ public: , productIdentifier(0) , hasVendorIdentifier(false) , hasProductIdentifier(false) - {} + { + } + + ~QSerialPortInfoPrivate() + { + } - ~QSerialPortInfoPrivate() {} + static QString portNameToSystemLocation(const QString &source); + static QString portNameFromSystemLocation(const QString &source); QString portName; QString device; diff --git a/src/serialport/qserialportinfo_unix.cpp b/src/serialport/qserialportinfo_unix.cpp index 7322a3c..9637581 100644 --- a/src/serialport/qserialportinfo_unix.cpp +++ b/src/serialport/qserialportinfo_unix.cpp @@ -100,7 +100,7 @@ QList availablePortsByFiltersOfDevices() foreach (const QString &deviceFilePath, filteredDeviceFilePaths()) { QSerialPortInfoPrivate priv; priv.device = deviceFilePath; - priv.portName = QSerialPortPrivate::portNameFromSystemLocation(deviceFilePath); + priv.portName = QSerialPortInfoPrivate::portNameFromSystemLocation(deviceFilePath); serialPortInfoList.append(priv); } @@ -202,7 +202,7 @@ QList availablePortsBySysfs() } priv.portName = targetPath.mid(lastIndexOfSlash + 1); - priv.device = QSerialPortPrivate::portNameToSystemLocation(priv.portName); + priv.device = QSerialPortInfoPrivate::portNameToSystemLocation(priv.portName); serialPortInfoList.append(priv); } @@ -401,4 +401,18 @@ bool QSerialPortInfo::isValid() const return f.exists(); } +QString QSerialPortInfoPrivate::portNameToSystemLocation(const QString &source) +{ + return (source.startsWith(QLatin1Char('/')) + || source.startsWith(QStringLiteral("./")) + || source.startsWith(QStringLiteral("../"))) + ? source : (QStringLiteral("/dev/") + source); +} + +QString QSerialPortInfoPrivate::portNameFromSystemLocation(const QString &source) +{ + return source.startsWith(QStringLiteral("/dev/")) + ? source.mid(5) : source; +} + QT_END_NAMESPACE diff --git a/src/serialport/qserialportinfo_win.cpp b/src/serialport/qserialportinfo_win.cpp index d4dff94..e595964 100644 --- a/src/serialport/qserialportinfo_win.cpp +++ b/src/serialport/qserialportinfo_win.cpp @@ -315,7 +315,7 @@ QList QSerialPortInfo::availablePorts() QSerialPortInfoPrivate priv; priv.portName = portName; - priv.device = QSerialPortPrivate::portNameToSystemLocation(portName); + priv.device = QSerialPortInfoPrivate::portNameToSystemLocation(portName); priv.description = deviceDescription(deviceInfoSet, &deviceInfoData); priv.manufacturer = deviceManufacturer(deviceInfoSet, &deviceInfoData); @@ -336,10 +336,10 @@ QList QSerialPortInfo::availablePorts() foreach (const QString &portName, portNamesFromHardwareDeviceMap()) { if (std::find_if(serialPortInfoList.begin(), serialPortInfoList.end(), SerialPortNameEqualFunctor(portName)) == serialPortInfoList.end()) { - QSerialPortInfo serialPortInfo; - serialPortInfo.d_ptr->portName = portName; - serialPortInfo.d_ptr->device = QSerialPortPrivate::portNameToSystemLocation(portName); - serialPortInfoList.append(serialPortInfo); + QSerialPortInfoPrivate priv; + priv.portName = portName; + priv.device = QSerialPortInfoPrivate::portNameToSystemLocation(portName); + serialPortInfoList.append(priv); } } @@ -379,4 +379,17 @@ bool QSerialPortInfo::isValid() const return true; } +QString QSerialPortInfoPrivate::portNameToSystemLocation(const QString &source) +{ + return source.startsWith(QStringLiteral("COM")) + ? (QStringLiteral("\\\\.\\") + source) : source; +} + +QString QSerialPortInfoPrivate::portNameFromSystemLocation(const QString &source) +{ + return (source.startsWith(QStringLiteral("\\\\.\\")) + || source.startsWith(QStringLiteral("//./"))) + ? source.mid(4) : source; +} + QT_END_NAMESPACE diff --git a/src/serialport/qserialportinfo_wince.cpp b/src/serialport/qserialportinfo_wince.cpp index f39b5a2..5a7ce62 100644 --- a/src/serialport/qserialportinfo_wince.cpp +++ b/src/serialport/qserialportinfo_wince.cpp @@ -107,7 +107,7 @@ QList QSerialPortInfo::availablePorts() do { QSerialPortInfoPrivate priv; priv.device = QString::fromWCharArray(di.szLegacyName); - priv.portName = QSerialPortPrivate::portNameFromSystemLocation(priv.device); + priv.portName = QSerialPortInfoPrivate::portNameFromSystemLocation(priv.device); priv.description = findDescription(HKEY_LOCAL_MACHINE, QString::fromWCharArray(di.szDeviceKey)); @@ -153,4 +153,16 @@ bool QSerialPortInfo::isValid() const return true; } +QString QSerialPortInfoPrivate::portNameToSystemLocation(const QString &source) +{ + return source.endsWith(QLatin1Char(':')) + ? source : (source + QLatin1Char(':')); +} + +QString QSerialPortInfoPrivate::portNameFromSystemLocation(const QString &source) +{ + return source.endsWith(QLatin1Char(':')) + ? source.mid(0, source.size() - 1) : source; +} + QT_END_NAMESPACE diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index 5e317d7..2fa03f0 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -1,2 +1,5 @@ TEMPLATE = subdirs -SUBDIRS += qserialport qserialportinfo cmake +SUBDIRS += qserialport qserialportinfo qserialportinfoprivate cmake + +!contains(QT_CONFIG, private_tests): SUBDIRS -= \ + qserialportinfoprivate diff --git a/tests/auto/qserialportinfoprivate/qserialportinfoprivate.pro b/tests/auto/qserialportinfoprivate/qserialportinfoprivate.pro new file mode 100644 index 0000000..f479a29 --- /dev/null +++ b/tests/auto/qserialportinfoprivate/qserialportinfoprivate.pro @@ -0,0 +1,4 @@ +QT = core testlib serialport-private +TARGET = tst_qserialportinfoprivate +#CONFIG += testcase +SOURCES = tst_qserialportinfoprivate.cpp diff --git a/tests/auto/qserialportinfoprivate/tst_qserialportinfoprivate.cpp b/tests/auto/qserialportinfoprivate/tst_qserialportinfoprivate.cpp new file mode 100644 index 0000000..cfd2d85 --- /dev/null +++ b/tests/auto/qserialportinfoprivate/tst_qserialportinfoprivate.cpp @@ -0,0 +1,110 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Denis Shienkov +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSerialPort module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include + +class tst_QSerialPortInfoPrivate : public QObject +{ + Q_OBJECT +public: + explicit tst_QSerialPortInfoPrivate(); + +private slots: + void canonical_data(); + void canonical(); +}; + +tst_QSerialPortInfoPrivate::tst_QSerialPortInfoPrivate() +{ +} + +void tst_QSerialPortInfoPrivate::canonical_data() +{ + QTest::addColumn("source"); + QTest::addColumn("name"); + QTest::addColumn("location"); + +#if defined (Q_OS_WINCE) + QTest::newRow("Test1") << "COM1" << "COM1" << "COM1:"; + QTest::newRow("Test2") << "COM1:" << "COM1" << "COM1:"; +#elif defined (Q_OS_WIN32) + QTest::newRow("Test1") << "COM1" << "COM1" << "\\\\.\\COM1"; + QTest::newRow("Test2") << "\\\\.\\COM1" << "COM1" << "\\\\.\\COM1"; + QTest::newRow("Test3") << "//./COM1" << "COM1" << "//./COM1"; +#elif defined (Q_OS_OSX) + QTest::newRow("Test1") << "ttyS0" << "ttyS0" << "/dev/ttyS0"; + QTest::newRow("Test2") << "cu.serial1" << "cu.serial1" << "/dev/cu.serial1"; + QTest::newRow("Test3") << "tty.serial1" << "tty.serial1" << "/dev/tty.serial1"; + QTest::newRow("Test4") << "/dev/ttyS0" << "ttyS0" << "/dev/ttyS0"; + QTest::newRow("Test5") << "/dev/tty.serial1" << "tty.serial1" << "/dev/tty.serial1"; + QTest::newRow("Test6") << "/dev/cu.serial1" << "cu.serial1" << "/dev/cu.serial1"; + QTest::newRow("Test7") << "/dev/serial/ttyS0" << "serial/ttyS0" << "/dev/serial/ttyS0"; + QTest::newRow("Test8") << "/home/ttyS0" << "/home/ttyS0" << "/home/ttyS0"; + QTest::newRow("Test9") << "/home/serial/ttyS0" << "/home/serial/ttyS0" << "/home/serial/ttyS0"; + QTest::newRow("Test10") << "serial/ttyS0" << "serial/ttyS0" << "/dev/serial/ttyS0"; + QTest::newRow("Test11") << "./ttyS0" << "./ttyS0" << "./ttyS0"; + QTest::newRow("Test12") << "../ttyS0" << "../ttyS0" << "../ttyS0"; +#elif defined (Q_OS_UNIX) + QTest::newRow("Test1") << "ttyS0" << "ttyS0" << "/dev/ttyS0"; + QTest::newRow("Test2") << "/dev/ttyS0" << "ttyS0" << "/dev/ttyS0"; + QTest::newRow("Test3") << "/dev/serial/ttyS0" << "serial/ttyS0" << "/dev/serial/ttyS0"; + QTest::newRow("Test4") << "/home/ttyS0" << "/home/ttyS0" << "/home/ttyS0"; + QTest::newRow("Test5") << "/home/serial/ttyS0" << "/home/serial/ttyS0" << "/home/serial/ttyS0"; + QTest::newRow("Test6") << "serial/ttyS0" << "serial/ttyS0" << "/dev/serial/ttyS0"; + QTest::newRow("Test7") << "./ttyS0" << "./ttyS0" << "./ttyS0"; + QTest::newRow("Test8") << "../ttyS0" << "../ttyS0" << "../ttyS0"; +#endif +} + +void tst_QSerialPortInfoPrivate::canonical() +{ + QFETCH(QString, source); + QFETCH(QString, name); + QFETCH(QString, location); + + QCOMPARE(QSerialPortInfoPrivate::portNameFromSystemLocation(source), name); + QCOMPARE(QSerialPortInfoPrivate::portNameToSystemLocation(source), location); +} + +QTEST_MAIN(tst_QSerialPortInfoPrivate) +#include "tst_qserialportinfoprivate.moc" -- cgit v1.2.1 From fbf3a8f5d50b5ae2dc90ac0af840a36530df3395 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Thu, 27 Nov 2014 12:24:17 +0100 Subject: Close the handle for the events that were created The handles should be closed when QSerialPort is deleted in order to clean up the native resources. Change-Id: If04521fc0fa3b898093bda3317962b4c44818034 Reviewed-by: Denis Shienkov Reviewed-by: Sergey Belyashov --- src/serialport/qserialport_win.cpp | 10 ++++++++++ src/serialport/qserialport_win_p.h | 1 + 2 files changed, 11 insertions(+) diff --git a/src/serialport/qserialport_win.cpp b/src/serialport/qserialport_win.cpp index 7b7405e..4c8ad07 100644 --- a/src/serialport/qserialport_win.cpp +++ b/src/serialport/qserialport_win.cpp @@ -127,6 +127,16 @@ QSerialPortPrivate::QSerialPortPrivate(QSerialPort *q) } } +QSerialPortPrivate::~QSerialPortPrivate() +{ + if (communicationOverlapped.hEvent) + CloseHandle(communicationOverlapped.hEvent); + if (readCompletionOverlapped.hEvent) + CloseHandle(readCompletionOverlapped.hEvent); + if (writeCompletionOverlapped.hEvent) + CloseHandle(writeCompletionOverlapped.hEvent); +} + bool QSerialPortPrivate::open(QIODevice::OpenMode mode) { Q_Q(QSerialPort); diff --git a/src/serialport/qserialport_win_p.h b/src/serialport/qserialport_win_p.h index 1e941a0..4af0ba4 100644 --- a/src/serialport/qserialport_win_p.h +++ b/src/serialport/qserialport_win_p.h @@ -63,6 +63,7 @@ class QSerialPortPrivate : public QSerialPortPrivateData public: QSerialPortPrivate(QSerialPort *q); + ~QSerialPortPrivate(); bool open(QIODevice::OpenMode mode); void close(); -- cgit v1.2.1