~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to tools/qtestlib/wince/cetest/main.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2009-11-02 18:30:08 UTC
  • mfrom: (1.2.2 upstream)
  • mto: (15.2.5 experimental)
  • mto: This revision was merged to the branch mainline in revision 88.
  • Revision ID: james.westby@ubuntu.com-20091102183008-b6a4gcs128mvfb3m
Tags: upstream-4.6.0~beta1
ImportĀ upstreamĀ versionĀ 4.6.0~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
 
4
** All rights reserved.
 
5
** Contact: Nokia Corporation (qt-info@nokia.com)
 
6
**
 
7
** This file is part of the tools applications of the Qt Toolkit.
 
8
**
 
9
** $QT_BEGIN_LICENSE:LGPL$
 
10
** No Commercial Usage
 
11
** This file contains pre-release code and may not be distributed.
 
12
** You may use this file in accordance with the terms and conditions
 
13
** contained in the Technology Preview License Agreement accompanying
 
14
** this package.
 
15
**
 
16
** GNU Lesser General Public License Usage
 
17
** Alternatively, this file may be used under the terms of the GNU Lesser
 
18
** General Public License version 2.1 as published by the Free Software
 
19
** Foundation and appearing in the file LICENSE.LGPL included in the
 
20
** packaging of this file.  Please review the following information to
 
21
** ensure the GNU Lesser General Public License version 2.1 requirements
 
22
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
 
23
**
 
24
** In addition, as a special exception, Nokia gives you certain additional
 
25
** rights.  These rights are described in the Nokia Qt LGPL Exception
 
26
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
 
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
**
 
34
**
 
35
**
 
36
**
 
37
**
 
38
** $QT_END_LICENSE$
 
39
**
 
40
****************************************************************************/
 
41
 
 
42
#ifdef QT_CETEST_NO_ACTIVESYNC
 
43
#   include "cetcpsyncconnection.h"
 
44
#else
 
45
#   include "activesyncconnection.h"
 
46
#endif
 
47
 
 
48
#include "deployment.h"
 
49
#include <option.h>
 
50
#include <project.h>
 
51
#include <property.h>
 
52
#include <qstringlist.h>
 
53
#include <qfileinfo.h>
 
54
#include <qdir.h>
 
55
#include <iostream>
 
56
using namespace std;
 
57
 
 
58
const int debugLevel = 0;
 
59
void debugOutput(const QString& text, int level)
 
60
{
 
61
    if (level <= debugLevel)
 
62
        cout << qPrintable(text) << endl;
 
63
}
 
64
 
 
65
// needed for QMake sources to compile
 
66
QString project_builtin_regx() { return QString();}
 
67
static QString pwd;
 
68
QString qmake_getpwd()
 
69
{
 
70
    if(pwd.isNull())
 
71
        pwd = QDir::currentPath();
 
72
    return pwd;
 
73
}
 
74
bool qmake_setpwd(const QString &p)
 
75
{
 
76
    if(QDir::setCurrent(p)) {
 
77
        pwd = QDir::currentPath();
 
78
        return true;
 
79
    }
 
80
    return false;
 
81
}
 
82
 
 
83
namespace TestConfiguration {
 
84
    QString localExecutable;
 
85
    QString localQtConf;
 
86
    QString remoteTestPath;
 
87
    QString remoteLibraryPath;
 
88
    QString remoteExecutable;
 
89
    QString remoteResultFile;
 
90
 
 
91
    bool testDebug;
 
92
    void init()
 
93
    {
 
94
        testDebug = true;
 
95
        localQtConf = QLatin1String("no");
 
96
        remoteTestPath = QLatin1String("\\Program Files\\qt_test");
 
97
        remoteLibraryPath = remoteTestPath;
 
98
        remoteResultFile = QLatin1String("\\qt_test_results.txt");
 
99
    }
 
100
}
 
101
 
 
102
void usage()
 
