OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / tests / auto / qml / qmldesigner / bauhaustests / testbauhaus.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
8 **
9 **
10 ** GNU Lesser General Public License Usage
11 **
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 **
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 **
23 ** Other Usage
24 **
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **************************************************************************/
32
33 #include "testbauhaus.h"
34
35 #include <QProcess>
36 #include <QFileInfo>
37 #include <QDir>
38 #include <QDebug>
39
40
41 TestBauhaus::TestBauhaus()
42     : QObject()
43 {
44     foreach (const QString &string, QProcess::systemEnvironment()) {
45         if (string.contains("qtdir", Qt::CaseInsensitive)) {
46             m_qtDir = string.split("=").last();
47             break;
48         }
49     }
50     Q_ASSERT(!m_qtDir.isEmpty());
51
52     m_creatorDir = QString(WORKDIR) + "../../../../..";
53 #ifdef Q_OS_WIN
54     m_executable = m_creatorDir + "/bin/qtcreator.exe";
55 #else
56     m_executable = m_creatorDir + "/bin/qtcreator";
57 #endif
58
59     Q_ASSERT(QFileInfo(m_executable).exists());
60 }
61
62 bool TestBauhaus::loadFile(const QString &fileName)
63 {
64     QProcess process;
65     qDebug() << "starting: " << fileName;
66     Q_ASSERT(QFileInfo(fileName).exists());
67
68     process.start(m_executable, QStringList() << fileName);
69     if (!process.waitForStarted())
70         return false;
71     if (!QProcess::Running == process.state()) {
72         return false;
73     }
74     QTest::qWait(10000);
75     if (!QProcess::Running == process.state()) {
76         return false;
77     }
78     return true;
79 }
80
81 QStringList findAllQmlFiles(const QDir &dir)
82 {
83     QStringList files;
84     foreach (const QString &file, dir.entryList(QStringList() << "*.qml", QDir::Files)) {
85         files += dir.absoluteFilePath(file);
86     }
87
88     foreach (const QString &directory, dir.entryList(QStringList(), QDir::AllDirs | QDir::NoDotAndDotDot))
89         files += findAllQmlFiles(QDir(dir.absoluteFilePath(directory)));
90     return files;
91 }
92
93 void TestBauhaus::loadExamples_data()
94 {
95     QTest::addColumn<QString>("filePath");
96     foreach (const QString &file, findAllQmlFiles(QDir(m_qtDir + "/examples/declarative"))) {
97         QTest::newRow("file") << file;
98     }
99 }
100
101 void TestBauhaus::loadExamples()
102 {
103     QFETCH(QString, filePath);
104     if (!loadFile(filePath))
105         QFAIL(filePath.toAscii());
106 }
107
108 void TestBauhaus::loadDemos_data()
109 {
110     QTest::addColumn<QString>("filePath");
111     foreach (const QString &file, findAllQmlFiles(QDir(m_qtDir + "/demos/declarative"))) {
112         QTest::newRow("file") << file;
113     }
114 }
115
116 void TestBauhaus::loadDemos()
117 {
118     QFETCH(QString, filePath);
119     if (!loadFile(filePath))
120         QFAIL(filePath.toAscii());
121 }
122
123 void TestBauhaus::loadCreator_data()
124 {
125     QTest::addColumn<QString>("filePath");
126     foreach (const QString &file, findAllQmlFiles(QDir(m_creatorDir))) {
127         QTest::newRow("file") << file;
128     }
129 }
130
131 void TestBauhaus::loadCreator()
132 {
133     QFETCH(QString, filePath);
134     if (!loadFile(filePath))
135         QFAIL(filePath.toAscii());
136 }
137
138 QTEST_MAIN(TestBauhaus);