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

Side by Side Diff: mojo/go/tests/validation_type_test.go

Issue 1483313002: go generator: generate full identifiers (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years 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 | « no previous file | mojo/public/tools/bindings/generators/go_templates/mojom_type_macros.tmpl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 package tests 5 package tests
6 6
7 import ( 7 import (
8 "reflect" 8 "reflect"
9 "testing" 9 "testing"
10 10
11 "mojo/public/interfaces/bindings/mojom_types" 11 "mojo/public/interfaces/bindings/mojom_types"
12 "mojo/public/interfaces/bindings/service_describer" 12 "mojo/public/interfaces/bindings/service_describer"
13 "mojo/public/interfaces/bindings/tests/test_included_unions" 13 "mojo/public/interfaces/bindings/tests/test_included_unions"
14 "mojo/public/interfaces/bindings/tests/test_unions" 14 "mojo/public/interfaces/bindings/tests/test_unions"
15 test "mojo/public/interfaces/bindings/tests/validation_test_interfaces" 15 test "mojo/public/interfaces/bindings/tests/validation_test_interfaces"
16 ) 16 )
17 17
18 var test_descriptor map[string]mojom_types.UserDefinedType 18 var test_descriptor map[string]mojom_types.UserDefinedType
19 var test_unions_descriptor map[string]mojom_types.UserDefinedType 19 var test_unions_descriptor map[string]mojom_types.UserDefinedType
20 20
21 func init() { 21 func init() {
22 test_descriptor = test.GetAllMojomTypeDefinitions() 22 test_descriptor = test.GetAllMojomTypeDefinitions()
23 test_unions_descriptor = test_unions.GetAllMojomTypeDefinitions() 23 test_unions_descriptor = test_unions.GetAllMojomTypeDefinitions()
24 } 24 }
25 25
26 // Perform a sanity check where we examine an MojomEnum's contents for correctne ss. 26 // Perform a sanity check where we examine an MojomEnum's contents for correctne ss.
27 func TestEnumType(t *testing.T) { 27 func TestEnumType(t *testing.T) {
28 enumID := test.ID_validation_test_interfaces_BasicEnum__ 28 enumID := test.ID_validation_test_interfaces_BasicEnum__
29 shortName := "BasicEnum" 29 shortName := "BasicEnum"
30 fullIdentifier := "mojo.test.BasicEnum"
30 labelMap := map[string]int32{ 31 labelMap := map[string]int32{
31 "A": 0, 32 "A": 0,
32 "B": 1, 33 "B": 1,
33 "C": 0, 34 "C": 0,
34 "D": -3, 35 "D": -3,
35 "E": 0xA, 36 "E": 0xA,
36 } 37 }
37 38
38 // Extract *UserDefinedType from the validation test's Descriptor using enumID. 39 // Extract *UserDefinedType from the validation test's Descriptor using enumID.
39 udt := test_descriptor[enumID] 40 udt := test_descriptor[enumID]
40 if udt == nil { 41 if udt == nil {
41 t.Fatalf("Descriptor did not contain %s", enumID) 42 t.Fatalf("Descriptor did not contain %s", enumID)
42 } 43 }
43 44
44 // The *UserDefinedType must be a *UserDefinedTypeEnumType. 45 // The *UserDefinedType must be a *UserDefinedTypeEnumType.
45 udet, ok := udt.(*mojom_types.UserDefinedTypeEnumType) 46 udet, ok := udt.(*mojom_types.UserDefinedTypeEnumType)
46 if !ok { 47 if !ok {
47 t.Fatalf("*UserDefinedType for %s was not *UserDefinedTypeEnumTy pe", enumID) 48 t.Fatalf("*UserDefinedType for %s was not *UserDefinedTypeEnumTy pe", enumID)
48 } 49 }
49 50
50 // The UserDefinedTypeEnumType has a MojomEnum inside. 51 // The UserDefinedTypeEnumType has a MojomEnum inside.
51 me := udet.Value 52 me := udet.Value
52 53
53 // Check that the generator produced the short name. 54 // Check that the generator produced the short name.
54 if me.DeclData == nil || me.DeclData.ShortName == nil { 55 if me.DeclData == nil || me.DeclData.ShortName == nil {
55 t.Fatalf("Declaration Data's ShortName for %s is missing", enumI D) 56 t.Fatalf("Declaration Data's ShortName for %s is missing", enumI D)
56 } 57 }
57 if *me.DeclData.ShortName != shortName { 58 if *me.DeclData.ShortName != shortName {
58 » » t.Fatalf("Declaration Data's ShortName for %s was not %s", enumI D, shortName) 59 » » t.Fatalf("Declaration Data's ShortName for %s was %s, expected % s", enumID, *me.DeclData.ShortName, shortName)
60 » }
61 » if me.DeclData.FullIdentifier == nil {
62 » » t.Fatalf("Declaration Data's FullIdentifier for %s is missing", enumID)
63 » }
64 » if *me.DeclData.FullIdentifier != fullIdentifier {
65 » » t.Fatalf("Declaration Data's FullIdentifier for %s was %s, expec ted %s", enumID, *me.DeclData.FullIdentifier, fullIdentifier)
59 } 66 }
60 67
61 // Verify that the number of entries matches the expected ones. 68 // Verify that the number of entries matches the expected ones.
62 if got, expected := len(me.Values), len(labelMap); got != expected { 69 if got, expected := len(me.Values), len(labelMap); got != expected {
63 t.Fatalf("MojomEnum for %s had %d labels, but expected %d", enum ID, got, expected) 70 t.Fatalf("MojomEnum for %s had %d labels, but expected %d", enum ID, got, expected)
64 } 71 }
65 72
66 // Go through each entry, verify type info and that the enum label match es the expected one. 73 // Go through each entry, verify type info and that the enum label match es the expected one.
67 for _, label := range me.Values { 74 for _, label := range me.Values {
68 // label is an EnumValue. 75 // label is an EnumValue.
(...skipping 15 matching lines...) Expand all
84 t.Fatalf("IntValue for Enum %s's label %s was %d but exp ected %d", 91 t.Fatalf("IntValue for Enum %s's label %s was %d but exp ected %d",
85 enumID, *label.DeclData.ShortName, label.IntValu e, expectedOrdinal) 92 enumID, *label.DeclData.ShortName, label.IntValu e, expectedOrdinal)
86 } 93 }
87 } 94 }
88 } 95 }
89 96
90 // Perform a sanity check where we examine a MojomStruct's contents for correctn ess. 97 // Perform a sanity check where we examine a MojomStruct's contents for correctn ess.
91 func TestStructType(t *testing.T) { 98 func TestStructType(t *testing.T) {
92 structID := test.ID_validation_test_interfaces_StructE__ 99 structID := test.ID_validation_test_interfaces_StructE__
93 shortName := "StructE" 100 shortName := "StructE"
101 fullIdentifier := "mojo.test.StructE"
94 fields := map[int]string{ 102 fields := map[int]string{
95 0: "StructD", 103 0: "StructD",
96 1: "DataPipeConsumer", 104 1: "DataPipeConsumer",
97 } 105 }
98 106
99 // Extract *UserDefinedType from the validation test's Descriptor using structID. 107 // Extract *UserDefinedType from the validation test's Descriptor using structID.
100 udt := test_descriptor[structID] 108 udt := test_descriptor[structID]
101 if udt == nil { 109 if udt == nil {
102 t.Fatalf("Descriptor did not contain %s", structID) 110 t.Fatalf("Descriptor did not contain %s", structID)
103 } 111 }
104 112
105 // The *UserDefinedType must be a *UserDefinedTypeStructType. 113 // The *UserDefinedType must be a *UserDefinedTypeStructType.
106 udst, ok := udt.(*mojom_types.UserDefinedTypeStructType) 114 udst, ok := udt.(*mojom_types.UserDefinedTypeStructType)
107 if !ok { 115 if !ok {
108 t.Fatalf("*UserDefinedType for %s was not *UserDefinedTypeStruct Type", structID) 116 t.Fatalf("*UserDefinedType for %s was not *UserDefinedTypeStruct Type", structID)
109 } 117 }
110 118
111 // The UserDefinedTypeStructType has a MojomStruct inside. 119 // The UserDefinedTypeStructType has a MojomStruct inside.
112 ms := udst.Value 120 ms := udst.Value
113 121
114 // Check that the generator produced the short name. 122 // Check that the generator produced the short name.
115 if ms.DeclData == nil || ms.DeclData.ShortName == nil { 123 if ms.DeclData == nil || ms.DeclData.ShortName == nil {
116 t.Fatalf("Declaration Data's ShortName for %s is missing", struc tID) 124 t.Fatalf("Declaration Data's ShortName for %s is missing", struc tID)
117 } 125 }
118 if *ms.DeclData.ShortName != shortName { 126 if *ms.DeclData.ShortName != shortName {
119 » » t.Fatalf("Declaration Data's ShortName for %s was not %s", struc tID, shortName) 127 » » t.Fatalf("Declaration Data's ShortName for %s was %s, expected % s", structID, *ms.DeclData.ShortName, shortName)
128 » }
129 » if ms.DeclData.FullIdentifier == nil {
130 » » t.Fatalf("Declaration Data's FullIdentifier for %s is missing", structID)
131 » }
132 » if *ms.DeclData.FullIdentifier != fullIdentifier {
133 » » t.Fatalf("Declaration Data's FullIdentifier for %s was %s, expec ted %s", structID, *ms.DeclData.FullIdentifier, fullIdentifier)
120 } 134 }
121 135
122 // Verify that the number of fields matches the expected ones. 136 // Verify that the number of fields matches the expected ones.
123 if got, expected := len(ms.Fields), len(fields); got != expected { 137 if got, expected := len(ms.Fields), len(fields); got != expected {
124 t.Fatalf("MojomStruct for %s had %d fields, but expected %d", st ructID, got, expected) 138 t.Fatalf("MojomStruct for %s had %d fields, but expected %d", st ructID, got, expected)
125 } 139 }
126 140
127 // Go through each StructField, checking DeclData and the Type of each f ield. 141 // Go through each StructField, checking DeclData and the Type of each f ield.
128 // Note that since ms.Fields is a slice, the "ordinal" is the index. 142 // Note that since ms.Fields is a slice, the "ordinal" is the index.
129 for i, field := range ms.Fields { 143 for i, field := range ms.Fields {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 default: 179 default:
166 t.Fatalf("There should not be a field %d for MojomStruct %s", i, structID) 180 t.Fatalf("There should not be a field %d for MojomStruct %s", i, structID)
167 } 181 }
168 } 182 }
169 } 183 }
170 184
171 // Perform a sanity check where we examine a MojomUnion's contents for correctne ss. 185 // Perform a sanity check where we examine a MojomUnion's contents for correctne ss.
172 func TestUnionType(t *testing.T) { 186 func TestUnionType(t *testing.T) {
173 unionID := test.ID_validation_test_interfaces_UnionB__ 187 unionID := test.ID_validation_test_interfaces_UnionB__
174 shortName := "UnionB" 188 shortName := "UnionB"
189 fullIdentifier := "mojo.test.UnionB"
175 fields := map[int]string{ 190 fields := map[int]string{
176 0: "A", 191 0: "A",
177 1: "B", 192 1: "B",
178 2: "C", 193 2: "C",
179 3: "D", 194 3: "D",
180 } 195 }
181 196
182 // Extract *UserDefinedType from the validation test's Descriptor using unionID. 197 // Extract *UserDefinedType from the validation test's Descriptor using unionID.
183 udt := test_descriptor[unionID] 198 udt := test_descriptor[unionID]
184 if udt == nil { 199 if udt == nil {
185 t.Fatalf("Descriptor did not contain %s", unionID) 200 t.Fatalf("Descriptor did not contain %s", unionID)
186 } 201 }
187 202
188 // The *UserDefinedType must be a *UserDefinedTypeUnionType. 203 // The *UserDefinedType must be a *UserDefinedTypeUnionType.
189 udut, ok := udt.(*mojom_types.UserDefinedTypeUnionType) 204 udut, ok := udt.(*mojom_types.UserDefinedTypeUnionType)
190 if !ok { 205 if !ok {
191 t.Fatalf("*UserDefinedType for %s was not *UserDefinedTypeUnionT ype", unionID) 206 t.Fatalf("*UserDefinedType for %s was not *UserDefinedTypeUnionT ype", unionID)
192 } 207 }
193 208
194 // The UserDefinedTypeUnionType has a MojomUnion inside. 209 // The UserDefinedTypeUnionType has a MojomUnion inside.
195 mu := udut.Value 210 mu := udut.Value
196 211
197 // Check that the generator produced the short name. 212 // Check that the generator produced the short name.
198 if mu.DeclData == nil || mu.DeclData.ShortName == nil { 213 if mu.DeclData == nil || mu.DeclData.ShortName == nil {
199 t.Fatalf("Declaration Data's ShortName for %s was missing", unio nID) 214 t.Fatalf("Declaration Data's ShortName for %s was missing", unio nID)
200 } 215 }
201 if *mu.DeclData.ShortName != shortName { 216 if *mu.DeclData.ShortName != shortName {
202 » » t.Fatalf("Declaration Data's ShortName for %s was not %s", union ID, shortName) 217 » » t.Fatalf("Declaration Data's ShortName for %s was %s, expected % s", unionID, *mu.DeclData.ShortName, shortName)
218 » }
219 » if mu.DeclData.FullIdentifier == nil {
220 » » t.Fatalf("Declaration Data's FullIdentifier for %s is missing", unionID)
221 » }
222 » if *mu.DeclData.FullIdentifier != fullIdentifier {
223 » » t.Fatalf("Declaration Data's FullIdentifier for %s was %s, expec ted %s", unionID, *mu.DeclData.FullIdentifier, fullIdentifier)
203 } 224 }
204 225
205 // Verify that the number of fields matches the expected ones. 226 // Verify that the number of fields matches the expected ones.
206 if got, expected := len(mu.Fields), len(fields); got != expected { 227 if got, expected := len(mu.Fields), len(fields); got != expected {
207 t.Fatalf("MojomUnion for %s had %d fields, but expected %d", uni onID, got, expected) 228 t.Fatalf("MojomUnion for %s had %d fields, but expected %d", uni onID, got, expected)
208 } 229 }
209 230
210 // Go through each UnionField, checking DeclData and the Type of each fi eld. 231 // Go through each UnionField, checking DeclData and the Type of each fi eld.
211 // Note that UnionField's rely on their Tag to determine their ordinal. 232 // Note that UnionField's rely on their Tag to determine their ordinal.
212 // It is NOT in definition order, like with MojomStruct's. 233 // It is NOT in definition order, like with MojomStruct's.
(...skipping 30 matching lines...) Expand all
243 t.Fatalf("There should not be a field Tag %d for MojomSt ruct %s", ordinal, unionID) 264 t.Fatalf("There should not be a field Tag %d for MojomSt ruct %s", ordinal, unionID)
244 } 265 }
245 } 266 }
246 } 267 }
247 268
248 // Perform a sanity check for a struct that imports a union from another file. 269 // Perform a sanity check for a struct that imports a union from another file.
249 // The descriptor should still handle it. 270 // The descriptor should still handle it.
250 func TestStructWithImportType(t *testing.T) { 271 func TestStructWithImportType(t *testing.T) {
251 structID := test_unions.ID_test_unions_IncludingStruct__ 272 structID := test_unions.ID_test_unions_IncludingStruct__
252 shortName := "IncludingStruct" 273 shortName := "IncludingStruct"
274 fullIdentifier := "mojo.test.IncludingStruct"
253 fields := map[int]string{ 275 fields := map[int]string{
254 0: "A", 276 0: "A",
255 } 277 }
256 278
257 // Extract *UserDefinedType from the validation test's Descriptor using structID. 279 // Extract *UserDefinedType from the validation test's Descriptor using structID.
258 udt := test_unions_descriptor[structID] 280 udt := test_unions_descriptor[structID]
259 if udt == nil { 281 if udt == nil {
260 t.Fatalf("Descriptor did not contain %s", structID) 282 t.Fatalf("Descriptor did not contain %s", structID)
261 } 283 }
262 284
263 // The *UserDefinedType must be a *UserDefinedTypeStructType. 285 // The *UserDefinedType must be a *UserDefinedTypeStructType.
264 udst, ok := udt.(*mojom_types.UserDefinedTypeStructType) 286 udst, ok := udt.(*mojom_types.UserDefinedTypeStructType)
265 if !ok { 287 if !ok {
266 t.Fatalf("*UserDefinedType for %s was not *UserDefinedTypeStruct Type", structID) 288 t.Fatalf("*UserDefinedType for %s was not *UserDefinedTypeStruct Type", structID)
267 } 289 }
268 290
269 // The UserDefinedTypeStructType has a MojomStruct inside. 291 // The UserDefinedTypeStructType has a MojomStruct inside.
270 ms := udst.Value 292 ms := udst.Value
271 293
272 // Check that the generator produced the short name. 294 // Check that the generator produced the short name.
273 if ms.DeclData == nil || ms.DeclData.ShortName == nil { 295 if ms.DeclData == nil || ms.DeclData.ShortName == nil {
274 t.Fatalf("Declaration Data's ShortName for %s is missing", struc tID) 296 t.Fatalf("Declaration Data's ShortName for %s is missing", struc tID)
275 } 297 }
276 if *ms.DeclData.ShortName != shortName { 298 if *ms.DeclData.ShortName != shortName {
277 » » t.Fatalf("Declaration Data's ShortName for %s was not %s", struc tID, shortName) 299 » » t.Fatalf("Declaration Data's ShortName for %s was %s, expected % s", structID, *ms.DeclData.ShortName, shortName)
300 » }
301 » if ms.DeclData.FullIdentifier == nil {
302 » » t.Fatalf("Declaration Data's FullIdentifier for %s is missing", structID)
303 » }
304 » if *ms.DeclData.FullIdentifier != fullIdentifier {
305 » » t.Fatalf("Declaration Data's FullIdentifier for %s was %s, expec ted %s", structID, *ms.DeclData.FullIdentifier, fullIdentifier)
278 } 306 }
279 307
280 // Verify that the number of fields matches the expected ones. 308 // Verify that the number of fields matches the expected ones.
281 if got, expected := len(ms.Fields), len(fields); got != expected { 309 if got, expected := len(ms.Fields), len(fields); got != expected {
282 t.Fatalf("MojomStruct for %s had %d fields, but expected %d", st ructID, got, expected) 310 t.Fatalf("MojomStruct for %s had %d fields, but expected %d", st ructID, got, expected)
283 } 311 }
284 312
285 // Go through each StructField, checking DeclData and the Type of each f ield. 313 // Go through each StructField, checking DeclData and the Type of each f ield.
286 // Note that since ms.Fields is a slice, the "ordinal" is the index. 314 // Note that since ms.Fields is a slice, the "ordinal" is the index.
287 for i, field := range ms.Fields { 315 for i, field := range ms.Fields {
(...skipping 29 matching lines...) Expand all
317 // for its input and output. Further, its Interface_Request and Interface_Factor y 345 // for its input and output. Further, its Interface_Request and Interface_Factor y
318 // must expose a usable ServiceDescription. 346 // must expose a usable ServiceDescription.
319 func TestInterfaceType(t *testing.T) { 347 func TestInterfaceType(t *testing.T) {
320 // interface BoundsCheckTestInterface { 348 // interface BoundsCheckTestInterface {
321 // Method0(uint8 param0) => (uint8 param0); 349 // Method0(uint8 param0) => (uint8 param0);
322 // Method1(uint8 param0); 350 // Method1(uint8 param0);
323 // }; 351 // };
324 352
325 interfaceID := test.ID_validation_test_interfaces_BoundsCheckTestInterfa ce__ 353 interfaceID := test.ID_validation_test_interfaces_BoundsCheckTestInterfa ce__
326 shortName := "BoundsCheckTestInterface" 354 shortName := "BoundsCheckTestInterface"
355 fullIdentifier := "mojo.test.BoundsCheckTestInterface"
327 methodMap := map[uint32]string{ 356 methodMap := map[uint32]string{
328 0: "Method0", 357 0: "Method0",
329 1: "Method1", 358 1: "Method1",
330 } 359 }
331 360
332 // Extract *UserDefinedType from the validation test's Descriptor using interfaceID. 361 // Extract *UserDefinedType from the validation test's Descriptor using interfaceID.
333 udt := test_descriptor[interfaceID] 362 udt := test_descriptor[interfaceID]
334 if udt == nil { 363 if udt == nil {
335 t.Fatalf("Descriptor did not contain %s", interfaceID) 364 t.Fatalf("Descriptor did not contain %s", interfaceID)
336 } 365 }
337 366
338 // The *UserDefinedType must be a *UserDefinedTypeInterfaceType. 367 // The *UserDefinedType must be a *UserDefinedTypeInterfaceType.
339 udit, ok := udt.(*mojom_types.UserDefinedTypeInterfaceType) 368 udit, ok := udt.(*mojom_types.UserDefinedTypeInterfaceType)
340 if !ok { 369 if !ok {
341 t.Fatalf("*UserDefinedType for %s was not *UserDefinedTypeInterf aceType", interfaceID) 370 t.Fatalf("*UserDefinedType for %s was not *UserDefinedTypeInterf aceType", interfaceID)
342 } 371 }
343 372
344 // The UserDefinedTypeInterfaceType has a MojomInterface inside. 373 // The UserDefinedTypeInterfaceType has a MojomInterface inside.
345 mi := udit.Value 374 mi := udit.Value
346 » checkMojomInterface(t, mi, interfaceID, shortName, methodMap) 375 » checkMojomInterface(t, mi, interfaceID, shortName, fullIdentifier, metho dMap)
347 376
348 // Now, we must check the ServiceDescription(s) exposed by the autogener ated 377 // Now, we must check the ServiceDescription(s) exposed by the autogener ated
349 // ServiceRequest and ServiceFactory. 378 // ServiceRequest and ServiceFactory.
350 var bcti_r test.BoundsCheckTestInterface_Request 379 var bcti_r test.BoundsCheckTestInterface_Request
351 » checkServiceDescription(t, bcti_r.ServiceDescription(), interfaceID, sho rtName, methodMap) 380 » checkServiceDescription(t, bcti_r.ServiceDescription(), interfaceID, sho rtName, fullIdentifier, methodMap)
352 381
353 var bcti_sf test.BoundsCheckTestInterface_ServiceFactory 382 var bcti_sf test.BoundsCheckTestInterface_ServiceFactory
354 » checkServiceDescription(t, bcti_sf.ServiceDescription(), interfaceID, sh ortName, methodMap) 383 » checkServiceDescription(t, bcti_sf.ServiceDescription(), interfaceID, sh ortName, fullIdentifier, methodMap)
355 } 384 }
356 385
357 func checkServiceDescription(t *testing.T, sd service_describer.ServiceDescripti on, interfaceID string, shortName string, methodMap map[uint32]string) { 386 func checkServiceDescription(t *testing.T, sd service_describer.ServiceDescripti on, interfaceID, shortName, fullIdentifier string, methodMap map[uint32]string) {
358 // Check out the top level interface. This must pass checkMojomInterface . 387 // Check out the top level interface. This must pass checkMojomInterface .
359 mi, err := sd.GetTopLevelInterface() 388 mi, err := sd.GetTopLevelInterface()
360 if err != nil { 389 if err != nil {
361 t.Fatalf("Unexpected error %s", err) 390 t.Fatalf("Unexpected error %s", err)
362 } 391 }
363 » checkMojomInterface(t, mi, interfaceID, shortName, methodMap) 392 » checkMojomInterface(t, mi, interfaceID, shortName, fullIdentifier, metho dMap)
364 393
365 // Try out sd.GetTypeDefinition. Pass in the interfaceID to see if you c an get it out. 394 // Try out sd.GetTypeDefinition. Pass in the interfaceID to see if you c an get it out.
366 udt, err := sd.GetTypeDefinition(interfaceID) 395 udt, err := sd.GetTypeDefinition(interfaceID)
367 if err != nil { 396 if err != nil {
368 t.Fatalf("Unexpected error %s", err) 397 t.Fatalf("Unexpected error %s", err)
369 } 398 }
370 if udtit, ok := udt.(*mojom_types.UserDefinedTypeInterfaceType); !ok { 399 if udtit, ok := udt.(*mojom_types.UserDefinedTypeInterfaceType); !ok {
371 t.Fatalf("This type should be a *UserDefinedTypeInterfaceType") 400 t.Fatalf("This type should be a *UserDefinedTypeInterfaceType")
372 } else { 401 } else {
373 » » checkMojomInterface(t, udtit.Value, interfaceID, shortName, meth odMap) 402 » » checkMojomInterface(t, udtit.Value, interfaceID, shortName, full Identifier, methodMap)
374 } 403 }
375 404
376 // Look at all the type definitions. Reflect-wise, all data inside shoul d match the imported Descriptor. 405 // Look at all the type definitions. Reflect-wise, all data inside shoul d match the imported Descriptor.
377 outDesc, err := sd.GetAllTypeDefinitions() 406 outDesc, err := sd.GetAllTypeDefinitions()
378 if err != nil { 407 if err != nil {
379 t.Fatalf("Unexpected error %s", err) 408 t.Fatalf("Unexpected error %s", err)
380 } 409 }
381 if !reflect.DeepEqual(*outDesc, test_descriptor) { 410 if !reflect.DeepEqual(*outDesc, test_descriptor) {
382 t.Fatalf("Descriptions did not match") 411 t.Fatalf("Descriptions did not match")
383 } 412 }
384 } 413 }
385 414
386 func checkMojomInterface(t *testing.T, mi mojom_types.MojomInterface, interfaceI D string, shortName string, methodMap map[uint32]string) { 415 func checkMojomInterface(t *testing.T, mi mojom_types.MojomInterface, interfaceI D, shortName, fullIdentifier string, methodMap map[uint32]string) {
387 // Check that the generator produced the short name. 416 // Check that the generator produced the short name.
388 if mi.DeclData == nil || mi.DeclData.ShortName == nil { 417 if mi.DeclData == nil || mi.DeclData.ShortName == nil {
389 t.Fatalf("Declaration Data's ShortName for %s was missing", inte rfaceID) 418 t.Fatalf("Declaration Data's ShortName for %s was missing", inte rfaceID)
390 } 419 }
391 if *mi.DeclData.ShortName != shortName { 420 if *mi.DeclData.ShortName != shortName {
392 » » t.Fatalf("Declaration Data's ShortName for %s was not %s", inter faceID, shortName) 421 » » t.Fatalf("Declaration Data's ShortName for %s was %s, expected % s", interfaceID, *mi.DeclData.ShortName, shortName)
422 » }
423 » if mi.DeclData.FullIdentifier == nil {
424 » » t.Fatalf("Declaration Data's FullIdentifier for %s was missing", fullIdentifier)
425 » }
426 » if *mi.DeclData.FullIdentifier != fullIdentifier {
427 » » t.Fatalf("Declaration Data's FullIdentifier for %s was %s, expce cted %s", interfaceID, *mi.DeclData.FullIdentifier, fullIdentifier)
393 } 428 }
394 429
395 // Verify that the number of methods matches the expected ones. 430 // Verify that the number of methods matches the expected ones.
396 if got, expected := len(mi.Methods), len(methodMap); got != expected { 431 if got, expected := len(mi.Methods), len(methodMap); got != expected {
397 t.Fatalf("MojomInterface for %s had %d methods, but expected %d" , interfaceID, got, expected) 432 t.Fatalf("MojomInterface for %s had %d methods, but expected %d" , interfaceID, got, expected)
398 } 433 }
399 434
400 // Go through each MojomMethod, checking DeclData and the Type of each f ield. 435 // Go through each MojomMethod, checking DeclData and the Type of each f ield.
401 // Note that since mi.Methods is a map, the "ordinal" is the key. 436 // Note that since mi.Methods is a map, the "ordinal" is the key.
402 for ordinal, method := range mi.Methods { 437 for ordinal, method := range mi.Methods {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 } 480 }
446 481
447 if method.ResponseParams != nil { 482 if method.ResponseParams != nil {
448 t.Fatalf("MojomMethod %d had a Response but shou ld not have", ordinal) 483 t.Fatalf("MojomMethod %d had a Response but shou ld not have", ordinal)
449 } 484 }
450 default: 485 default:
451 t.Fatalf("There should not be a method %d for MojomInter face %s", ordinal, interfaceID) 486 t.Fatalf("There should not be a method %d for MojomInter face %s", ordinal, interfaceID)
452 } 487 }
453 } 488 }
454 } 489 }
OLDNEW
« no previous file with comments | « no previous file | mojo/public/tools/bindings/generators/go_templates/mojom_type_macros.tmpl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698