merkledagpb_test.go 13.7 KB
Newer Older
Jakub Sztandera's avatar
Jakub Sztandera committed
1
// Code generated by protoc-gen-gogo. DO NOT EDIT.
2
// source: merkledag.proto
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
3

4
package merkledag_pb
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
5

Jakub Sztandera's avatar
Jakub Sztandera committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
import (
	fmt "fmt"
	_ "github.com/gogo/protobuf/gogoproto"
	github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb"
	github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto"
	proto "github.com/gogo/protobuf/proto"
	go_parser "go/parser"
	math "math"
	math_rand "math/rand"
	testing "testing"
	time "time"
)

// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
23 24

func TestPBLinkProto(t *testing.T) {
Jakub Sztandera's avatar
Jakub Sztandera committed
25 26
	seed := time.Now().UnixNano()
	popr := math_rand.New(math_rand.NewSource(seed))
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
27
	p := NewPopulatedPBLink(popr, false)
Jakub Sztandera's avatar
Jakub Sztandera committed
28
	dAtA, err := github_com_gogo_protobuf_proto.Marshal(p)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
29
	if err != nil {
Jakub Sztandera's avatar
Jakub Sztandera committed
30
		t.Fatalf("seed = %d, err = %v", seed, err)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
31 32
	}
	msg := &PBLink{}
Jakub Sztandera's avatar
Jakub Sztandera committed
33 34
	if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil {
		t.Fatalf("seed = %d, err = %v", seed, err)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
35
	}
Jakub Sztandera's avatar
Jakub Sztandera committed
36 37 38 39
	littlefuzz := make([]byte, len(dAtA))
	copy(littlefuzz, dAtA)
	for i := range dAtA {
		dAtA[i] = byte(popr.Intn(256))
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
40 41
	}
	if err := p.VerboseEqual(msg); err != nil {
Jakub Sztandera's avatar
Jakub Sztandera committed
42
		t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
43 44
	}
	if !p.Equal(msg) {
Jakub Sztandera's avatar
Jakub Sztandera committed
45 46 47 48 49 50 51 52 53 54
		t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
	}
	if len(littlefuzz) > 0 {
		fuzzamount := 100
		for i := 0; i < fuzzamount; i++ {
			littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256))
			littlefuzz = append(littlefuzz, byte(popr.Intn(256)))
		}
		// shouldn't panic
		_ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
55 56 57 58
	}
}

func TestPBLinkMarshalTo(t *testing.T) {
Jakub Sztandera's avatar
Jakub Sztandera committed
59 60
	seed := time.Now().UnixNano()
	popr := math_rand.New(math_rand.NewSource(seed))
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
61 62
	p := NewPopulatedPBLink(popr, false)
	size := p.Size()
Jakub Sztandera's avatar
Jakub Sztandera committed
63 64 65
	dAtA := make([]byte, size)
	for i := range dAtA {
		dAtA[i] = byte(popr.Intn(256))
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
66
	}
Jakub Sztandera's avatar
Jakub Sztandera committed
67
	_, err := p.MarshalTo(dAtA)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
68
	if err != nil {
Jakub Sztandera's avatar
Jakub Sztandera committed
69
		t.Fatalf("seed = %d, err = %v", seed, err)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
70 71
	}
	msg := &PBLink{}
Jakub Sztandera's avatar
Jakub Sztandera committed
72 73
	if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil {
		t.Fatalf("seed = %d, err = %v", seed, err)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
74
	}
Jakub Sztandera's avatar
Jakub Sztandera committed
75 76
	for i := range dAtA {
		dAtA[i] = byte(popr.Intn(256))
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
77 78
	}
	if err := p.VerboseEqual(msg); err != nil {
Jakub Sztandera's avatar
Jakub Sztandera committed
79
		t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
80 81
	}
	if !p.Equal(msg) {
Jakub Sztandera's avatar
Jakub Sztandera committed
82
		t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
83 84 85 86 87 88 89 90 91 92 93 94
	}
}

func BenchmarkPBLinkProtoMarshal(b *testing.B) {
	popr := math_rand.New(math_rand.NewSource(616))
	total := 0
	pops := make([]*PBLink, 10000)
	for i := 0; i < 10000; i++ {
		pops[i] = NewPopulatedPBLink(popr, false)
	}
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
Jakub Sztandera's avatar
Jakub Sztandera committed
95
		dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000])
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
96 97 98
		if err != nil {
			panic(err)
		}
Jakub Sztandera's avatar
Jakub Sztandera committed
99
		total += len(dAtA)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
100 101 102 103 104 105 106 107 108
	}
	b.SetBytes(int64(total / b.N))
}

