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

/*
6
Package merkledag_pb is a generated protocol buffer package.
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
7 8

It is generated from these files:
9
	merkledag.proto
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
10 11 12 13 14

It has these top-level messages:
	PBLink
	PBNode
*/
15
package merkledag_pb
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
16 17 18 19

import testing "testing"
import math_rand "math/rand"
import time "time"
20
import github_com_gogo_protobuf_proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
21 22 23 24 25 26 27
import encoding_json "encoding/json"
import fmt "fmt"
import go_parser "go/parser"

func TestPBLinkProto(t *testing.T) {
	popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
	p := NewPopulatedPBLink(popr, false)
28
	data, err := github_com_gogo_protobuf_proto.Marshal(p)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
29 30 31 32
	if err != nil {
		panic(err)
	}
	msg := &PBLink{}
33
	if err := github_com_gogo_protobuf_proto.Unmarshal(data, msg); err != nil {
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
		panic(err)
	}
	for i := range data {
		data[i] = byte(popr.Intn(256))
	}
	if err := p.VerboseEqual(msg); err != nil {
		t.Fatalf("%#v !VerboseProto %#v, since %v", msg, p, err)
	}
	if !p.Equal(msg) {
		t.Fatalf("%#v !Proto %#v", msg, p)
	}
}

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

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++ {
83
		data, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000])
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
84 85 86 87 88 89 90 91 92 93 94 95 96
		if err != nil {
			panic(err)
		}
		total += len(data)
	}
	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++ {
97
		data, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedPBLink(popr, false))
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
98 99 100 101 102 103 104 105 106
		if err != nil {
			panic(err)
		}
		datas[i] = data
	}
	msg := &PBLink{}
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		total += len(datas[i%10000])
107
		if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil {
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
108 109 110 111 112 113 114 115 116
			panic(err)
		}
	}
	b.SetBytes(int64(total / b.N))
}

func TestPBNodeProto(t *testing.T) {
	popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
	p := NewPopulatedPBNode(popr, false)
117
	data, err := github_com_gogo_protobuf_proto.Marshal(p)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
118 119 120 121
	if err != nil {
		panic(err)
	}
	msg := &PBNode{}
122
	if err := github_com_gogo_protobuf_proto.Unmarshal(data, msg); err != nil {
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
		panic(err)
	}
	for i := range data {
		data[i] = byte(popr.Intn(256))
	}
	if err := p.VerboseEqual(msg); err != nil {
		t.Fatalf("%#v !VerboseProto %#v, since %v", msg, p, err)
	}
	if !p.Equal(msg) {
		t.Fatalf("%#v !Proto %#v", msg, p)
	}
}

func TestPBNodeMarshalTo(t *testing.T) {
	popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
	p := NewPopulatedPBNode(popr, false)
	size := p.Size()
	data := make([]byte, size)
	for i := range data {
		data[i] = byte(popr.Intn(256))
	}
	_, err := p.MarshalTo(data)
	if err != nil {
		panic(err)
	}
	msg := &PBNode{}
149
	if err := github_com_gogo_protobuf_proto.Unmarshal(data, msg); err != nil {
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
		panic(err)
	}
	for i := range data {
		data[i] = byte(popr.Intn(256))
	}
	if err := p.VerboseEqual(msg); err != nil {
		t.Fatalf("%#v !VerboseProto %#v, since %v", msg, p, err)
	}
	if !p.Equal(msg) {
		t.Fatalf("%#v !Proto %#v", msg, p)
	}
}

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++ {
172
		data, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000])
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
173 174 175 176 177 178 179 180 181 182 183 184 185
		if err != nil {
			panic(err)
		}
		total += len(data)
	}
	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++ {
186
		data, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedPBNode(popr, false))
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
187 188 189 190 191 192 193 194 195
		if err != nil {
			panic(err)
		}
		datas[i] = data
	}
	msg := &PBNode{}
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		total += len(datas[i%10000])
196
		if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil {
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
197 198 199 200 201 202
			panic(err)
		}
	}
	b.SetBytes(int64(total / b.N))
}

