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

Side by Side Diff: mojo/public/tools/bindings/pylib/mojom/generate/pack_tests.py

Issue 437643002: Support nullable types in mojom. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
OLDNEW
1 # Copyright 2013 The Chromium Authors. All rights reserved. 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 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 sys 5 import sys
6 6
7 import module as mojom 7 import module as mojom
8 import pack 8 import pack
9 import test_support 9 import test_support
10 10
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 81
82 82
83 def TestPaddingPackedOverflow(): 83 def TestPaddingPackedOverflow():
84 kinds = (mojom.INT8, mojom.INT32, mojom.INT16, mojom.INT8, mojom.INT8) 84 kinds = (mojom.INT8, mojom.INT32, mojom.INT16, mojom.INT8, mojom.INT8)
85 # 2 bytes should be packed together first, followed by short, then by int. 85 # 2 bytes should be packed together first, followed by short, then by int.
86 fields = (1, 4, 3, 2, 5) 86 fields = (1, 4, 3, 2, 5)
87 offsets = (0, 1, 2, 4, 8) 87 offsets = (0, 1, 2, 4, 8)
88 return TestSequence(kinds, fields, offsets) 88 return TestSequence(kinds, fields, offsets)
89 89
90 90
91 def TestNullableTypes():
92 kinds = (mojom.STRING.MakeNullableKind(),
93 mojom.HANDLE.MakeNullableKind(),
94 mojom.Struct('test_struct').MakeNullableKind(),
95 mojom.DCPIPE.MakeNullableKind(),
96 mojom.Array().MakeNullableKind(),
97 mojom.DPPIPE.MakeNullableKind(),
98 mojom.FixedArray(5).MakeNullableKind(),
99 mojom.MSGPIPE.MakeNullableKind(),
100 mojom.Interface('test_inteface').MakeNullableKind(),
101 mojom.SHAREDBUFFER.MakeNullableKind(),
102 mojom.InterfaceRequest().MakeNullableKind())
103 fields = (1, 2, 4, 3, 5, 6, 8, 7, 9, 10, 11)
104 offsets = (0, 8, 12, 16, 24, 32, 36, 40, 48, 52, 56)
105 return TestSequence(kinds, fields, offsets)
106
107
91 def TestAllTypes(): 108 def TestAllTypes():
92 struct = mojom.Struct('test')
93 array = mojom.Array()
94 return TestSequence( 109 return TestSequence(
95 (mojom.BOOL, mojom.INT8, mojom.STRING, mojom.UINT8, 110 (mojom.BOOL, mojom.INT8, mojom.STRING, mojom.UINT8,
96 mojom.INT16, mojom.DOUBLE, mojom.UINT16, 111 mojom.INT16, mojom.DOUBLE, mojom.UINT16,
97 mojom.INT32, mojom.UINT32, mojom.INT64, 112 mojom.INT32, mojom.UINT32, mojom.INT64,
98 mojom.FLOAT, mojom.STRING, mojom.HANDLE, 113 mojom.FLOAT, mojom.STRING, mojom.HANDLE,
99 mojom.UINT64, mojom.Struct('test'), mojom.Array()), 114 mojom.UINT64, mojom.Struct('test'), mojom.Array(),
100 (1, 2, 4, 5, 7, 3, 6, 8, 9, 10, 11, 13, 12, 14, 15, 16, 17), 115 mojom.STRING.MakeNullableKind()),
101 (0, 1, 2, 4, 6, 8, 16, 24, 28, 32, 40, 44, 48, 56, 64, 72, 80)) 116 (1, 2, 4, 5, 7, 3, 6, 8, 9, 10, 11, 13, 12, 14, 15, 16, 17, 18),
117 (0, 1, 2, 4, 6, 8, 16, 24, 28, 32, 40, 44, 48, 56, 64, 72, 80, 88))
102 118
103 119
104 def TestPaddingPackedOutOfOrderByOrdinal(): 120 def TestPaddingPackedOutOfOrderByOrdinal():
105 errors = 0 121 errors = 0
106 struct = mojom.Struct('test') 122 struct = mojom.Struct('test')
107 struct.AddField('testfield1', mojom.INT8) 123 struct.AddField('testfield1', mojom.INT8)
108 struct.AddField('testfield3', mojom.UINT8, 3) 124 struct.AddField('testfield3', mojom.UINT8, 3)
109 struct.AddField('testfield2', mojom.INT32, 2) 125 struct.AddField('testfield2', mojom.INT32, 2)
110 ps = pack.PackedStruct(struct) 126 ps = pack.PackedStruct(struct)
111 errors += EXPECT_EQ(3, len(ps.packed_fields)) 127 errors += EXPECT_EQ(3, len(ps.packed_fields))
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 return errors 174 return errors
159 175
160 176
161 def Main(args): 177 def Main(args):
162 errors = 0 178 errors = 0
163 errors += RunTest(TestZeroFields) 179 errors += RunTest(TestZeroFields)
164 errors += RunTest(TestOneField) 180 errors += RunTest(TestOneField)
165 errors += RunTest(TestPaddingPackedInOrder) 181 errors += RunTest(TestPaddingPackedInOrder)
166 errors += RunTest(TestPaddingPackedOutOfOrder) 182 errors += RunTest(TestPaddingPackedOutOfOrder)
167 errors += RunTest(TestPaddingPackedOverflow) 183 errors += RunTest(TestPaddingPackedOverflow)
184 errors += RunTest(TestNullableTypes)
168 errors += RunTest(TestAllTypes) 185 errors += RunTest(TestAllTypes)
169 errors += RunTest(TestPaddingPackedOutOfOrderByOrdinal) 186 errors += RunTest(TestPaddingPackedOutOfOrderByOrdinal)
170 errors += RunTest(TestBools) 187 errors += RunTest(TestBools)
171 188
172 return errors 189 return errors
173 190
174 191
175 if __name__ == '__main__': 192 if __name__ == '__main__':
176 sys.exit(Main(sys.argv[1:])) 193 sys.exit(Main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « mojo/public/tools/bindings/pylib/mojom/generate/pack.py ('k') | mojo/public/tools/bindings/pylib/mojom/parse/lexer.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698