MCPcopy
hub / github.com/golang/protobuf / TestNumericPrimitives

Function TestNumericPrimitives

proto/proto_test.go:138–206  ·  view source on GitHub ↗

Simple tests for numeric encode/decode primitives (varint, etc.)

(t *testing.T)

Source from the content-addressed store, hash-verified

136
137// Simple tests for numeric encode/decode primitives (varint, etc.)
138func TestNumericPrimitives(t *testing.T) {
139 for i := uint64(0); i < 1e6; i += 111 {
140 o := new(proto.Buffer)
141 if o.EncodeVarint(i) != nil {
142 t.Error("EncodeVarint")
143 break
144 }
145 x, e := o.DecodeVarint()
146 if e != nil {
147 t.Fatal("DecodeVarint")
148 }
149 if x != i {
150 t.Fatal("varint decode fail:", i, x)
151 }
152
153 o.Reset()
154 if o.EncodeFixed32(i) != nil {
155 t.Fatal("encFixed32")
156 }
157 x, e = o.DecodeFixed32()
158 if e != nil {
159 t.Fatal("decFixed32")
160 }
161 if x != i {
162 t.Fatal("fixed32 decode fail:", i, x)
163 }
164
165 o.Reset()
166 if o.EncodeFixed64(i*1234567) != nil {
167 t.Error("encFixed64")
168 break
169 }
170 x, e = o.DecodeFixed64()
171 if e != nil {
172 t.Error("decFixed64")
173 break
174 }
175 if x != i*1234567 {
176 t.Error("fixed64 decode fail:", i*1234567, x)
177 break
178 }
179
180 o.Reset()
181 i32 := int32(i - 12345)
182 if o.EncodeZigzag32(uint64(i32)) != nil {
183 t.Fatal("EncodeZigzag32")
184 }
185 x, e = o.DecodeZigzag32()
186 if e != nil {
187 t.Fatal("DecodeZigzag32")
188 }
189 if x != uint64(uint32(i32)) {
190 t.Fatal("zigzag32 decode fail:", i32, x)
191 }
192
193 o.Reset()
194 i64 := int64(i - 12345)
195 if o.EncodeZigzag64(uint64(i64)) != nil {

Callers

nothing calls this directly

Calls 12

EncodeVarintMethod · 0.80
DecodeVarintMethod · 0.80
EncodeFixed32Method · 0.80
DecodeFixed32Method · 0.80
EncodeFixed64Method · 0.80
DecodeFixed64Method · 0.80
EncodeZigzag32Method · 0.80
DecodeZigzag32Method · 0.80
EncodeZigzag64Method · 0.80
DecodeZigzag64Method · 0.80
ErrorMethod · 0.45
ResetMethod · 0.45

Tested by

no test coverage detected