103
{
 
104
    cout <<
 
105
        "QTestLib options\n"
 
106
        " -functions : Returns a list of current testfunctions\n"
 
107
        " -xml       : Outputs results as XML document\n"
 
108
        " -lightxml  : Outputs results as stream of XML tags\n"
 
109
        " -o filename: Writes all output into a file\n"
 
110
        " -silent    : Only outputs warnings and failures\n"
 
111
        " -v1        : Print enter messages for each testfunction\n"
 
112
        " -v2        : Also print out each QVERIFY/QCOMPARE/QTEST\n"
 
113
        " -vs        : Print every signal emitted\n"
 
114
        " -eventdelay ms    : Set default delay for mouse and keyboard simulation to ms milliseconds\n"
 
115
        " -keydelay ms      : Set default delay for keyboard simulation to ms milliseconds\n"
 
116
        " -mousedelay ms    : Set default delay for mouse simulation to ms milliseconds\n"
 
117
        " -keyevent-verbose : Turn on verbose messages for keyboard simulation\n"
 
118
        " -maxwarnings n    : Sets the maximum amount of messages to output.\n"
 
119
        "                     0 means unlimited, default: 2000\n"
 
120
        " -help             : This help\n";
 
121
    cout <<
 
122
        "cetest specific options\n"
 
123
        " -debug            : Test debug version[default]\n"
 
124
        " -release          : Test release version\n"
 
125
        " -libpath <path>   : Remote path to deploy Qt libraries to\n"
 
126
        " -qt-delete        : Delete the Qt libraries after execution\n"
 
127
        " -project-delete   : Delete the project file(s) after execution\n"
 
128
        " -delete           : Delete everything deployed after execution\n"
 
129
        " -conf             : Specify location of qt.conf file\n"
 
130
        " -f <file>         : Specify project file\n"
 
131
        " -cache <file>     : Specify .qmake.cache file to use\n"
 
132
        " -timeout <value>  : Specify a timeout value after which the test will be terminated\n"
 
133
        "                     -1 specifies waiting forever (default)\n"
 
134
        "                      0 specifies starting the process detached\n"
 
135
        "                     >0 wait <value> seconds\n"
 
136
        "\n";
 
137
}
 
138
 
 
139
int main(int argc, char **argv)
 