func BenchmarkPBLinkProtoUnmarshal(b *testing.B) {
	popr := math_rand.New(math_rand.NewSource(616))
	total := 0
	datas := make([][]byte, 10000)
	for i := 0; i < 10000; i++ {
Jakub Sztandera's avatar
Jakub Sztandera committed
109
		dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedPBLink(popr, false))
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
110 111 112
		if err != nil {
			panic(err)
		}
Jakub Sztandera's avatar
Jakub Sztandera committed
113
		datas[i] = dAtA
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
114 115 116 117 118
	}
	msg := &PBLink{}
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		total += len(datas[i%10000])
119
		if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil {
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
120 121 122 123 124 125 126
			panic(err)
		}
	}
	b.SetBytes(int64(total / b.N))
}

func TestPBNodeProto(t *testing.T) {
Jakub Sztandera's avatar
Jakub Sztandera committed
127 128
	seed := time.Now().UnixNano()
	popr := math_rand.New(math_rand.NewSource(seed))
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
129
	p := NewPopulatedPBNode(popr, false)
Jakub Sztandera's avatar
Jakub Sztandera committed
130
	dAtA, err := github_com_gogo_protobuf_proto.Marshal(p)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
131
	if err != nil {
Jakub Sztandera's avatar
Jakub Sztandera committed
132
		t.Fatalf("seed = %d, err = %v", seed, err)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
133 134
	}
	msg := &PBNode{}
Jakub Sztandera's avatar
Jakub Sztandera committed
135 136
	if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil {
		t.Fatalf("seed = %d, err = %v", seed, err)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
137
	}
Jakub Sztandera's avatar
Jakub Sztandera committed
138 139 140 141
	littlefuzz := make([]byte, len(dAtA))
	copy(littlefuzz, dAtA)
	for i := range dAtA {
		dAtA[i] = byte(popr.Intn(256))
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
142 143
	}
	if err := p.VerboseEqual(msg); err != nil {
Jakub Sztandera's avatar
Jakub Sztandera committed
144
		t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
145 146
	}
	if !p.Equal(msg) {
Jakub Sztandera's avatar
Jakub Sztandera committed
147 148 149 150 151 152 153 154 155 156
		t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
	}
	if len(littlefuzz) > 0 {
		fuzzamount := 100
		for i := 0; i < fuzzamount; i++ {
			littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256))
			littlefuzz = append(littlefuzz, byte(popr.Intn(256)))
		}
		// shouldn't panic
		_ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
157 158 159 160
	}
}

func TestPBNodeMarshalTo(t *testing.T) {
Jakub Sztandera's avatar
Jakub Sztandera committed
161 162
	seed := time.Now().UnixNano()
	popr := math_rand.New(math_rand.NewSource(seed))
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
163 164
	p := NewPopulatedPBNode(popr, false)
	size := p.Size()
Jakub Sztandera's avatar
Jakub Sztandera committed
165 166 167
	dAtA := make([]byte, size)
	for i := range dAtA {
		dAtA[i] = byte(popr.Intn(256))
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
168
	}
Jakub Sztandera's avatar
Jakub Sztandera committed
169
	_, err := p.MarshalTo(dAtA)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
170
	if err != nil {
Jakub Sztandera's avatar
Jakub Sztandera committed
171
		t.Fatalf("seed = %d, err = %v", seed, err)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
172 173
	}
	msg := &PBNode{}
Jakub Sztandera's avatar
Jakub Sztandera committed
174 175
	if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil {
		t.Fatalf("seed = %d, err = %v", seed, err)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
176
	}
Jakub Sztandera's avatar
Jakub Sztandera committed
177 178
	for i := range dAtA {
		dAtA[i] = byte(popr.Intn(256))
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
179 180
	}
	if err := p.VerboseEqual(msg); err != nil {
Jakub Sztandera's avatar
Jakub Sztandera committed
181
		t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
182 183
	}
	if !p.Equal(msg) {
Jakub Sztandera's avatar
Jakub Sztandera committed
184
		t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
185 186 187 188 189 190 191 192 193 194 195 196
	}
}

func BenchmarkPBNodeProtoMarshal(b *testing.B) {
	popr := math_rand.New(math_rand.NewSource(616))
	total := 0
	pops := make([]*PBNode, 10000)
	for i := 0; i < 10000; i++ {
		pops[i] = NewPopulatedPBNode(popr, false)
	}
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
Jakub Sztandera's avatar
Jakub Sztandera committed
197
		dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000])
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
198 199 200
		if err != nil {
			panic(err)
		}
