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 | #include <QtSerialPort/QSerialPort> |
31 | #include <QtSerialPort/QSerialPortInfo> |
32 | |
33 | class tst_QSerialPortInfo : public QObject |
34 | { |
35 | Q_OBJECT |
36 | public: |
37 | explicit tst_QSerialPortInfo(); |
38 | |
39 | private slots: |
40 | void initTestCase(); |
41 | |
42 | void constructors(); |
43 | void assignment(); |
44 | |
45 | private: |
46 | QString m_senderPortName; |
47 | QString m_receiverPortName; |
48 | QStringList m_availablePortNames; |
49 | }; |
50 | |
51 | tst_QSerialPortInfo::tst_QSerialPortInfo() |
52 | { |
53 | } |
54 | |
55 | void tst_QSerialPortInfo::initTestCase() |
56 | { |
57 | m_senderPortName = QString::fromLocal8Bit(str: qgetenv(varName: "QTEST_SERIALPORT_SENDER")); |
58 | m_receiverPortName = QString::fromLocal8Bit(str: qgetenv(varName: "QTEST_SERIALPORT_RECEIVER")); |
59 | if (m_senderPortName.isEmpty() || m_receiverPortName.isEmpty()) { |
60 | static const char message[] = |
61 | "Test doesn't work because the names of serial ports aren't found in env.\n" |
62 | "Please set environment variables:\n" |
63 | " QTEST_SERIALPORT_SENDER to name of output serial port\n" |
64 | " QTEST_SERIALPORT_RECEIVER to name of input serial port\n" |
65 | "Specify short names of port" |
66 | #if defined(Q_OS_UNIX) |
67 | ", like 'ttyS0'\n"; |
68 | #elif defined(Q_OS_WIN32) |
69 | ", like 'COM1'\n"; |
70 | #else |
71 | "\n"; |
72 | #endif |
73 | QSKIP(message); |
74 | } else { |
75 | m_availablePortNames << m_senderPortName << m_receiverPortName; |
76 | } |
77 | } |
78 | |
79 | void tst_QSerialPortInfo::constructors() |
80 | { |
81 | QSerialPortInfo empty; |
82 | QVERIFY(empty.isNull()); |
83 | QSerialPortInfo empty2(QLatin1String("ABCD")); |
84 | QVERIFY(empty2.isNull()); |
85 | QSerialPortInfo empty3(empty); |
86 | QVERIFY(empty3.isNull()); |
87 | |
88 | QSerialPortInfo exist(m_senderPortName); |
89 | QVERIFY(!exist.isNull()); |
90 | QSerialPortInfo exist2(exist); |
91 | QVERIFY(!exist2.isNull()); |
92 | } |
93 | |
94 | void tst_QSerialPortInfo::assignment() |
95 | { |
96 | QSerialPortInfo empty; |
97 | QVERIFY(empty.isNull()); |
98 | QSerialPortInfo empty2; |
99 | empty2 = empty; |
100 | QVERIFY(empty2.isNull()); |
101 | |
102 | QSerialPortInfo exist(m_senderPortName); |
103 | QVERIFY(!exist.isNull()); |
104 | QSerialPortInfo exist2; |
105 | exist2 = exist; |
106 | QVERIFY(!exist2.isNull()); |
107 | } |
108 | |
109 | QTEST_MAIN(tst_QSerialPortInfo) |
110 | #include "tst_qserialportinfo.moc" |
111 |