http://scons.tigris.org/issues/show_bug.cgi?id=2329
[scons.git] / src / engine / SCons / Scanner / RCTests.py
1 #
2 # __COPYRIGHT__
3 #
4 # Permission is hereby granted, free of charge, to any person obtaining
5 # a copy of this software and associated documentation files (the
6 # "Software"), to deal in the Software without restriction, including
7 # without limitation the rights to use, copy, modify, merge, publish,
8 # distribute, sublicense, and/or sell copies of the Software, and to
9 # permit persons to whom the Software is furnished to do so, subject to
10 # the following conditions:
11 #
12 # The above copyright notice and this permission notice shall be included
13 # in all copies or substantial portions of the Software.
14 #
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
16 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
17 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 #
23
24 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
25
26 import TestCmd
27 import SCons.Scanner.RC
28 import unittest
29 import sys
30 import os
31 import os.path
32 import SCons.Node.FS
33 import SCons.Warnings
34 import UserDict
35
36 test = TestCmd.TestCmd(workdir = '')
37
38 os.chdir(test.workpath(''))
39
40 # create some source files and headers:
41
42 test.write('t1.rc','''
43 #include "t1.h"
44 ''')
45
46 test.write('t2.rc',"""
47 #include "t1.h"
48 ICO_TEST               ICON    DISCARDABLE     "abc.ico"
49 BMP_TEST               BITMAP  DISCARDABLE     "def.bmp"
50 cursor1 CURSOR "bullseye.cur"
51 ID_RESPONSE_ERROR_PAGE  HTML  "responseerrorpage.htm"
52 5 FONT  "cmroman.fnt"
53 1  MESSAGETABLE "MSG00409.bin"
54 1  MESSAGETABLE MSG00410.bin
55 1 TYPELIB "testtypelib.tlb"
56 TEST_REGIS   REGISTRY MOVEABLE PURE  "testregis.rgs"
57 TEST_D3DFX   D3DFX DISCARDABLE "testEffect.fx"
58
59 """)
60
61
62 # Create dummy include files
63 headers = ['t1.h',
64            'abc.ico','def.bmp','bullseye.cur','responseerrorpage.htm','cmroman.fnt',
65            'testEffect.fx',
66            'MSG00409.bin','MSG00410.bin','testtypelib.tlb','testregis.rgs']
67
68 for h in headers:
69     test.write(h, " ")
70
71
72 # define some helpers:
73
74 class DummyEnvironment(UserDict.UserDict):
75     def __init__(self,**kw):
76         UserDict.UserDict.__init__(self)
77         self.data.update(kw)
78         self.fs = SCons.Node.FS.FS(test.workpath(''))
79         
80     def Dictionary(self, *args):
81         return self.data
82
83     def subst(self, arg, target=None, source=None, conv=None):
84         if strSubst[0] == '$':
85             return self.data[strSubst[1:]]
86         return strSubst
87
88     def subst_path(self, path, target=None, source=None, conv=None):
89         if not isinstance(path, list):
90             path = [path]
91         return list(map(self.subst, path))
92
93     def has_key(self, key):
94         return key in self.Dictionary()
95
96     def get_calculator(self):
97         return None
98
99     def get_factory(self, factory):
100         return factory or self.fs.File
101
102     def Dir(self, filename):
103         return self.fs.Dir(filename)
104
105     def File(self, filename):
106         return self.fs.File(filename)
107
108 global my_normpath
109 my_normpath = os.path.normpath
110
111 if os.path.normcase('foo') == os.path.normcase('FOO'):
112     my_normpath = os.path.normcase
113
114 def deps_match(self, deps, headers):
115     scanned = sorted(map(my_normpath, list(map(str, deps))))
116     expect = sorted(map(my_normpath, headers))
117     self.failUnless(scanned == expect, "expect %s != scanned %s" % (expect, scanned))
118
119 # define some tests:
120
121 class RCScannerTestCase1(unittest.TestCase):
122     def runTest(self):
123         path = []
124         env = DummyEnvironment(RCSUFFIXES=['.rc','.rc2'],
125                                CPPPATH=path)
126         s = SCons.Scanner.RC.RCScan()
127         deps = s(env.File('t1.rc'), env, path)
128         headers = ['t1.h']
129         deps_match(self, deps, headers)
130
131 class RCScannerTestCase2(unittest.TestCase):
132     def runTest(self):
133         path = []
134         env = DummyEnvironment(RCSUFFIXES=['.rc','.rc2'],
135                                CPPPATH=path)
136         s = SCons.Scanner.RC.RCScan()
137         deps = s(env.File('t2.rc'), env, path)
138         headers = ['MSG00410.bin',
139                    'abc.ico','bullseye.cur',
140                    'cmroman.fnt','def.bmp',
141                    'MSG00409.bin',
142                    'responseerrorpage.htm',
143                    't1.h',
144                    'testEffect.fx',
145                    'testregis.rgs','testtypelib.tlb']
146         deps_match(self, deps, headers)
147
148         
149
150 def suite():
151     suite = unittest.TestSuite()
152     suite.addTest(RCScannerTestCase1())
153     suite.addTest(RCScannerTestCase2())
154     return suite
155
156 if __name__ == "__main__":
157     runner = unittest.TextTestRunner()
158     result = runner.run(suite())
159     if not result.wasSuccessful():
160         sys.exit(1)
161
162 # Local Variables:
163 # tab-width:4
164 # indent-tabs-mode:nil
165 # End:
166 # vim: set expandtab tabstop=4 shiftwidth=4: