| 1 |
/**************************************************************************** |
| 2 |
** |
| 3 |
** Copyright (C) 2012 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 |
|
| 45 |
#include <q3dns.h> |
| 46 |
#include <qapplication.h> |
| 47 |
#include <q3socket.h> |
| 48 |
|
| 49 |
//TESTED_CLASS= |
| 50 |
//TESTED_FILES= |
| 51 |
|
| 52 |
class tst_Q3Dns : public QObject |
| 53 |
{ |
| 54 |
Q_OBJECT |
| 55 |
|
| 56 |
public: |
| 57 |
tst_Q3Dns(); |
| 58 |
virtual ~tst_Q3Dns(); |
| 59 |
|
| 60 |
|
| 61 |
public slots: |
| 62 |
void initTestCase(); |
| 63 |
void cleanupTestCase(); |
| 64 |
void init(); |
| 65 |
void cleanup(); |
| 66 |
private slots: |
| 67 |
void destructor(); |
| 68 |
void literals(); |
| 69 |
void txtRecords(); |
| 70 |
void longTxtRecord(); |
| 71 |
void simpleLookup(); |
| 72 |
|
| 73 |
protected slots: |
| 74 |
void txtRecordAnswer(); |
| 75 |
void longTxtRecordAnswer(); |
| 76 |
void simpleLookupDone(); |
| 77 |
}; |
| 78 |
|
| 79 |
tst_Q3Dns::tst_Q3Dns() |
| 80 |
{ |
| 81 |
} |
| 82 |
|
| 83 |
tst_Q3Dns::~tst_Q3Dns() |
| 84 |
{ |
| 85 |
} |
| 86 |
|
| 87 |
void tst_Q3Dns::initTestCase() |
| 88 |
{ |
| 89 |
} |
| 90 |
|
| 91 |
void tst_Q3Dns::cleanupTestCase() |
| 92 |
{ |
| 93 |
} |
| 94 |
|
| 95 |
void tst_Q3Dns::init() |
| 96 |
{ |
| 97 |
} |
| 98 |
|
| 99 |
void tst_Q3Dns::cleanup() |
| 100 |
{ |
| 101 |
} |
| 102 |
|
| 103 |
void tst_Q3Dns::destructor() |
| 104 |
{ |
| 105 |
/* |
| 106 |
The following small program used to crash because of a bug in the Q3Dns |
| 107 |
constructor that should be fixed by change 67978: |
| 108 |
|
| 109 |
#include <qapplication.h> |
| 110 |
#include <qsocket.h> |
| 111 |
|
| 112 |
int main( int argc, char **argv ) |
| 113 |
{ |
| 114 |
QApplication a( argc, argv ); |
| 115 |
Q3Socket *s = new Q3Socket( &a ); |
| 116 |
s->connectToHost( "ftp.qt.nokia.com", 21 ); |
| 117 |
return 0; |
| 118 |
} |
| 119 |
*/ |
| 120 |
int c = 0; |
| 121 |
char **v = 0; |
| 122 |
QCoreApplication a(c, v); |
| 123 |
Q3Socket *s = new Q3Socket(&a); |
| 124 |
s->connectToHost("ftp.qt.nokia.com", 21); |
| 125 |
|
| 126 |
// dummy verify since this test only makes sure that it does not crash |
| 127 |
QVERIFY( TRUE ); |
| 128 |
} |
| 129 |
|
| 130 |
void tst_Q3Dns::literals() |
| 131 |
{ |
| 132 |
int c = 0; |
| 133 |
char **v = 0; |
| 134 |
QCoreApplication a(c, v); |
| 135 |
|
| 136 |
Q3Dns ip4literal1("4.2.2.1", Q3Dns::A); |
| 137 |
QCOMPARE((int) ip4literal1.addresses().count(), 1); |
| 138 |
QCOMPARE(ip4literal1.addresses().first().toString(), QString("4.2.2.1")); |
| 139 |
|
| 140 |
Q3Dns ip4literal2("4.2.2.1", Q3Dns::Aaaa); |
| 141 |
QCOMPARE((int) ip4literal2.addresses().count(), 0); |
| 142 |
|
| 143 |
Q3Dns ip6literal1("::1", Q3Dns::A); |
| 144 |
QCOMPARE((int) ip6literal1.addresses().count(), 0); |
| 145 |
|
| 146 |
Q3Dns ip6literal2("::1", Q3Dns::Aaaa); |
| 147 |
QCOMPARE(ip6literal2.addresses().first().toString(), QString("::1")); |
| 148 |
QCOMPARE((int) ip6literal2.addresses().count(), 1); |
| 149 |
} |
| 150 |
|
| 151 |
void tst_Q3Dns::txtRecords() |
| 152 |
{ |
| 153 |
QSKIP("TXT record support is broken.", SkipAll); |
| 154 |
int argc = 0; |
| 155 |
char **argv = 0; |
| 156 |
QCoreApplication qapp(argc, argv); |
| 157 |
|
| 158 |
Q3Dns dns("Sales._ipp._tcp.dns-sd.org", Q3Dns::Txt); |
| 159 |
connect(&dns, SIGNAL(resultsReady()), SLOT(txtRecordAnswer())); |
| 160 |
QTestEventLoop::instance().enterLoop(10); |
| 161 |
if (QTestEventLoop::instance().timeout()) |
| 162 |
QFAIL("Timed out while looking up TXT record for Sales._ipp._tcp.dns-sd.org"); |
| 163 |
|
| 164 |
QStringList texts = dns.texts(); |
| 165 |
#if defined Q_OS_DARWIN |
| 166 |
QSKIP("TXT records in Q3Dns don't work for Mac OS X.", SkipSingle); |
| 167 |
#endif |
| 168 |
QVERIFY(!texts.isEmpty()); |
| 169 |
QCOMPARE(texts.at(0), QString("rp=lpt1")); |
| 170 |
} |
| 171 |
|
| 172 |
void tst_Q3Dns::txtRecordAnswer() |
| 173 |
{ |
| 174 |
QTestEventLoop::instance().exitLoop(); |
| 175 |
} |
| 176 |
|
| 177 |
void tst_Q3Dns::longTxtRecord() |
| 178 |
{ |
| 179 |
QSKIP("Long TXT records in Q3Dns don't work.", SkipSingle); |
| 180 |
|
| 181 |
int c = 0; |
| 182 |
char **v = 0; |
| 183 |
QCoreApplication a(c, v); |
| 184 |
|
| 185 |
Q3Dns dns(QString::fromLatin1("andreas.hanssen.name"), Q3Dns::Txt); |
| 186 |
QObject::connect(&dns, SIGNAL(resultsReady()), this, SLOT(longTxtRecordAnswer())); |
| 187 |
|
| 188 |
QTestEventLoop::instance().enterLoop(30); |
| 189 |
if (QTestEventLoop::instance().timeout()) |
| 190 |
QFAIL("Network operation timed out"); |
| 191 |
|
| 192 |
QStringList list = dns.texts(); |
| 193 |
|
| 194 |
QCOMPARE(list.count(), 1); |
| 195 |
QCOMPARE(list[0], QString::fromLatin1("I have a remarkable solution to Fermat's last theorem, but it doesn't fit into this TXT record")); |
| 196 |
} |
| 197 |
|
| 198 |
void tst_Q3Dns::longTxtRecordAnswer() |
| 199 |
{ |
| 200 |
QTestEventLoop::instance().exitLoop(); |
| 201 |
} |
| 202 |
|
| 203 |
void tst_Q3Dns::simpleLookup() |
| 204 |
{ |
| 205 |
// Stuff |
| 206 |
int c = 0; |
| 207 |
char **v = 0; |
| 208 |
QCoreApplication a(c, v); |
| 209 |
Q3Dns dns("qt.nokia.com"); |
| 210 |
|
| 211 |
QSignalSpy spy(&dns, SIGNAL(resultsReady())); |
| 212 |
connect(&dns, SIGNAL(resultsReady()), this, SLOT(simpleLookupDone())); |
| 213 |
QTestEventLoop::instance().enterLoop(5); |
| 214 |
if (QTestEventLoop::instance().timeout()) |
| 215 |
QFAIL("Network operation timed out"); |
| 216 |
QCOMPARE(spy.count(), 1); |
| 217 |
} |
| 218 |
|
| 219 |
void tst_Q3Dns::simpleLookupDone() |
| 220 |
{ |
| 221 |
QTestEventLoop::instance().exitLoop(); |
| 222 |
} |
| 223 |
|
| 224 |
|
| 225 |
QTEST_APPLESS_MAIN(tst_Q3Dns) |
| 226 |
#include "tst_q3dns.moc" |