|
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 test suite 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 <QtTest/QtTest> |
|
43 |
|
44 #if !defined(QMAKE_CROSS_COMPILED) |
|
45 |
|
46 #include "testcompiler.h" |
|
47 |
|
48 #include <QObject> |
|
49 #include <QDir> |
|
50 |
|
51 class tst_qmake : public QObject |
|
52 { |
|
53 Q_OBJECT |
|
54 |
|
55 public: |
|
56 tst_qmake(); |
|
57 virtual ~tst_qmake(); |
|
58 |
|
59 public slots: |
|
60 void initTestCase(); |
|
61 void cleanupTestCase(); |
|
62 void init(); |
|
63 void cleanup(); |
|
64 |
|
65 private slots: |
|
66 void simple_app(); |
|
67 void simple_app_shadowbuild(); |
|
68 void simple_lib(); |
|
69 void simple_dll(); |
|
70 void subdirs(); |
|
71 void functions(); |
|
72 void operators(); |
|
73 void variables(); |
|
74 void func_export(); |
|
75 void func_variables(); |
|
76 void comments(); |
|
77 void duplicateLibraryEntries(); |
|
78 void export_across_file_boundaries(); |
|
79 void include_dir(); |
|
80 void install_files(); |
|
81 void install_depends(); |
|
82 void quotedfilenames(); |
|
83 void prompt(); |
|
84 void one_space(); |
|
85 void findMocs(); |
|
86 void findDeps(); |
|
87 #ifndef Q_OS_WIN |
|
88 // Test requires make |
|
89 void bundle_spaces(); |
|
90 #endif |
|
91 void includefunction(); |
|
92 |
|
93 private: |
|
94 TestCompiler test_compiler; |
|
95 QString base_path; |
|
96 }; |
|
97 |
|
98 tst_qmake::tst_qmake() |
|
99 { |
|
100 QString cmd = QString("qmake \"QT_VERSION=%1\"").arg(QT_VERSION); |
|
101 #ifdef Q_CC_MSVC |
|
102 test_compiler.setBaseCommands( "nmake", cmd ); |
|
103 #elif defined(Q_CC_MINGW) |
|
104 test_compiler.setBaseCommands( "mingw32-make", cmd ); |
|
105 #elif defined(Q_OS_WIN) && defined(Q_CC_GNU) |
|
106 test_compiler.setBaseCommands( "mmmake", cmd ); |
|
107 #else |
|
108 test_compiler.setBaseCommands( "make", cmd ); |
|
109 #endif |
|
110 QDir dir; |
|
111 base_path = dir.currentPath(); |
|
112 } |
|
113 |
|
114 tst_qmake::~tst_qmake() |
|
115 { |
|
116 |
|
117 } |
|
118 |
|
119 void tst_qmake::initTestCase() |
|
120 { |
|
121 } |
|
122 |
|
123 void tst_qmake::cleanupTestCase() |
|
124 { |
|
125 } |
|
126 |
|
127 void tst_qmake::init() |
|
128 { |
|
129 test_compiler.clearCommandOutput(); |
|
130 } |
|
131 |
|
132 void tst_qmake::cleanup() |
|
133 { |
|
134 test_compiler.clearCommandOutput(); |
|
135 } |
|
136 |
|
137 void tst_qmake::simple_app() |
|
138 { |
|
139 QString workDir = base_path + "/testdata/simple_app"; |
|
140 |
|
141 QVERIFY( test_compiler.qmake( workDir, "simple_app" )); |
|
142 QVERIFY( test_compiler.make( workDir )); |
|
143 QVERIFY( test_compiler.exists( workDir, "simple_app", Exe, "1.0.0" )); |
|
144 QVERIFY( test_compiler.makeClean( workDir )); |
|
145 QVERIFY( test_compiler.exists( workDir, "simple_app", Exe, "1.0.0" )); // Should still exist after a make clean |
|
146 QVERIFY( test_compiler.makeDistClean( workDir )); |
|
147 QVERIFY( !test_compiler.exists( workDir, "simple_app", Exe, "1.0.0" )); // Should not exist after a make distclean |
|
148 QVERIFY( test_compiler.removeMakefile( workDir ) ); |
|
149 } |
|
150 |
|
151 void tst_qmake::simple_app_shadowbuild() |
|
152 { |
|
153 QString workDir = base_path + "/testdata/simple_app"; |
|
154 QString buildDir = base_path + "/testdata/simple_app_build"; |
|
155 |
|
156 QVERIFY( test_compiler.qmake( workDir, "simple_app", buildDir )); |
|
157 QVERIFY( test_compiler.make( buildDir )); |
|
158 QVERIFY( test_compiler.exists( buildDir, "simple_app", Exe, "1.0.0" )); |
|
159 QVERIFY( test_compiler.makeClean( buildDir )); |
|
160 QVERIFY( test_compiler.exists( buildDir, "simple_app", Exe, "1.0.0" )); // Should still exist after a make clean |
|
161 QVERIFY( test_compiler.makeDistClean( buildDir )); |
|
162 QVERIFY( !test_compiler.exists( buildDir, "simple_app", Exe, "1.0.0" )); // Should not exist after a make distclean |
|
163 QVERIFY( test_compiler.removeMakefile( buildDir ) ); |
|
164 } |
|
165 |
|
166 void tst_qmake::simple_dll() |
|
167 { |
|
168 QString workDir = base_path + "/testdata/simple_dll"; |
|
169 |
|
170 QDir D; |
|
171 D.remove( workDir + "/Makefile"); |
|
172 QVERIFY( test_compiler.qmake( workDir, "simple_dll" )); |
|
173 QVERIFY( test_compiler.make( workDir )); |
|
174 QVERIFY( test_compiler.exists( workDir, "simple_dll", Dll, "1.0.0" )); |
|
175 QVERIFY( test_compiler.makeClean( workDir )); |
|
176 QVERIFY( test_compiler.exists( workDir, "simple_dll", Dll, "1.0.0" )); // Should still exist after a make clean |
|
177 QVERIFY( test_compiler.makeDistClean( workDir )); |
|
178 QVERIFY( !test_compiler.exists( workDir, "simple_dll", Dll, "1.0.0" )); // Should not exist after a make distclean |
|
179 QVERIFY( test_compiler.removeMakefile( workDir ) ); |
|
180 } |
|
181 |
|
182 void tst_qmake::simple_lib() |
|
183 { |
|
184 QString workDir = base_path + "/testdata/simple_lib"; |
|
185 |
|
186 QDir D; |
|
187 D.remove( workDir + "/Makefile"); |
|
188 QVERIFY( test_compiler.qmake( workDir, "simple_lib" )); |
|
189 QVERIFY( test_compiler.make( workDir )); |
|
190 QVERIFY( test_compiler.exists( workDir, "simple_lib", Lib, "1.0.0" )); |
|
191 QVERIFY( test_compiler.makeClean( workDir )); |
|
192 QVERIFY( test_compiler.exists( workDir, "simple_lib", Lib, "1.0.0" )); // Should still exist after a make clean |
|
193 QVERIFY( test_compiler.makeDistClean( workDir )); |
|
194 QVERIFY( !test_compiler.exists( workDir, "simple_lib", Lib, "1.0.0" )); // Should not exist after a make distclean |
|
195 QVERIFY( test_compiler.removeMakefile( workDir ) ); |
|
196 } |
|
197 |
|
198 void tst_qmake::subdirs() |
|
199 { |
|
200 QString workDir = base_path + "/testdata/subdirs"; |
|
201 |
|
202 QDir D; |
|
203 D.remove( workDir + "/simple_app/Makefile"); |
|
204 D.remove( workDir + "/simple_dll/Makefile"); |
|
205 QVERIFY( test_compiler.qmake( workDir, "subdirs" )); |
|
206 QVERIFY( test_compiler.make( workDir )); |
|
207 QVERIFY( test_compiler.exists( workDir + "/simple_app", "simple_app", Exe, "1.0.0" )); |
|
208 QVERIFY( test_compiler.exists( workDir + "/simple_dll", "simple_dll", Dll, "1.0.0" )); |
|
209 QVERIFY( test_compiler.makeClean( workDir )); |
|
210 // Should still exist after a make clean |
|
211 QVERIFY( test_compiler.exists( workDir + "/simple_app", "simple_app", Exe, "1.0.0" )); |
|
212 QVERIFY( test_compiler.exists( workDir + "/simple_dll", "simple_dll", Dll, "1.0.0" )); |
|
213 // Since subdirs templates do not have a make dist clean, we should clean up ourselves |
|
214 // properly |
|
215 QVERIFY( test_compiler.makeDistClean( workDir )); |
|
216 QVERIFY( test_compiler.removeMakefile( workDir ) ); |
|
217 } |
|
218 |
|
219 void tst_qmake::functions() |
|
220 { |
|
221 QString workDir = base_path + "/testdata/functions"; |
|
222 QVERIFY( test_compiler.qmake( workDir, "functions" )); |
|
223 } |
|
224 |
|
225 void tst_qmake::operators() |
|
226 { |
|
227 QString workDir = base_path + "/testdata/operators"; |
|
228 QVERIFY( test_compiler.qmake( workDir, "operators" )); |
|
229 } |
|
230 |
|
231 void tst_qmake::variables() |
|
232 { |
|
233 QString workDir = base_path + "/testdata/variables"; |
|
234 QVERIFY(test_compiler.qmake( workDir, "variables" )); |
|
235 } |
|
236 |
|
237 void tst_qmake::func_export() |
|
238 { |
|
239 QString workDir = base_path + "/testdata/func_export"; |
|
240 QVERIFY(test_compiler.qmake( workDir, "func_export" )); |
|
241 } |
|
242 |
|
243 void tst_qmake::func_variables() |
|
244 { |
|
245 QString workDir = base_path + "/testdata/func_variables"; |
|
246 QVERIFY(test_compiler.qmake( workDir, "func_variables" )); |
|
247 } |
|
248 |
|
249 void tst_qmake::comments() |
|
250 { |
|
251 QString workDir = base_path + "/testdata/comments"; |
|
252 QVERIFY(test_compiler.qmake( workDir, "comments" )); |
|
253 } |
|
254 |
|
255 void tst_qmake::duplicateLibraryEntries() |
|
256 { |
|
257 QVERIFY(true); |
|
258 /* TODO: this test does not work as the problem it tests doesn't happen |
|
259 until after the parsing of the pro-file and thus has to be tested |
|
260 by parsing the Makefile. This is not doable with the current |
|
261 testcompiler framework and has as such been put on hold. |
|
262 |
|
263 QString workDir = base_path + "/testdata/duplicateLibraryEntries"; |
|
264 QVERIFY(test_compiler.qmake(workDir, "duplicateLibraryEntries")); */ |
|
265 } |
|
266 |
|
267 void tst_qmake::export_across_file_boundaries() |
|
268 { |
|
269 // This relies on features so we need to set the QMAKEFEATURES environment variable |
|
270 test_compiler.addToEnvironment("QMAKEFEATURES=."); |
|
271 QString workDir = base_path + "/testdata/export_across_file_boundaries"; |
|
272 QVERIFY( test_compiler.qmake( workDir, "foo" )); |
|
273 test_compiler.resetEnvironment(); |
|
274 } |
|
275 |
|
276 void tst_qmake::include_dir() |
|
277 { |
|
278 QString workDir = base_path + "/testdata/include_dir"; |
|
279 QVERIFY( test_compiler.qmake( workDir, "foo" )); |
|
280 QVERIFY( test_compiler.make( workDir )); |
|
281 QVERIFY( test_compiler.exists( workDir, "foo", Exe, "1.0.0" )); |
|
282 QVERIFY( test_compiler.makeDistClean( workDir )); |
|
283 |
|
284 QString buildDir = base_path + "/testdata/include_dir_build"; |
|
285 QVERIFY( test_compiler.qmake( workDir, "foo", buildDir )); |
|
286 QVERIFY( test_compiler.make( buildDir )); |
|
287 QVERIFY( test_compiler.exists( buildDir, "foo", Exe, "1.0.0" )); |
|
288 QVERIFY( test_compiler.makeDistClean( buildDir )); |
|
289 } |
|
290 |
|
291 void tst_qmake::install_files() |
|
292 { |
|
293 QString workDir = base_path + "/testdata/shadow_files"; |
|
294 QVERIFY( test_compiler.qmake( workDir, "foo" )); |
|
295 QVERIFY( test_compiler.make( workDir )); |
|
296 QVERIFY( test_compiler.exists( workDir, "foo", Exe, "1.0.0" )); |
|
297 QVERIFY( test_compiler.make( workDir, "install" )); |
|
298 QVERIFY( test_compiler.exists( workDir + "/dist", "foo", Exe, "1.0.0" )); |
|
299 QVERIFY( test_compiler.exists( workDir + "/dist", "test.txt", Plain, "1.0.0" )); |
|
300 QVERIFY( test_compiler.make( workDir, "uninstall" )); |
|
301 QVERIFY( test_compiler.makeDistClean( workDir )); |
|
302 |
|
303 QString buildDir = base_path + "/testdata/shadow_files_build"; |
|
304 QVERIFY( test_compiler.qmake( workDir, "foo", buildDir )); |
|
305 QVERIFY( test_compiler.make( buildDir )); |
|
306 QVERIFY( test_compiler.exists( buildDir, "foo", Exe, "1.0.0" )); |
|
307 QVERIFY( test_compiler.make( buildDir, "install" )); |
|
308 QVERIFY( test_compiler.exists( workDir + "/dist", "foo", Exe, "1.0.0" )); |
|
309 QVERIFY( test_compiler.exists( workDir + "/dist", "test.txt", Plain, "1.0.0" )); |
|
310 QVERIFY( test_compiler.exists( workDir + "/dist", "foo.bar", Plain, "1.0.0" )); |
|
311 QVERIFY( test_compiler.make( buildDir, "uninstall" )); |
|
312 QVERIFY( test_compiler.makeDistClean( buildDir )); |
|
313 } |
|
314 |
|
315 void tst_qmake::install_depends() |
|
316 { |
|
317 QString workDir = base_path + "/testdata/install_depends"; |
|
318 QVERIFY( test_compiler.qmake( workDir, "foo" )); |
|
319 QVERIFY( test_compiler.make( workDir )); |
|
320 QVERIFY( test_compiler.exists( workDir, "foo", Exe, "1.0.0" )); |
|
321 QVERIFY( test_compiler.make( workDir, "install" )); |
|
322 QVERIFY( test_compiler.exists( workDir + "/dist", "foo", Exe, "1.0.0" )); |
|
323 QVERIFY( test_compiler.exists( workDir + "/dist", "test1", Plain, "1.0.0" )); |
|
324 QVERIFY( test_compiler.exists( workDir + "/dist", "test2", Plain, "1.0.0" )); |
|
325 QVERIFY( test_compiler.make( workDir, "uninstall" )); |
|
326 QVERIFY( test_compiler.makeDistClean( workDir )); |
|
327 } |
|
328 void tst_qmake::quotedfilenames() |
|
329 { |
|
330 QString workDir = base_path + "/testdata/quotedfilenames"; |
|
331 QVERIFY( test_compiler.qmake( workDir, "quotedfilenames" )); |
|
332 QVERIFY( test_compiler.makeClean( workDir )); |
|
333 QVERIFY( test_compiler.make( workDir )); |
|
334 QVERIFY( test_compiler.exists( workDir, "quotedfilenames", Exe, "1.0.0" )); |
|
335 } |
|
336 |
|
337 void tst_qmake::prompt() |
|
338 { |
|
339 #if 0 |
|
340 QProcess qmake; |
|
341 qmake.setReadChannelMode(QProcess::MergedChannels); |
|
342 qmake.setWorkingDirectory(QLatin1String("testdata/prompt")); |
|
343 qmake.start(QLatin1String("qmake CONFIG-=debug_and_release CONFIG-=debug CONFIG+=release"), |
|
344 QIODevice::Text | QIODevice::ReadWrite); |
|
345 QVERIFY(qmake.waitForStarted(20000)); |
|
346 QByteArray read = qmake.readAll(); |
|
347 qDebug() << read; |
|
348 QCOMPARE(read, QByteArray("Project PROMPT: Prompteroo? ")); |
|
349 qmake.write("promptetiprompt\n"); |
|
350 QVERIFY(qmake.waitForFinished(20000)); |
|
351 #endif |
|
352 } |
|
353 |
|
354 void tst_qmake::one_space() |
|
355 { |
|
356 QString workDir = base_path + "/testdata/one_space"; |
|
357 |
|
358 QVERIFY( test_compiler.qmake( workDir, "one_space" )); |
|
359 QVERIFY( test_compiler.make( workDir )); |
|
360 QVERIFY( test_compiler.exists( workDir, "one space", Exe, "1.0.0" )); |
|
361 QVERIFY( test_compiler.makeClean( workDir )); |
|
362 QVERIFY( test_compiler.exists( workDir, "one space", Exe, "1.0.0" )); // Should still exist after a make clean |
|
363 QVERIFY( test_compiler.makeDistClean( workDir )); |
|
364 QVERIFY( !test_compiler.exists( workDir, "one space", Exe, "1.0.0" )); // Should not exist after a make distclean |
|
365 QVERIFY( test_compiler.removeMakefile( workDir ) ); |
|
366 } |
|
367 |
|
368 void tst_qmake::findMocs() |
|
369 { |
|
370 QString workDir = base_path + "/testdata/findMocs"; |
|
371 |
|
372 QVERIFY( test_compiler.qmake(workDir, "findMocs") ); |
|
373 QVERIFY( test_compiler.make(workDir) ); |
|
374 QVERIFY( test_compiler.exists(workDir, "findMocs", Exe, "1.0.0" ) ); |
|
375 QVERIFY( test_compiler.makeClean(workDir) ); |
|
376 QVERIFY( test_compiler.exists(workDir, "findMocs", Exe, "1.0.0" ) ); |
|
377 QVERIFY( test_compiler.makeDistClean(workDir ) ); |
|
378 QVERIFY( !test_compiler.exists(workDir, "findMocs", Exe, "1.0.0" ) ); |
|
379 QVERIFY( test_compiler.removeMakefile(workDir) ); |
|
380 } |
|
381 |
|
382 void tst_qmake::findDeps() |
|
383 { |
|
384 QString workDir = base_path + "/testdata/findDeps"; |
|
385 |
|
386 QVERIFY( test_compiler.qmake(workDir, "findDeps") ); |
|
387 QVERIFY( test_compiler.make(workDir) ); |
|
388 QVERIFY( test_compiler.exists(workDir, "findDeps", Exe, "1.0.0" ) ); |
|
389 QVERIFY( test_compiler.makeClean(workDir) ); |
|
390 QVERIFY( test_compiler.exists(workDir, "findDeps", Exe, "1.0.0" ) ); |
|
391 QVERIFY( test_compiler.makeDistClean(workDir ) ); |
|
392 QVERIFY( !test_compiler.exists(workDir, "findDeps", Exe, "1.0.0" ) ); |
|
393 QVERIFY( test_compiler.removeMakefile(workDir) ); |
|
394 } |
|
395 |
|
396 struct TempFile |
|
397 : QFile |
|
398 { |
|
399 TempFile(QString filename) |
|
400 : QFile(filename) |
|
401 { |
|
402 } |
|
403 |
|
404 ~TempFile() |
|
405 { |
|
406 if (this->exists()) |
|
407 this->remove(); |
|
408 } |
|
409 }; |
|
410 |
|
411 #ifndef Q_OS_WIN |
|
412 void tst_qmake::bundle_spaces() |
|
413 { |
|
414 QString workDir = base_path + "/testdata/bundle-spaces"; |
|
415 |
|
416 // We set up alternate commands here, to make sure we're testing Mac |
|
417 // Bundles and since this might be the wrong output we rely on dry-running |
|
418 // make (-n). |
|
419 |
|
420 TestCompiler local_tc; |
|
421 local_tc.setBaseCommands("make -n", "qmake -macx -spec macx-g++"); |
|
422 |
|
423 QVERIFY( local_tc.qmake(workDir, "bundle-spaces") ); |
|
424 |
|
425 TempFile non_existing_file(workDir + "/non-existing file"); |
|
426 QVERIFY( !non_existing_file.exists() ); |
|
427 |
|
428 // Make fails: no rule to make "non-existing file" |
|
429 QVERIFY( !local_tc.make(workDir) ); |
|
430 |
|
431 QVERIFY( non_existing_file.open(QIODevice::WriteOnly) ); |
|
432 QVERIFY( non_existing_file.exists() ); |
|
433 |
|
434 // Aha! |
|
435 QVERIFY( local_tc.make(workDir) ); |
|
436 |
|
437 // Cleanup |
|
438 QVERIFY( non_existing_file.remove() ); |
|
439 QVERIFY( !non_existing_file.exists() ); |
|
440 QVERIFY( local_tc.removeMakefile(workDir) ); |
|
441 } |
|
442 #endif // Q_OS_WIN |
|
443 |
|
444 void tst_qmake::includefunction() |
|
445 { |
|
446 QString workDir = base_path + "/testdata/include_function"; |
|
447 QString warningMsg("Unable to find file for inclusion"); |
|
448 QVERIFY(test_compiler.qmake( workDir, "include_existing_file")); |
|
449 QVERIFY(!test_compiler.commandOutput().contains(warningMsg)); |
|
450 |
|
451 // test include() usage on a missing file |
|
452 test_compiler.clearCommandOutput(); |
|
453 workDir = base_path + "/testdata/include_function"; |
|
454 QVERIFY(test_compiler.qmake( workDir, "include_missing_file" )); |
|
455 QVERIFY(test_compiler.commandOutput().contains(warningMsg)); |
|
456 |
|
457 // test include() usage on a missing file when all function parameters are used |
|
458 test_compiler.clearCommandOutput(); |
|
459 workDir = base_path + "/testdata/include_function"; |
|
460 QVERIFY(test_compiler.qmake( workDir, "include_missing_file2" )); |
|
461 QVERIFY(test_compiler.commandOutput().contains(warningMsg)); |
|
462 } |
|
463 |
|
464 QTEST_MAIN(tst_qmake) |
|
465 #include "tst_qmake.moc" |
|
466 |
|
467 #else // QMAKE_CROSS_COMPILED |
|
468 QTEST_NOOP_MAIN |
|
469 #endif |