1
2
3
4 package importduplicate
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 _ "github.com/gogo/protobuf/test/importduplicate/proto"
13 _ "github.com/gogo/protobuf/test/importduplicate/sortkeys"
14 go_parser "go/parser"
15 math "math"
16 math_rand "math/rand"
17 testing "testing"
18 time "time"
19 )
20
21
22 var _ = proto.Marshal
23 var _ = fmt.Errorf
24 var _ = math.Inf
25
26 func TestMapAndSortKeysProto(t *testing.T) {
27 seed := time.Now().UnixNano()
28 popr := math_rand.New(math_rand.NewSource(seed))
29 p := NewPopulatedMapAndSortKeys(popr, false)
30 dAtA, err := github_com_gogo_protobuf_proto.Marshal(p)
31 if err != nil {
32 t.Fatalf("seed = %d, err = %v", seed, err)
33 }
34 msg := &MapAndSortKeys{}
35 if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil {
36 t.Fatalf("seed = %d, err = %v", seed, err)
37 }
38 littlefuzz := make([]byte, len(dAtA))
39 copy(littlefuzz, dAtA)
40 for i := range dAtA {
41 dAtA[i] = byte(popr.Intn(256))
42 }
43 if !p.Equal(msg) {
44 t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
45 }
46 if len(littlefuzz) > 0 {
47 fuzzamount := 100
48 for i := 0; i < fuzzamount; i++ {
49 littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256))
50 littlefuzz = append(littlefuzz, byte(popr.Intn(256)))
51 }
52
53 _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg)
54 }
55 }
56
57 func TestMapAndSortKeysJSON(t *testing.T) {
58 seed := time.Now().UnixNano()
59 popr := math_rand.New(math_rand.NewSource(seed))
60 p := NewPopulatedMapAndSortKeys(popr, true)
61 marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{}
62 jsondata, err := marshaler.MarshalToString(p)
63 if err != nil {
64 t.Fatalf("seed = %d, err = %v", seed, err)
65 }
66 msg := &MapAndSortKeys{}
67 err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg)
68 if err != nil {
69 t.Fatalf("seed = %d, err = %v", seed, err)
70 }
71 if !p.Equal(msg) {
72 t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p)
73 }
74 }
75 func TestMapAndSortKeysProtoText(t *testing.T) {
76 seed := time.Now().UnixNano()
77 popr := math_rand.New(math_rand.NewSource(seed))
78 p := NewPopulatedMapAndSortKeys(popr, true)
79 dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p)
80 msg := &MapAndSortKeys{}
81 if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil {
82 t.Fatalf("seed = %d, err = %v", seed, err)
83 }
84 if !p.Equal(msg) {
85 t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
86 }
87 }
88
89 func TestMapAndSortKeysProtoCompactText(t *testing.T) {
90 seed := time.Now().UnixNano()
91 popr := math_rand.New(math_rand.NewSource(seed))
92 p := NewPopulatedMapAndSortKeys(popr, true)
93 dAtA := github_com_gogo_protobuf_proto.CompactTextString(p)
94 msg := &MapAndSortKeys{}
95 if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil {
96 t.Fatalf("seed = %d, err = %v", seed, err)
97 }
98 if !p.Equal(msg) {
99 t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
100 }
101 }
102
103 func TestMapAndSortKeysGoString(t *testing.T) {
104 popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
105 p := NewPopulatedMapAndSortKeys(popr, false)
106 s1 := p.GoString()
107 s2 := fmt.Sprintf("%#v", p)
108 if s1 != s2 {
109 t.Fatalf("GoString want %v got %v", s1, s2)
110 }
111 _, err := go_parser.ParseExpr(s1)
112 if err != nil {
113 t.Fatal(err)
114 }
115 }
116
117
118
View as plain text