Jakub Sztandera's avatar
Jakub Sztandera committed
201
		total += len(dAtA)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
202 203 204 205 206 207 208 209 210
	}
	b.SetBytes(int64(total / b.N))
}

func BenchmarkPBNodeProtoUnmarshal(b *testing.B) {
	popr := math_rand.New(math_rand.NewSource(616))
	total := 0
	datas := make([][]byte, 10000)
	for i := 0; i < 10000; i++ {
Jakub Sztandera's avatar
Jakub Sztandera committed
211
		dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedPBNode(popr, false))
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
212 213 214
		if err != nil {
			panic(err)
		}
Jakub Sztandera's avatar
Jakub Sztandera committed
215
		datas[i] = dAtA
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
216 217 218 219 220
	}
	msg := &PBNode{}
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		total += len(datas[i%10000])
221
		if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil {
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
222 223 224 225 226 227
			panic(err)
		}
	}
	b.SetBytes(int64(total / b.N))
}

228
func TestPBLinkJSON(t *testing.T) {
Jakub Sztandera's avatar
Jakub Sztandera committed
229 230
	seed := time.Now().UnixNano()
	popr := math_rand.New(math_rand.NewSource(seed))
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
231
	p := NewPopulatedPBLink(popr, true)
Jakub Sztandera's avatar
Jakub Sztandera committed
232 233
	marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{}
	jsondata, err := marshaler.MarshalToString(p)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
234
	if err != nil {
Jakub Sztandera's avatar
Jakub Sztandera committed
235
		t.Fatalf("seed = %d, err = %v", seed, err)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
236 237
	}
	msg := &PBLink{}
Jakub Sztandera's avatar
Jakub Sztandera committed
238
	err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
239
	if err != nil {
Jakub Sztandera's avatar
Jakub Sztandera committed
240
		t.Fatalf("seed = %d, err = %v", seed, err)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
241 242
	}
	if err := p.VerboseEqual(msg); err != nil {
Jakub Sztandera's avatar
Jakub Sztandera committed
243
		t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
244 245
	}
	if !p.Equal(msg) {
Jakub Sztandera's avatar
Jakub Sztandera committed
246
		t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
247 248
	}
}
249
func TestPBNodeJSON(t *testing.T) {
Jakub Sztandera's avatar
Jakub Sztandera committed
250 251
	seed := time.Now().UnixNano()
	popr := math_rand.New(math_rand.NewSource(seed))
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
252
	p := NewPopulatedPBNode(popr, true)
Jakub Sztandera's avatar
Jakub Sztandera committed
253 254
	marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{}
	jsondata, err := marshaler.MarshalToString(p)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
255
	if err != nil {
Jakub Sztandera's avatar
Jakub Sztandera committed
256
		t.Fatalf("seed = %d, err = %v", seed, err)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
257 258
	}
	msg := &PBNode{}
Jakub Sztandera's avatar
Jakub Sztandera committed
259
	err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
260
	if err != nil {
Jakub Sztandera's avatar
Jakub Sztandera committed
261
		t.Fatalf("seed = %d, err = %v", seed, err)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
262 263
	}
	if err := p.VerboseEqual(msg); err != nil {
Jakub Sztandera's avatar
Jakub Sztandera committed
264
		t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
265 266
	}
	if !p.Equal(msg) {
Jakub Sztandera's avatar
Jakub Sztandera committed
267
		t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
268 269
	}
}
270
func TestPBLinkProtoText(t *testing.T) {
Jakub Sztandera's avatar
Jakub Sztandera committed
271 272
	seed := time.Now().UnixNano()
	popr := math_rand.New(math_rand.NewSource(seed))
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
273
	p := NewPopulatedPBLink(popr, true)
Jakub Sztandera's avatar
Jakub Sztandera committed
274
	dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
275
	msg := &PBLink{}
Jakub Sztandera's avatar
Jakub Sztandera committed
276 277
	if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil {
		t.Fatalf("seed = %d, err = %v", seed, err)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
278 279
	}
	if err := p.VerboseEqual(msg); err != nil {
Jakub Sztandera's avatar
Jakub Sztandera committed
280
		t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
281 282
	}
	if !p.Equal(msg) {
Jakub Sztandera's avatar
Jakub Sztandera committed
283
		t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
284 285 286
	}
}

