1
/****************************************************************************
2
**
3
** Copyright (C) 2011 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
** GNU Lesser General Public License Usage
11
** This file may be used under the terms of the GNU Lesser General Public
12
** License version 2.1 as published by the Free Software Foundation and
13
** appearing in the file LICENSE.LGPL included in the packaging of this
14
** file. Please review the following information to ensure the GNU Lesser
15
** General Public License version 2.1 requirements will be met:
16
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17
**
18
** In addition, as a special exception, Nokia gives you certain additional
19
** rights. These rights are described in the Nokia Qt LGPL Exception
20
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21
**
22
** GNU General Public License Usage
23
** Alternatively, this file may be used under the terms of the GNU General
24
** Public License version 3.0 as published by the Free Software Foundation
25
** and appearing in the file LICENSE.GPL included in the packaging of this
26
** file. Please review the following information to ensure the GNU General
27
** Public License version 3.0 requirements will be met:
28
** http://www.gnu.org/copyleft/gpl.html.
29
**
30
** Other Usage
31
** Alternatively, this file may be used in accordance with the terms and
32
** conditions contained in a signed written agreement between you and Nokia.
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"