From 05585c623e87b0830bde8faf6b9b50d6cc4bcd5c Mon Sep 17 00:00:00 2001
From: Kai Koehne <kai.koehne@nokia.com>
Date: Thu, 25 Mar 2010 13:20:57 +0100
Subject: [PATCH] QmlDesigner: Beautify Bauhaus autotest

Use data based tests
---
 .../qmldesigner/bauhaustests/testbauhaus.cpp  | 101 ++++++++++--------
 .../qmldesigner/bauhaustests/testbauhaus.h    |   8 ++
 .../qml/qmldesigner/coretests/testcore.cpp    |   4 +-
 3 files changed, 64 insertions(+), 49 deletions(-)

diff --git a/tests/auto/qml/qmldesigner/bauhaustests/testbauhaus.cpp b/tests/auto/qml/qmldesigner/bauhaustests/testbauhaus.cpp
index 9cd69aed50e..03d5c807879 100644
--- a/tests/auto/qml/qmldesigner/bauhaustests/testbauhaus.cpp
+++ b/tests/auto/qml/qmldesigner/bauhaustests/testbauhaus.cpp
@@ -34,88 +34,95 @@
 #include <QDir>
 #include <QDebug>
 
-QStringList failures;
-
 
 TestBauhaus::TestBauhaus()
     : QObject()
 {
+    foreach (const QString &string, QProcess::systemEnvironment()) {
+        if (string.contains("qtdir", Qt::CaseInsensitive)) {
+            m_qtDir = string.split("=").last();
+            break;
+        }
+    }
+    Q_ASSERT(!m_qtDir.isEmpty());
+
+    m_creatorDir = QString(WORKDIR) + "../../../../..";
+#ifdef Q_OS_WIN
+    m_executable = m_creatorDir + "/bin/qtcreator.exe";
+#else
+    m_executable = m_creatorDir + "/bin/qtcreator.bin";
+#endif
+
+    Q_ASSERT(QFileInfo(m_executable).exists());
 }
 
 void TestBauhaus::initTestCase()
 {
 }
 
-void loadFile(const QString &fileName)
+bool TestBauhaus::loadFile(const QString &fileName)
 {
     QProcess process;
     qDebug() << "starting: " << fileName;
-    QVERIFY(QFileInfo(fileName).exists());
-#ifdef Q_OS_WIN
-    const QString bauhausExecutable = "../../../../../bin/qtcreator.exe";
-#else
-    const QString bauhausExecutable = QDir::current().absoluteFilePath("../../../../../bin/qtcreator.bin");
-#endif
-    QVERIFY(QFileInfo(bauhausExecutable).isExecutable());
-    process.start(bauhausExecutable, QStringList() << fileName);
+    Q_ASSERT(QFileInfo(fileName).exists());
+
+    process.start(m_executable, QStringList() << fileName);
     if (!process.waitForStarted())
-        QFAIL(fileName.toLatin1());
+        return false;
     if (!QProcess::Running == process.state()) {
-        QFAIL(fileName.toLatin1());
-        failures << fileName;
+        return false;
     }
     QTest::qWait(5000);
     if (!QProcess::Running == process.state()) {
-        QFAIL(fileName.toLatin1());
-        failures << fileName;
+        return false;
     }
+    return true;
 }
 
-void loadAllFiles(const QString &path)
+QStringList findAllQmlFiles(const QDir &dir)
 {
-    QDir::setCurrent(WORKDIR);
-    QVERIFY(QFileInfo(path).exists());
-    QDir dir(path);
-    foreach (const QString &file, dir.entryList(QStringList() << "*.qml", QDir::Files))
-        loadFile(path + "/" + file);
+    QStringList files;
+    foreach (const QString &file, dir.entryList(QStringList() << "*.qml", QDir::Files)) {
+        files += dir.absoluteFilePath(file);
+    }
+
     foreach (const QString &directory, dir.entryList(QStringList(), QDir::AllDirs | QDir::NoDotAndDotDot))
-        loadAllFiles(path + "/" + directory);
+        files += findAllQmlFiles(QDir(dir.absoluteFilePath(directory)));
+    return files;
 }
 
 void TestBauhaus::cleanupTestCase()
 {
 }
 
