OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import unittest | 5 import unittest |
6 | 6 |
7 from mojom_bindings_generator import MakeImportStackMessage | 7 from mojom_bindings_generator import MakeImportStackMessage |
| 8 from mojom_bindings_generator import ScrambleMethodOrdinals |
| 9 |
| 10 |
| 11 class FakeIface(object): |
| 12 def __init__( self ): |
| 13 self.name = None |
| 14 self.methods = None |
| 15 |
| 16 |
| 17 class FakeMethod(object): |
| 18 def __init__( self ): |
| 19 self.ordinal = None |
| 20 self.ordinal_comment = None |
8 | 21 |
9 | 22 |
10 class MojoBindingsGeneratorTest(unittest.TestCase): | 23 class MojoBindingsGeneratorTest(unittest.TestCase): |
11 """Tests mojo_bindings_generator.""" | 24 """Tests mojo_bindings_generator.""" |
12 | 25 |
13 def testMakeImportStackMessage(self): | 26 def testMakeImportStackMessage(self): |
14 """Tests MakeImportStackMessage().""" | 27 """Tests MakeImportStackMessage().""" |
15 self.assertEquals(MakeImportStackMessage(["x"]), "") | 28 self.assertEquals(MakeImportStackMessage(["x"]), "") |
16 self.assertEquals(MakeImportStackMessage(["x", "y"]), | 29 self.assertEquals(MakeImportStackMessage(["x", "y"]), |
17 "\n y was imported by x") | 30 "\n y was imported by x") |
18 self.assertEquals(MakeImportStackMessage(["x", "y", "z"]), | 31 self.assertEquals(MakeImportStackMessage(["x", "y", "z"]), |
19 "\n z was imported by y\n y was imported by x") | 32 "\n z was imported by y\n y was imported by x") |
20 | 33 |
| 34 def testScrambleMethodOrdinals(self): |
| 35 """Tests ScrambleMethodOrdinals().""" |
| 36 interface = FakeIface() |
| 37 interface.name = 'RendererConfiguration' |
| 38 interface.methods = [FakeMethod(), FakeMethod(), FakeMethod()] |
| 39 ScrambleMethodOrdinals([interface], "foo") |
| 40 # These next three values are hard-coded. If the generation algorithm |
| 41 # changes from being based on sha256(seed + interface.name + str(i)) then |
| 42 # these numbers will obviously need to change too. |
| 43 # |
| 44 # Note that hashlib.sha256('fooRendererConfiguration1').digest()[:4] is |
| 45 # '\xa5\xbc\xf9\xca' and that hex(1257880741) = '0x4af9bca5'. The |
| 46 # difference in 0x4a vs 0xca is because we only take 31 bits. |
| 47 self.assertEquals(interface.methods[0].ordinal, 1257880741) |
| 48 self.assertEquals(interface.methods[1].ordinal, 631133653) |
| 49 self.assertEquals(interface.methods[2].ordinal, 549336076) |
| 50 |
21 | 51 |
22 if __name__ == "__main__": | 52 if __name__ == "__main__": |
23 unittest.main() | 53 unittest.main() |
OLD | NEW |