author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 02 Feb 2010 00:43:10 +0200 | |
changeset 3 | 41300fa6a67c |
parent 0 | 1918ee327afb |
permissions | -rw-r--r-- |
0 | 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 Qt Linguist 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 |
#include "testlupdate.h" |
|
43 |
#include <stdlib.h> |
|
44 |
#include <QtGui/QApplication> |
|
45 |
#include <QtCore/QProcess> |
|
46 |
#include <QtCore/QTimer> |
|
47 |
#include <QtCore/QDir> |
|
48 |
||
49 |
#ifdef Q_OS_WIN32 |
|
50 |
# include <windows.h> |
|
51 |
#endif |
|
52 |
||
53 |
#include <QtTest/QtTest> |
|
54 |
||
55 |
||
56 |
TestLUpdate::TestLUpdate() |
|
57 |
{ |
|
58 |
childProc = 0; |
|
59 |
QString binPath = QLibraryInfo::location(QLibraryInfo::BinariesPath); |
|
60 |
m_cmdLupdate = binPath + QLatin1String("/lupdate"); |
|
61 |
m_cmdQMake = binPath + QLatin1String("/qmake"); |
|
62 |
} |
|
63 |
||
64 |
TestLUpdate::~TestLUpdate() |
|
65 |
{ |
|
66 |
if (childProc) |
|
67 |
delete childProc; |
|
68 |
} |
|
69 |
||
70 |
void TestLUpdate::setWorkingDirectory(const QString &workDir) |
|
71 |
{ |
|
72 |
m_workDir = workDir; |
|
73 |
QDir::setCurrent(m_workDir); |
|
74 |
} |
|
75 |
||
76 |
void TestLUpdate::addMakeResult( const QString &result ) |
|
77 |
{ |
|
78 |
make_result.append( result ); |
|
79 |
} |
|
80 |
||
81 |
bool TestLUpdate::runChild( bool showOutput, const QString &program, const QStringList &argList) |
|
82 |
{ |
|
83 |
make_result.clear(); |
|
84 |
exit_ok = FALSE; |
|
85 |
if (childProc) |
|
86 |
delete childProc; |
|
87 |
||
88 |
child_show = showOutput; |
|
89 |
if ( showOutput ) { |
|
90 |
QString S = argList.join(" "); |
|
91 |
addMakeResult( program + QLatin1String(" ") + S ); |
|
92 |
} |
|
93 |
||
94 |
childProc = new QProcess(); |
|
95 |
Q_ASSERT(childProc); |
|
96 |
||
97 |
childProc->setWorkingDirectory(m_workDir); |
|
98 |
connect(childProc, SIGNAL(finished(int)), this, SLOT(childReady(int))); |
|
99 |
childProc->setProcessChannelMode(QProcess::MergedChannels); |
|
100 |
if (argList.isEmpty()) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
101 |
childProc->start( program, QIODevice::ReadWrite | QIODevice::Text ); |
0 | 102 |
} else { |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
103 |
childProc->start( program, argList, QIODevice::ReadWrite | QIODevice::Text ); |
0 | 104 |
} |
105 |
bool ok; |
|
106 |
||
107 |
ok = childProc->waitForStarted(); |
|
108 |
||
109 |
if (ok) |
|
110 |
ok = childProc->waitForFinished(); |
|
111 |
||
112 |
if (!ok) |
|
113 |
addMakeResult( "Error executing '" + program + "'." ); |
|
114 |
||
115 |
childReady(ok ? 0 : -1); |
|
116 |
||
117 |
return ok; |
|
118 |
} |
|
119 |
||
120 |
void TestLUpdate::childReady(int /*exitCode*/) |
|
121 |
{ |
|
122 |
if (childProc != 0) { |
|
123 |
childHasData(); |
|
124 |
exit_ok = childProc->state() == QProcess::NotRunning |
|
125 |
&& childProc->exitStatus() == 0; |
|
126 |
childProc->deleteLater(); |
|
127 |
} |
|
128 |
childProc = 0; |
|
129 |
} |
|
130 |
||
131 |
void TestLUpdate::childHasData() |
|
132 |
{ |
|
133 |
//QByteArray ba = childProc->readAllStandardError(); |
|
134 |
//qDebug() << "ERROR:" << ba; |
|
135 |
QString stdoutput = childProc->readAllStandardOutput(); |
|
136 |
stdoutput = stdoutput.replace("\t", " "); |
|
137 |
if (child_show) |
|
138 |
addMakeResult(stdoutput); |
|
139 |
} |
|
140 |
||
141 |
bool TestLUpdate::run(const QString &commandline) |
|
142 |
{ |
|
143 |
return runChild(true, m_cmdLupdate + QLatin1String(" ") + commandline); |
|
144 |
} |
|
145 |
||
146 |
||
147 |
bool TestLUpdate::updateProFile(const QString &arguments) |
|
148 |
{ |
|
149 |
QStringList args = arguments.split(QChar(' ')); |
|
150 |
return runChild( true, m_cmdLupdate, args ); |
|
151 |
} |
|
152 |
||
153 |
bool TestLUpdate::qmake() |
|
154 |
{ |
|
155 |
QStringList args; |
|
156 |
args << "-r"; |
|
157 |
return runChild(true, m_cmdQMake, args); |
|
158 |
} |