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 math | 5 import math |
6 import unittest | 6 import unittest |
7 | 7 |
8 import mojo.bindings.reflection as reflection | 8 import mojo.bindings.reflection as reflection |
9 | 9 |
10 # pylint: disable=E0611,F0401 | 10 # pylint: disable=E0611,F0401 |
(...skipping 14 matching lines...) Expand all Loading... |
25 if x == y: | 25 if x == y: |
26 return True | 26 return True |
27 | 27 |
28 if type(x) != type(y): | 28 if type(x) != type(y): |
29 print '\n%r != %r. Element are not of the same type.' % (x, y) | 29 print '\n%r != %r. Element are not of the same type.' % (x, y) |
30 return False | 30 return False |
31 | 31 |
32 if isinstance(x, float) and math.isnan(x) and math.isnan(y): | 32 if isinstance(x, float) and math.isnan(x) and math.isnan(y): |
33 return True | 33 return True |
34 | 34 |
| 35 if isinstance(x, dict): |
| 36 if len(x) != len(y): |
| 37 print '\n%r != %r. Dictionaries are not of the same size.' % (x, y) |
| 38 return False |
| 39 for xk, xv in x.iteritems(): |
| 40 if xk not in y: |
| 41 print '\n%r != %r. Key %r is not in %r.' % (x, y, xk, y) |
| 42 return False |
| 43 if not _TestEquality(xv, y[xk]): |
| 44 return False |
| 45 return True |
| 46 |
35 if hasattr(x, '__len__'): | 47 if hasattr(x, '__len__'): |
36 if len(x) != len(y): | 48 if len(x) != len(y): |
37 print '\n%r != %r. Iterables are not of the same size.' % (x, y) | 49 print '\n%r != %r. Iterables are not of the same size.' % (x, y) |
38 return False | 50 return False |
39 for (x1, y1) in zip(x, y): | 51 for (x1, y1) in zip(x, y): |
40 if not _TestEquality(x1, y1): | 52 if not _TestEquality(x1, y1): |
41 return False | 53 return False |
42 return True | 54 return True |
43 | 55 |
44 if (hasattr(x, '__metaclass__') and | 56 if (hasattr(x, '__metaclass__') and |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 [], | 103 [], |
92 ] | 104 ] |
93 foo_instance.array_of_bools = [ True, 0, 1, 2, 0, 0, 0, 0, 0, True ] | 105 foo_instance.array_of_bools = [ True, 0, 1, 2, 0, 0, 0, 0, 0, True ] |
94 return foo_instance | 106 return foo_instance |
95 | 107 |
96 | 108 |
97 class SerializationDeserializationTest(unittest.TestCase): | 109 class SerializationDeserializationTest(unittest.TestCase): |
98 | 110 |
99 def testTestEquality(self): | 111 def testTestEquality(self): |
100 self.assertFalse(_TestEquality(1, 2)) | 112 self.assertFalse(_TestEquality(1, 2)) |
| 113 self.assertTrue(_TestEquality({1: 2, 2: 1}, {2: 1, 1: 2})) |
101 | 114 |
102 def testFooSerialization(self): | 115 def testFooSerialization(self): |
103 (data, _) = _NewFoo().Serialize() | 116 (data, _) = _NewFoo().Serialize() |
104 self.assertTrue(len(data)) | 117 self.assertTrue(len(data)) |
105 self.assertEquals(len(data) % 8, 0) | 118 self.assertEquals(len(data) % 8, 0) |
106 | 119 |
107 def testFooDeserialization(self): | 120 def testFooDeserialization(self): |
108 (data, handles) = _NewFoo().Serialize() | 121 (data, handles) = _NewFoo().Serialize() |
109 self.assertTrue( | 122 self.assertTrue( |
110 sample_service_mojom.Foo.Deserialize(data, handles)) | 123 sample_service_mojom.Foo.Deserialize(data, handles)) |
(...skipping 11 matching lines...) Expand all Loading... |
122 v1.a21 = sample_import_mojom.Point() | 135 v1.a21 = sample_import_mojom.Point() |
123 v1.a22.location = sample_import_mojom.Point() | 136 v1.a22.location = sample_import_mojom.Point() |
124 v1.a22.size = sample_import2_mojom.Size() | 137 v1.a22.size = sample_import2_mojom.Size() |
125 (data, handles) = v1.Serialize() | 138 (data, handles) = v1.Serialize() |
126 v2 = sample_service_mojom.DefaultsTest.Deserialize(data, handles) | 139 v2 = sample_service_mojom.DefaultsTest.Deserialize(data, handles) |
127 self.assertTrue(_TestEquality(v1, v2)) | 140 self.assertTrue(_TestEquality(v1, v2)) |
128 | 141 |
129 def testFooDeserializationError(self): | 142 def testFooDeserializationError(self): |
130 with self.assertRaises(Exception): | 143 with self.assertRaises(Exception): |
131 sample_service_mojom.Foo.Deserialize("", []) | 144 sample_service_mojom.Foo.Deserialize("", []) |
OLD | NEW |