#!/usr/bin/env python # # __COPYRIGHT__ # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, modify, merge, publish, # distribute, sublicense, and/or sell copies of the Software, and to # permit persons to whom the Software is furnished to do so, subject to # the following conditions: # # The above copyright notice and this permission notice shall be included # in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" """ Look if qt is installed, and try out all builders. """ import os import re import string import sys import TestSCons test = TestSCons.TestSCons() if not os.environ.get('QTDIR', None): x ="External environment variable $QTDIR not set; skipping test(s).\n" test.skip_test(x) test.Qt_dummy_installation() QTDIR=os.environ['QTDIR'] test.write('SConstruct', """\ import os dummy_env = Environment() ENV = dummy_env['ENV'] try: PATH=ARGUMENTS['PATH'] if ENV.has_key('PATH'): ENV_PATH = PATH + os.pathsep + ENV['PATH'] else: Exit(0) # this is certainly a weird system :-) except KeyError: ENV_PATH=ENV.get('PATH', '') env = Environment(tools=['default','qt'], ENV={'PATH':ENV_PATH, 'PATHEXT':os.environ.get('PATHEXT'), 'HOME':os.getcwd(), 'SYSTEMROOT':ENV.get('SYSTEMROOT')}, # moc / uic want to write stuff in ~/.qt CXXFILESUFFIX=".cpp") conf = env.Configure() if not conf.CheckLib(env.subst("$QT_LIB"), autoadd=0): conf.env['QT_LIB'] = 'qt-mt' if not conf.CheckLib(env.subst("$QT_LIB"), autoadd=0): Exit(0) env = conf.Finish() BuildDir('bld', '.') env.Program('bld/test_realqt', ['bld/mocFromCpp.cpp', 'bld/mocFromH.cpp', 'bld/anUiFile.ui', 'bld/main.cpp']) """) test.write('mocFromCpp.h', """\ void mocFromCpp(); """) test.write('mocFromCpp.cpp', """\ #include #include "mocFromCpp.h" class MyClass1 : public QObject { Q_OBJECT public: MyClass1() : QObject() {}; public slots: void myslot() {}; }; void mocFromCpp() { MyClass1 myclass; } #include "mocFromCpp.moc" """) test.write('mocFromH.h', """\ #include class MyClass2 : public QObject { Q_OBJECT; public: MyClass2(); public slots: void myslot(); }; void mocFromH(); """) test.write('mocFromH.cpp', """\ #include "mocFromH.h" MyClass2::MyClass2() : QObject() {} void MyClass2::myslot() {} void mocFromH() { MyClass2 myclass; } """) test.write('anUiFile.ui', """\ MyWidget QWidget MyWidget MyWidget anUiFile.ui.h testSlot() """) test.write('anUiFile.ui.h', r""" #include #if QT_VERSION >= 0x030100 void MyWidget::testSlot() { printf("Hello World\n"); } #endif """) test.write('main.cpp', r""" #include #include "mocFromCpp.h" #include "mocFromH.h" #include "anUiFile.h" #include int main(int argc, char **argv) { QApplication app(argc, argv); mocFromCpp(); mocFromH(); MyWidget mywidget; #if QT_VERSION >= 0x030100 mywidget.testSlot(); #else printf("Hello World\n"); #endif return 0; } """) test.run(arguments="bld/test_realqt" + TestSCons._exe) test.run(program=test.workpath("bld", "test_realqt"), stdout=None, status=None, stderr=None) if test.stdout() != "Hello World\n" or test.stderr() != '' or test.status: sys.stdout.write(test.stdout()) sys.stderr.write(test.stderr()) # The test might be run on a system that doesn't have an X server # running, or may be run by an ID that can't connect to the server. # If so, then print whatever it showed us (which is in and of itself # an indication that it built correctly) but don't fail the test. expect = 'cannot connect to X server' test.fail_test(test.stdout() != '' or string.find(test.stderr(), expect) == -1 or \ (test.status>>8) != 1) QTDIR = os.environ['QTDIR'] PATH = os.environ['PATH'] os.environ['QTDIR']='' os.environ['PATH']='.' test.run(stderr=None, arguments="-c bld/test_realqt" + TestSCons._exe) expect1 = "scons: warning: Could not detect qt, using empty QTDIR" expect2 = "scons: warning: Could not detect qt, using moc executable as a hint" test.fail_test(string.find(test.stderr(), expect1) == -1 and string.find(test.stderr(), expect2) == -1) test.pass_test()