1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the test suite 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 | |
30 | #include <QtTest/QtTest> |
31 | |
32 | #include <qcoreapplication.h> |
33 | #include <qdebug.h> |
34 | #include <qabstractsocket.h> |
35 | |
36 | class tst_QAbstractSocket : public QObject |
37 | { |
38 | Q_OBJECT |
39 | |
40 | public: |
41 | tst_QAbstractSocket(); |
42 | virtual ~tst_QAbstractSocket(); |
43 | |
44 | private slots: |
45 | void getSetCheck(); |
46 | }; |
47 | |
48 | tst_QAbstractSocket::tst_QAbstractSocket() |
49 | { |
50 | } |
51 | |
52 | tst_QAbstractSocket::~tst_QAbstractSocket() |
53 | { |
54 | } |
55 | |
56 | class MyAbstractSocket : public QAbstractSocket |
57 | { |
58 | public: |
59 | MyAbstractSocket() : QAbstractSocket(QAbstractSocket::TcpSocket, 0) {} |
60 | void setLocalPort(quint16 port) { QAbstractSocket::setLocalPort(port); } |
61 | void setPeerPort(quint16 port) { QAbstractSocket::setPeerPort(port); } |
62 | }; |
63 | |
64 | // Testing get/set functions |
65 | void tst_QAbstractSocket::getSetCheck() |
66 | { |
67 | MyAbstractSocket obj1; |
68 | // qint64 QAbstractSocket::readBufferSize() |
69 | // void QAbstractSocket::setReadBufferSize(qint64) |
70 | obj1.setReadBufferSize(qint64(0)); |
71 | QCOMPARE(qint64(0), obj1.readBufferSize()); |
72 | obj1.setReadBufferSize((Q_INT64_C(-9223372036854775807) - 1)); |
73 | QCOMPARE((Q_INT64_C(-9223372036854775807) - 1), obj1.readBufferSize()); |
74 | obj1.setReadBufferSize(Q_INT64_C(9223372036854775807)); |
75 | QCOMPARE(Q_INT64_C(9223372036854775807), obj1.readBufferSize()); |
76 | |
77 | // quint16 QAbstractSocket::localPort() |
78 | // void QAbstractSocket::setLocalPort(quint16) |
79 | obj1.setLocalPort(quint16(0)); |
80 | QCOMPARE(quint16(0), obj1.localPort()); |
81 | obj1.setLocalPort(quint16(0xffff)); |
82 | QCOMPARE(quint16(0xffff), obj1.localPort()); |
83 | |
84 | // quint16 QAbstractSocket::peerPort() |
85 | // void QAbstractSocket::setPeerPort(quint16) |
86 | obj1.setPeerPort(quint16(0)); |
87 | QCOMPARE(quint16(0), obj1.peerPort()); |
88 | obj1.setPeerPort(quint16(0xffff)); |
89 | QCOMPARE(quint16(0xffff), obj1.peerPort()); |
90 | } |
91 | |
92 | QTEST_MAIN(tst_QAbstractSocket) |
93 | #include "tst_qabstractsocket.moc" |
94 | |