...

Source file src/github.com/gogo/protobuf/test/castvalue/combos/marshaler/castvaluepb_test.go

Documentation: github.com/gogo/protobuf/test/castvalue/combos/marshaler

     1  // Code generated by protoc-gen-gogo. DO NOT EDIT.
     2  // source: combos/marshaler/castvalue.proto
     3  
     4  package castvalue
     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 TestCastawayProto(t *testing.T) {
    25  	seed := time.Now().UnixNano()
    26  	popr := math_rand.New(math_rand.NewSource(seed))
    27  	p := NewPopulatedCastaway(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 := &Castaway{}
    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 err := p.VerboseEqual(msg); err != nil {
    42  		t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
    43  	}
    44  	if !p.Equal(msg) {
    45  		t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
    46  	}
    47  	if len(littlefuzz) > 0 {
    48  		fuzzamount := 100
    49  		for i := 0; i < fuzzamount; i++ {
    50  			littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256))
    51  			littlefuzz = append(littlefuzz, byte(popr.Intn(256)))
    52  		}
    53  		// shouldn't panic
    54  		_ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg)
    55  	}
    56  }
    57  
    58  func TestCastawayMarshalTo(t *testing.T) {
    59  	seed := time.Now().UnixNano()
    60  	popr := math_rand.New(math_rand.NewSource(seed))
    61  	p := NewPopulatedCastaway(popr, false)
    62  	size := p.Size()
    63  	dAtA := make([]byte, size)
    64  	for i := range dAtA {
    65  		dAtA[i] = byte(popr.Intn(256))
    66  	}
    67  	_, err := p.MarshalTo(dAtA)
    68  	if err != nil {
    69  		t.Fatalf("seed = %d, err = %v", seed, err)
    70  	}
    71  	msg := &Castaway{}
    72  	if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil {
    73  		t.Fatalf("seed = %d, err = %v", seed, err)
    74  	}
    75  	for i := range dAtA {
    76  		dAtA[i] = byte(popr.Intn(256))
    77  	}
    78  	if err := p.VerboseEqual(msg); err != nil {
    79  		t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
    80  	}
    81  	if !p.Equal(msg) {
    82  		t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
    83  	}
    84  }
    85  
    86  func BenchmarkCastawayProtoMarshal(b *testing.B) {
    87  	popr := math_rand.New(math_rand.NewSource(616))
    88  	total := 0
    89  	pops := make([]*Castaway, 10000)
    90  	for i := 0; i < 10000; i++ {
    91  		pops[i] = NewPopulatedCastaway(popr, false)
    92  	}
    93  	b.ResetTimer()
    94  	for i := 0; i < b.N; i++ {
    95  		dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000])
    96  		if err != nil {
    97  			panic(err)
    98  		}
    99  		total += len(dAtA)
   100  	}
   101  	b.SetBytes(int64(total / b.N))
   102  }
   103  
   104  func BenchmarkCastawayProtoUnmarshal(b *testing.B) {
   105  	popr := math_rand.New(math_rand.NewSource(616))
   106  	total := 0
   107  	datas := make([][]byte, 10000)
   108  	for i := 0; i < 10000; i++ {
   109  		dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedCastaway(popr, false))
   110  		if err != nil {
   111  			panic(err)
   112  		}
   113  		datas[i] = dAtA
   114  	}
   115  	msg := &Castaway{}
   116  	b.ResetTimer()
   117  	for i := 0; i < b.N; i++ {
   118  		total += len(datas[i%10000])
   119  		if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil {
   120  			panic(err)
   121  		}
   122  	}
   123  	b.SetBytes(int64(total / b.N))
   124  }
   125  
   126  func TestWilsonProto(t *testing.T) {
   127  	seed := time.Now().UnixNano()
   128  	popr := math_rand.New(math_rand.NewSource(seed))
   129  	p := NewPopulatedWilson(popr, false)
   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  	msg := &Wilson{}
   135  	if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil {
   136  		t.Fatalf("seed = %d, err = %v", seed, err)
   137  	}
   138  	littlefuzz := make([]byte, len(dAtA))
   139  	copy(littlefuzz, dAtA)
   140  	for i := range dAtA {
   141  		dAtA[i] = byte(popr.Intn(256))
   142  	}
   143  	if err := p.VerboseEqual(msg); err != nil {
   144  		t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
   145  	}
   146  	if !p.Equal(msg) {
   147  		t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
   148  	}
   149  	if len(littlefuzz) > 0 {
   150  		fuzzamount := 100
   151  		for i := 0; i < fuzzamount; i++ {
   152  			littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256))
   153  			littlefuzz = append(littlefuzz, byte(popr.Intn(256)))
   154  		}
   155  		// shouldn't panic
   156  		_ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg)
   157  	}
   158  }
   159  
   160  func TestWilsonMarshalTo(t *testing.T) {
   161  	seed := time.Now().UnixNano()
   162  	popr := math_rand.New(math_rand.NewSource(seed))
   163  	p := NewPopulatedWilson(popr, false)
   164  	size := p.Size()
   165  	dAtA := make([]byte, size)
   166  	for i := range dAtA {
   167  		dAtA[i] = byte(popr.Intn(256))
   168  	}
   169  	_, err := p.MarshalTo(dAtA)
   170  	if err != nil {
   171  		t.Fatalf("seed = %d, err = %v", seed, err)
   172  	}
   173  	msg := &Wilson{}
   174  	if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil {
   175  		t.Fatalf("seed = %d, err = %v", seed, err)
   176  	}
   177  	for i := range dAtA {
   178  		dAtA[i] = byte(popr.Intn(256))
   179  	}
   180  	if err := p.VerboseEqual(msg); err != nil {
   181  		t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
   182  	}
   183  	if !p.Equal(msg) {
   184  		t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
   185  	}
   186  }
   187  
   188  func BenchmarkWilsonProtoMarshal(b *testing.B) {
   189  	popr := math_rand.New(math_rand.NewSource(616))
   190  	total := 0
   191  	pops := make([]*Wilson, 10000)
   192  	for i := 0; i < 10000; i++ {
   193  		pops[i] = NewPopulatedWilson(popr, false)
   194  	}
   195  	b.ResetTimer()
   196  	for i := 0; i < b.N; i++ {
   197  		dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000])
   198  		if err != nil {
   199  			panic(err)
   200  		}
   201  		total += len(dAtA)
   202  	}
   203  	b.SetBytes(int64(total / b.N))
   204  }
   205  
   206  func BenchmarkWilsonProtoUnmarshal(b *testing.B) {
   207  	popr := math_rand.New(math_rand.NewSource(616))
   208  	total := 0
   209  	datas := make([][]byte, 10000)
   210  	for i := 0; i < 10000; i++ {
   211  		dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedWilson(popr, false))
   212  		if err != nil {
   213  			panic(err)
   214  		}
   215  		datas[i] = dAtA
   216  	}
   217  	msg := &Wilson{}
   218  	b.ResetTimer()
   219  	for i := 0; i < b.N; i++ {
   220  		total += len(datas[i%10000])
   221  		if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil {
   222  			panic(err)
   223  		}
   224  	}
   225  	b.SetBytes(int64(total / b.N))
   226  }
   227  
   228  func TestCastawayJSON(t *testing.T) {
   229  	seed := time.Now().UnixNano()
   230  	popr := math_rand.New(math_rand.NewSource(seed))
   231  	p := NewPopulatedCastaway(popr, true)
   232  	marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{}
   233  	jsondata, err := marshaler.MarshalToString(p)
   234  	if err != nil {
   235  		t.Fatalf("seed = %d, err = %v", seed, err)
   236  	}
   237  	msg := &Castaway{}
   238  	err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg)
   239  	if err != nil {
   240  		t.Fatalf("seed = %d, err = %v", seed, err)
   241  	}
   242  	if err := p.VerboseEqual(msg); err != nil {
   243  		t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
   244  	}
   245  	if !p.Equal(msg) {
   246  		t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p)
   247  	}
   248  }
   249  func TestWilsonJSON(t *testing.T) {
   250  	seed := time.Now().UnixNano()
   251  	popr := math_rand.New(math_rand.NewSource(seed))
   252  	p := NewPopulatedWilson(popr, true)
   253  	marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{}
   254  	jsondata, err := marshaler.MarshalToString(p)
   255  	if err != nil {
   256  		t.Fatalf("seed = %d, err = %v", seed, err)
   257  	}
   258  	msg := &Wilson{}
   259  	err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg)
   260  	if err != nil {
   261  		t.Fatalf("seed = %d, err = %v", seed, err)
   262  	}
   263  	if err := p.VerboseEqual(msg); err != nil {
   264  		t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
   265  	}
   266  	if !p.Equal(msg) {
   267  		t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p)
   268  	}
   269  }
   270  func TestCastawayProtoText(t *testing.T) {
   271  	seed := time.Now().UnixNano()
   272  	popr := math_rand.New(math_rand.NewSource(seed))
   273  	p := NewPopulatedCastaway(popr, true)
   274  	dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p)
   275  	msg := &Castaway{}
   276  	if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil {
   277  		t.Fatalf("seed = %d, err = %v", seed, err)
   278  	}
   279  	if err := p.VerboseEqual(msg); err != nil {
   280  		t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
   281  	}
   282  	if !p.Equal(msg) {
   283  		t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
   284  	}
   285  }
   286  
   287  func TestCastawayProtoCompactText(t *testing.T) {
   288  	seed := time.Now().UnixNano()
   289  	popr := math_rand.New(math_rand.NewSource(seed))
   290  	p := NewPopulatedCastaway(popr, true)
   291  	dAtA := github_com_gogo_protobuf_proto.CompactTextString(p)
   292  	msg := &Castaway{}
   293  	if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil {
   294  		t.Fatalf("seed = %d, err = %v", seed, err)
   295  	}
   296  	if err := p.VerboseEqual(msg); err != nil {
   297  		t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
   298  	}
   299  	if !p.Equal(msg) {
   300  		t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
   301  	}
   302  }
   303  
   304  func TestWilsonProtoText(t *testing.T) {
   305  	seed := time.Now().UnixNano()
   306  	popr := math_rand.New(math_rand.NewSource(seed))
   307  	p := NewPopulatedWilson(popr, true)
   308  	dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p)
   309  	msg := &Wilson{}
   310  	if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil {
   311  		t.Fatalf("seed = %d, err = %v", seed, err)
   312  	}
   313  	if err := p.VerboseEqual(msg); err != nil {
   314  		t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
   315  	}
   316  	if !p.Equal(msg) {
   317  		t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
   318  	}
   319  }
   320  
   321  func TestWilsonProtoCompactText(t *testing.T) {
   322  	seed := time.Now().UnixNano()
   323  	popr := math_rand.New(math_rand.NewSource(seed))
   324  	p := NewPopulatedWilson(popr, true)
   325  	dAtA := github_com_gogo_protobuf_proto.CompactTextString(p)
   326  	msg := &Wilson{}
   327  	if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil {
   328  		t.Fatalf("seed = %d, err = %v", seed, err)
   329  	}
   330  	if err := p.VerboseEqual(msg); err != nil {
   331  		t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
   332  	}
   333  	if !p.Equal(msg) {
   334  		t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
   335  	}
   336  }
   337  
   338  func TestCastvalueDescription(t *testing.T) {
   339  	CastvalueDescription()
   340  }
   341  func TestCastawayVerboseEqual(t *testing.T) {
   342  	popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
   343  	p := NewPopulatedCastaway(popr, false)
   344  	dAtA, err := github_com_gogo_protobuf_proto.Marshal(p)
   345  	if err != nil {
   346  		panic(err)
   347  	}
   348  	msg := &Castaway{}
   349  	if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil {
   350  		panic(err)
   351  	}
   352  	if err := p.VerboseEqual(msg); err != nil {
   353  		t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err)
   354  	}
   355  }
   356  func TestWilsonVerboseEqual(t *testing.T) {
   357  	popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
   358  	p := NewPopulatedWilson(popr, false)
   359  	dAtA, err := github_com_gogo_protobuf_proto.Marshal(p)
   360  	if err != nil {
   361  		panic(err)
   362  	}
   363  	msg := &Wilson{}
   364  	if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil {
   365  		panic(err)
   366  	}
   367  	if err := p.VerboseEqual(msg); err != nil {
   368  		t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err)
   369  	}
   370  }
   371  func TestCastawayFace(t *testing.T) {
   372  	popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
   373  	p := NewPopulatedCastaway(popr, true)
   374  	msg := p.TestProto()
   375  	if !p.Equal(msg) {
   376  		t.Fatalf("%#v !Face Equal %#v", msg, p)
   377  	}
   378  }
   379  func TestWilsonFace(t *testing.T) {
   380  	popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
   381  	p := NewPopulatedWilson(popr, true)
   382  	msg := p.TestProto()
   383  	if !p.Equal(msg) {
   384  		t.Fatalf("%#v !Face Equal %#v", msg, p)
   385  	}
   386  }
   387  func TestCastawayGoString(t *testing.T) {
   388  	popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
   389  	p := NewPopulatedCastaway(popr, false)
   390  	s1 := p.GoString()
   391  	s2 := fmt.Sprintf("%#v", p)
   392  	if s1 != s2 {
   393  		t.Fatalf("GoString want %v got %v", s1, s2)
   394  	}
   395  	_, err := go_parser.ParseExpr(s1)
   396  	if err != nil {
   397  		t.Fatal(err)
   398  	}
   399  }
   400  func TestWilsonGoString(t *testing.T) {
   401  	popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
   402  	p := NewPopulatedWilson(popr, false)
   403  	s1 := p.GoString()
   404  	s2 := fmt.Sprintf("%#v", p)
   405  	if s1 != s2 {
   406  		t.Fatalf("GoString want %v got %v", s1, s2)
   407  	}
   408  	_, err := go_parser.ParseExpr(s1)
   409  	if err != nil {
   410  		t.Fatal(err)
   411  	}
   412  }
   413  func TestCastawaySize(t *testing.T) {
   414  	seed := time.Now().UnixNano()
   415  	popr := math_rand.New(math_rand.NewSource(seed))
   416  	p := NewPopulatedCastaway(popr, true)
   417  	size2 := github_com_gogo_protobuf_proto.Size(p)
   418  	dAtA, err := github_com_gogo_protobuf_proto.Marshal(p)
   419  	if err != nil {
   420  		t.Fatalf("seed = %d, err = %v", seed, err)
   421  	}
   422  	size := p.Size()
   423  	if len(dAtA) != size {
   424  		t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA))
   425  	}
   426  	if size2 != size {
   427  		t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2)
   428  	}
   429  	size3 := github_com_gogo_protobuf_proto.Size(p)
   430  	if size3 != size {
   431  		t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3)
   432  	}
   433  }
   434  
   435  func BenchmarkCastawaySize(b *testing.B) {
   436  	popr := math_rand.New(math_rand.NewSource(616))
   437  	total := 0
   438  	pops := make([]*Castaway, 1000)
   439  	for i := 0; i < 1000; i++ {
   440  		pops[i] = NewPopulatedCastaway(popr, false)
   441  	}
   442  	b.ResetTimer()
   443  	for i := 0; i < b.N; i++ {
   444  		total += pops[i%1000].Size()
   445  	}
   446  	b.SetBytes(int64(total / b.N))
   447  }
   448  
   449  func TestWilsonSize(t *testing.T) {
   450  	seed := time.Now().UnixNano()
   451  	popr := math_rand.New(math_rand.NewSource(seed))
   452  	p := NewPopulatedWilson(popr, true)
   453  	size2 := github_com_gogo_protobuf_proto.Size(p)
   454  	dAtA, err := github_com_gogo_protobuf_proto.Marshal(p)
   455  	if err != nil {
   456  		t.Fatalf("seed = %d, err = %v", seed, err)
   457  	}
   458  	size := p.Size()
   459  	if len(dAtA) != size {
   460  		t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA))
   461  	}
   462  	if size2 != size {
   463  		t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2)
   464  	}
   465  	size3 := github_com_gogo_protobuf_proto.Size(p)
   466  	if size3 != size {
   467  		t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3)
   468  	}
   469  }
   470  
   471  func BenchmarkWilsonSize(b *testing.B) {
   472  	popr := math_rand.New(math_rand.NewSource(616))
   473  	total := 0
   474  	pops := make([]*Wilson, 1000)
   475  	for i := 0; i < 1000; i++ {
   476  		pops[i] = NewPopulatedWilson(popr, false)
   477  	}
   478  	b.ResetTimer()
   479  	for i := 0; i < b.N; i++ {
   480  		total += pops[i%1000].Size()
   481  	}
   482  	b.SetBytes(int64(total / b.N))
   483  }
   484  
   485  func TestCastawayStringer(t *testing.T) {
   486  	popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
   487  	p := NewPopulatedCastaway(popr, false)
   488  	s1 := p.String()
   489  	s2 := fmt.Sprintf("%v", p)
   490  	if s1 != s2 {
   491  		t.Fatalf("String want %v got %v", s1, s2)
   492  	}
   493  }
   494  func TestWilsonStringer(t *testing.T) {
   495  	popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
   496  	p := NewPopulatedWilson(popr, false)
   497  	s1 := p.String()
   498  	s2 := fmt.Sprintf("%v", p)
   499  	if s1 != s2 {
   500  		t.Fatalf("String want %v got %v", s1, s2)
   501  	}
   502  }
   503  
   504  //These tests are generated by github.com/gogo/protobuf/plugin/testgen
   505  

View as plain text