287
func TestPBLinkProtoCompactText(t *testing.T) {
Jakub Sztandera's avatar
Jakub Sztandera committed
288 289
	seed := time.Now().UnixNano()
	popr := math_rand.New(math_rand.NewSource(seed))
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
290
	p := NewPopulatedPBLink(popr, true)
Jakub Sztandera's avatar
Jakub Sztandera committed
291
	dAtA := github_com_gogo_protobuf_proto.CompactTextString(p)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
292
	msg := &PBLink{}
Jakub Sztandera's avatar
Jakub Sztandera committed
293 294
	if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil {
		t.Fatalf("seed = %d, err = %v", seed, err)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
295 296
	}
	if err := p.VerboseEqual(msg); err != nil {
Jakub Sztandera's avatar
Jakub Sztandera committed
297
		t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
298 299
	}
	if !p.Equal(msg) {
Jakub Sztandera's avatar
Jakub Sztandera committed
300
		t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
301 302 303
	}
}

304
func TestPBNodeProtoText(t *testing.T) {
Jakub Sztandera's avatar
Jakub Sztandera committed
305 306
	seed := time.Now().UnixNano()
	popr := math_rand.New(math_rand.NewSource(seed))
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
307
	p := NewPopulatedPBNode(popr, true)
Jakub Sztandera's avatar
Jakub Sztandera committed
308
	dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
309
	msg := &PBNode{}
Jakub Sztandera's avatar
Jakub Sztandera committed
310 311
	if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil {
		t.Fatalf("seed = %d, err = %v", seed, err)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
312 313
	}
	if err := p.VerboseEqual(msg); err != nil {
Jakub Sztandera's avatar
Jakub Sztandera committed
314
		t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
315 316
	}
	if !p.Equal(msg) {
Jakub Sztandera's avatar
Jakub Sztandera committed
317
		t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
318 319 320
	}
}

321
func TestPBNodeProtoCompactText(t *testing.T) {
Jakub Sztandera's avatar
Jakub Sztandera committed
322 323
	seed := time.Now().UnixNano()
	popr := math_rand.New(math_rand.NewSource(seed))
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
324
	p := NewPopulatedPBNode(popr, true)
Jakub Sztandera's avatar
Jakub Sztandera committed
325
	dAtA := github_com_gogo_protobuf_proto.CompactTextString(p)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
326
	msg := &PBNode{}
Jakub Sztandera's avatar
Jakub Sztandera committed
327 328
	if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil {
		t.Fatalf("seed = %d, err = %v", seed, err)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
329 330
	}
	if err := p.VerboseEqual(msg); err != nil {
Jakub Sztandera's avatar
Jakub Sztandera committed
331
		t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
332 333
	}
	if !p.Equal(msg) {
Jakub Sztandera's avatar
Jakub Sztandera committed
334
		t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
335 336 337
	}
}

Jakub Sztandera's avatar
Jakub Sztandera committed
338
func TestPBLinkVerboseEqual(t *testing.T) {
339
	popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
340
	p := NewPopulatedPBLink(popr, false)
Jakub Sztandera's avatar
Jakub Sztandera committed
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372
	dAtA, err := github_com_gogo_protobuf_proto.Marshal(p)
	if err != nil {
		panic(err)
	}
	msg := &PBLink{}
	if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil {
		panic(err)
	}
	if err := p.VerboseEqual(msg); err != nil {
		t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err)
	}
}
func TestPBNodeVerboseEqual(t *testing.T) {
	popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
	p := NewPopulatedPBNode(popr, false)
	dAtA, err := github_com_gogo_protobuf_proto.Marshal(p)
	if err != nil {
		panic(err)
	}
	msg := &PBNode{}
	if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil {
		panic(err)
	}
	if err := p.VerboseEqual(msg); err != nil {
		t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err)
	}
}
func TestPBLinkGoString(t *testing.T) {
	popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
	p := NewPopulatedPBLink(popr, false)
	s1 := p.GoString()
	s2 := fmt.Sprintf("%#v", p)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
373
	if s1 != s2 {
Jakub Sztandera's avatar
Jakub Sztandera committed
374 375 376 377 378
		t.Fatalf("GoString want %v got %v", s1, s2)
	}
	_, err := go_parser.ParseExpr(s1)
	if err != nil {
		t.Fatal(err)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
379 380
	}
}
Jakub Sztandera's avatar
Jakub Sztandera committed
381
func TestPBNodeGoString(t *testing.T) {
382
	popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
383
	p := NewPopulatedPBNode(popr, false)
Jakub Sztandera's avatar
Jakub Sztandera committed
384 385
	s1 := p.GoString()
	s2 := fmt.Sprintf("%#v", p)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
386
	if s1 != s2 {
Jakub Sztandera's avatar
Jakub Sztandera committed
387 388 389 390 391
		t.Fatalf("GoString want %v got %v", s1, s2)
	}
	_, err := go_parser.ParseExpr(s1)
	if err != nil {
		t.Fatal(err)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
392 393
	}
}
394
func TestPBLinkSize(t *testing.T) {
Jakub Sztandera's avatar
Jakub Sztandera committed
395 396
	seed := time.Now().UnixNano()
	popr := math_rand.New(math_rand.NewSource(seed))
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
397
	p := NewPopulatedPBLink(popr, true)
398
	size2 := github_com_gogo_protobuf_proto.Size(p)
Jakub Sztandera's avatar
Jakub Sztandera committed
399
	dAtA, err := github_com_gogo_protobuf_proto.Marshal(p)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
400
	if err != nil {
Jakub Sztandera's avatar
Jakub Sztandera committed
401
		t.Fatalf("seed = %d, err = %v", seed, err)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
402 403
	}
	size := p.Size()
Jakub Sztandera's avatar
Jakub Sztandera committed
404 405
	if len(dAtA) != size {
		t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA))
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
406 407
	}
	if size2 != size {
Jakub Sztandera's avatar
Jakub Sztandera committed
408
		t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
409
	}
