/test/oneof3/combos/unmarshaler/onepb_test.go
https://github.com/gogo/protobuf · Go · 372 lines · 353 code · 13 blank · 6 comment · 110 complexity · 484211b75d2317ef09e85d4d13c08987 MD5 · raw file
- // Code generated by protoc-gen-gogo. DO NOT EDIT.
- // source: combos/unmarshaler/one.proto
- package one
- import (
- fmt "fmt"
- _ "github.com/gogo/protobuf/gogoproto"
- github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb"
- github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto"
- proto "github.com/gogo/protobuf/proto"
- go_parser "go/parser"
- math "math"
- math_rand "math/rand"
- testing "testing"
- time "time"
- )
- // Reference imports to suppress errors if they are not otherwise used.
- var _ = proto.Marshal
- var _ = fmt.Errorf
- var _ = math.Inf
- func TestSubbyProto(t *testing.T) {
- seed := time.Now().UnixNano()
- popr := math_rand.New(math_rand.NewSource(seed))
- p := NewPopulatedSubby(popr, false)
- dAtA, err := github_com_gogo_protobuf_proto.Marshal(p)
- if err != nil {
- t.Fatalf("seed = %d, err = %v", seed, err)
- }
- msg := &Subby{}
- if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil {
- t.Fatalf("seed = %d, err = %v", seed, err)
- }
- littlefuzz := make([]byte, len(dAtA))
- copy(littlefuzz, dAtA)
- for i := range dAtA {
- dAtA[i] = byte(popr.Intn(256))
- }
- if err := p.VerboseEqual(msg); err != nil {
- t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
- }
- if !p.Equal(msg) {
- t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
- }
- if len(littlefuzz) > 0 {
- fuzzamount := 100
- for i := 0; i < fuzzamount; i++ {
- littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256))
- littlefuzz = append(littlefuzz, byte(popr.Intn(256)))
- }
- // shouldn't panic
- _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg)
- }
- }
- func TestSampleOneOfProto(t *testing.T) {
- seed := time.Now().UnixNano()
- popr := math_rand.New(math_rand.NewSource(seed))
- p := NewPopulatedSampleOneOf(popr, false)
- dAtA, err := github_com_gogo_protobuf_proto.Marshal(p)
- if err != nil {
- t.Fatalf("seed = %d, err = %v", seed, err)
- }
- msg := &SampleOneOf{}
- if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil {
- t.Fatalf("seed = %d, err = %v", seed, err)
- }
- littlefuzz := make([]byte, len(dAtA))
- copy(littlefuzz, dAtA)
- for i := range dAtA {
- dAtA[i] = byte(popr.Intn(256))
- }
- if err := p.VerboseEqual(msg); err != nil {
- t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
- }
- if !p.Equal(msg) {
- t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
- }
- if len(littlefuzz) > 0 {
- fuzzamount := 100
- for i := 0; i < fuzzamount; i++ {
- littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256))
- littlefuzz = append(littlefuzz, byte(popr.Intn(256)))
- }
- // shouldn't panic
- _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg)
- }
- }
- func TestSubbyJSON(t *testing.T) {
- seed := time.Now().UnixNano()
- popr := math_rand.New(math_rand.NewSource(seed))
- p := NewPopulatedSubby(popr, true)
- marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{}
- jsondata, err := marshaler.MarshalToString(p)
- if err != nil {
- t.Fatalf("seed = %d, err = %v", seed, err)
- }
- msg := &Subby{}
- err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg)
- if err != nil {
- t.Fatalf("seed = %d, err = %v", seed, err)
- }
- if err := p.VerboseEqual(msg); err != nil {
- t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
- }
- if !p.Equal(msg) {
- t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p)
- }
- }
- func TestSampleOneOfJSON(t *testing.T) {
- seed := time.Now().UnixNano()
- popr := math_rand.New(math_rand.NewSource(seed))
- p := NewPopulatedSampleOneOf(popr, true)
- marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{}
- jsondata, err := marshaler.MarshalToString(p)
- if err != nil {
- t.Fatalf("seed = %d, err = %v", seed, err)
- }
- msg := &SampleOneOf{}
- err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg)
- if err != nil {
- t.Fatalf("seed = %d, err = %v", seed, err)
- }
- if err := p.VerboseEqual(msg); err != nil {
- t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
- }
- if !p.Equal(msg) {
- t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p)
- }
- }
- func TestSubbyProtoText(t *testing.T) {
- seed := time.Now().UnixNano()
- popr := math_rand.New(math_rand.NewSource(seed))
- p := NewPopulatedSubby(popr, true)
- dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p)
- msg := &Subby{}
- if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil {
- t.Fatalf("seed = %d, err = %v", seed, err)
- }
- if err := p.VerboseEqual(msg); err != nil {
- t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
- }
- if !p.Equal(msg) {
- t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
- }
- }
- func TestSubbyProtoCompactText(t *testing.T) {
- seed := time.Now().UnixNano()
- popr := math_rand.New(math_rand.NewSource(seed))
- p := NewPopulatedSubby(popr, true)
- dAtA := github_com_gogo_protobuf_proto.CompactTextString(p)
- msg := &Subby{}
- if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil {
- t.Fatalf("seed = %d, err = %v", seed, err)
- }
- if err := p.VerboseEqual(msg); err != nil {
- t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
- }
- if !p.Equal(msg) {
- t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
- }
- }
- func TestSampleOneOfProtoText(t *testing.T) {
- seed := time.Now().UnixNano()
- popr := math_rand.New(math_rand.NewSource(seed))
- p := NewPopulatedSampleOneOf(popr, true)
- dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p)
- msg := &SampleOneOf{}
- if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil {
- t.Fatalf("seed = %d, err = %v", seed, err)
- }
- if err := p.VerboseEqual(msg); err != nil {
- t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
- }
- if !p.Equal(msg) {
- t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
- }
- }
- func TestSampleOneOfProtoCompactText(t *testing.T) {
- seed := time.Now().UnixNano()
- popr := math_rand.New(math_rand.NewSource(seed))
- p := NewPopulatedSampleOneOf(popr, true)
- dAtA := github_com_gogo_protobuf_proto.CompactTextString(p)
- msg := &SampleOneOf{}
- if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil {
- t.Fatalf("seed = %d, err = %v", seed, err)
- }
- if err := p.VerboseEqual(msg); err != nil {
- t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
- }
- if !p.Equal(msg) {
- t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
- }
- }
- func TestSubbyCompare(t *testing.T) {
- popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
- p := NewPopulatedSubby(popr, false)
- dAtA, err := github_com_gogo_protobuf_proto.Marshal(p)
- if err != nil {
- panic(err)
- }
- msg := &Subby{}
- if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil {
- panic(err)
- }
- if c := p.Compare(msg); c != 0 {
- t.Fatalf("%#v !Compare %#v, since %d", msg, p, c)
- }
- p2 := NewPopulatedSubby(popr, false)
- c := p.Compare(p2)
- c2 := p2.Compare(p)
- if c != (-1 * c2) {
- t.Errorf("p.Compare(p2) = %d", c)
- t.Errorf("p2.Compare(p) = %d", c2)
- t.Errorf("p = %#v", p)
- t.Errorf("p2 = %#v", p2)
- }
- }
- func TestSampleOneOfCompare(t *testing.T) {
- popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
- p := NewPopulatedSampleOneOf(popr, false)
- dAtA, err := github_com_gogo_protobuf_proto.Marshal(p)
- if err != nil {
- panic(err)
- }
- msg := &SampleOneOf{}
- if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil {
- panic(err)
- }
- if c := p.Compare(msg); c != 0 {
- t.Fatalf("%#v !Compare %#v, since %d", msg, p, c)
- }
- p2 := NewPopulatedSampleOneOf(popr, false)
- c := p.Compare(p2)
- c2 := p2.Compare(p)
- if c != (-1 * c2) {
- t.Errorf("p.Compare(p2) = %d", c)
- t.Errorf("p2.Compare(p) = %d", c2)
- t.Errorf("p = %#v", p)
- t.Errorf("p2 = %#v", p2)
- }
- }
- func TestOneDescription(t *testing.T) {
- OneDescription()
- }
- func TestSubbyVerboseEqual(t *testing.T) {
- popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
- p := NewPopulatedSubby(popr, false)
- dAtA, err := github_com_gogo_protobuf_proto.Marshal(p)
- if err != nil {
- panic(err)
- }
- msg := &Subby{}
- if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil {
- panic(err)
- }
- if err := p.VerboseEqual(msg); err != nil {
- t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err)
- }
- }
- func TestSampleOneOfVerboseEqual(t *testing.T) {
- popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
- p := NewPopulatedSampleOneOf(popr, false)
- dAtA, err := github_com_gogo_protobuf_proto.Marshal(p)
- if err != nil {
- panic(err)
- }
- msg := &SampleOneOf{}
- if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil {
- panic(err)
- }
- if err := p.VerboseEqual(msg); err != nil {
- t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err)
- }
- }
- func TestSubbyGoString(t *testing.T) {
- popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
- p := NewPopulatedSubby(popr, false)
- s1 := p.GoString()
- s2 := fmt.Sprintf("%#v", p)
- if s1 != s2 {
- t.Fatalf("GoString want %v got %v", s1, s2)
- }
- _, err := go_parser.ParseExpr(s1)
- if err != nil {
- t.Fatal(err)
- }
- }
- func TestSampleOneOfGoString(t *testing.T) {
- popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
- p := NewPopulatedSampleOneOf(popr, false)
- s1 := p.GoString()
- s2 := fmt.Sprintf("%#v", p)
- if s1 != s2 {
- t.Fatalf("GoString want %v got %v", s1, s2)
- }
- _, err := go_parser.ParseExpr(s1)
- if err != nil {
- t.Fatal(err)
- }
- }
- func TestSubbySize(t *testing.T) {
- seed := time.Now().UnixNano()
- popr := math_rand.New(math_rand.NewSource(seed))
- p := NewPopulatedSubby(popr, true)
- size2 := github_com_gogo_protobuf_proto.Size(p)
- dAtA, err := github_com_gogo_protobuf_proto.Marshal(p)
- if err != nil {
- t.Fatalf("seed = %d, err = %v", seed, err)
- }
- size := p.Size()
- if len(dAtA) != size {
- t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA))
- }
- if size2 != size {
- t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2)
- }
- size3 := github_com_gogo_protobuf_proto.Size(p)
- if size3 != size {
- t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3)
- }
- }
- func TestSampleOneOfSize(t *testing.T) {
- seed := time.Now().UnixNano()
- popr := math_rand.New(math_rand.NewSource(seed))
- p := NewPopulatedSampleOneOf(popr, true)
- size2 := github_com_gogo_protobuf_proto.Size(p)
- dAtA, err := github_com_gogo_protobuf_proto.Marshal(p)
- if err != nil {
- t.Fatalf("seed = %d, err = %v", seed, err)
- }
- size := p.Size()
- if len(dAtA) != size {
- t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA))
- }
- if size2 != size {
- t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2)
- }
- size3 := github_com_gogo_protobuf_proto.Size(p)
- if size3 != size {
- t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3)
- }
- }
- func TestSubbyStringer(t *testing.T) {
- popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
- p := NewPopulatedSubby(popr, false)
- s1 := p.String()
- s2 := fmt.Sprintf("%v", p)
- if s1 != s2 {
- t.Fatalf("String want %v got %v", s1, s2)
- }
- }
- func TestSampleOneOfStringer(t *testing.T) {
- popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
- p := NewPopulatedSampleOneOf(popr, false)
- s1 := p.String()
- s2 := fmt.Sprintf("%v", p)
- if s1 != s2 {
- t.Fatalf("String want %v got %v", s1, s2)
- }
- }
- //These tests are generated by github.com/gogo/protobuf/plugin/testgen