Debian Codegraph @

tests/auto/qserialportinfo/tst_qserialportinfo.cpp

raw
1 // Copyright (C) 2014 Denis Shienkov <[email protected]>
2 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4 #include <QtTest/QtTest>
5 #include <QtSerialPort/QSerialPort>
6 #include <QtSerialPort/QSerialPortInfo>
7
8 class tst_QSerialPortInfo : public QObject
9 {
10 Q_OBJECT
11 public:
12 explicit tst_QSerialPortInfo();
13
14 private slots:
15 void initTestCase();
16
17 void constructors();
18 void assignment();
19
20 private:
21 QString m_senderPortName;
22 QString m_receiverPortName;
23 QStringList m_availablePortNames;
24 };
25
26 tst_QSerialPortInfo::tst_QSerialPortInfo()
27 {
28 }
29
30 void tst_QSerialPortInfo::initTestCase()
31 {
32 m_senderPortName = QString::fromLocal8Bit(qgetenv("QTEST_SERIALPORT_SENDER"));
33 m_receiverPortName = QString::fromLocal8Bit(qgetenv("QTEST_SERIALPORT_RECEIVER"));
34 if (m_senderPortName.isEmpty() || m_receiverPortName.isEmpty()) {
35 static const char message[] =
36 "Test doesn't work because the names of serial ports aren't found in env.\n"
37 "Please set environment variables:\n"
38 " QTEST_SERIALPORT_SENDER to name of output serial port\n"
39 " QTEST_SERIALPORT_RECEIVER to name of input serial port\n"
40 "Specify short names of port"
41 #if defined(Q_OS_UNIX)
42 ", like 'ttyS0'\n";
43 #elif defined(Q_OS_WIN32)
44 ", like 'COM1'\n";
45 #else
46 "\n";
47 #endif
48 QSKIP(message);
49 } else {
50 m_availablePortNames << m_senderPortName << m_receiverPortName;
51 }
52 }
53
54 void tst_QSerialPortInfo::constructors()
55 {
56 QSerialPortInfo empty;
57 QVERIFY(empty.isNull());
58 QSerialPortInfo empty2(QLatin1String("ABCD"));
59 QVERIFY(empty2.isNull());
60 QSerialPortInfo empty3(empty);
61 QVERIFY(empty3.isNull());
62
63 QSerialPortInfo exist(m_senderPortName);
64 QVERIFY(!exist.isNull());
65 QSerialPortInfo exist2(exist);
66 QVERIFY(!exist2.isNull());
67 }
68
69 void tst_QSerialPortInfo::assignment()
70 {
71 QSerialPortInfo empty;
72 QVERIFY(empty.isNull());
73 QSerialPortInfo empty2;
74 empty2 = empty;
75 QVERIFY(empty2.isNull());
76
77 QSerialPortInfo exist(m_senderPortName);
78 QVERIFY(!exist.isNull());
79 QSerialPortInfo exist2;
80 exist2 = exist;
81 QVERIFY(!exist2.isNull());
82 }
83
84 QTEST_MAIN(tst_QSerialPortInfo)
85 #include "tst_qserialportinfo.moc"