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

Side by Side Diff: mojo/python/tests/bindings_serialization_deserialization_unittest.py

Issue 675563002: Remove mojo/python and gyp targets (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
OLDNEW
(Empty)
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
3 # found in the LICENSE file.
4
5 import math
6 import unittest
7
8 # pylint: disable=E0611,F0401
9 import mojo.system
10
11 # Generated files
12 # pylint: disable=F0401
13 import sample_import_mojom
14 import sample_import2_mojom
15 import sample_service_mojom
16
17
18 def _NewHandle():
19 return mojo.system.MessagePipe().handle0
20
21
22 def _NewBar():
23 bar_instance = sample_service_mojom.Bar()
24 bar_instance.alpha = 22
25 bar_instance.beta = 87
26 bar_instance.gamma = 122
27 bar_instance.type = sample_service_mojom.Bar.Type.BOTH
28 return bar_instance
29
30
31 def _NewFoo():
32 foo_instance = sample_service_mojom.Foo()
33 foo_instance.name = "Foo.name"
34 foo_instance.x = 23
35 foo_instance.y = -23
36 foo_instance.a = False
37 foo_instance.b = True
38 foo_instance.c = True
39 foo_instance.bar = _NewBar()
40 foo_instance.extra_bars = [
41 _NewBar(),
42 _NewBar(),
43 ]
44 foo_instance.data = 'Hello world'
45 foo_instance.source = _NewHandle()
46 foo_instance.input_streams = [ _NewHandle() ]
47 foo_instance.output_streams = [ _NewHandle(), _NewHandle() ]
48 foo_instance.array_of_array_of_bools = [ [ True, False ], [] ]
49 foo_instance.multi_array_of_strings = [
50 [
51 [ "1", "2" ],
52 [],
53 [ "3", "4" ],
54 ],
55 [],
56 ]
57 foo_instance.array_of_bools = [ True, 0, 1, 2, 0, 0, 0, 0, 0, True ]
58 return foo_instance
59
60
61 class SerializationDeserializationTest(unittest.TestCase):
62
63 def testFooSerialization(self):
64 (data, _) = _NewFoo().Serialize()
65 self.assertTrue(len(data))
66 self.assertEquals(len(data) % 8, 0)
67
68 def testFooDeserialization(self):
69 (data, handles) = _NewFoo().Serialize()
70 self.assertTrue(
71 sample_service_mojom.Foo.Deserialize(data, handles))
72
73 def testFooSerializationDeserialization(self):
74 foo1 = _NewFoo()
75 (data, handles) = foo1.Serialize()
76 foo2 = sample_service_mojom.Foo.Deserialize(data, handles)
77 self.assertEquals(foo1, foo2)
78
79 def testDefaultsTestSerializationDeserialization(self):
80 v1 = sample_service_mojom.DefaultsTest()
81 v1.a18 = []
82 v1.a19 = ""
83 v1.a21 = sample_import_mojom.Point()
84 v1.a22.location = sample_import_mojom.Point()
85 v1.a22.size = sample_import2_mojom.Size()
86 (data, handles) = v1.Serialize()
87 v2 = sample_service_mojom.DefaultsTest.Deserialize(data, handles)
88 # NaN needs to be a special case.
89 self.assertNotEquals(v1, v2)
90 self.assertTrue(math.isnan(v2.a28))
91 self.assertTrue(math.isnan(v2.a31))
92 v1.a28 = v2.a28 = v1.a31 = v2.a31 = 0
93 self.assertEquals(v1, v2)
94
95 def testFooDeserializationError(self):
96 with self.assertRaises(Exception):
97 sample_service_mojom.Foo.Deserialize("", [])
OLDNEW
« no previous file with comments | « mojo/python/tests/bindings_enums_unittest.py ('k') | mojo/python/tests/bindings_structs_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698