203 204
func TestPBLinkJSON(t *testing.T) {
	popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
	p := NewPopulatedPBLink(popr, true)
	jsondata, err := encoding_json.Marshal(p)
	if err != nil {
		panic(err)
	}
	msg := &PBLink{}
	err = encoding_json.Unmarshal(jsondata, msg)
	if err != nil {
		panic(err)
	}
	if err := p.VerboseEqual(msg); err != nil {
		t.Fatalf("%#v !VerboseProto %#v, since %v", msg, p, err)
	}
	if !p.Equal(msg) {
		t.Fatalf("%#v !Json Equal %#v", msg, p)
	}
}
222 223
func TestPBNodeJSON(t *testing.T) {
	popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240
	p := NewPopulatedPBNode(popr, true)
	jsondata, err := encoding_json.Marshal(p)
	if err != nil {
		panic(err)
	}
	msg := &PBNode{}
	err = encoding_json.Unmarshal(jsondata, msg)
	if err != nil {
		panic(err)
	}
	if err := p.VerboseEqual(msg); err != nil {
		t.Fatalf("%#v !VerboseProto %#v, since %v", msg, p, err)
	}
	if !p.Equal(msg) {
		t.Fatalf("%#v !Json Equal %#v", msg, p)
	}
}
241 242
func TestPBLinkProtoText(t *testing.T) {
	popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
243
	p := NewPopulatedPBLink(popr, true)
244
	data := github_com_gogo_protobuf_proto.MarshalTextString(p)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
245
	msg := &PBLink{}
246
	if err := github_com_gogo_protobuf_proto.UnmarshalText(data, msg); err != nil {
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
247 248 249 250 251 252 253 254 255 256
		panic(err)
	}
	if err := p.VerboseEqual(msg); err != nil {
		t.Fatalf("%#v !VerboseProto %#v, since %v", msg, p, err)
	}
	if !p.Equal(msg) {
		t.Fatalf("%#v !Proto %#v", msg, p)
	}
}

257 258
func TestPBLinkProtoCompactText(t *testing.T) {
	popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
259
	p := NewPopulatedPBLink(popr, true)
260
	data := github_com_gogo_protobuf_proto.CompactTextString(p)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
261
	msg := &PBLink{}
262
	if err := github_com_gogo_protobuf_proto.UnmarshalText(data, msg); err != nil {
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
263 264 265 266 267 268 269 270 271 272
		panic(err)
	}
	if err := p.VerboseEqual(msg); err != nil {
		t.Fatalf("%#v !VerboseProto %#v, since %v", msg, p, err)
	}
	if !p.Equal(msg) {
		t.Fatalf("%#v !Proto %#v", msg, p)
	}
}

273 274
func TestPBNodeProtoText(t *testing.T) {
	popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
275
	p := NewPopulatedPBNode(popr, true)
276
	data := github_com_gogo_protobuf_proto.MarshalTextString(p)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
277
	msg := &PBNode{}
278
	if err := github_com_gogo_protobuf_proto.UnmarshalText(data, msg); err != nil {
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
279 280 281 282 283 284 285 286 287 288
		panic(err)
	}
	if err := p.VerboseEqual(msg); err != nil {
		t.Fatalf("%#v !VerboseProto %#v, since %v", msg, p, err)
	}
	if !p.Equal(msg) {
		t.Fatalf("%#v !Proto %#v", msg, p)
	}
}

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

