Debian Codegraph @

test/unrecognizedgroup/oldnew_test.go

raw
1 // Protocol Buffers for Go with Gadgets
2 //
3 // Copyright (c) 2013, The GoGo Authors. All rights reserved.
4 // http://github.com/gogo/protobuf
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are
8 // met:
9 //
10 // * Redistributions of source code must retain the above copyright
11 // notice, this list of conditions and the following disclaimer.
12 // * Redistributions in binary form must reproduce the above
13 // copyright notice, this list of conditions and the following disclaimer
14 // in the documentation and/or other materials provided with the
15 // distribution.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29 package unrecognizedgroup
30
31 import (
32 "github.com/gogo/protobuf/proto"
33 math_rand "math/rand"
34 "testing"
35 time "time"
36 )
37
38 func TestNewOld(t *testing.T) {
39 popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
40 newer := NewPopulatedNewNoGroup(popr, true)
41 data1, err := proto.Marshal(newer)
42 if err != nil {
43 panic(err)
44 }
45 older := &OldWithGroup{}
46 if err = proto.Unmarshal(data1, older); err != nil {
47 panic(err)
48 }
49 data2, err := proto.Marshal(older)
50 if err != nil {
51 panic(err)
52 }
53 bluer := &NewNoGroup{}
54 if err := proto.Unmarshal(data2, bluer); err != nil {
55 panic(err)
56 }
57 if err := newer.VerboseEqual(bluer); err != nil {
58 t.Fatalf("%#v !VerboseProto %#v, since %v", newer, bluer, err)
59 }
60 }
61
62 func TestOldNew(t *testing.T) {
63 popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
64 older := NewPopulatedOldWithGroup(popr, true)
65 data1, err := proto.Marshal(older)
66 if err != nil {
67 panic(err)
68 }
69 newer := &NewNoGroup{}
70 if err = proto.Unmarshal(data1, newer); err != nil {
71 panic(err)
72 }
73 data2, err := proto.Marshal(newer)
74 if err != nil {
75 panic(err)
76 }
77 bluer := &OldWithGroup{}
78 if err := proto.Unmarshal(data2, bluer); err != nil {
79 panic(err)
80 }
81 if err := older.VerboseEqual(bluer); err != nil {
82 t.Fatalf("%#v !VerboseProto %#v, since %v", older, bluer, err)
83 }
84 }
85
86 func TestOldNewOldNew(t *testing.T) {
87 popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
88 older := NewPopulatedOldWithGroup(popr, true)
89 data1, err := proto.Marshal(older)
90 if err != nil {
91 panic(err)
92 }
93 newer := &NewNoGroup{}
94 if err = proto.Unmarshal(data1, newer); err != nil {
95 panic(err)
96 }
97 data2, err := proto.Marshal(newer)
98 if err != nil {
99 panic(err)
100 }
101 bluer := &OldWithGroup{}
102 if err = proto.Unmarshal(data2, bluer); err != nil {
103 panic(err)
104 }
105 if err = older.VerboseEqual(bluer); err != nil {
106 t.Fatalf("%#v !VerboseProto %#v, since %v", older, bluer, err)
107 }
108
109 data3, err := proto.Marshal(bluer)
110 if err != nil {
111 panic(err)
112 }
113 purple := &NewNoGroup{}
114 if err = proto.Unmarshal(data3, purple); err != nil {
115 panic(err)
116 }
117 data4, err := proto.Marshal(purple)
118 if err != nil {
119 panic(err)
120 }
121 magenta := &OldWithGroup{}
122 if err := proto.Unmarshal(data4, magenta); err != nil {
123 panic(err)
124 }
125 if err := older.VerboseEqual(magenta); err != nil {
126 t.Fatalf("%#v !VerboseProto %#v, since %v", older, magenta, err)
127 }
128 }