...

Source file src/github.com/gogo/protobuf/test/oneof3/combos/unmarshaler/onepb_test.go

Documentation: github.com/gogo/protobuf/test/oneof3/combos/unmarshaler

     1  // Code generated by protoc-gen-gogo. DO NOT EDIT.
     2  // source: combos/unmarshaler/one.proto
     3  
     4  package one
     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 TestSubbyProto(t *testing.T) {
    25  	seed := time.Now().UnixNano()
    26  	popr := math_rand.New(math_rand.NewSource(seed))
    27  	p := NewPopulatedSubby(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 := &Subby{}
    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 TestSampleOneOfProto(t *testing.T) {
    59  	seed := time.Now().UnixNano()
    60  	popr := math_rand.New(math_rand.NewSource(seed))
    61  	p := NewPopulatedSampleOneOf(popr, false)
    62  	dAtA, err := github_com_gogo_protobuf_proto.Marshal(p)
    63  	if err != nil {
    64  		t.Fatalf("seed = %d, err = %v", seed, err)
    65  	}
    66  	msg := &SampleOneOf{}
    67  	if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil {
    68  		t.Fatalf("seed = %d, err = %v", seed, err)
    69  	}
    70  	littlefuzz := make([]byte, len(dAtA))
    71  	copy(littlefuzz, dAtA)
    72  	for i := range dAtA {
    73  		dAtA[i] = byte(popr.Intn(256))
    74  	}
    75  	if err := p.VerboseEqual(msg); err != nil {
    76  		t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
    77  	}
    78  	if !p.Equal(msg) {
    79  		t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
    80  	}
    81  	if len(littlefuzz) > 0 {
    82  		fuzzamount := 100
    83  		for i := 0; i < fuzzamount; i++ {
    84  			littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256))
    85  			littlefuzz = append(littlefuzz, byte(popr.Intn(256)))
    86  		}
    87  		// shouldn't panic
    88  		_ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg)
    89  	}
    90  }
    91  
    92  func TestSubbyJSON(t *testing.T) {
    93  	seed := time.Now().UnixNano()
    94  	popr := math_rand.New(math_rand.NewSource(seed))
    95  	p := NewPopulatedSubby(popr, true)
    96  	marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{}
    97  	jsondata, err := marshaler.MarshalToString(p)
    98  	if err != nil {
    99  		t.Fatalf("seed = %d, err = %v", seed, err)
   100  	}
   101  	msg := &Subby{}
   102  	err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg)
   103  	if err != nil {
   104  		t.Fatalf("seed = %d, err = %v", seed, err)
   105  	}
   106  	if err := p.VerboseEqual(msg); err != nil {
   107  		t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
   108  	}
   109  	if !p.Equal(msg) {
   110  		t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p)
   111  	}
   112  }
   113  func TestSampleOneOfJSON(t *testing.T) {
   114  	seed := time.Now().UnixNano()
   115  	popr := math_rand.New(math_rand.NewSource(seed))
   116  	p := NewPopulatedSampleOneOf(popr, true)
   117  	marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{}
   118  	jsondata, err := marshaler.MarshalToString(p)
   119  	if err != nil {
   120  		t.Fatalf("seed = %d, err = %v", seed, err)
   121  	}
   122  	msg := &SampleOneOf{}
   123  	err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg)
   124  	if err != nil {
   125  		t.Fatalf("seed = %d, err = %v", seed, err)
   126  	}
   127  	if err := p.VerboseEqual(msg); err != nil {
   128  		t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
   129  	}
   130  	if !p.Equal(msg) {
   131  		t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p)
   132  	}
   133  }
   134  func TestSubbyProtoText(t *testing.T) {
   135  	seed := time.Now().UnixNano()
   136  	popr := math_rand.New(math_rand.NewSource(seed))
   137  	p := NewPopulatedSubby(popr, true)
   138  	dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p)
   139  	msg := &Subby{}
   140  	if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil {
   141  		t.Fatalf("seed = %d, err = %v", seed, err)
   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  }
   150  
   151  func TestSubbyProtoCompactText(t *testing.T) {
   152  	seed := time.Now().UnixNano()
   153  	popr := math_rand.New(math_rand.NewSource(seed))
   154  	p := NewPopulatedSubby(popr, true)
   155  	dAtA := github_com_gogo_protobuf_proto.CompactTextString(p)
   156  	msg := &Subby{}
   157  	if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil {
   158  		t.Fatalf("seed = %d, err = %v", seed, err)
   159  	}
   160  	if err := p.VerboseEqual(msg); err != nil {
   161  		t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
   162  	}
   163  	if !p.Equal(msg) {
   164  		t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
   165  	}
   166  }
   167  
   168  func TestSampleOneOfProtoText(t *testing.T) {
   169  	seed := time.Now().UnixNano()
   170  	popr := math_rand.New(math_rand.NewSource(seed))
   171  	p := NewPopulatedSampleOneOf(popr, true)
   172  	dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p)
   173  	msg := &SampleOneOf{}
   174  	if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil {
   175  		t.Fatalf("seed = %d, err = %v", seed, err)
   176  	}
   177  	if err := p.VerboseEqual(msg); err != nil {
   178  		t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
   179  	}
   180  	if !p.Equal(msg) {
   181  		t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
   182  	}
   183  }
   184  
   185  func TestSampleOneOfProtoCompactText(t *testing.T) {
   186  	seed := time.Now().UnixNano()
   187  	popr := math_rand.New(math_rand.NewSource(seed))
   188  	p := NewPopulatedSampleOneOf(popr, true)
   189  	dAtA := github_com_gogo_protobuf_proto.CompactTextString(p)
   190  	msg := &SampleOneOf{}
   191  	if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil {
   192  		t.Fatalf("seed = %d, err = %v", seed, err)
   193  	}
   194  	if err := p.VerboseEqual(msg); err != nil {
   195  		t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
   196  	}
   197  	if !p.Equal(msg) {
   198  		t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
   199  	}
   200  }
   201  
   202  func TestSubbyCompare(t *testing.T) {
   203  	popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
   204  	p := NewPopulatedSubby(popr, false)
   205  	dAtA, err := github_com_gogo_protobuf_proto.Marshal(p)
   206  	if err != nil {
   207  		panic(err)
   208  	}
   209  	msg := &Subby{}
   210  	if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil {
   211  		panic(err)
   212  	}
   213  	if c := p.Compare(msg); c != 0 {
   214  		t.Fatalf("%#v !Compare %#v, since %d", msg, p, c)
   215  	}
   216  	p2 := NewPopulatedSubby(popr, false)
   217  	c := p.Compare(p2)
   218  	c2 := p2.Compare(p)
   219  	if c != (-1 * c2) {
   220  		t.Errorf("p.Compare(p2) = %d", c)
   221  		t.Errorf("p2.Compare(p) = %d", c2)
   222  		t.Errorf("p = %#v", p)
   223  		t.Errorf("p2 = %#v", p2)
   224  	}
   225  }
   226  func TestSampleOneOfCompare(t *testing.T) {
   227  	popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
   228  	p := NewPopulatedSampleOneOf(popr, false)
   229  	dAtA, err := github_com_gogo_protobuf_proto.Marshal(p)
   230  	if err != nil {
   231  		panic(err)
   232  	}
   233  	msg := &SampleOneOf{}
   234  	if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil {
   235  		panic(err)
   236  	}
   237  	if c := p.Compare(msg); c != 0 {
   238  		t.Fatalf("%#v !Compare %#v, since %d", msg, p, c)
   239  	}
   240  	p2 := NewPopulatedSampleOneOf(popr, false)
   241  	c := p.Compare(p2)
   242  	c2 := p2.Compare(p)
   243  	if c != (-1 * c2) {
   244  		t.Errorf("p.Compare(p2) = %d", c)
   245  		t.Errorf("p2.Compare(p) = %d", c2)
   246  		t.Errorf("p = %#v", p)
   247  		t.Errorf("p2 = %#v", p2)
   248  	}
   249  }
   250  func TestOneDescription(t *testing.T) {
   251  	OneDescription()
   252  }
   253  func TestSubbyVerboseEqual(t *testing.T) {
   254  	popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
   255  	p := NewPopulatedSubby(popr, false)
   256  	dAtA, err := github_com_gogo_protobuf_proto.Marshal(p)
   257  	if err != nil {
   258  		panic(err)
   259  	}
   260  	msg := &Subby{}
   261  	if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil {
   262  		panic(err)
   263  	}
   264  	if err := p.VerboseEqual(msg); err != nil {
   265  		t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err)
   266  	}
   267  }
   268  func TestSampleOneOfVerboseEqual(t *testing.T) {
   269  	popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
   270  	p := NewPopulatedSampleOneOf(popr, false)
   271  	dAtA, err := github_com_gogo_protobuf_proto.Marshal(p)
   272  	if err != nil {
   273  		panic(err)
   274  	}
   275  	msg := &SampleOneOf{}
   276  	if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil {
   277  		panic(err)
   278  	}
   279  	if err := p.VerboseEqual(msg); err != nil {
   280  		t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err)
   281  	}
   282  }
   283  func TestSubbyGoString(t *testing.T) {
   284  	popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
   285  	p := NewPopulatedSubby(popr, false)
   286  	s1 := p.GoString()
   287  	s2 := fmt.Sprintf("%#v", p)
   288  	if s1 != s2 {
   289  		t.Fatalf("GoString want %v got %v", s1, s2)
   290  	}
   291  	_, err := go_parser.ParseExpr(s1)
   292  	if err != nil {
   293  		t.Fatal(err)
   294  	}
   295  }
   296  func TestSampleOneOfGoString(t *testing.T) {
   297  	popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
   298  	p := NewPopulatedSampleOneOf(popr, false)
   299  	s1 := p.GoString()
   300  	s2 := fmt.Sprintf("%#v", p)
   301  	if s1 != s2 {
   302  		t.Fatalf("GoString want %v got %v", s1, s2)
   303  	}
   304  	_, err := go_parser.ParseExpr(s1)
   305  	if err != nil {
   306  		t.Fatal(err)
   307  	}
   308  }
   309  func TestSubbySize(t *testing.T) {
   310  	seed := time.Now().UnixNano()
   311  	popr := math_rand.New(math_rand.NewSource(seed))
   312  	p := NewPopulatedSubby(popr, true)
   313  	size2 := github_com_gogo_protobuf_proto.Size(p)
   314  	dAtA, err := github_com_gogo_protobuf_proto.Marshal(p)
   315  	if err != nil {
   316  		t.Fatalf("seed = %d, err = %v", seed, err)
   317  	}
   318  	size := p.Size()
   319  	if len(dAtA) != size {
   320  		t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA))
   321  	}
   322  	if size2 != size {
   323  		t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2)
   324  	}
   325  	size3 := github_com_gogo_protobuf_proto.Size(p)
   326  	if size3 != size {
   327  		t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3)
   328  	}
   329  }
   330  
   331  func TestSampleOneOfSize(t *testing.T) {
   332  	seed := time.Now().UnixNano()
   333  	popr := math_rand.New(math_rand.NewSource(seed))
   334  	p := NewPopulatedSampleOneOf(popr, true)
   335  	size2 := github_com_gogo_protobuf_proto.Size(p)
   336  	dAtA, err := github_com_gogo_protobuf_proto.Marshal(p)
   337  	if err != nil {
   338  		t.Fatalf("seed = %d, err = %v", seed, err)
   339  	}
   340  	size := p.Size()
   341  	if len(dAtA) != size {
   342  		t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA))
   343  	}
   344  	if size2 != size {
   345  		t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2)
   346  	}
   347  	size3 := github_com_gogo_protobuf_proto.Size(p)
   348  	if size3 != size {
   349  		t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3)
   350  	}
   351  }
   352  
   353  func TestSubbyStringer(t *testing.T) {
   354  	popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
   355  	p := NewPopulatedSubby(popr, false)
   356  	s1 := p.String()
   357  	s2 := fmt.Sprintf("%v", p)
   358  	if s1 != s2 {
   359  		t.Fatalf("String want %v got %v", s1, s2)
   360  	}
   361  }
   362  func TestSampleOneOfStringer(t *testing.T) {
   363  	popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
   364  	p := NewPopulatedSampleOneOf(popr, false)
   365  	s1 := p.String()
   366  	s2 := fmt.Sprintf("%v", p)
   367  	if s1 != s2 {
   368  		t.Fatalf("String want %v got %v", s1, s2)
   369  	}
   370  }
   371  
   372  //These tests are generated by github.com/gogo/protobuf/plugin/testgen
   373  

View as plain text