summaryrefslogtreecommitdiffstats
path: root/tests/auto/network-settings.h
diff options
context:
space:
mode:
authorAleksandar Sasha Babic <aleksandar.babic@nokia.com>2009-04-27 12:11:39 (GMT)
committerAleksandar Sasha Babic <aleksandar.babic@nokia.com>2009-04-27 12:11:39 (GMT)
commita10e5b8102abde1f3edff44f24d8fcdcab859393 (patch)
tree0ac5123f62d942bf1d5ce779d2d0ce92b7c2a330 /tests/auto/network-settings.h
parent0bb4ffa7c8e8a546d9e03304e61b440921d830c0 (diff)
downloadQt-a10e5b8102abde1f3edff44f24d8fcdcab859393.zip
Qt-a10e5b8102abde1f3edff44f24d8fcdcab859393.tar.gz
Qt-a10e5b8102abde1f3edff44f24d8fcdcab859393.tar.bz2
Network server test related data (serever name, IP address ...) can now
be read from a file at runtime. This should make auto testing more flexibile. Currently this is supported for Symbian platform. The file is named "iap.txt" and should be placed under "C:\data". When creating file use UNIX line ending and UTF 16 LE encoding. Conflicts: tests/auto/network-settings.h
Diffstat (limited to 'tests/auto/network-settings.h')
-rw-r--r--tests/auto/network-settings.h140
1 files changed, 127 insertions, 13 deletions
diff --git a/tests/auto/network-settings.h b/tests/auto/network-settings.h
index 663d817..4cee7ed 100644
--- a/tests/auto/network-settings.h
+++ b/tests/auto/network-settings.h
@@ -43,6 +43,8 @@
#ifdef Q_OS_SYMBIAN
#include <sys/socket.h>
#include <net/if.h>
+#include <QSharedPointer>
+#include <QHash>
#endif
#if defined(Q_OS_SYMBIAN) && defined(Q_CC_NOKIAX86)
// In emulator we use WINSOCK connectivity by default. Unfortunately winsock
@@ -55,22 +57,62 @@
//#define SYMBIAN_WINSOCK_CONNECTIVITY
#endif
+ class QtNetworkSettingsRecord {
+ public:
+ QtNetworkSettingsRecord() { }
+
+ QtNetworkSettingsRecord(const QString& recName, const QString& recVal)
+ : strRecordName(recName), strRecordValue(recVal) { }
+
+ QtNetworkSettingsRecord(const QtNetworkSettingsRecord & other)
+ : strRecordName(other.strRecordName), strRecordValue(other.strRecordValue) { }
+
+ ~QtNetworkSettingsRecord() { }
+
+ const QString& recordName() const { return strRecordName; }
+ const QString& recordValue() const { return strRecordValue; }
+
+ private:
+ QString strRecordName;
+ QString strRecordValue;
+ };
+
class QtNetworkSettings
{
public:
+
static QString serverLocalName()
{
+#ifdef Q_OS_SYMBIAN
+ loadTestSettings();
+
+ if(QtNetworkSettings::entries.contains("server.localname")) {
+ QtNetworkSettingsRecord* entry = entries["server.localname"];
+ return entry->recordValue();
+ }
+#endif
return QString("qttest");
//return QString("aspiriniks");
//return QString("qt-test-server");
}
static QString serverDomainName()
{
+#ifdef Q_OS_SYMBIAN
+ loadTestSettings();
+
+ if(QtNetworkSettings::entries.contains("server.domainname")) {
+ QtNetworkSettingsRecord* entry = entries["server.domainname"];
+ return entry->recordValue();
+ }
+#endif
return QString("it.local");
//return QString("troll.no");
}
static QString serverName()
{
+#ifdef Q_OS_SYMBIAN
+ loadTestSettings();
+#endif
return serverLocalName() + "." + serverDomainName();
}
static QString winServerName()
@@ -84,6 +126,18 @@ public:
}
static const char *serverIP()
{
+#ifdef Q_OS_SYMBIAN
+ loadTestSettings();
+
+ if(QtNetworkSettings::entries.contains("server.ip")) {
+ QtNetworkSettingsRecord* entry = entries["server.ip"];
+ QByteArray valueAsAscii = entry->recordValue().toAscii();
+ if(*serverIPAscii == 0) {
+ ::strcpy(serverIPAscii, valueAsAscii.data());
+ }
+ return serverIPAscii;
+ }
+#endif
//return "10.10.0.147";
return "10.10.14.172";
//return "10.3.7.2";
@@ -114,6 +168,7 @@ public:
expected = expected.append(" Cyrus IMAP4 v2.3.11-Mandriva-RPM-2.3.11-6mdv2008.1 server ready\r\n");
return expected;
}
+<<<<<<< HEAD:tests/auto/network-settings.h
static QByteArray expectedReplyFtp()
{
@@ -122,6 +177,8 @@ public:
expected = expected.append(" Cyrus IMAP4 v2.3.11-Mandriva-RPM-2.3.11-6mdv2008.1 server ready\r\n");
return expected;
}
+=======
+>>>>>>> 6d41f31... Nwteork server test related data (serever name, IP address ...) can now:tests/auto/network-settings.h
#ifdef Q_OS_SYMBIAN
static void setDefaultIap()
@@ -139,50 +196,107 @@ public:
private:
#ifdef Q_OS_SYMBIAN
- static bool bIsIapLoaded;
+
+ static QHash<QString, QtNetworkSettingsRecord* > entries;
+ static bool bDefaultIapLoaded;
+ static bool bTestSettingsLoaded;
static QString iapFileFullPath;
- static QString defaultIap;
+ static QString strDefaultIap;
+ static char serverIPAscii[256];
static QString getDefaultIap() {
- if(!bIsIapLoaded)
- loadIapCfg();
+ if(!bDefaultIapLoaded) {
+ if(!loadDefaultIap()) // not found in file - use default
+ strDefaultIap = QString("Lab");
+ }
- return defaultIap;
+ return strDefaultIap;
}
- static void loadIapCfg() {
+ static bool loadDefaultIap() {
QFile iapCfgFile(iapFileFullPath);
+ bool bFoundDefaultIapTag = false;
+
if (iapCfgFile.open(QFile::ReadOnly)) {
QTextStream input(&iapCfgFile);
QString line;
- bool bFoundDefaultTag = false;
do {
line = input.readLine().trimmed();
if(line.startsWith(QString("#")))
continue; // comment found
if(line.contains(QString("[DEFAULT]"))) {
- bFoundDefaultTag = true;
- } else if(line.startsWith(QString("[")) && bFoundDefaultTag) {
+ bFoundDefaultIapTag = true;
+ } else if(line.startsWith(QString("[")) && bFoundDefaultIapTag) {
+ bFoundDefaultIapTag = false;
break; // stick to default
}
- if(bFoundDefaultTag && line.contains("name")) {
+ if(bFoundDefaultIapTag && line.contains("name")) {
int position = line.indexOf(QString("="));
position += QString("=").length();
- defaultIap = line.mid(position).trimmed();
+ strDefaultIap = line.mid(position).trimmed();
break;
}
} while (!line.isNull());
}
+
+ return bFoundDefaultIapTag;
+ }
+
+ static bool loadTestSettings() {
+ if(bTestSettingsLoaded)
+ return true;
+
+ QFile cfgFile(iapFileFullPath);
+ bool bFoundTestTag = false;
+
+ if (cfgFile.open(QFile::ReadOnly)) {
+ QTextStream input(&cfgFile);
+ QString line;
+ do {
+ line = input.readLine().trimmed();
+
+ if(line.startsWith(QString("#")) || line.length() == 0)
+ continue; // comment or empty line found
+
+ if(line.contains(QString("[TEST]"))) {
+ bFoundTestTag = true;
+ } else if(line.startsWith(QString("[")) && bFoundTestTag) {
+ bFoundTestTag = false;
+ break; // finished with test tag
+ }
+
+ if(bFoundTestTag) { // non-empty line
+ int position = line.indexOf(QString("="));
+
+ if(position <= 0) // not found
+ continue;
+
+ // found - extract
+
+ QString recname = line.mid(0, position - QString("=").length()).trimmed();
+ QString recval = line.mid(position + QString("=").length()).trimmed();
+
+ //create record
+ QtNetworkSettingsRecord *entry = new QtNetworkSettingsRecord(recname, recval);
+ entries.insert(entry->recordName(), entry);
+ }
+ } while (!line.isNull());
+ }
+
+ return bTestSettingsLoaded = true;
}
#endif
};
#ifdef Q_OS_SYMBIAN
-bool QtNetworkSettings::bIsIapLoaded = false;
+QHash<QString, QtNetworkSettingsRecord* > QtNetworkSettings::entries = QHash<QString, QtNetworkSettingsRecord* > ();
+bool QtNetworkSettings::bDefaultIapLoaded = false;
+bool QtNetworkSettings::bTestSettingsLoaded = false;
QString QtNetworkSettings::iapFileFullPath = QString("C:\\Data\\iap.txt");
-QString QtNetworkSettings::defaultIap = QString("Lab"); // this will be default value
+QString QtNetworkSettings::strDefaultIap = QString("");
+char QtNetworkSettings::serverIPAscii[256];
#endif
#ifdef Q_OS_SYMBIAN