...

Source file src/github.com/gogo/protobuf/test/indeximport-issue72/indeximportpb_test.go

Documentation: github.com/gogo/protobuf/test/indeximport-issue72

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

View as plain text