...

Source file src/github.com/gogo/protobuf/test/importduplicate/sortkeys/sortablepb_test.go

Documentation: github.com/gogo/protobuf/test/importduplicate/sortkeys

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

View as plain text