Merged revisions 2647-2719 via svnmerge from
[scons.git] / test / QT / moc-from-cpp.py
1 #!/usr/bin/env python
2 #
3 # __COPYRIGHT__
4 #
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:
12 #
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
15 #
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.
23 #
24
25 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
26
27 """
28 Create a moc file from a cpp file.
29 """
30
31 import TestSCons
32
33 test = TestSCons.TestSCons()
34
35 test.Qt_dummy_installation()
36
37 ##############################################################################
38
39 lib_aaa = TestSCons.lib_ + 'aaa' + TestSCons._lib
40 moc = 'aaa.moc'
41
42 test.Qt_create_SConstruct('SConstruct')
43
44 test.write('SConscript', """
45 Import("env dup")
46 if dup == 0: env.Append(CPPPATH=['.'])
47 env.StaticLibrary(target = '%s', source = ['aaa.cpp','useit.cpp'])
48 """ % lib_aaa)
49
50 test.write('aaa.h', r"""
51 void aaa(void);
52 """)
53
54 test.write('aaa.cpp', r"""
55 #include "my_qobject.h"
56 void aaa(void) Q_OBJECT
57 #include "%s"
58 """ % moc)
59
60 test.write('useit.cpp', r"""
61 #include "aaa.h"
62 void useit() {
63   aaa();
64 }
65 """)
66
67 test.run(arguments=lib_aaa,
68          stderr=TestSCons.noisy_ar,
69          match=TestSCons.match_re_dotall)
70
71 test.up_to_date(options = '-n', arguments = lib_aaa)
72
73 test.write('aaa.cpp', r"""
74 #include "my_qobject.h"
75 /* a change */
76 void aaa(void) Q_OBJECT
77 #include "%s"
78 """ % moc)
79
80 test.not_up_to_date(options = '-n', arguments = moc)
81
82 test.run(options = '-c', arguments = lib_aaa)
83
84 test.run(arguments = "variant_dir=1 " + test.workpath('build', lib_aaa),
85          stderr=TestSCons.noisy_ar,
86          match=TestSCons.match_re_dotall)
87
88 test.run(arguments = "variant_dir=1 chdir=1 " + test.workpath('build', lib_aaa))
89
90 test.must_exist(test.workpath('build', moc))
91
92 test.run(arguments = "variant_dir=1 dup=0 " +
93                      test.workpath('build_dup0', lib_aaa),
94          stderr=TestSCons.noisy_ar,
95          match=TestSCons.match_re_dotall)
96
97 test.must_exist(test.workpath('build_dup0', moc))
98
99 test.pass_test()