...

Source file src/github.com/gogo/protobuf/test/importcustom-issue389/imported/apb_test.go

Documentation: github.com/gogo/protobuf/test/importcustom-issue389/imported

     1  // Code generated by protoc-gen-gogo. DO NOT EDIT.
     2  // source: a.proto
     3  
     4  package imported
     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 TestAProto(t *testing.T) {
    24  	seed := time.Now().UnixNano()
    25  	popr := math_rand.New(math_rand.NewSource(seed))
    26  	p := NewPopulatedA(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 := &A{}
    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 TestAMarshalTo(t *testing.T) {
    55  	seed := time.Now().UnixNano()
    56  	popr := math_rand.New(math_rand.NewSource(seed))
    57  	p := NewPopulatedA(popr, false)
    58  	size := p.Size()
    59  	dAtA := make([]byte, size)
    60  	for i := range dAtA {
    61  		dAtA[i] = byte(popr.Intn(256))
    62  	}
    63  	_, err := p.MarshalTo(dAtA)
    64  	if err != nil {
    65  		t.Fatalf("seed = %d, err = %v", seed, err)
    66  	}
    67  	msg := &A{}
    68  	if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil {
    69  		t.Fatalf("seed = %d, err = %v", seed, err)
    70  	}
    71  	for i := range dAtA {
    72  		dAtA[i] = byte(popr.Intn(256))
    73  	}
    74  	if !p.Equal(msg) {
    75  		t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
    76  	}
    77  }
    78  
    79  func TestAJSON(t *testing.T) {
    80  	seed := time.Now().UnixNano()
    81  	popr := math_rand.New(math_rand.NewSource(seed))
    82  	p := NewPopulatedA(popr, true)
    83  	marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{}
    84  	jsondata, err := marshaler.MarshalToString(p)
    85  	if err != nil {
    86  		t.Fatalf("seed = %d, err = %v", seed, err)
    87  	}
    88  	msg := &A{}
    89  	err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg)
    90  	if err != nil {
    91  		t.Fatalf("seed = %d, err = %v", seed, err)
    92  	}
    93  	if !p.Equal(msg) {
    94  		t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p)
    95  	}
    96  }
    97  func TestAProtoText(t *testing.T) {
    98  	seed := time.Now().UnixNano()
    99  	popr := math_rand.New(math_rand.NewSource(seed))
   100  	p := NewPopulatedA(popr, true)
   101  	dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p)
   102  	msg := &A{}
   103  	if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil {
   104  		t.Fatalf("seed = %d, err = %v", seed, err)
   105  	}
   106  	if !p.Equal(msg) {
   107  		t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
   108  	}
   109  }
   110  
   111  func TestAProtoCompactText(t *testing.T) {
   112  	seed := time.Now().UnixNano()
   113  	popr := math_rand.New(math_rand.NewSource(seed))
   114  	p := NewPopulatedA(popr, true)
   115  	dAtA := github_com_gogo_protobuf_proto.CompactTextString(p)
   116  	msg := &A{}
   117  	if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil {
   118  		t.Fatalf("seed = %d, err = %v", seed, err)
   119  	}
   120  	if !p.Equal(msg) {
   121  		t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
   122  	}
   123  }
   124  
   125  func TestASize(t *testing.T) {
   126  	seed := time.Now().UnixNano()
   127  	popr := math_rand.New(math_rand.NewSource(seed))
   128  	p := NewPopulatedA(popr, true)
   129  	size2 := github_com_gogo_protobuf_proto.Size(p)
   130  	dAtA, err := github_com_gogo_protobuf_proto.Marshal(p)
   131  	if err != nil {
   132  		t.Fatalf("seed = %d, err = %v", seed, err)
   133  	}
   134  	size := p.Size()
   135  	if len(dAtA) != size {
   136  		t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA))
   137  	}
   138  	if size2 != size {
   139  		t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2)
   140  	}
   141  	size3 := github_com_gogo_protobuf_proto.Size(p)
   142  	if size3 != size {
   143  		t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3)
   144  	}
   145  }
   146  
   147  //These tests are generated by github.com/gogo/protobuf/plugin/testgen
   148  

View as plain text