305 306
func TestPBLinkStringer(t *testing.T) {
	popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
307 308 309 310 311 312 313
	p := NewPopulatedPBLink(popr, false)
	s1 := p.String()
	s2 := fmt.Sprintf("%v", p)
	if s1 != s2 {
		t.Fatalf("String want %v got %v", s1, s2)
	}
}
314 315
func TestPBNodeStringer(t *testing.T) {
	popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
316 317 318 319 320 321 322
	p := NewPopulatedPBNode(popr, false)
	s1 := p.String()
	s2 := fmt.Sprintf("%v", p)
	if s1 != s2 {
		t.Fatalf("String want %v got %v", s1, s2)
	}
}
323 324
func TestPBLinkSize(t *testing.T) {
	popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
325
	p := NewPopulatedPBLink(popr, true)
326 327
	size2 := github_com_gogo_protobuf_proto.Size(p)
	data, err := github_com_gogo_protobuf_proto.Marshal(p)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
328 329 330 331 332 333 334 335 336 337
	if err != nil {
		panic(err)
	}
	size := p.Size()
	if len(data) != size {
		t.Fatalf("size %v != marshalled size %v", size, len(data))
	}
	if size2 != size {
		t.Fatalf("size %v != before marshal proto.Size %v", size, size2)
	}
338
	size3 := github_com_gogo_protobuf_proto.Size(p)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
339 340 341 342 343
	if size3 != size {
		t.Fatalf("size %v != after marshal proto.Size %v", size, size3)
	}
}

344 345
func BenchmarkPBLinkSize(b *testing.B) {
	popr := math_rand.New(math_rand.NewSource(616))
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
346 347 348 349 350 351 352 353 354 355 356 357
	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))
}

358 359
func TestPBNodeSize(t *testing.T) {
	popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
360
	p := NewPopulatedPBNode(popr, true)
361 362
	size2 := github_com_gogo_protobuf_proto.Size(p)
	data, err := github_com_gogo_protobuf_proto.Marshal(p)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
363 364 365 366 367 368 369 370 371 372
	if err != nil {
		panic(err)
	}
	size := p.Size()
	if len(data) != size {
		t.Fatalf("size %v != marshalled size %v", size, len(data))
	}
	if size2 != size {
		t.Fatalf("size %v != before marshal proto.Size %v", size, size2)
	}
373
	size3 := github_com_gogo_protobuf_proto.Size(p)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
374 375 376 377 378
	if size3 != size {
		t.Fatalf("size %v != after marshal proto.Size %v", size, size3)
	}
}

379 380
func BenchmarkPBNodeSize(b *testing.B) {
	popr := math_rand.New(math_rand.NewSource(616))
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
381 382 383 384 385 386 387 388 389 390 391 392
	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))
}

393 394
func TestPBLinkGoString(t *testing.T) {
	popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
395 396
	p := NewPopulatedPBLink(popr, false)
	s1 := p.GoString()
397
	s2 := fmt.Sprintf("%#v", p)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
398 399 400 401 402 403 404 405
	if s1 != s2 {
		t.Fatalf("GoString want %v got %v", s1, s2)
	}
	_, err := go_parser.ParseExpr(s1)
	if err != nil {
		panic(err)
	}
}
406 407
func TestPBNodeGoString(t *testing.T) {
	popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
408 409
	p := NewPopulatedPBNode(popr, false)
	s1 := p.GoString()
410
	s2 := fmt.Sprintf("%#v", p)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
411 412 413 414 415 416 417 418
	if s1 != s2 {
		t.Fatalf("GoString want %v got %v", s1, s2)
	}
	_, err := go_parser.ParseExpr(s1)
	if err != nil {
		panic(err)
	}
}
419 420
func TestPBLinkVerboseEqual(t *testing.T) {
	popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
421
	p := NewPopulatedPBLink(popr, false)
422
	data, err := github_com_gogo_protobuf_proto.Marshal(p)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
423 424 425 426
	if err != nil {
		panic(err)
	}
	msg := &PBLink{}
427
	if err := github_com_gogo_protobuf_proto.Unmarshal(data, msg); err != nil {
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
428 429 430 431 432 433
		panic(err)
	}
	if err := p.VerboseEqual(msg); err != nil {
		t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err)
	}
}
434 435
func TestPBNodeVerboseEqual(t *testing.T) {
	popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
436
	p := NewPopulatedPBNode(popr, false)
437
	data, err := github_com_gogo_protobuf_proto.Marshal(p)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
438 439 440 441
	if err != nil {
		panic(err)
	}
	msg := &PBNode{}
442
	if err := github_com_gogo_protobuf_proto.Unmarshal(data, msg); err != nil {
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
443 444 445 446 447 448 449
		panic(err)
	}
	if err := p.VerboseEqual(msg); err != nil {
		t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err)
	}
}

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