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

Unified Diff: mojom/generators/go/templates/decoding_test.go

Issue 2082173002: New go generator shakedown. (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 side-by-side diff with in-line comments
Download patch
Index: mojom/generators/go/templates/decoding_test.go
diff --git a/mojom/generators/go/templates/decoding_test.go b/mojom/generators/go/templates/decoding_test.go
index de706171d110f399b06c2132ad3a70eb05d1630a..08d60e08e22f1aa03aa34517f7ed49f0c44f7a70 100644
--- a/mojom/generators/go/templates/decoding_test.go
+++ b/mojom/generators/go/templates/decoding_test.go
@@ -247,3 +247,72 @@ s.EnumField = SomeEnum(value)`
check(t, expected, "FieldDecodingTmpl", encodingInfo)
}
+
+func TestDecodingNullableInterfaceFieldDecoding(t *testing.T) {
+ expected := `handle, err := decoder.ReadInterface()
+if err != nil {
+ return err
+}
+if handle.IsValid() {
+ handleOwner := bindings.NewMessagePipeHandleOwner(handle)
+ s.IntField = SomeInterface_Pointer{handleOwner}
+} else {
+ return &bindings.ValidationError{bindings.UnexpectedInvalidHandle, "unexpected invalid handle"}
+}`
+
+ encodingInfo := mockEncodingInfo{
+ isInterface: true,
+ identifier: "s.IntField",
+ readFunction: "ReadInterface",
+ goType: "SomeInterface",
+ }
+
+ check(t, expected, "FieldDecodingTmpl", encodingInfo)
+}
+
+func TestDecodingInterfaceRequestFieldDecoding(t *testing.T) {
+ expected := `handle, err := decoder.ReadMessagePipeHandle()
+if err != nil {
+ return err
+}
+if handle.IsValid() {
+ handleOwner := bindings.NewMessagePipeHandleOwner(handle)
+ s.IntField = SomeInterface_Request{handleOwner}
+} else {
+ return &bindings.ValidationError{bindings.UnexpectedInvalidHandle, "unexpected invalid handle"}
+}`
+
+ encodingInfo := mockEncodingInfo{
+ isInterface: true,
+ isInterfaceRequest: true,
+ identifier: "s.IntField",
+ readFunction: "ReadMessagePipeHandle",
+ goType: "SomeInterface",
+ }
+
+ check(t, expected, "FieldDecodingTmpl", encodingInfo)
+}
+
+func TestDecodingNullableInterfaceRequestFieldDecoding(t *testing.T) {
+ expected := `handle, err := decoder.ReadMessagePipeHandle()
+if err != nil {
+ return err
+}
+if handle.IsValid() {
+ handleOwner := bindings.NewMessagePipeHandleOwner(handle)
+ s.IntField = &SomeInterface_Request{handleOwner}
+} else {
+ s.IntField = nil
+}`
+
+ encodingInfo := mockEncodingInfo{
+ isInterface: true,
+ isInterfaceRequest: true,
+ isNullable: true,
+ identifier: "s.IntField",
+ readFunction: "ReadMessagePipeHandle",
+ goType: "SomeInterface",
+ }
+
+ check(t, expected, "FieldDecodingTmpl", encodingInfo)
+}

Powered by Google App Engine
This is Rietveld 408576698