+void TestBauhaus::loadExamples_data()
+{
+    QTest::addColumn<QString>("filePath");
+    foreach (const QString &file, findAllQmlFiles(QDir(m_qtDir + "/examples/declarative"))) {
+        QTest::newRow("file") << file;
+    }
+}
+
 void TestBauhaus::loadExamples()
 {
-    failures.clear();
-    QString qtdir;
-    foreach (const QString &string, QProcess::systemEnvironment())
-        if (string.contains("qtdir", Qt::CaseInsensitive))
-            qtdir = string.split("=").last();
-    if (qtdir.isEmpty())
-        qWarning() << "QTDIR has to be set";
-    QVERIFY(!qtdir.isEmpty());
-    QVERIFY(QFileInfo(qtdir + "/examples/declarative").exists());
-    loadAllFiles(qtdir + "/examples/declarative");
-    qDebug() << failures;
-    QVERIFY(failures.isEmpty());
+    QFETCH(QString, filePath);
+    if (!loadFile(filePath))
+        QFAIL(filePath.toAscii());
+}
+
+void TestBauhaus::loadDemos_data()
+{
+    QTest::addColumn<QString>("filePath");
+    foreach (const QString &file, findAllQmlFiles(QDir(m_qtDir + "/demos/declarative"))) {
+        QTest::newRow("file") << file;
+    }
 }
 
 void TestBauhaus::loadDemos()
 {
-    failures.clear();
-    QString qtdir;
-    foreach (const QString &string, QProcess::systemEnvironment())
-        if (string.contains("qtdir", Qt::CaseInsensitive))
-            qtdir = string.split("=").last();
-    if (qtdir.isEmpty())
-        qWarning() << "QTDIR has to be set";
-    QVERIFY(!qtdir.isEmpty());
-    QVERIFY(QFileInfo(qtdir + "/demos/declarative").exists());
-    loadAllFiles(qtdir + "/demos/declarative");
-    qDebug() << failures;
-    QVERIFY(failures.isEmpty());
+    QFETCH(QString, filePath);
+    if (!loadFile(filePath))
+        QFAIL(filePath.toAscii());
 }
 
 
diff --git a/tests/auto/qml/qmldesigner/bauhaustests/testbauhaus.h b/tests/auto/qml/qmldesigner/bauhaustests/testbauhaus.h
index 893321dbeef..70f7be88a2f 100644
--- a/tests/auto/qml/qmldesigner/bauhaustests/testbauhaus.h
+++ b/tests/auto/qml/qmldesigner/bauhaustests/testbauhaus.h
@@ -44,8 +44,16 @@ public:
 private slots:
     void initTestCase();
     void cleanupTestCase();
+    void loadExamples_data();
     void loadExamples();
+    void loadDemos_data();
     void loadDemos();
+private:
+    bool loadFile(const QString &file);
+
+    QString m_executable;
+    QString m_creatorDir;
+    QString m_qtDir;
 };
 
 #endif // TESTBAUHAUS_H
diff --git a/tests/auto/qml/qmldesigner/coretests/testcore.cpp b/tests/auto/qml/qmldesigner/coretests/testcore.cpp
index dcdc8713cbe..168ab25b699 100644
--- a/tests/auto/qml/qmldesigner/coretests/testcore.cpp
+++ b/tests/auto/qml/qmldesigner/coretests/testcore.cpp
@@ -404,7 +404,7 @@ void TestCore::loadComponentPropertiesInCoreModel()
     model1->attachView(testRewriterView1.data());
 
     QVERIFY(testRewriterView1->rootModelNode().variantProperty("pushed").isDynamic());
-    QVERIFY(!testRewriterView1->rootModelNode().variantProperty("pushed").value().isValid());
+    QCOMPARE(false, testRewriterView1->rootModelNode().variantProperty("pushed").value().toBool());
 
     QPlainTextEdit textEdit2;
     textEdit2.setPlainText("import Qt 4.6; Item{}");
@@ -416,7 +416,7 @@ void TestCore::loadComponentPropertiesInCoreModel()
     testRewriterView2->setTextModifier(&modifier2);
     model2->attachView(testRewriterView2.data());
 
-    testRewriterView2->rootModelNode().variantProperty("pushed").setDynamicTypeNameAndValue("bool", QVariant());
+    testRewriterView2->rootModelNode().variantProperty("pushed").setDynamicTypeNameAndValue("bool", QVariant(false));
 
     QVERIFY(compareTree(testRewriterView1->rootModelNode(), testRewriterView2->rootModelNode()));
 }
-- 
GitLab