Commit 05585c62 authored by Kai Koehne's avatar Kai Koehne
Browse files

QmlDesigner: Beautify Bauhaus autotest

Use data based tests
parent 744b0ef0
......@@ -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());
}
......
......@@ -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
......@@ -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()));
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment