1
/****************************************************************************
3
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4
** All rights reserved.
5
** Contact: Nokia Corporation (qt-info@nokia.com)
7
** This file is part of the tools applications of the Qt Toolkit.
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
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.
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.
28
** If you have questions regarding the use of this file, please contact
29
** Nokia at qt-info@nokia.com.
40
****************************************************************************/
42
#ifdef QT_CETEST_NO_ACTIVESYNC
43
# include "cetcpsyncconnection.h"
45
# include "activesyncconnection.h"
48
#include "deployment.h"
52
#include <qstringlist.h>
53
#include <qfileinfo.h>
58
const int debugLevel = 0;
59
void debugOutput(const QString& text, int level)
61
if (level <= debugLevel)
62
cout << qPrintable(text) << endl;
65
// needed for QMake sources to compile
66
QString project_builtin_regx() { return QString();}
68
QString qmake_getpwd()
71
pwd = QDir::currentPath();
74
bool qmake_setpwd(const QString &p)
76
if(QDir::setCurrent(p)) {
77
pwd = QDir::currentPath();
83
namespace TestConfiguration {
84
QString localExecutable;
86
QString remoteTestPath;
87
QString remoteLibraryPath;
88
QString remoteExecutable;
89
QString remoteResultFile;
95
localQtConf = QLatin1String("no");
96
remoteTestPath = QLatin1String("\\Program Files\\qt_test");
97
remoteLibraryPath = remoteTestPath;
98
remoteResultFile = QLatin1String("\\qt_test_results.txt");
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";
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"
139
int main(int argc, char **argv)
141
QStringList arguments;
142
for (int i=0; i<argc; ++i)
143
arguments.append(QString::fromLatin1(argv[i]));
145
TestConfiguration::init();
147
QStringList launchArguments;
152
bool cleanupQt = false;
153
bool cleanupProject = false;
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("/?")) {
161
} else if (arguments.at(i).toLower() == QLatin1String("-o")) {
162
if (++i == arguments.size()) {
163
cout << "Error: No output file specified!" << endl;
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;
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;
190
TestConfiguration::remoteLibraryPath = arguments.at(i);
191
} else if (arguments.at(i).toLower() == QLatin1String("-qt-delete")) {
193
} else if (arguments.at(i).toLower() == QLatin1String("-project-delete")) {
194
cleanupProject = true;
195
} else if (arguments.at(i).toLower() == QLatin1String("-delete")) {
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;
203
if (!QFileInfo(arguments.at(i)).exists())
204
cout << "Warning: could not find qt.conf file at:" << qPrintable(arguments.at(i)) << endl;
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;
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;
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;
224
timeout = QString(arguments.at(i)).toInt();
226
launchArguments.append(arguments.at(i));
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;
237
debugOutput(QString::fromLatin1("Using Project File:").append(proFile),1);
240
// read target and deployment rules
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;
254
QMakeProject project(&prop);
256
project.read(proFile);
257
if (project.values("TEMPLATE").join(" ").toLower() != QString("app")) {
258
cout << "Error: Can only test executables!" << endl;
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;
266
TestConfiguration::testDebug = false;
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");
275
destDir = fi.absolutePath() + QDir::separator() + destDir;
278
QFileInfo fi(proFile);
279
destDir = fi.absolutePath();
280
destDir += QDir::separator() + QLatin1String(TestConfiguration::testDebug ? "debug" : "release");
283
DeploymentList qtDeploymentList;
284
DeploymentList projectDeploymentList;
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;
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));
298
#ifdef QT_CETEST_NO_ACTIVESYNC
299
CeTcpSyncConnection connection;
301
ActiveSyncConnection connection;
303
if (!connection.connect()) {
304
cout << "Error: Could not connect to device!" << endl;
307
DeploymentHandler deployment;
308
deployment.setConnection(&connection);
310
deployment.initQtDeploy(&project, qtDeploymentList, TestConfiguration::remoteLibraryPath);
311
deployment.initProjectDeploy(&project , projectDeploymentList, TestConfiguration::remoteTestPath);
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));
320
if (!deployment.deviceDeploy(qtDeploymentList) || !deployment.deviceDeploy(projectDeploymentList)) {
321
cout << "Error: Could not copy file(s) to device" << endl;
326
launchArguments.append("-o");
327
launchArguments.append(TestConfiguration::remoteResultFile);
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;
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);
343
if (file.open(QIODevice::ReadOnly)) {
344
arr = file.readAll();
345
cout << arr.constData() << endl;
351
connection.copyFileFromDevice(TestConfiguration::remoteResultFile, resultFile);
355
connection.deleteFile(TestConfiguration::remoteResultFile);
357
deployment.cleanup(qtDeploymentList);
359
deployment.cleanup(projectDeploymentList);