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.
33 _python_
= TestSCons
._python
_
36 test
= TestSCons
.TestSCons()
38 test
.Qt_dummy_installation()
39 test
.subdir('work1', 'work2')
42 chdir
=test
.workpath('qt', 'lib'),
44 stderr
=TestSCons
.noisy_ar
,
45 match
=TestSCons
.match_re_dotall
,
48 QT
= test
.workpath('qt')
50 QT_MOC
= '%s %s' % (_python_
, test
.workpath('qt', 'bin', 'mymoc.py'))
51 QT_UIC
= '%s %s' % (_python_
, test
.workpath('qt', 'bin', 'myuic.py'))
53 def createSConstruct(test
, place
, overrides
):
54 test
.write(place
, """\
56 tools=['default','qt'],
61 %s # last because 'overrides' may add comma
63 if ARGUMENTS.get('variant_dir', 0):
64 if ARGUMENTS.get('chdir', 0):
68 VariantDir('build', '.', duplicate=1)
69 sconscript = Dir('build').File('SConscript')
71 sconscript = File('SConscript')
73 SConscript(sconscript)
74 """ % (QT
, QT_LIB
, QT_MOC
, QT_UIC
, overrides
))
77 createSConstruct(test
, ['work1', 'SConstruct'],
78 """QT_UICIMPLFLAGS='-x',
80 QT_MOCFROMHFLAGS='-z',
81 QT_MOCFROMCXXFLAGS='-i -w',
82 QT_UICDECLPREFIX='uic-',
83 QT_UICDECLSUFFIX='.hpp',
85 QT_UICIMPLSUFFIX='.cxx',
88 QT_MOCCXXPREFIX='moc',
89 QT_MOCCXXSUFFIX='.inl',
90 QT_UISUFFIX='.myui',""")
91 test
.write(['work1', 'SConscript'],"""
93 env.Program('mytest', ['mocFromH.cpp',
96 'another_ui_file.myui',
100 test
.write(['work1', 'mocFromH.hpp'], """
101 #include "my_qobject.h"
102 void mocFromH() Q_OBJECT
105 test
.write(['work1', 'mocFromH.cpp'], """
106 #include "mocFromH.hpp"
109 test
.write(['work1', 'mocFromCpp.cpp'], """
110 #include "my_qobject.h"
111 void mocFromCpp() Q_OBJECT
112 #include "mocmocFromCpp.inl"
115 test
.write(['work1', 'an_ui_file.myui'], """
119 test
.write(['work1', 'another_ui_file.myui'], """
120 void another_ui_file()
123 test
.write(['work1', 'another_ui_file.desc.hpp'], """
124 /* just a dependency checker */
127 test
.write(['work1', 'main.cpp'], """
128 #include "mocFromH.hpp"
129 #include "uic-an_ui_file.hpp"
130 #include "uic-another_ui_file.hpp"
141 test
.run(chdir
= 'work1', arguments
= "mytest" + _exe
)
143 test
.must_exist(['work1', 'mmmmocFromH.cxx'],
144 ['work1', 'mocmocFromCpp.inl'],
145 ['work1', 'an_ui_file.cxx'],
146 ['work1', 'uic-an_ui_file.hpp'],
147 ['work1', 'mmman_ui_file.cxx'],
148 ['work1', 'another_ui_file.cxx'],
149 ['work1', 'uic-another_ui_file.hpp'],
150 ['work1', 'mmmanother_ui_file.cxx'])
152 def _flagTest(test
,fileToContentsStart
):
153 for f
,c
in fileToContentsStart
.items():
154 if test
.read(test
.workpath('work1', f
), mode
='r').find(c
) != 0:
158 test
.fail_test(_flagTest(test
, {'mmmmocFromH.cxx':'/* mymoc.py -z */',
159 'mocmocFromCpp.inl':'/* mymoc.py -w */',
160 'an_ui_file.cxx':'/* myuic.py -x */',
161 'uic-an_ui_file.hpp':'/* myuic.py -y */',
162 'mmman_ui_file.cxx':'/* mymoc.py -z */'}))
164 test
.write(['work2', 'SConstruct'], """
166 env1 = Environment(tools=['qt'],
167 QTDIR = r'%(QTDIR)s',
168 QT_BINPATH='$QTDIR/bin64',
169 QT_LIBPATH='$QTDIR/lib64',
170 QT_CPPPATH='$QTDIR/h64')
172 cpppath = env1.subst('$CPPPATH')
173 if os.path.normpath(cpppath) != os.path.join(r'%(QTDIR)s', 'h64'):
176 libpath = env1.subst('$LIBPATH')
177 if os.path.normpath(libpath) != os.path.join(r'%(QTDIR)s', 'lib64'):
180 qt_moc = env1.subst('$QT_MOC')
181 if os.path.normpath(qt_moc) != os.path.join(r'%(QTDIR)s', 'bin64', 'moc'):
185 env2 = Environment(tools=['default', 'qt'],
191 env2.Program('main.cpp')
194 test
.write(['work2', 'main.cpp'], """
195 int main(void) { return 0; }
198 # Ignore stderr, because if Qt is not installed,
199 # there may be a warning about an empty QTDIR on stderr.
200 test
.run(chdir
='work2', stderr
=None)
202 test
.must_exist(['work2', 'main' + _exe
])
208 # indent-tabs-mode:nil
210 # vim: set expandtab tabstop=4 shiftwidth=4: