summaryrefslogtreecommitdiffstats
path: root/tests/auto/qsysteminfo/tst_qsysteminfo.cpp
diff options
context:
space:
mode:
authorEckhart Koppen <eckhart.koppen@nokia.com>2011-04-20 11:52:57 +0300
committerEckhart Koppen <eckhart.koppen@nokia.com>2011-04-20 11:52:57 +0300
commitfb3e9bc2d941462f1244aaf0ea79425a307f883d (patch)
treeafce91959098ec887ce466abc6e40342261df3db /tests/auto/qsysteminfo/tst_qsysteminfo.cpp
parentc61d909c7b815319e40ba27d7f84e92aa5f1f946 (diff)
parent6f0dc7cc40dd63763a581a7fb6d4e76649b8026c (diff)
Merge branch 'master' into 1.2.0v1.2.0
Diffstat (limited to 'tests/auto/qsysteminfo/tst_qsysteminfo.cpp')
-rw-r--r--tests/auto/qsysteminfo/tst_qsysteminfo.cpp121
1 files changed, 120 insertions, 1 deletions
diff --git a/tests/auto/qsysteminfo/tst_qsysteminfo.cpp b/tests/auto/qsysteminfo/tst_qsysteminfo.cpp
index 5637244c2e..a9828ff3ed 100644
--- a/tests/auto/qsysteminfo/tst_qsysteminfo.cpp
+++ b/tests/auto/qsysteminfo/tst_qsysteminfo.cpp
@@ -43,16 +43,68 @@
#include <QtTest/QtTest>
#include "qsysteminfo.h"
+#include "qsysteminfo_simulator_p.h"
#include <QDebug>
QTM_USE_NAMESPACE
Q_DECLARE_METATYPE(QSystemInfo::Version);
Q_DECLARE_METATYPE(QSystemInfo::Feature);
+/**
+ * Starts an event loop that runs until the given signal is received.
+ * Optionally the event loop can return earlier on a timeout.
+ *
+ * \return \p true if the requested signal was received
+ * \p false on timeout
+ */
+#ifdef TESTR
+
+static bool waitForSignal(QObject *obj, const char *signal, int timeout = 0)
+{
+ QEventLoop loop;
+ QObject::connect(obj, signal, &loop, SLOT(quit()));
+ QTimer timer;
+ QSignalSpy timeoutSpy(&timer, SIGNAL(timeout()));
+ if (timeout > 0) {
+ QObject::connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
+ timer.setSingleShot(true);
+ timer.start(timeout);
+ }
+ loop.exec();
+ return timeoutSpy.isEmpty();
+}
+
+//static void setLanguage(const QString & lang)
+//{
+// QSystemInfoPrivate *s = getSystemInfoPrivate();
+// s->setCurrentLanguage(lang);
+//}
+
+
+class ChangeLanguageThread : public QThread
+{
+public:
+ void run()
+ {
+ SystemInfoConnection si;
+ QSystemInfoPrivate *d = si.systeminfoPrivate();
+ d->setCurrentLanguage(lang);
+
+ }
+ QString lang;
+};
+#endif
+
class tst_QSystemInfo : public QObject
{
Q_OBJECT
+public:
+ tst_QSystemInfo();
+ virtual ~tst_QSystemInfo();
+
+ friend class QSystemInfo;
+
private slots:
void initTestCase();
@@ -69,8 +121,31 @@ private slots:
void tst_detailFeatures_data();
void tst_detailFeatures();
+#ifdef TESTR
+ void currentLanguageChanged();
+
+ void slotCurrentLanguageChanged(const QString &);
+#endif
+private:
+#ifdef TESTR
+ ChangeLanguageThread *changeLangThread;
+#endif
};
+tst_QSystemInfo::tst_QSystemInfo()
+{
+#ifdef TESTR
+ changeLangThread = new ChangeLanguageThread();
+#endif
+}
+
+tst_QSystemInfo::~tst_QSystemInfo()
+{
+#ifdef TESTR
+ delete changeLangThread, changeLangThread = 0;
+#endif
+}
+
void tst_QSystemInfo::initTestCase()
{
qRegisterMetaType<QSystemInfo::Version>("QSystemInfo::Version");
@@ -80,6 +155,11 @@ void tst_QSystemInfo::initTestCase()
void tst_QSystemInfo::tst_currentLanguage()
{
QSystemInfo si;
+#ifdef TESTR
+ SystemInfoConnection sic;
+ QSystemInfoPrivate *d = sic.systeminfoPrivate();
+ d->setInitialData();
+#endif
QVERIFY(!si.currentLanguage().isEmpty());
QCOMPARE(si.currentLanguage().length(), 2);
QVERIFY(si.currentLanguage() == si.currentLanguage().toLower());
@@ -89,6 +169,11 @@ void tst_QSystemInfo::tst_currentLanguage()
void tst_QSystemInfo::tst_availableLanguages()
{
QSystemInfo si;
+#ifdef TESTR
+ SystemInfoConnection sic;
+ QSystemInfoPrivate *d = sic.systeminfoPrivate();
+ d->setInitialData();
+#endif
QVERIFY(!si.availableLanguages().isEmpty());
QStringList available = si.availableLanguages();
foreach(QString lang, available) {
@@ -114,6 +199,11 @@ void tst_QSystemInfo::tst_versions()
QFETCH(QSystemInfo::Version, version);
QFETCH(QString, parameter);
QSystemInfo si;
+#ifdef TESTR
+ SystemInfoConnection sic;
+ QSystemInfoPrivate *d = sic.systeminfoPrivate();
+ d->setInitialData();
+#endif
QString vers = si.version(version, parameter);
QVERIFY(!vers.isEmpty()
|| vers.isEmpty());
@@ -123,6 +213,11 @@ void tst_QSystemInfo::tst_versions()
void tst_QSystemInfo::tst_countryCode()
{
QSystemInfo si;
+#ifdef TESTR
+ SystemInfoConnection sic;
+ QSystemInfoPrivate *d = sic.systeminfoPrivate();
+ d->setInitialData();
+#endif
QVERIFY(!si.currentCountryCode().isEmpty());
QCOMPARE(si.currentCountryCode().length(),2);
QVERIFY(si.currentCountryCode() == si.currentCountryCode().toUpper());
@@ -152,7 +247,11 @@ void tst_QSystemInfo::tst_hasFeatures()
{
QFETCH(QSystemInfo::Feature, feature);
QSystemInfo si;
- qWarning() << si.hasFeatureSupported(feature);
+#ifdef TESTR
+ SystemInfoConnection sic;
+ QSystemInfoPrivate *d = sic.systeminfoPrivate();
+ d->setInitialData();
+#endif
QVERIFY(si.hasFeatureSupported(feature) == false
|| si.hasFeatureSupported(feature) == true);
}
@@ -171,7 +270,27 @@ void tst_QSystemInfo::tst_detailFeatures()
// QVERIFY(!si.getDetailOfFeature(feature).isEmpty());
// }
}
+#ifdef TESTR
+void tst_QSystemInfo::currentLanguageChanged()
+{
+ QSystemInfo si;
+ connect(&si,SIGNAL(currentLanguageChanged(const QString &)),this,
+ SLOT(slotCurrentLanguageChanged(const QString &)));
+
+ changeLangThread->lang = "kl";
+ changeLangThread->start();
+ QSignalSpy errorSpy(&si, SIGNAL(currentLanguageChanged(const QString &)));
+ QVERIFY(::waitForSignal(&si, SIGNAL(currentLanguageChanged(const QString &)), 10 * 1000));
+ QVERIFY(errorSpy.count() == 1);
+}
+
+void tst_QSystemInfo::slotCurrentLanguageChanged(const QString &lang)
+{
+ QVERIFY(lang == "kl");
+}
+#endif
QTEST_MAIN(tst_QSystemInfo)
#include "tst_qsysteminfo.moc"
+