[ci skip] update generated files
[scons.git] / test / QT / qt3 / installed.py
blob71ff98fb70750a6721165e26469bb38fad6423b5
1 #!/usr/bin/env python
3 # MIT License
5 # Copyright The SCons Foundation
7 # Permission is hereby granted, free of charge, to any person obtaining
8 # a copy of this software and associated documentation files (the
9 # "Software"), to deal in the Software without restriction, including
10 # without limitation the rights to use, copy, modify, merge, publish,
11 # distribute, sublicense, and/or sell copies of the Software, and to
12 # permit persons to whom the Software is furnished to do so, subject to
13 # the following conditions:
15 # The above copyright notice and this permission notice shall be included
16 # in all copies or substantial portions of the Software.
18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
19 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
20 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 """
27 Look if qt3 is installed, and try out all builders.
28 """
30 import os
31 import sys
33 import TestSCons
35 test = TestSCons.TestSCons()
37 if not os.environ.get('QTDIR', None):
38 x ="External environment variable $QTDIR not set; skipping test(s).\n"
39 test.skip_test(x)
41 test.Qt_dummy_installation()
43 QTDIR=os.environ['QTDIR']
46 test.write('SConstruct', """\
47 import os
48 dummy_env = Environment()
49 ENV = dummy_env['ENV']
50 try:
51 PATH=ARGUMENTS['PATH']
52 if 'PATH' in ENV:
53 ENV_PATH = PATH + os.pathsep + ENV['PATH']
54 else:
55 Exit(0) # this is certainly a weird system :-)
56 except KeyError:
57 ENV_PATH=ENV.get('PATH', '')
59 env = Environment(tools=['default','qt3'],
60 ENV={'PATH':ENV_PATH,
61 'PATHEXT':os.environ.get('PATHEXT'),
62 'HOME':os.getcwd(),
63 'SystemRoot':ENV.get('SystemRoot')},
64 # moc / uic want to write stuff in ~/.qt
65 CXXFILESUFFIX=".cpp")
67 conf = env.Configure()
68 if not conf.CheckLib(env.subst("$QT3_LIB"), autoadd=0):
69 conf.env['QT3_LIB'] = 'qt-mt'
70 if not conf.CheckLib(env.subst("$QT3_LIB"), autoadd=0):
71 Exit(0)
72 env = conf.Finish()
73 VariantDir('bld', '.')
74 env.Program('bld/test_realqt', ['bld/mocFromCpp.cpp',
75 'bld/mocFromH.cpp',
76 'bld/anUiFile.ui',
77 'bld/main.cpp'])
78 """)
80 test.write('mocFromCpp.h', """\
81 void mocFromCpp();
82 """)
84 test.write('mocFromCpp.cpp', """\
85 #include <qobject.h>
86 #include "mocFromCpp.h"
87 class MyClass1 : public QObject {
88 Q_OBJECT
89 public:
90 MyClass1() : QObject() {};
91 public slots:
92 void myslot() {};
94 void mocFromCpp() {
95 MyClass1 myclass;
97 #include "mocFromCpp.moc"
98 """)
100 test.write('mocFromH.h', """\
101 #include <qobject.h>
102 class MyClass2 : public QObject {
103 Q_OBJECT;
104 public:
105 MyClass2();
106 public slots:
107 void myslot();
109 void mocFromH();
110 """)
112 test.write('mocFromH.cpp', """\
113 #include "mocFromH.h"
115 MyClass2::MyClass2() : QObject() {}
116 void MyClass2::myslot() {}
117 void mocFromH() {
118 MyClass2 myclass;
120 """)
122 test.write('anUiFile.ui', """\
123 <!DOCTYPE UI><UI>
124 <class>MyWidget</class>
125 <widget>
126 <class>QWidget</class>
127 <property name="name">
128 <cstring>MyWidget</cstring>
129 </property>
130 <property name="caption">
131 <string>MyWidget</string>
132 </property>
133 </widget>
134 <includes>
135 <include location="local" impldecl="in implementation">anUiFile.ui.h</include>
136 </includes>
137 <slots>
138 <slot>testSlot()</slot>
139 </slots>
140 <layoutdefaults spacing="6" margin="11"/>
141 </UI>
142 """)
144 test.write('anUiFile.ui.h', r"""
145 #include <stdio.h>
146 #if QT_VERSION >= 0x030100
147 void MyWidget::testSlot()
149 printf("Hello World\n");
151 #endif
152 """)
154 test.write('main.cpp', r"""
155 #include <qapp.h>
156 #include "mocFromCpp.h"
157 #include "mocFromH.h"
158 #include "anUiFile.h"
159 #include <stdio.h>
161 int main(int argc, char **argv) {
162 QApplication app(argc, argv);
163 mocFromCpp();
164 mocFromH();
165 MyWidget mywidget;
166 #if QT_VERSION >= 0x030100
167 mywidget.testSlot();
168 #else
169 printf("Hello World\n");
170 #endif
171 return 0;
173 """)
175 test.run(arguments="--warn=no-tool-qt-deprecated bld/test_realqt" + TestSCons._exe)
177 test.run(
178 program=test.workpath("bld", "test_realqt"),
179 arguments="--warn=no-tool-qt-deprecated",
180 stdout=None,
181 status=None,
182 stderr=None,
185 if test.stdout() != "Hello World\n" or test.stderr() != '' or test.status:
186 sys.stdout.write(test.stdout())
187 sys.stderr.write(test.stderr())
188 # The test might be run on a system that doesn't have an X server
189 # running, or may be run by an ID that can't connect to the server.
190 # If so, then print whatever it showed us (which is in and of itself
191 # an indication that it built correctly) but don't fail the test.
192 expect = 'cannot connect to X server'
193 test.fail_test(test.stdout())
194 test.fail_test(expect not in test.stderr())
195 if test.status != 1 and (test.status >> 8) != 1:
196 sys.stdout.write('test_realqt returned status %s\n' % test.status)
197 test.fail_test()
199 QT3DIR = os.environ['QTDIR']
200 PATH = os.environ['PATH']
201 os.environ['QTDIR'] = ''
202 os.environ['PATH'] = '.'
204 test.run(
205 stderr=None,
206 arguments="-c bld/test_realqt" + TestSCons._exe,
209 expect1 = "scons: warning: Could not detect qt3, using empty QT3DIR"
210 expect2 = "scons: warning: Could not detect qt3, using moc executable as a hint"
212 test.fail_test(expect1 not in test.stderr() and expect2 not in test.stderr())
214 test.pass_test()
216 # Local Variables:
217 # tab-width:4
218 # indent-tabs-mode:nil
219 # End:
220 # vim: set expandtab tabstop=4 shiftwidth=4: