Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(794)

Side by Side Diff: mojo/public/tools/bindings/mojom_bindings_generator_unittest.py

Issue 2794743002: Add a mechanism to scramble Mojo message IDs. (Closed)
Patch Set: Add a mechanism to scramble Mojo message IDs. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/public/tools/bindings/mojom_bindings_generator.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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()
OLDNEW
« no previous file with comments | « mojo/public/tools/bindings/mojom_bindings_generator.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698