OLD | NEW |
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 templates | 5 package templates |
6 | 6 |
7 import ( | 7 import ( |
8 "testing" | 8 "testing" |
9 ) | 9 ) |
10 | 10 |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 | 240 |
241 encodingInfo := mockEncodingInfo{ | 241 encodingInfo := mockEncodingInfo{ |
242 isEnum: true, | 242 isEnum: true, |
243 identifier: "s.EnumField", | 243 identifier: "s.EnumField", |
244 goType: "SomeEnum", | 244 goType: "SomeEnum", |
245 readFunction: "ReadInt32", | 245 readFunction: "ReadInt32", |
246 } | 246 } |
247 | 247 |
248 check(t, expected, "FieldDecodingTmpl", encodingInfo) | 248 check(t, expected, "FieldDecodingTmpl", encodingInfo) |
249 } | 249 } |
| 250 |
| 251 func TestDecodingNullableInterfaceFieldDecoding(t *testing.T) { |
| 252 expected := `handle, err := decoder.ReadInterface() |
| 253 if err != nil { |
| 254 return err |
| 255 } |
| 256 if handle.IsValid() { |
| 257 handleOwner := bindings.NewMessagePipeHandleOwner(handle) |
| 258 s.IntField = SomeInterface_Pointer{handleOwner} |
| 259 } else { |
| 260 return &bindings.ValidationError{bindings.UnexpectedInvalidHandle, "unex
pected invalid handle"} |
| 261 }` |
| 262 |
| 263 encodingInfo := mockEncodingInfo{ |
| 264 isInterface: true, |
| 265 identifier: "s.IntField", |
| 266 readFunction: "ReadInterface", |
| 267 goType: "SomeInterface", |
| 268 } |
| 269 |
| 270 check(t, expected, "FieldDecodingTmpl", encodingInfo) |
| 271 } |
| 272 |
| 273 func TestDecodingInterfaceRequestFieldDecoding(t *testing.T) { |
| 274 expected := `handle, err := decoder.ReadMessagePipeHandle() |
| 275 if err != nil { |
| 276 return err |
| 277 } |
| 278 if handle.IsValid() { |
| 279 handleOwner := bindings.NewMessagePipeHandleOwner(handle) |
| 280 s.IntField = SomeInterface_Request{handleOwner} |
| 281 } else { |
| 282 return &bindings.ValidationError{bindings.UnexpectedInvalidHandle, "unex
pected invalid handle"} |
| 283 }` |
| 284 |
| 285 encodingInfo := mockEncodingInfo{ |
| 286 isInterface: true, |
| 287 isInterfaceRequest: true, |
| 288 identifier: "s.IntField", |
| 289 readFunction: "ReadMessagePipeHandle", |
| 290 goType: "SomeInterface", |
| 291 } |
| 292 |
| 293 check(t, expected, "FieldDecodingTmpl", encodingInfo) |
| 294 } |
| 295 |
| 296 func TestDecodingNullableInterfaceRequestFieldDecoding(t *testing.T) { |
| 297 expected := `handle, err := decoder.ReadMessagePipeHandle() |
| 298 if err != nil { |
| 299 return err |
| 300 } |
| 301 if handle.IsValid() { |
| 302 handleOwner := bindings.NewMessagePipeHandleOwner(handle) |
| 303 s.IntField = &SomeInterface_Request{handleOwner} |
| 304 } else { |
| 305 s.IntField = nil |
| 306 }` |
| 307 |
| 308 encodingInfo := mockEncodingInfo{ |
| 309 isInterface: true, |
| 310 isInterfaceRequest: true, |
| 311 isNullable: true, |
| 312 identifier: "s.IntField", |
| 313 readFunction: "ReadMessagePipeHandle", |
| 314 goType: "SomeInterface", |
| 315 } |
| 316 |
| 317 check(t, expected, "FieldDecodingTmpl", encodingInfo) |
| 318 } |
OLD | NEW |