5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
17 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
28 Testing the configuration mechanisms of the 'qt' tool.
34 python = TestSCons.python
37 test = TestSCons.TestSCons(match=TestSCons.match_re_dotall)
39 test.subdir( 'qt', ['qt', 'bin'], ['qt', 'include'], ['qt', 'lib'] )
41 # create a dummy qt installation
43 test.write(['qt', 'bin', 'mymoc.py'], """
48 cmd_opts, args = getopt.getopt(sys.argv[1:], 'wzio:', [])
52 for opt, arg in cmd_opts:
53 if opt == '-o': output = open(arg, 'wb')
54 elif opt == '-i': impl = 1
55 else: opt_string = opt_string + ' ' + opt
56 output.write( "/* mymoc.py%s */\\n" % opt_string)
58 contents = open(a, 'rb').read()
59 subst = r'{ my_qt_symbol( "' + a + '\\\\n" ); }'
61 contents = re.sub( r'#include.*', '', contents )
62 output.write(string.replace(contents, 'Q_OBJECT', subst))
67 test.write(['qt', 'bin', 'myuic.py'], """
75 for arg in sys.argv[1:]:
77 output = open(arg, 'wb')
87 opt_string = opt_string + ' ' + arg
91 source = open(arg, 'rb')
92 output.write("/* myuic.py%s */\\n" % opt_string)
94 output.write( '#include "' + impl + '"\\n' )
96 output.write( '#include "my_qobject.h"\\n' + source.read() + " Q_OBJECT \\n" )
101 test.write(['qt', 'include', 'my_qobject.h'], r"""
103 void my_qt_symbol(const char *arg);
106 test.write(['qt', 'lib', 'my_qobject.cpp'], r"""
107 #include "../include/my_qobject.h"
109 void my_qt_symbol(const char *arg) {
114 test.write(['qt', 'lib', 'SConstruct'], r"""
116 env.StaticLibrary( 'myqt', 'my_qobject.cpp' )
119 test.run(chdir=test.workpath('qt','lib'), arguments = '.',
120 stderr=TestSCons.noisy_ar)
122 QT = test.workpath('qt')
124 QT_MOC = '%s %s' % (python, test.workpath('qt','bin','mymoc.py'))
125 QT_UIC = '%s %s' % (python, test.workpath('qt','bin','myuic.py'))
127 # 3 test cases with 3 different operation modes
129 def createSConstruct(test,place,overrides):
130 test.write(place, """
131 env = Environment(QTDIR = r'%s',
136 tools=['default','qt'])
137 if ARGUMENTS.get('build_dir', 0):
138 if ARGUMENTS.get('chdir', 0):
142 BuildDir('build', '.', duplicate=1)
143 sconscript = Dir('build').File('SConscript')
145 sconscript = File('SConscript')
147 SConscript( sconscript )
148 """ % (QT, QT_LIB, QT_MOC, QT_UIC, overrides))
151 createSConstruct(test, ['SConstruct'],
152 """QT_UICIMPLFLAGS='-x',
153 QT_UICDECLFLAGS='-y',
154 QT_MOCFROMHFLAGS='-z',
155 QT_MOCFROMCXXFLAGS='-i -w',
156 QT_UICDECLPREFIX='uic-',
157 QT_UICDECLSUFFIX='.hpp',
159 QT_UICIMPLSUFFIX='.cxx',
161 QT_MOCHSUFFIX='.cxx',
162 QT_MOCCXXPREFIX='moc',
163 QT_MOCCXXSUFFIX='.inl',
164 QT_UISUFFIX='.myui',""")
165 test.write('SConscript',"""
167 env.Program('mytest', ['mocFromH.cpp',
170 'another_ui_file.myui',
174 test.write('mocFromH.hpp', """
175 #include "my_qobject.h"
176 void mocFromH() Q_OBJECT
179 test.write('mocFromH.cpp', """
180 #include "mocFromH.hpp"
183 test.write('mocFromCpp.cpp', """
184 #include "my_qobject.h"
185 void mocFromCpp() Q_OBJECT
186 #include "mocmocFromCpp.inl"
189 test.write('an_ui_file.myui', """
193 test.write('another_ui_file.myui', """
194 void another_ui_file()
197 test.write('another_ui_file.desc.hpp', """
198 /* just a dependency checker */
201 test.write('main.cpp', """
202 #include "mocFromH.hpp"
203 #include "uic-an_ui_file.hpp"
204 #include "uic-another_ui_file.hpp"
215 test.run( arguments = "mytest" + _exe )
217 def _existAll( test, files ):
218 return reduce(lambda x,y: x and y,
219 map(os.path.exists,map(test.workpath, files)))
221 createSConstruct(test, ['SConstruct'],
222 """QT_UICIMPLFLAGS='-x',
223 QT_UICDECLFLAGS='-y',
224 QT_MOCFROMHFLAGS='-z',
225 QT_MOCFROMCXXFLAGS='-i -w',
226 QT_UICDECLPREFIX='uic-',
227 QT_UICDECLSUFFIX='.hpp',
229 QT_UICIMPLSUFFIX='.cxx',
231 QT_MOCHSUFFIX='.cxx',
232 QT_MOCCXXPREFIX='moc',
233 QT_MOCCXXSUFFIX=`.inl',
234 QT_UISUFFIX='.myui',""")
236 test.fail_test(not _existAll(test, ['mmmmocFromH.cxx',
239 'uic-an_ui_file.hpp',
241 'another_ui_file.cxx',
242 'uic-another_ui_file.hpp',
243 'mmmanother_ui_file.cxx']))
245 def _flagTest(test,fileToContentsStart):
247 for f,c in fileToContentsStart.items():
248 if string.find(test.read(f), c) != 0:
252 test.fail_test(_flagTest(test, {'mmmmocFromH.cxx':'/* mymoc.py -z */',
253 'mocmocFromCpp.inl':'/* mymoc.py -w */',
254 'an_ui_file.cxx':'/* myuic.py -x */',
255 'uic-an_ui_file.hpp':'/* myuic.py -y */',
256 'mmman_ui_file.cxx':'/* mymoc.py -z */'}))