a20c9199f0d0c4374e8c46f3b95889ae2052a4b5
[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 type(path) != type([]):
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 = list(map(my_normpath, list(map(str, deps))))
116     expect = list(map(my_normpath, headers))
117     scanned.sort()
118     expect.sort()
119     self.failUnless(scanned == expect, "expect %s != scanned %s" % (expect, scanned))
120
121 # define some tests:
122
123 class RCScannerTestCase1(unittest.TestCase):
124     def runTest(self):
125         path = []
126         env = DummyEnvironment(RCSUFFIXES=['.rc','.rc2'],
127                                CPPPATH=path)
128         s = SCons.Scanner.RC.RCScan()
129         deps = s(env.File('t1.rc'), env, path)
130         headers = ['t1.h']
131         deps_match(self, deps, headers)
132
133 class RCScannerTestCase2(unittest.TestCase):
134     def runTest(self):
135         path = []
136         env = DummyEnvironment(RCSUFFIXES=['.rc','.rc2'],
137                                CPPPATH=path)
138         s = SCons.Scanner.RC.RCScan()
139         deps = s(env.File('t2.rc'), env, path)
140         headers = ['MSG00410.bin',
141                    'abc.ico','bullseye.cur',
142                    'cmroman.fnt','def.bmp',
143                    'MSG00409.bin',
144                    'responseerrorpage.htm',
145                    't1.h',
146                    'testEffect.fx',
147                    'testregis.rgs','testtypelib.tlb']
148         deps_match(self, deps, headers)
149
150         
151
152 def suite():
153     suite = unittest.TestSuite()
154     suite.addTest(RCScannerTestCase1())
155     suite.addTest(RCScannerTestCase2())
156     return suite
157
158 if __name__ == "__main__":
159     runner = unittest.TextTestRunner()
160     result = runner.run(suite())
161     if not result.wasSuccessful():
162         sys.exit(1)
163
164 # Local Variables:
165 # tab-width:4
166 # indent-tabs-mode:nil
167 # End:
168 # vim: set expandtab tabstop=4 shiftwidth=4: