|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the test suite of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 |
|
43 #include <QtTest/QtTest> |
|
44 #include <qapplication.h> |
|
45 |
|
46 #include <q3socketdevice.h> |
|
47 |
|
48 #include "../network-settings.h" |
|
49 |
|
50 //TESTED_CLASS= |
|
51 //TESTED_FILES= |
|
52 |
|
53 class tst_Q3SocketDevice : public QObject |
|
54 { |
|
55 Q_OBJECT |
|
56 |
|
57 public: |
|
58 tst_Q3SocketDevice(); |
|
59 virtual ~tst_Q3SocketDevice(); |
|
60 |
|
61 public slots: |
|
62 void initTestCase(); |
|
63 void cleanupTestCase(); |
|
64 void init(); |
|
65 void cleanup(); |
|
66 |
|
67 private slots: |
|
68 void readNull(); |
|
69 }; |
|
70 |
|
71 tst_Q3SocketDevice::tst_Q3SocketDevice() |
|
72 { |
|
73 } |
|
74 |
|
75 tst_Q3SocketDevice::~tst_Q3SocketDevice() |
|
76 { |
|
77 } |
|
78 |
|
79 void tst_Q3SocketDevice::initTestCase() |
|
80 { |
|
81 } |
|
82 |
|
83 void tst_Q3SocketDevice::cleanupTestCase() |
|
84 { |
|
85 } |
|
86 |
|
87 void tst_Q3SocketDevice::init() |
|
88 { |
|
89 } |
|
90 |
|
91 void tst_Q3SocketDevice::cleanup() |
|
92 { |
|
93 } |
|
94 |
|
95 void tst_Q3SocketDevice::readNull() |
|
96 { |
|
97 Q3SocketDevice device; |
|
98 device.setBlocking(true); |
|
99 |
|
100 int attempts = 10; |
|
101 while (attempts--) { |
|
102 if (device.connect(QtNetworkSettings::serverIP(), 143)) |
|
103 break; |
|
104 } |
|
105 |
|
106 // some static state checking |
|
107 QVERIFY(device.isValid()); |
|
108 QCOMPARE(device.type(), Q3SocketDevice::Stream); |
|
109 QCOMPARE(device.protocol(), Q3SocketDevice::IPv4); |
|
110 QVERIFY(device.socket() != -1); |
|
111 QVERIFY(device.blocking()); |
|
112 #if defined Q_OS_IRIX |
|
113 // IRIX defaults to the opposite in Qt 3, so we won't fix |
|
114 // this in Qt 4. |
|
115 QVERIFY(device.addressReusable()); |
|
116 #else |
|
117 QVERIFY(!device.addressReusable()); |
|
118 #endif |
|
119 QCOMPARE(device.peerPort(), quint16(143)); |
|
120 QCOMPARE(device.peerAddress().toString(), |
|
121 QtNetworkSettings::serverIP().toString()); |
|
122 QCOMPARE(device.error(), Q3SocketDevice::NoError); |
|
123 |
|
124 // write a logout notice |
|
125 QCOMPARE(device.writeBlock("X LOGOUT\r\n", Q_ULONG(10)), Q_LONG(10)); |
|
126 |
|
127 // expect three lines of response: greeting, bye-warning and |
|
128 // logout command completion. |
|
129 int ch; |
|
130 for (int i = 0; i < 3; ++i) { |
|
131 do { |
|
132 QVERIFY((ch = device.getch()) != -1); |
|
133 } while (char(ch) != '\n'); |
|
134 } |
|
135 |
|
136 // here, read() will return 0. |
|
137 char c; |
|
138 QCOMPARE(device.readBlock(&c, 1), qint64(0)); |
|
139 QVERIFY(!device.isValid()); |
|
140 } |
|
141 |
|
142 QTEST_APPLESS_MAIN(tst_Q3SocketDevice) |
|
143 #include "tst_q3socketdevice.moc" |