| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2014 Denis Shienkov <denis.shienkov@gmail.com> |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the QtSerialPort module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
| 21 | ** included in the packaging of this file. Please review the following |
| 22 | ** information to ensure the GNU General Public License requirements will |
| 23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
| 24 | ** |
| 25 | ** $QT_END_LICENSE$ |
| 26 | ** |
| 27 | ****************************************************************************/ |
| 28 | |
| 29 | #include <QtTest/QtTest> |
| 30 | |
| 31 | #include <private/qserialportinfo_p.h> |
| 32 | |
| 33 | class tst_QSerialPortInfoPrivate : public QObject |
| 34 | { |
| 35 | Q_OBJECT |
| 36 | public: |
| 37 | explicit tst_QSerialPortInfoPrivate(); |
| 38 | |
| 39 | private slots: |
| 40 | void canonical_data(); |
| 41 | void canonical(); |
| 42 | }; |
| 43 | |
| 44 | tst_QSerialPortInfoPrivate::tst_QSerialPortInfoPrivate() |
| 45 | { |
| 46 | } |
| 47 | |
| 48 | void tst_QSerialPortInfoPrivate::canonical_data() |
| 49 | { |
| 50 | QTest::addColumn<QString>(name: "source" ); |
| 51 | QTest::addColumn<QString>(name: "name" ); |
| 52 | QTest::addColumn<QString>(name: "location" ); |
| 53 | |
| 54 | #if defined(Q_OS_WINCE) |
| 55 | QTest::newRow("Test1" ) << "COM1" << "COM1" << "COM1:" ; |
| 56 | QTest::newRow("Test2" ) << "COM1:" << "COM1" << "COM1:" ; |
| 57 | #elif defined(Q_OS_WIN32) |
| 58 | QTest::newRow("Test1" ) << "COM1" << "COM1" << "\\\\.\\COM1" ; |
| 59 | QTest::newRow("Test2" ) << "\\\\.\\COM1" << "COM1" << "\\\\.\\COM1" ; |
| 60 | QTest::newRow("Test3" ) << "//./COM1" << "COM1" << "//./COM1" ; |
| 61 | #elif defined(Q_OS_OSX) |
| 62 | QTest::newRow("Test1" ) << "ttyS0" << "ttyS0" << "/dev/ttyS0" ; |
| 63 | QTest::newRow("Test2" ) << "cu.serial1" << "cu.serial1" << "/dev/cu.serial1" ; |
| 64 | QTest::newRow("Test3" ) << "tty.serial1" << "tty.serial1" << "/dev/tty.serial1" ; |
| 65 | QTest::newRow("Test4" ) << "/dev/ttyS0" << "ttyS0" << "/dev/ttyS0" ; |
| 66 | QTest::newRow("Test5" ) << "/dev/tty.serial1" << "tty.serial1" << "/dev/tty.serial1" ; |
| 67 | QTest::newRow("Test6" ) << "/dev/cu.serial1" << "cu.serial1" << "/dev/cu.serial1" ; |
| 68 | QTest::newRow("Test7" ) << "/dev/serial/ttyS0" << "serial/ttyS0" << "/dev/serial/ttyS0" ; |
| 69 | QTest::newRow("Test8" ) << "/home/ttyS0" << "/home/ttyS0" << "/home/ttyS0" ; |
| 70 | QTest::newRow("Test9" ) << "/home/serial/ttyS0" << "/home/serial/ttyS0" << "/home/serial/ttyS0" ; |
| 71 | QTest::newRow("Test10" ) << "serial/ttyS0" << "serial/ttyS0" << "/dev/serial/ttyS0" ; |
| 72 | QTest::newRow("Test11" ) << "./ttyS0" << "./ttyS0" << "./ttyS0" ; |
| 73 | QTest::newRow("Test12" ) << "../ttyS0" << "../ttyS0" << "../ttyS0" ; |
| 74 | #elif defined(Q_OS_UNIX) |
| 75 | QTest::newRow(dataTag: "Test1" ) << "ttyS0" << "ttyS0" << "/dev/ttyS0" ; |
| 76 | QTest::newRow(dataTag: "Test2" ) << "/dev/ttyS0" << "ttyS0" << "/dev/ttyS0" ; |
| 77 | QTest::newRow(dataTag: "Test3" ) << "/dev/serial/ttyS0" << "serial/ttyS0" << "/dev/serial/ttyS0" ; |
| 78 | QTest::newRow(dataTag: "Test4" ) << "/home/ttyS0" << "/home/ttyS0" << "/home/ttyS0" ; |
| 79 | QTest::newRow(dataTag: "Test5" ) << "/home/serial/ttyS0" << "/home/serial/ttyS0" << "/home/serial/ttyS0" ; |
| 80 | QTest::newRow(dataTag: "Test6" ) << "serial/ttyS0" << "serial/ttyS0" << "/dev/serial/ttyS0" ; |
| 81 | QTest::newRow(dataTag: "Test7" ) << "./ttyS0" << "./ttyS0" << "./ttyS0" ; |
| 82 | QTest::newRow(dataTag: "Test8" ) << "../ttyS0" << "../ttyS0" << "../ttyS0" ; |
| 83 | #endif |
| 84 | } |
| 85 | |
| 86 | void tst_QSerialPortInfoPrivate::canonical() |
| 87 | { |
| 88 | QFETCH(QString, source); |
| 89 | QFETCH(QString, name); |
| 90 | QFETCH(QString, location); |
| 91 | |
| 92 | QCOMPARE(QSerialPortInfoPrivate::portNameFromSystemLocation(source), name); |
| 93 | QCOMPARE(QSerialPortInfoPrivate::portNameToSystemLocation(source), location); |
| 94 | } |
| 95 | |
| 96 | QTEST_MAIN(tst_QSerialPortInfoPrivate) |
| 97 | #include "tst_qserialportinfoprivate.moc" |
| 98 | |