1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
9 EXPECT_EQ = mojom_test.EXPECT_EQ
10 EXPECT_TRUE = mojom_test.EXPECT_TRUE
11 RunTest = mojom_test.RunTest
14 def DeepEquals(d1, d2):
17 if d2.__class__ != d2.__class__:
19 if isinstance(d1, dict):
20 if set(d1.keys()) != set(d2.keys()):
23 if not DeepEquals(d1[key], d2[key]):
26 if isinstance(d1, (list, tuple)):
27 if len(d1) != len(d2):
29 for i in range(len(d1)):
30 if not DeepEquals(d1[i], d2[i]):
38 'namespace': 'testspace',
42 {'name': 'testfield1', 'kind': 'i32'},
43 {'name': 'testfield2', 'kind': 'a:i32', 'ordinal': 42}]}],
50 {'name': 'foo', 'kind': 'i32'},
51 {'name': 'bar', 'kind': 'a:x:teststruct'}],
57 module = mojom_data.ModuleFromData(test_dict)
58 return mojom_test.TestTestModule(module)
62 module = mojom_test.BuildTestModule()
63 d = mojom_data.ModuleToData(module)
64 return EXPECT_TRUE(DeepEquals(test_dict, d))
68 module1 = mojom_test.BuildTestModule()
70 dict1 = mojom_data.ModuleToData(module1)
71 module2 = mojom_data.ModuleFromData(dict1)
72 return EXPECT_TRUE(mojom_test.ModulesAreEqual(module1, module2))
77 errors += RunTest(TestWriteRead)
78 errors += RunTest(TestRead)
79 errors += RunTest(TestWrite)
84 if __name__ == '__main__':
85 sys.exit(Main(sys.argv[1:]))