Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / ffmpeg / chromium / scripts / generate_gyp_unittest.py
1 #!/usr/bin/python
2 #
3 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
6
7 """Unittest for generate_gyp_py.
8
9 It's tough to test the lower-level GetSourceFiles() and GetObjectFiles()
10 functions, so this focuses on the higher-level functions assuming those two
11 functions are working as intended (i.e., producing lists of files).
12 """
13
14 import string
15 import unittest
16 import generate_gyp as gg
17
18
19 class ModuleUnittest(unittest.TestCase):
20   def testGetObjectToSourceMapping(self):
21     srcs = [
22         'a.c',
23         'b.asm',
24         'c.cc',
25     ]
26     expected = {
27         'a.o': 'a.c',
28         'b.o': 'b.asm',
29         'c.o': 'c.cc',
30     }
31     self.assertEqual(expected, gg.GetObjectToSourceMapping(srcs))
32
33   def testGetSourceFileSet(self):
34     objs_to_srcs = {
35         'a.o': 'a.c',
36         'b.o': 'b.asm',
37         'c.o': 'c.cc',
38     }
39     objs = [
40         'a.o',
41         'c.o',
42     ]
43     expected = set(['a.c', 'c.cc'])
44     self.assertEqual(expected, gg.GetSourceFileSet(objs_to_srcs, objs))
45
46   def testGetSourceFileSet_NotFound(self):
47     objs_to_srcs = {
48         'a.o': 'a.c',
49         'b.o': 'b.asm',
50         'c.o': 'c.cc',
51     }
52     objs = [
53         'd.o',
54     ]
55     self.assertRaises(KeyError, gg.GetSourceFileSet, objs_to_srcs, objs)
56
57
58 class SourceSetUnittest(unittest.TestCase):
59   def testEquals(self):
60     a = gg.SourceSet(set(['a', 'b']), set(['1']), set(['2']), set(['3']))
61     b = gg.SourceSet(set(['a', 'b']), set(['1']), set(['2']), set(['3']))
62     c = gg.SourceSet(set(['c', 'd']), set(['1']), set(['2']), set(['3']))
63     d = gg.SourceSet(set(['a', 'b']), set(['0']), set(['2']), set(['3']))
64     e = gg.SourceSet(set(['a', 'b']), set(['1']), set(['0']), set(['3']))
65     f = gg.SourceSet(set(['a', 'b']), set(['1']), set(['2']), set(['0']))
66
67     self.assertEqual(a, b)
68     self.assertNotEqual(a, c)
69     self.assertNotEqual(a, d)
70     self.assertNotEqual(a, e)
71     self.assertNotEqual(a, f)
72
73   def testIntersect_Exact(self):
74     a = gg.SourceSet(set(['a', 'b']), set(['1']), set(['2']), set(['5']))
75     b = gg.SourceSet(set(['a', 'b']), set(['3']), set(['4']), set(['6']))
76
77     c = a.Intersect(b)
78
79     self.assertEqual(c.sources, set(['a', 'b']))
80     self.assertEqual(c.architectures, set(['1', '3']))
81     self.assertEqual(c.targets, set(['2', '4']))
82     self.assertEqual(c.platforms, set(['5', '6']))
83     self.assertFalse(c.IsEmpty())
84
85   def testIntersect_Disjoint(self):
86     a = gg.SourceSet(set(['a', 'b']), set(['1']), set(['2']), set(['5']))
87     b = gg.SourceSet(set(['c', 'd']), set(['3']), set(['4']), set(['6']))
88
89     c = a.Intersect(b)
90
91     self.assertEqual(c.sources, set())
92     self.assertEqual(c.architectures, set(['1', '3']))
93     self.assertEqual(c.targets, set(['2', '4']))
94     self.assertEqual(c.platforms, set(['5', '6']))
95     self.assertTrue(c.IsEmpty())
96
97   def testIntersect_Overlap(self):
98     a = gg.SourceSet(set(['a', 'b']), set(['1']), set(['2']), set(['5']))
99     b = gg.SourceSet(set(['b', 'c']), set(['3']), set(['4']), set(['6']))
100
101     c = a.Intersect(b)
102
103     self.assertEqual(c.sources, set(['b']))
104     self.assertEqual(c.architectures, set(['1', '3']))
105     self.assertEqual(c.targets, set(['2', '4']))
106     self.assertEqual(c.platforms, set(['5', '6']))
107     self.assertFalse(c.IsEmpty())
108
109   def testDifference_Exact(self):
110     a = gg.SourceSet(set(['a', 'b']), set(['1']), set(['2']), set(['3']))
111     b = gg.SourceSet(set(['a', 'b']), set(['1']), set(['2']), set(['3']))
112
113     c = a.Difference(b)
114
115     self.assertEqual(c.sources, set())
116     self.assertEqual(c.architectures, set(['1']))
117     self.assertEqual(c.targets, set(['2']))
118     self.assertEqual(c.platforms, set(['3']))
119     self.assertTrue(c.IsEmpty())
120
121   def testDifference_Disjoint(self):
122     a = gg.SourceSet(set(['a', 'b']), set(['1']), set(['2']), set(['5']))
123     b = gg.SourceSet(set(['c', 'd']), set(['3']), set(['4']), set(['6']))
124
125     c = a.Difference(b)
126
127     self.assertEqual(c.sources, set(['a', 'b']))
128     self.assertEqual(c.architectures, set())
129     self.assertEqual(c.targets, set())
130     self.assertEqual(c.platforms, set())
131     self.assertTrue(c.IsEmpty())
132
133   def testDifference_Overlap(self):
134     a = gg.SourceSet(set(['a', 'b']), set(['1']), set(['2']), set(['5']))
135     b = gg.SourceSet(set(['b', 'c', 'd']), set(['1', '3']), set(['2', '4']),
136                      set(['5', '6']))
137
138     c = a.Difference(b)
139
140     self.assertEqual(c.sources, set(['a']))
141     self.assertEqual(c.architectures, set(['1']))
142     self.assertEqual(c.targets, set(['2']))
143     self.assertEqual(c.platforms, set(['5']))
144     self.assertFalse(c.IsEmpty())
145
146   def testGenerateGypStanza(self):
147     # ia32 should just be ia32.  Win should appear as an OS restriction.
148     a = gg.SourceSet(set(['a', 'b']), set(['ia32']), set(['Chromium']),
149                      set(['win'])).GenerateGypStanza()
150     string.index(a, 'target_arch == "ia32"')
151     string.index(a, 'OS == "win"')
152
153     # x64 should just be x64.  Linux should not appear as an OS restriction.
154     a = gg.SourceSet(set(['a', 'b']), set(['x64']), set(['Chromium']),
155                      set(['linux'])).GenerateGypStanza()
156     string.index(a, 'target_arch == "x64"')
157     self.assertEqual(string.find(a, 'OS == "linux"'), -1)
158
159     # arm should just be arm.
160     a = gg.SourceSet(set(['a', 'b']), set(['arm']), set(['Chromium']),
161                      set(['linux'])).GenerateGypStanza()
162     string.index(a, 'target_arch == "arm"')
163
164     # arm-neon should be arm and flip the arm_neon switch.
165     a = gg.SourceSet(set(['a', 'b']), set(['arm-neon']), set(['Chromium']),
166                      set(['linux'])).GenerateGypStanza()
167     string.index(a, 'target_arch == "arm" and arm_neon == 1')
168
169     # All architectures and all platforms case.
170     a = gg.SourceSet(set(['a', 'b']), set(['arm', 'arm-neon', 'x64', 'ia32']),
171                      set(['Chromium']),
172                      set(['win', 'linux'])).GenerateGypStanza()
173     string.index(a, '(1)')
174     self.assertEqual(string.find(a, 'OS == "linux"'), -1)
175     self.assertEqual(string.find(a, 'OS == "win"'), -1)
176
177     # All targets case.
178     a = gg.SourceSet(set(['a', 'b']), set(['arm']),
179                      set(['Chromium', 'ChromiumOS', 'Chrome', 'ChromeOS']),
180                      set(['win'])).GenerateGypStanza()
181     string.index(a, '(1)')
182
183   def testGenerateGnStanza(self):
184     # ia32 should be x86.  Win should appear as an OS restriction.
185     a = gg.SourceSet(set(['a', 'b']), set(['ia32']), set(['Chromium']),
186                      set(['win'])).GenerateGnStanza()
187     string.index(a, 'cpu_arch == "x86"')
188     string.index(a, 'is_win')
189
190     # x64 should just be x64.  Linux should not appear as an OS restriction.
191     a = gg.SourceSet(set(['a', 'b']), set(['x64']), set(['Chromium']),
192                      set(['linux'])).GenerateGnStanza()
193     string.index(a, 'cpu_arch == "x64"')
194     self.assertEqual(string.find(a, 'is_linux'), -1)
195
196     # arm should just be arm.
197     a = gg.SourceSet(set(['a', 'b']), set(['arm']), set(['Chromium']),
198                      set(['linux'])).GenerateGnStanza()
199     string.index(a, 'cpu_arch == "arm"')
200
201     # arm-neon should be arm and flip the arm_neon switch.
202     a = gg.SourceSet(set(['a', 'b']), set(['arm-neon']), set(['Chromium']),
203                      set(['linux'])).GenerateGnStanza()
204     string.index(a, 'cpu_arch == "arm" && arm_use_neon')
205
206     # All architectures and all platforms case.
207     a = gg.SourceSet(set(['a', 'b']), set(['arm', 'arm-neon', 'x64', 'ia32']),
208                      set(['Chromium']),
209                      set(['win', 'linux'])).GenerateGnStanza()
210     string.index(a, 'if (ffmpeg_branding == "Chromium")')
211
212     # All targets case.
213     a = gg.SourceSet(set(['a', 'b']), set(['arm']),
214                      set(['Chromium', 'ChromiumOS', 'Chrome', 'ChromeOS']),
215                      set(['win'])).GenerateGnStanza()
216     string.index(a, 'cpu_arch == "arm"')
217     string.index(a, 'is_win')
218
219
220   def assertEqualSets(self, actual, expected):
221     # Do pairwise checks for easier debugging.
222     for a in actual:
223       self.assertTrue(a in expected, msg='Unexpected set: %s' % a)
224     for e in expected:
225       self.assertTrue(e in actual, msg='Did not find expected set: %s' % e)
226
227   def testCreatePairwiseDisjointSets_Pair(self):
228     a = gg.SourceSet(set(['common', 'intel']), set(['ia32']),
229                      set(['Chromium']), set(['win']))
230     b = gg.SourceSet(set(['common', 'intel', 'chrome']), set(['ia32']),
231                      set(['Chrome']), set(['win']))
232
233     expected = []
234     expected.append(gg.SourceSet(set(['common', 'intel']), set(['ia32']),
235                                  set(['Chromium', 'Chrome']), set(['win'])))
236     expected.append(gg.SourceSet(set(['chrome']), set(['ia32']),
237                                  set(['Chrome']), set(['win'])))
238
239     sets = gg.CreatePairwiseDisjointSets([a, b])
240     self.assertEqualSets(sets, expected)
241
242   def testCreatePairwiseDisjointSets_Triplet(self):
243     a = gg.SourceSet(set(['common', 'intel']), set(['ia32']), set(['Chromium']),
244                      set(['win']))
245     b = gg.SourceSet(set(['common', 'intel', 'chrome']), set(['x64']),
246                      set(['Chrome']), set(['win']))
247     c = gg.SourceSet(set(['common', 'arm']), set(['arm']), set(['Chromium']),
248                      set(['win']))
249
250     expected = []
251     expected.append(gg.SourceSet(set(['common']), set(['ia32', 'x64', 'arm']),
252                                  set(['Chromium', 'Chrome']), set(['win'])))
253     expected.append(gg.SourceSet(set(['intel']), set(['ia32', 'x64']),
254                                  set(['Chromium', 'Chrome']), set(['win'])))
255     expected.append(gg.SourceSet(set(['chrome']), set(['x64']),
256                                  set(['Chrome']), set(['win'])))
257     expected.append(gg.SourceSet(set(['arm']), set(['arm']), set(['Chromium']),
258                                  set(['win'])))
259
260     sets = gg.CreatePairwiseDisjointSets([a, b, c])
261     self.assertEqualSets(sets, expected)
262
263   def testCreatePairwiseDisjointSets_Multiple(self):
264     a = gg.SourceSet(set(['common', 'intel']),
265                      set(['ia32']),
266                      set(['Chromium']),
267                      set(['linux']))
268     b = gg.SourceSet(set(['common', 'intel', 'chrome']),
269                      set(['ia32']),
270                      set(['Chrome']),
271                      set(['linux']))
272     c = gg.SourceSet(set(['common', 'intel']),
273                      set(['x64']),
274                      set(['Chromium']),
275                      set(['linux']))
276     d = gg.SourceSet(set(['common', 'intel', 'chrome']),
277                      set(['x64']),
278                      set(['Chrome']),
279                      set(['linux']))
280     e = gg.SourceSet(set(['common', 'arm']),
281                      set(['arm']),
282                      set(['Chromium']),
283                      set(['linux']))
284     f = gg.SourceSet(set(['common', 'arm-neon', 'chrome', 'chromeos']),
285                      set(['arm-neon']),
286                      set(['ChromeOS']),
287                      set(['linux']))
288
289     expected = []
290     expected.append(gg.SourceSet(set(['common']),
291                                  set(['ia32', 'x64', 'arm', 'arm-neon']),
292                                  set(['Chromium', 'Chrome', 'ChromeOS']),
293                                  set(['linux'])))
294     expected.append(gg.SourceSet(set(['intel']),
295                                  set(['ia32', 'x64']),
296                                  set(['Chromium', 'Chrome']),
297                                  set(['linux'])))
298     expected.append(gg.SourceSet(set(['arm']),
299                                  set(['arm']),
300                                  set(['Chromium']),
301                                  set(['linux'])))
302     expected.append(gg.SourceSet(set(['chrome']),
303                                  set(['ia32', 'x64', 'arm-neon']),
304                                  set(['Chrome', 'ChromeOS']),
305                                  set(['linux'])))
306     expected.append(gg.SourceSet(set(['arm-neon', 'chromeos']),
307                                  set(['arm-neon']),
308                                  set(['ChromeOS']),
309                                  set(['linux'])))
310
311     sets = gg.CreatePairwiseDisjointSets([a, b, c, d, e, f])
312     self.assertEqualSets(sets, expected)
313
314 if __name__ == '__main__':
315   unittest.main()