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

Side by Side Diff: mojom/generators/go/translator/translator_test.go

Issue 2061243002: Encode and decode fields of union type. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 6 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
« no previous file with comments | « mojom/generators/go/translator/translator.go ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 translator 5 package translator
6 6
7 import ( 7 import (
8 "sort" 8 "sort"
9 "testing" 9 "testing"
10 10
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 translator := NewTranslator(&fileGraph) 206 translator := NewTranslator(&fileGraph)
207 207
208 typeRef := &mojom_types.TypeTypeReference{mojom_types.TypeReference{Type Key: &typeKey}} 208 typeRef := &mojom_types.TypeTypeReference{mojom_types.TypeReference{Type Key: &typeKey}}
209 209
210 info := translator.encodingInfo(typeRef) 210 info := translator.encodingInfo(typeRef)
211 211
212 checkEq(t, true, info.IsPointer()) 212 checkEq(t, true, info.IsPointer())
213 checkEq(t, "SomeStruct", info.GoType()) 213 checkEq(t, "SomeStruct", info.GoType())
214 } 214 }
215 215
216 func TestUnionTypeEncodingInfo(t *testing.T) {
217 fileGraph := mojom_files.MojomFileGraph{}
218 shortName := "SomeUnion"
219 typeKey := "typeKey"
220
221 mojomUnion := mojom_types.MojomUnion{
222 DeclData: &mojom_types.DeclarationData{ShortName: &shortName}}
223 fileGraph.ResolvedTypes = map[string]mojom_types.UserDefinedType{}
224 fileGraph.ResolvedTypes[typeKey] = &mojom_types.UserDefinedTypeUnionType {mojomUnion}
225 translator := NewTranslator(&fileGraph)
226
227 typeRef := &mojom_types.TypeTypeReference{mojom_types.TypeReference{Type Key: &typeKey}}
228
229 info := translator.encodingInfo(typeRef)
230
231 checkEq(t, true, info.IsUnion())
232 checkEq(t, false, info.IsPointer())
233 checkEq(t, uint32(128), info.BitSize())
234 checkEq(t, "SomeUnion", info.GoType())
235
236 info.(*unionTypeEncodingInfo).nestedUnion = true
237 checkEq(t, true, info.IsPointer())
238 checkEq(t, uint32(64), info.BitSize())
239 }
240
216 func TestTranslateMojomUnion(t *testing.T) { 241 func TestTranslateMojomUnion(t *testing.T) {
217 field1Name := "f_uint32" 242 field1Name := "f_uint32"
218 field1 := mojom_types.UnionField{ 243 field1 := mojom_types.UnionField{
219 DeclData: &mojom_types.DeclarationData{ShortName: &field1Name}, 244 DeclData: &mojom_types.DeclarationData{ShortName: &field1Name},
220 Type: &mojom_types.TypeSimpleType{Value: mojom_types.SimpleT ype_Uint32}, 245 Type: &mojom_types.TypeSimpleType{Value: mojom_types.SimpleT ype_Uint32},
221 Tag: 5} 246 Tag: 5}
222 247
223 field2Name := "f_uint16" 248 field2Name := "f_uint16"
224 field2 := mojom_types.UnionField{ 249 field2 := mojom_types.UnionField{
225 DeclData: &mojom_types.DeclarationData{ShortName: &field2Name}, 250 DeclData: &mojom_types.DeclarationData{ShortName: &field2Name},
(...skipping 19 matching lines...) Expand all
245 checkEq(t, "Foo", m.Name) 270 checkEq(t, "Foo", m.Name)
246 checkEq(t, "FUint32", m.Fields[0].Name) 271 checkEq(t, "FUint32", m.Fields[0].Name)
247 checkEq(t, "uint32", m.Fields[0].Type) 272 checkEq(t, "uint32", m.Fields[0].Type)
248 checkEq(t, uint32(5), m.Fields[0].Tag) 273 checkEq(t, uint32(5), m.Fields[0].Tag)
249 checkEq(t, m, m.Fields[0].Union) 274 checkEq(t, m, m.Fields[0].Union)
250 checkEq(t, "FUint16", m.Fields[1].Name) 275 checkEq(t, "FUint16", m.Fields[1].Name)
251 checkEq(t, "uint16", m.Fields[1].Type) 276 checkEq(t, "uint16", m.Fields[1].Type)
252 checkEq(t, uint32(6), m.Fields[1].Tag) 277 checkEq(t, uint32(6), m.Fields[1].Tag)
253 checkEq(t, m, m.Fields[1].Union) 278 checkEq(t, m, m.Fields[1].Union)
254 } 279 }
OLDNEW
« no previous file with comments | « mojom/generators/go/translator/translator.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698