github.com/gogo/protobuf@v1.3.2/test/issue312/events/eventspb_test.go (about) 1 // Code generated by protoc-gen-gogo. DO NOT EDIT. 2 // source: events.proto 3 4 package events 5 6 import ( 7 fmt "fmt" 8 _ "github.com/gogo/protobuf/gogoproto" 9 github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" 10 github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" 11 proto "github.com/gogo/protobuf/proto" 12 _ "github.com/gogo/protobuf/test/issue312" 13 go_parser "go/parser" 14 math "math" 15 math_rand "math/rand" 16 testing "testing" 17 time "time" 18 ) 19 20 // Reference imports to suppress errors if they are not otherwise used. 21 var _ = proto.Marshal 22 var _ = fmt.Errorf 23 var _ = math.Inf 24 25 func TestSubtypeProto(t *testing.T) { 26 seed := time.Now().UnixNano() 27 popr := math_rand.New(math_rand.NewSource(seed)) 28 p := NewPopulatedSubtype(popr, false) 29 dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) 30 if err != nil { 31 t.Fatalf("seed = %d, err = %v", seed, err) 32 } 33 msg := &Subtype{} 34 if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { 35 t.Fatalf("seed = %d, err = %v", seed, err) 36 } 37 littlefuzz := make([]byte, len(dAtA)) 38 copy(littlefuzz, dAtA) 39 for i := range dAtA { 40 dAtA[i] = byte(popr.Intn(256)) 41 } 42 if !p.Equal(msg) { 43 t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) 44 } 45 if len(littlefuzz) > 0 { 46 fuzzamount := 100 47 for i := 0; i < fuzzamount; i++ { 48 littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) 49 littlefuzz = append(littlefuzz, byte(popr.Intn(256))) 50 } 51 // shouldn't panic 52 _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) 53 } 54 } 55 56 func TestSubtypeJSON(t *testing.T) { 57 seed := time.Now().UnixNano() 58 popr := math_rand.New(math_rand.NewSource(seed)) 59 p := NewPopulatedSubtype(popr, true) 60 marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} 61 jsondata, err := marshaler.MarshalToString(p) 62 if err != nil { 63 t.Fatalf("seed = %d, err = %v", seed, err) 64 } 65 msg := &Subtype{} 66 err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) 67 if err != nil { 68 t.Fatalf("seed = %d, err = %v", seed, err) 69 } 70 if !p.Equal(msg) { 71 t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) 72 } 73 } 74 func TestSubtypeProtoText(t *testing.T) { 75 seed := time.Now().UnixNano() 76 popr := math_rand.New(math_rand.NewSource(seed)) 77 p := NewPopulatedSubtype(popr, true) 78 dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) 79 msg := &Subtype{} 80 if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { 81 t.Fatalf("seed = %d, err = %v", seed, err) 82 } 83 if !p.Equal(msg) { 84 t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) 85 } 86 } 87 88 func TestSubtypeProtoCompactText(t *testing.T) { 89 seed := time.Now().UnixNano() 90 popr := math_rand.New(math_rand.NewSource(seed)) 91 p := NewPopulatedSubtype(popr, true) 92 dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) 93 msg := &Subtype{} 94 if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { 95 t.Fatalf("seed = %d, err = %v", seed, err) 96 } 97 if !p.Equal(msg) { 98 t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) 99 } 100 } 101 102 func TestSubtypeGoString(t *testing.T) { 103 popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) 104 p := NewPopulatedSubtype(popr, false) 105 s1 := p.GoString() 106 s2 := fmt.Sprintf("%#v", p) 107 if s1 != s2 { 108 t.Fatalf("GoString want %v got %v", s1, s2) 109 } 110 _, err := go_parser.ParseExpr(s1) 111 if err != nil { 112 t.Fatal(err) 113 } 114 } 115 116 //These tests are generated by github.com/gogo/protobuf/plugin/testgen