...

Source file src/github.com/gogo/protobuf/test/issue8/protopb_test.go

Documentation: github.com/gogo/protobuf/test/issue8

     1  // Code generated by protoc-gen-gogo. DO NOT EDIT.
     2  // source: proto.proto
     3  
     4  package proto
     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  	math "math"
    13  	math_rand "math/rand"
    14  	testing "testing"
    15  	time "time"
    16  )
    17  
    18  // Reference imports to suppress errors if they are not otherwise used.
    19  var _ = proto.Marshal
    20  var _ = fmt.Errorf
    21  var _ = math.Inf
    22  
    23  func TestFooProto(t *testing.T) {
    24  	seed := time.Now().UnixNano()
    25  	popr := math_rand.New(math_rand.NewSource(seed))
    26  	p := NewPopulatedFoo(popr, false)
    27  	dAtA, err := github_com_gogo_protobuf_proto.Marshal(p)
    28  	if err != nil {
    29  		t.Fatalf("seed = %d, err = %v", seed, err)
    30  	}
    31  	msg := &Foo{}
    32  	if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil {
    33  		t.Fatalf("seed = %d, err = %v", seed, err)
    34  	}
    35  	littlefuzz := make([]byte, len(dAtA))
    36  	copy(littlefuzz, dAtA)
    37  	for i := range dAtA {
    38  		dAtA[i] = byte(popr.Intn(256))
    39  	}
    40  	if !p.Equal(msg) {
    41  		t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
    42  	}
    43  	if len(littlefuzz) > 0 {
    44  		fuzzamount := 100
    45  		for i := 0; i < fuzzamount; i++ {
    46  			littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256))
    47  			littlefuzz = append(littlefuzz, byte(popr.Intn(256)))
    48  		}
    49  		// shouldn't panic
    50  		_ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg)
    51  	}
    52  }
    53  
    54  func TestFooJSON(t *testing.T) {
    55  	seed := time.Now().UnixNano()
    56  	popr := math_rand.New(math_rand.NewSource(seed))
    57  	p := NewPopulatedFoo(popr, true)
    58  	marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{}
    59  	jsondata, err := marshaler.MarshalToString(p)
    60  	if err != nil {
    61  		t.Fatalf("seed = %d, err = %v", seed, err)
    62  	}
    63  	msg := &Foo{}
    64  	err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg)
    65  	if err != nil {
    66  		t.Fatalf("seed = %d, err = %v", seed, err)
    67  	}
    68  	if !p.Equal(msg) {
    69  		t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p)
    70  	}
    71  }
    72  func TestFooProtoText(t *testing.T) {
    73  	seed := time.Now().UnixNano()
    74  	popr := math_rand.New(math_rand.NewSource(seed))
    75  	p := NewPopulatedFoo(popr, true)
    76  	dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p)
    77  	msg := &Foo{}
    78  	if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil {
    79  		t.Fatalf("seed = %d, err = %v", seed, err)
    80  	}
    81  	if !p.Equal(msg) {
    82  		t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
    83  	}
    84  }
    85  
    86  func TestFooProtoCompactText(t *testing.T) {
    87  	seed := time.Now().UnixNano()
    88  	popr := math_rand.New(math_rand.NewSource(seed))
    89  	p := NewPopulatedFoo(popr, true)
    90  	dAtA := github_com_gogo_protobuf_proto.CompactTextString(p)
    91  	msg := &Foo{}
    92  	if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil {
    93  		t.Fatalf("seed = %d, err = %v", seed, err)
    94  	}
    95  	if !p.Equal(msg) {
    96  		t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
    97  	}
    98  }
    99  
   100  //These tests are generated by github.com/gogo/protobuf/plugin/testgen
   101  

View as plain text