410
	size3 := github_com_gogo_protobuf_proto.Size(p)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
411
	if size3 != size {
Jakub Sztandera's avatar
Jakub Sztandera committed
412
		t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
413 414 415
	}
}

416 417
func BenchmarkPBLinkSize(b *testing.B) {
	popr := math_rand.New(math_rand.NewSource(616))
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
418 419 420 421 422 423 424 425 426 427 428 429
	total := 0
	pops := make([]*PBLink, 1000)
	for i := 0; i < 1000; i++ {
		pops[i] = NewPopulatedPBLink(popr, false)
	}
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		total += pops[i%1000].Size()
	}
	b.SetBytes(int64(total / b.N))
}

430
func TestPBNodeSize(t *testing.T) {
Jakub Sztandera's avatar
Jakub Sztandera committed
431 432
	seed := time.Now().UnixNano()
	popr := math_rand.New(math_rand.NewSource(seed))
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
433
	p := NewPopulatedPBNode(popr, true)
434
	size2 := github_com_gogo_protobuf_proto.Size(p)
Jakub Sztandera's avatar
Jakub Sztandera committed
435
	dAtA, err := github_com_gogo_protobuf_proto.Marshal(p)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
436
	if err != nil {
Jakub Sztandera's avatar
Jakub Sztandera committed
437
		t.Fatalf("seed = %d, err = %v", seed, err)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
438 439
	}
	size := p.Size()
Jakub Sztandera's avatar
Jakub Sztandera committed
440 441
	if len(dAtA) != size {
		t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA))
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
442 443
	}
	if size2 != size {
Jakub Sztandera's avatar
Jakub Sztandera committed
444
		t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
445
	}
446
	size3 := github_com_gogo_protobuf_proto.Size(p)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
447
	if size3 != size {
Jakub Sztandera's avatar
Jakub Sztandera committed
448
		t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
449 450 451
	}
}

452 453
func BenchmarkPBNodeSize(b *testing.B) {
	popr := math_rand.New(math_rand.NewSource(616))
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
454 455 456 457 458 459 460 461 462 463 464 465
	total := 0
	pops := make([]*PBNode, 1000)
	for i := 0; i < 1000; i++ {
		pops[i] = NewPopulatedPBNode(popr, false)
	}
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		total += pops[i%1000].Size()
	}
	b.SetBytes(int64(total / b.N))
}

Jakub Sztandera's avatar
Jakub Sztandera committed
466
func TestPBLinkStringer(t *testing.T) {
467
	popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
468
	p := NewPopulatedPBLink(popr, false)
Jakub Sztandera's avatar
Jakub Sztandera committed
469 470
	s1 := p.String()
	s2 := fmt.Sprintf("%v", p)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
471
	if s1 != s2 {
Jakub Sztandera's avatar
Jakub Sztandera committed
472
		t.Fatalf("String want %v got %v", s1, s2)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
473 474
	}
}
Jakub Sztandera's avatar
Jakub Sztandera committed
475
func TestPBNodeStringer(t *testing.T) {
476
	popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
477
	p := NewPopulatedPBNode(popr, false)
Jakub Sztandera's avatar
Jakub Sztandera committed
478 479
	s1 := p.String()
	s2 := fmt.Sprintf("%v", p)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
480
	if s1 != s2 {
Jakub Sztandera's avatar
Jakub Sztandera committed
481
		t.Fatalf("String want %v got %v", s1, s2)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
482 483 484
	}
}

485
//These tests are generated by github.com/gogo/protobuf/plugin/testgen