[ci skip] update generated files
[scons.git] / test / QT / qt3 / source-from-ui.py
blob1404f75328778a51d611533c730a4339c7243b11
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 Create .cpp, .h, moc_....cpp from a .ui file.
28 """
30 import os.path
32 import TestSCons
34 test = TestSCons.TestSCons()
36 test.Qt_dummy_installation()
38 ##############################################################################
40 aaa_dll = TestSCons.dll_ + 'aaa' + TestSCons._dll
41 moc = 'moc_aaa.cc'
42 cpp = 'uic_aaa.cc'
43 obj = TestSCons.shobj_ + os.path.splitext(cpp)[0] + TestSCons._shobj
44 h = 'aaa.h'
46 test.Qt_create_SConstruct('SConstruct')
48 test.write('SConscript', """\
49 Import("env dup")
50 if dup == 0: env.Append(CPPPATH=['#', '.'])
51 env.SharedLibrary(target = 'aaa', source = ['aaa.ui', 'useit.cpp'])
52 """)
54 test.write('aaa.ui', r"""
55 #if defined (_WIN32) || defined(__CYGWIN__)
56 #define DLLEXPORT __declspec(dllexport)
57 #else
58 #define DLLEXPORT
59 #endif
60 DLLEXPORT void aaa(void)
61 """)
63 test.write('useit.cpp', r"""
64 #include "aaa.h"
65 void useit() {
66 aaa();
68 """)
70 test.run(arguments=aaa_dll)
72 test.up_to_date(options='-n', arguments=aaa_dll)
74 test.write('aaa.ui', r"""
75 /* a change */
76 #if defined (_WIN32) || defined(__CYGWIN__)
77 #define DLLEXPORT __declspec(dllexport)
78 #else
79 #define DLLEXPORT
80 #endif
81 DLLEXPORT void aaa(void)
82 """)
84 test.not_up_to_date(options='-n', arguments=moc)
85 test.not_up_to_date(options='-n', arguments=cpp)
86 test.not_up_to_date(options='-n', arguments=h)
88 test.run(arguments=" " + aaa_dll)
90 test.write('aaa.ui', r"""
91 void aaa(void)
92 //<include>aaa.ui.h</include>
93 """)
95 # test that non-existant ui.h files are ignored (as uic does)
96 test.run(arguments=" " + aaa_dll)
98 test.write('aaa.ui.h', r"""
99 /* test dependency to .ui.h */
100 """)
102 test.run(arguments=" " + aaa_dll)
104 test.write('aaa.ui.h', r"""
105 /* changed */
106 """)
108 test.not_up_to_date(options='-n', arguments=obj)
109 test.not_up_to_date(options='-n', arguments=cpp)
110 test.not_up_to_date(options='-n', arguments=h)
111 test.not_up_to_date(options='-n', arguments=moc)
113 # clean up
114 test.run(arguments=" -c " + aaa_dll)
116 test.run(
117 arguments="variant_dir=1 "
118 + test.workpath('build', aaa_dll)
121 test.must_exist(test.workpath('build', moc))
122 test.must_exist(test.workpath('build', cpp))
123 test.must_exist(test.workpath('build', h))
124 test.must_not_exist(test.workpath(moc))
125 test.must_not_exist(test.workpath(cpp))
126 test.must_not_exist(test.workpath(h))
128 cppContents = test.read(test.workpath('build', cpp), mode='r')
129 test.fail_test(cppContents.find('#include "aaa.ui.h"') == -1)
131 test.run(
132 arguments="variant_dir=1 chdir=1 "
133 + test.workpath('build', aaa_dll)
136 test.must_exist(test.workpath('build', moc))
137 test.must_exist(test.workpath('build', cpp))
138 test.must_exist(test.workpath('build', h))
139 test.must_not_exist(test.workpath(moc))
140 test.must_not_exist(test.workpath(cpp))
141 test.must_not_exist(test.workpath(h))
143 test.run(
144 arguments=" variant_dir=1 chdir=1 dup=0 "
145 + test.workpath('build_dup0', aaa_dll)
148 test.must_exist(test.workpath('build_dup0', moc))
149 test.must_exist(test.workpath('build_dup0', cpp))
150 test.must_exist(test.workpath('build_dup0', h))
151 test.must_not_exist(test.workpath(moc))
152 test.must_not_exist(test.workpath(cpp))
153 test.must_not_exist(test.workpath(h))
155 test.pass_test()
157 # Local Variables:
158 # tab-width:4
159 # indent-tabs-mode:nil
160 # End:
161 # vim: set expandtab tabstop=4 shiftwidth=4: