github.com/gogo/protobuf@v1.3.2/test/oneofembed/oneofembedpb_test.go (about) 1 // Code generated by protoc-gen-gogo. DO NOT EDIT. 2 // source: oneofembed.proto 3 4 package proto 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 TestFooProto(t *testing.T) { 24 seed := time.Now().UnixNano() 25 popr := math_rand.New(math_rand.NewSource(seed)) 26 p := NewPopulatedFoo(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 := &Foo{} 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 TestBarProto(t *testing.T) { 55 seed := time.Now().UnixNano() 56 popr := math_rand.New(math_rand.NewSource(seed)) 57 p := NewPopulatedBar(popr, false) 58 dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) 59 if err != nil { 60 t.Fatalf("seed = %d, err = %v", seed, err) 61 } 62 msg := &Bar{} 63 if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { 64 t.Fatalf("seed = %d, err = %v", seed, err) 65 } 66 littlefuzz := make([]byte, len(dAtA)) 67 copy(littlefuzz, dAtA) 68 for i := range dAtA { 69 dAtA[i] = byte(popr.Intn(256)) 70 } 71 if !p.Equal(msg) { 72 t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) 73 } 74 if len(littlefuzz) > 0 { 75 fuzzamount := 100 76 for i := 0; i < fuzzamount; i++ { 77 littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) 78 littlefuzz = append(littlefuzz, byte(popr.Intn(256))) 79 } 80 // shouldn't panic 81 _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) 82 } 83 } 84 85 func TestFooJSON(t *testing.T) { 86 seed := time.Now().UnixNano() 87 popr := math_rand.New(math_rand.NewSource(seed)) 88 p := NewPopulatedFoo(popr, true) 89 marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} 90 jsondata, err := marshaler.MarshalToString(p) 91 if err != nil { 92 t.Fatalf("seed = %d, err = %v", seed, err) 93 } 94 msg := &Foo{} 95 err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) 96 if err != nil { 97 t.Fatalf("seed = %d, err = %v", seed, err) 98 } 99 if !p.Equal(msg) { 100 t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) 101 } 102 } 103 func TestBarJSON(t *testing.T) { 104 seed := time.Now().UnixNano() 105 popr := math_rand.New(math_rand.NewSource(seed)) 106 p := NewPopulatedBar(popr, true) 107 marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} 108 jsondata, err := marshaler.MarshalToString(p) 109 if err != nil { 110 t.Fatalf("seed = %d, err = %v", seed, err) 111 } 112 msg := &Bar{} 113 err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) 114 if err != nil { 115 t.Fatalf("seed = %d, err = %v", seed, err) 116 } 117 if !p.Equal(msg) { 118 t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) 119 } 120 } 121 func TestFooProtoText(t *testing.T) { 122 seed := time.Now().UnixNano() 123 popr := math_rand.New(math_rand.NewSource(seed)) 124 p := NewPopulatedFoo(popr, true) 125 dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) 126 msg := &Foo{} 127 if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { 128 t.Fatalf("seed = %d, err = %v", seed, err) 129 } 130 if !p.Equal(msg) { 131 t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) 132 } 133 } 134 135 func TestFooProtoCompactText(t *testing.T) { 136 seed := time.Now().UnixNano() 137 popr := math_rand.New(math_rand.NewSource(seed)) 138 p := NewPopulatedFoo(popr, true) 139 dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) 140 msg := &Foo{} 141 if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { 142 t.Fatalf("seed = %d, err = %v", seed, err) 143 } 144 if !p.Equal(msg) { 145 t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) 146 } 147 } 148 149 func TestBarProtoText(t *testing.T) { 150 seed := time.Now().UnixNano() 151 popr := math_rand.New(math_rand.NewSource(seed)) 152 p := NewPopulatedBar(popr, true) 153 dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) 154 msg := &Bar{} 155 if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { 156 t.Fatalf("seed = %d, err = %v", seed, err) 157 } 158 if !p.Equal(msg) { 159 t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) 160 } 161 } 162 163 func TestBarProtoCompactText(t *testing.T) { 164 seed := time.Now().UnixNano() 165 popr := math_rand.New(math_rand.NewSource(seed)) 166 p := NewPopulatedBar(popr, true) 167 dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) 168 msg := &Bar{} 169 if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { 170 t.Fatalf("seed = %d, err = %v", seed, err) 171 } 172 if !p.Equal(msg) { 173 t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) 174 } 175 } 176 177 func TestFooCompare(t *testing.T) { 178 popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) 179 p := NewPopulatedFoo(popr, false) 180 dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) 181 if err != nil { 182 panic(err) 183 } 184 msg := &Foo{} 185 if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { 186 panic(err) 187 } 188 if c := p.Compare(msg); c != 0 { 189 t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) 190 } 191 p2 := NewPopulatedFoo(popr, false) 192 c := p.Compare(p2) 193 c2 := p2.Compare(p) 194 if c != (-1 * c2) { 195 t.Errorf("p.Compare(p2) = %d", c) 196 t.Errorf("p2.Compare(p) = %d", c2) 197 t.Errorf("p = %#v", p) 198 t.Errorf("p2 = %#v", p2) 199 } 200 } 201 func TestBarCompare(t *testing.T) { 202 popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) 203 p := NewPopulatedBar(popr, false) 204 dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) 205 if err != nil { 206 panic(err) 207 } 208 msg := &Bar{} 209 if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { 210 panic(err) 211 } 212 if c := p.Compare(msg); c != 0 { 213 t.Fatalf("%#v !Compare %#v, since %d", msg, p, c) 214 } 215 p2 := NewPopulatedBar(popr, false) 216 c := p.Compare(p2) 217 c2 := p2.Compare(p) 218 if c != (-1 * c2) { 219 t.Errorf("p.Compare(p2) = %d", c) 220 t.Errorf("p2.Compare(p) = %d", c2) 221 t.Errorf("p = %#v", p) 222 t.Errorf("p2 = %#v", p2) 223 } 224 } 225 226 //These tests are generated by github.com/gogo/protobuf/plugin/testgen