140
{
 
141
    QStringList arguments;
 
142
    for (int i=0; i<argc; ++i)
 
143
        arguments.append(QString::fromLatin1(argv[i]));
 
144
 
 
145
    TestConfiguration::init();
 
146
 
 
147
    QStringList launchArguments;
 
148
    QString resultFile;
 
149
    QString proFile;
 
150
    QString cacheFile;
 
151
    int timeout = -1;
 
152
    bool cleanupQt = false;
 
153
    bool cleanupProject = false;
 
154
 
 
155
    for (int i=1; i<arguments.size(); ++i) {
 
156
        if (arguments.at(i).toLower() == QLatin1String("-help")
 
157
                    || arguments.at(i).toLower() == QLatin1String("--help")
 
158
                    || arguments.at(i).toLower() == QLatin1String("/?")) {
 
159
            usage();
 
160
            return 0;
 
161
        } else if (arguments.at(i).toLower() == QLatin1String("-o")) {
 
162
            if (++i == arguments.size()) {
 
163
                cout << "Error: No output file specified!" << endl;
 
164
                return -1;
 
165
            }
 
166
            resultFile = arguments.at(i);
 
167
        } else if (arguments.at(i).toLower() == QLatin1String("-eventdelay")
 
168
                    || arguments.at(i).toLower() == QLatin1String("-keydelay")
 
169
                    || arguments.at(i).toLower() == QLatin1String("-mousedelay")
 
170
                    || arguments.at(i).toLower() == QLatin1String("-maxwarnings")) {
 
171
            launchArguments.append(arguments.at(i++));
 
172
            if (i == arguments.size()) {
 
173
                cout << "Please specify value for:" << qPrintable(arguments.at(i-1).mid(1)) << endl;
 
174
                return -1;
 
175
            }
 
176
            launchArguments.append(arguments.at(i));
 
177
        } else if (arguments.at(i).toLower() == QLatin1String("-debug")) {
 
178
            TestConfiguration::testDebug = true;
 
179
            Option::before_user_vars.append("CONFIG-=release");
 
180
            Option::before_user_vars.append("CONFIG+=debug");
 
181
        } else if (arguments.at(i).toLower() == QLatin1String("-release")) {
 
182
            TestConfiguration::testDebug = false;
 
183
            Option::before_user_vars.append("CONFIG-=debug");
 
184
            Option::before_user_vars.append("CONFIG+=release");
 
185
        } else if (arguments.at(i).toLower() == QLatin1String("-libpath")) {
 
186
            if (++i == arguments.size()) {
 
187
                cout << "Error: No library path specified!" << endl;
 
188
                return -1;
 
189
            }
 
190
            TestConfiguration::remoteLibraryPath = arguments.at(i);
 
191
        } else if (arguments.at(i).toLower() == QLatin1String("-qt-delete")) {
 
192
            cleanupQt = true;
 
193
        } else if (arguments.at(i).toLower() == QLatin1String("-project-delete")) {
 
194
            cleanupProject = true;
 
195
        } else if (arguments.at(i).toLower() == QLatin1String("-delete")) {
 
196
            cleanupQt = true;
 
197
            cleanupProject = true;
 
198
        } else if (arguments.at(i).toLower() == QLatin1String("-conf")) {
 
199
            if (++i == arguments.size()) {
 
200
                cout << "Error: No qt.conf file specified!" << endl;
 
201
                return -1;
 
202
            }
 
203
            if (!QFileInfo(arguments.at(i)).exists())
 
204
                cout << "Warning: could not find qt.conf file at:" << qPrintable(arguments.at(i)) << endl;
 
205
            else
 
206
                TestConfiguration::localQtConf = arguments.at(i);
 
207
        } else if (arguments.at(i).toLower() == QLatin1String("-f")) {
 
208
            if (++i == arguments.size()) {
 
209
                cout << "Error: No output file specified!" << endl;
 
210
                return -1;
 
211
            }
 
212
            proFile = arguments.at(i);
 
213
        } else if (arguments.at(i).toLower() == QLatin1String("-cache")) {
 
214
            if (++i == arguments.size()) {
 
215
                cout << "Error: No cache file specified!" << endl;
 
216
                return -1;
 
217
            }
 
218
            cacheFile = arguments.at(i);
 
219
        } else if (arguments.at(i).toLower() == QLatin1String("-timeout")) {
 
220
            if (++i == arguments.size()) {
 
221
                cout << "Error: No timeout value specified!" << endl;
 
222
                return -1;
 
223
            }
 
224
            timeout = QString(arguments.at(i)).toInt();
 
225
        } else {
 
226
            launchArguments.append(arguments.at(i));
 
227
        }
 
228
    }
 
229
 
 
230
    // check for .pro file
 
231
    if (proFile.isEmpty()) {
 
232
        proFile = QDir::current().dirName() + QLatin1String(".pro");
 
233
        if (!QFileInfo(proFile).exists()) {
 
234
            cout << "Error: Could not find project file in current directory." << endl;
 
235
            return -1;
 
236
        }
 
237
        debugOutput(QString::fromLatin1("Using Project File:").append(proFile),1);
 
238
    }
 
239
 
 
240
    // read target and deployment rules
 
241
    int qmakeArgc = 1;
 
242
    char* qmakeArgv[] = { "qmake.exe" };
 
243
    Option::qmake_mode = Option::QMAKE_GENERATE_NOTHING;
 
244
    Option::output_dir = qmake_getpwd();
 
245
    if (!cacheFile.isEmpty())
 
246
        Option::mkfile::cachefile = cacheFile;
 
247
    int ret = Option::init(qmakeArgc, qmakeArgv);
 
248
    if(ret != Option::QMAKE_CMDLINE_SUCCESS) {
 
249
        cout << "Error: could not parse " << qPrintable(proFile) << endl;
 
250
        return -1;
 
251
    }
 
252
 
 
253
    QMakeProperty prop;
 
254
    QMakeProject project(&prop);
 
255
 
 
256
    project.read(proFile);
 
257
    if (project.values("TEMPLATE").join(" ").toLower() != QString("app")) {
 
258
        cout << "Error: Can only test executables!" << endl;
 
259
        return -1;
 
260
    }
 
261
    // Check wether the project is still in debug/release mode after reading
 
262
    // If .pro specifies to be one mode only, we need to accept this
 
263
    if (project.isActiveConfig("debug"))
 
264
        TestConfiguration::testDebug = true;
 
265
    else
 
266
        TestConfiguration::testDebug = false;
 
267
 
 
268
    QString destDir = project.values("DESTDIR").join(" ");
 
269
    if (!destDir.isEmpty()) {
 
270
        if (QDir::isRelativePath(destDir)) {
 
271
            QFileInfo fi(proFile);
 
272
            if (destDir == QLatin1String("."))
 
273
                destDir = fi.absolutePath() + "/" + destDir + "/" + (TestConfiguration::testDebug ? "debug" : "release");
 
274
            else
 
275
                destDir = fi.absolutePath() + QDir::separator() + destDir;
 
276
        }
 
277
    } else {
 
278
        QFileInfo fi(proFile);
 
279
        destDir = fi.absolutePath();
 
280
        destDir += QDir::separator() + QLatin1String(TestConfiguration::testDebug ? "debug" : "release");
 
281
    }
 
282
 
 
283
    DeploymentList qtDeploymentList;
 
284
    DeploymentList projectDeploymentList;
 
285
 
 
286
    TestConfiguration::localExecutable = Option::fixPathToLocalOS(destDir + QDir::separator() + project.values("TARGET").join(" ") + QLatin1String(".exe"));
 
287
    TestConfiguration::remoteTestPath = QLatin1String("\\Program Files\\") + Option::fixPathToLocalOS(project.values("TARGET").join(QLatin1String(" ")));
 
288
    if (!arguments.contains(QLatin1String("-libpath"), Qt::CaseInsensitive))
 
289
        TestConfiguration::remoteLibraryPath = TestConfiguration::remoteTestPath;
 
290
 
 
291
    QString targetExecutable = Option::fixPathToLocalOS(project.values("TARGET").join(QLatin1String(" ")));
 
292
    int last = targetExecutable.lastIndexOf(QLatin1Char('\\'));
 
293
    targetExecutable = targetExecutable.mid( last == -1 ? 0 : last+1 );
 
294
    TestConfiguration::remoteExecutable = TestConfiguration::remoteTestPath + QDir::separator() + targetExecutable + QLatin1String(".exe");
 
295
    projectDeploymentList.append(CopyItem(TestConfiguration::localExecutable , TestConfiguration::remoteExecutable));
 
296
 
 
297
    // deploy
 
298
#ifdef QT_CETEST_NO_ACTIVESYNC
 
299
    CeTcpSyncConnection connection;
 
300
#else
 
301
    ActiveSyncConnection connection;
 
302
#endif
 
303
    if (!connection.connect()) {
 
304
        cout << "Error: Could not connect to device!" << endl;
 
305
        return -1;
 
306
    }
 
307
    DeploymentHandler deployment;
 
308
    deployment.setConnection(&connection);
 
309
 
 
310
    deployment.initQtDeploy(&project, qtDeploymentList, TestConfiguration::remoteLibraryPath);
 
311
    deployment.initProjectDeploy(&project , projectDeploymentList, TestConfiguration::remoteTestPath);
 
312
 
 
313
    // add qt.conf
 
314
    if (TestConfiguration::localQtConf != QLatin1String("no")) {
 
315
        QString qtConfOrigin = QFileInfo(TestConfiguration::localQtConf).absoluteFilePath();
 
316
        QString qtConfTarget = Option::fixPathToLocalOS(TestConfiguration::remoteTestPath + QDir::separator() + QLatin1String("qt.conf"));
 
317
        projectDeploymentList.append(CopyItem(qtConfOrigin, qtConfTarget));
 
318
    }
 
319
 
 
320
    if (!deployment.deviceDeploy(qtDeploymentList) || !deployment.deviceDeploy(projectDeploymentList)) {
 
321
        cout << "Error: Could not copy file(s) to device" << endl;
 
322
        return -1;
 
323
    }
 
324
 
 
325
    // launch
 
326
    launchArguments.append("-o");
 
327
    launchArguments.append(TestConfiguration::remoteResultFile);
 
328
 
 
329
    cout << endl << "Remote Launch:" << qPrintable(TestConfiguration::remoteExecutable) << " " << qPrintable(launchArguments.join(" ")) << endl;
 
330
    if (!connection.execute(TestConfiguration::remoteExecutable, launchArguments.join(" "), timeout)) {
 
331
        cout << "Error: Could not execute target file" << endl;
 
332
        return -1;
 
333
    }
 
334
 
 
335
 
 
336
    // copy result file
 
337
    // show results
 
338
    if (resultFile.isEmpty()) {
 
339
        QString tempResultFile = Option::fixPathToLocalOS(QDir::tempPath() + "/qt_ce_temp_result_file.txt");
 
340
        if (connection.copyFileFromDevice(TestConfiguration::remoteResultFile, tempResultFile)) {
 
341
            QFile file(tempResultFile);
 
342
            QByteArray arr;
 
343
            if (file.open(QIODevice::ReadOnly)) {
 
344
                arr = file.readAll();
 
345
                cout << arr.constData() << endl;
 
346
            }
 
347
            file.close();
 
348
            file.remove();
 
349
        }
 
350
    } else {
 
351
        connection.copyFileFromDevice(TestConfiguration::remoteResultFile, resultFile);
 
352
    }
 
353
 
 
354
    // delete
 
355
    connection.deleteFile(TestConfiguration::remoteResultFile);
 
356
    if (cleanupQt)
 
357
        deployment.cleanup(qtDeploymentList);
 
358
    if (cleanupProject)
 
359
        deployment.cleanup(projectDeploymentList);
 
360
    return 0;
 
361
}