github.com/chrislusf/greenpack@v3.7.1-0.20170911073826-ad5bd10b7c47+incompatible/green/green_gen_test.go (about) 1 package green 2 3 // NOTE: THIS FILE WAS PRODUCED BY THE 4 // GREENPACK CODE GENERATION TOOL (github.com/glycerine/greenpack) 5 // DO NOT EDIT 6 7 import ( 8 "bytes" 9 "testing" 10 11 "github.com/glycerine/greenpack/msgp" 12 ) 13 14 func TestMarshalUnmarshalField(t *testing.T) { 15 v := Field{} 16 bts, err := v.MarshalMsg(nil) 17 if err != nil { 18 t.Fatal(err) 19 } 20 left, err := v.UnmarshalMsg(bts) 21 if err != nil { 22 t.Fatal(err) 23 } 24 if len(left) > 0 { 25 t.Errorf("%d bytes left over after UnmarshalMsg(): %q", len(left), left) 26 } 27 28 left, err = msgp.Skip(bts) 29 if err != nil { 30 t.Fatal(err) 31 } 32 if len(left) > 0 { 33 t.Errorf("%d bytes left over after Skip(): %q", len(left), left) 34 } 35 } 36 37 func BenchmarkMarshalMsgField(b *testing.B) { 38 v := Field{} 39 b.ReportAllocs() 40 b.ResetTimer() 41 for i := 0; i < b.N; i++ { 42 v.MarshalMsg(nil) 43 } 44 } 45 46 func BenchmarkAppendMsgField(b *testing.B) { 47 v := Field{} 48 bts := make([]byte, 0, v.Msgsize()) 49 bts, _ = v.MarshalMsg(bts[0:0]) 50 b.SetBytes(int64(len(bts))) 51 b.ReportAllocs() 52 b.ResetTimer() 53 for i := 0; i < b.N; i++ { 54 bts, _ = v.MarshalMsg(bts[0:0]) 55 } 56 } 57 58 func BenchmarkUnmarshalField(b *testing.B) { 59 v := Field{} 60 bts, _ := v.MarshalMsg(nil) 61 b.ReportAllocs() 62 b.SetBytes(int64(len(bts))) 63 b.ResetTimer() 64 for i := 0; i < b.N; i++ { 65 _, err := v.UnmarshalMsg(bts) 66 if err != nil { 67 b.Fatal(err) 68 } 69 } 70 } 71 72 func TestEncodeDecodeField(t *testing.T) { 73 v := Field{} 74 var buf bytes.Buffer 75 msgp.Encode(&buf, &v) 76 77 m := v.Msgsize() 78 if buf.Len() > m { 79 t.Logf("WARNING: Msgsize() for %v is inaccurate", v) 80 } 81 82 vn := Field{} 83 err := msgp.Decode(&buf, &vn) 84 if err != nil { 85 t.Error(err) 86 } 87 88 buf.Reset() 89 msgp.Encode(&buf, &v) 90 err = msgp.NewReader(&buf).Skip() 91 if err != nil { 92 t.Error(err) 93 } 94 } 95 96 func BenchmarkEncodeField(b *testing.B) { 97 v := Field{} 98 var buf bytes.Buffer 99 msgp.Encode(&buf, &v) 100 b.SetBytes(int64(buf.Len())) 101 en := msgp.NewWriter(msgp.Nowhere) 102 b.ReportAllocs() 103 b.ResetTimer() 104 for i := 0; i < b.N; i++ { 105 v.EncodeMsg(en) 106 } 107 en.Flush() 108 } 109 110 func BenchmarkDecodeField(b *testing.B) { 111 v := Field{} 112 var buf bytes.Buffer 113 msgp.Encode(&buf, &v) 114 b.SetBytes(int64(buf.Len())) 115 rd := msgp.NewEndlessReader(buf.Bytes(), b) 116 dc := msgp.NewReader(rd) 117 b.ReportAllocs() 118 b.ResetTimer() 119 for i := 0; i < b.N; i++ { 120 err := v.DecodeMsg(dc) 121 if err != nil { 122 b.Fatal(err) 123 } 124 } 125 } 126 127 func TestMarshalUnmarshalSchema(t *testing.T) { 128 v := Schema{} 129 bts, err := v.MarshalMsg(nil) 130 if err != nil { 131 t.Fatal(err) 132 } 133 left, err := v.UnmarshalMsg(bts) 134 if err != nil { 135 t.Fatal(err) 136 } 137 if len(left) > 0 { 138 t.Errorf("%d bytes left over after UnmarshalMsg(): %q", len(left), left) 139 } 140 141 left, err = msgp.Skip(bts) 142 if err != nil { 143 t.Fatal(err) 144 } 145 if len(left) > 0 { 146 t.Errorf("%d bytes left over after Skip(): %q", len(left), left) 147 } 148 } 149 150 func BenchmarkMarshalMsgSchema(b *testing.B) { 151 v := Schema{} 152 b.ReportAllocs() 153 b.ResetTimer() 154 for i := 0; i < b.N; i++ { 155 v.MarshalMsg(nil) 156 } 157 } 158 159 func BenchmarkAppendMsgSchema(b *testing.B) { 160 v := Schema{} 161 bts := make([]byte, 0, v.Msgsize()) 162 bts, _ = v.MarshalMsg(bts[0:0]) 163 b.SetBytes(int64(len(bts))) 164 b.ReportAllocs() 165 b.ResetTimer() 166 for i := 0; i < b.N; i++ { 167 bts, _ = v.MarshalMsg(bts[0:0]) 168 } 169 } 170 171 func BenchmarkUnmarshalSchema(b *testing.B) { 172 v := Schema{} 173 bts, _ := v.MarshalMsg(nil) 174 b.ReportAllocs() 175 b.SetBytes(int64(len(bts))) 176 b.ResetTimer() 177 for i := 0; i < b.N; i++ { 178 _, err := v.UnmarshalMsg(bts) 179 if err != nil { 180 b.Fatal(err) 181 } 182 } 183 } 184 185 func TestEncodeDecodeSchema(t *testing.T) { 186 v := Schema{} 187 var buf bytes.Buffer 188 msgp.Encode(&buf, &v) 189 190 m := v.Msgsize() 191 if buf.Len() > m { 192 t.Logf("WARNING: Msgsize() for %v is inaccurate", v) 193 } 194 195 vn := Schema{} 196 err := msgp.Decode(&buf, &vn) 197 if err != nil { 198 t.Error(err) 199 } 200 201 buf.Reset() 202 msgp.Encode(&buf, &v) 203 err = msgp.NewReader(&buf).Skip() 204 if err != nil { 205 t.Error(err) 206 } 207 } 208 209 func BenchmarkEncodeSchema(b *testing.B) { 210 v := Schema{} 211 var buf bytes.Buffer 212 msgp.Encode(&buf, &v) 213 b.SetBytes(int64(buf.Len())) 214 en := msgp.NewWriter(msgp.Nowhere) 215 b.ReportAllocs() 216 b.ResetTimer() 217 for i := 0; i < b.N; i++ { 218 v.EncodeMsg(en) 219 } 220 en.Flush() 221 } 222 223 func BenchmarkDecodeSchema(b *testing.B) { 224 v := Schema{} 225 var buf bytes.Buffer 226 msgp.Encode(&buf, &v) 227 b.SetBytes(int64(buf.Len())) 228 rd := msgp.NewEndlessReader(buf.Bytes(), b) 229 dc := msgp.NewReader(rd) 230 b.ReportAllocs() 231 b.ResetTimer() 232 for i := 0; i < b.N; i++ { 233 err := v.DecodeMsg(dc) 234 if err != nil { 235 b.Fatal(err) 236 } 237 } 238 } 239 240 func TestMarshalUnmarshalStruct(t *testing.T) { 241 v := Struct{} 242 bts, err := v.MarshalMsg(nil) 243 if err != nil { 244 t.Fatal(err) 245 } 246 left, err := v.UnmarshalMsg(bts) 247 if err != nil { 248 t.Fatal(err) 249 } 250 if len(left) > 0 { 251 t.Errorf("%d bytes left over after UnmarshalMsg(): %q", len(left), left) 252 } 253 254 left, err = msgp.Skip(bts) 255 if err != nil { 256 t.Fatal(err) 257 } 258 if len(left) > 0 { 259 t.Errorf("%d bytes left over after Skip(): %q", len(left), left) 260 } 261 } 262 263 func BenchmarkMarshalMsgStruct(b *testing.B) { 264 v := Struct{} 265 b.ReportAllocs() 266 b.ResetTimer() 267 for i := 0; i < b.N; i++ { 268 v.MarshalMsg(nil) 269 } 270 } 271 272 func BenchmarkAppendMsgStruct(b *testing.B) { 273 v := Struct{} 274 bts := make([]byte, 0, v.Msgsize()) 275 bts, _ = v.MarshalMsg(bts[0:0]) 276 b.SetBytes(int64(len(bts))) 277 b.ReportAllocs() 278 b.ResetTimer() 279 for i := 0; i < b.N; i++ { 280 bts, _ = v.MarshalMsg(bts[0:0]) 281 } 282 } 283 284 func BenchmarkUnmarshalStruct(b *testing.B) { 285 v := Struct{} 286 bts, _ := v.MarshalMsg(nil) 287 b.ReportAllocs() 288 b.SetBytes(int64(len(bts))) 289 b.ResetTimer() 290 for i := 0; i < b.N; i++ { 291 _, err := v.UnmarshalMsg(bts) 292 if err != nil { 293 b.Fatal(err) 294 } 295 } 296 } 297 298 func TestEncodeDecodeStruct(t *testing.T) { 299 v := Struct{} 300 var buf bytes.Buffer 301 msgp.Encode(&buf, &v) 302 303 m := v.Msgsize() 304 if buf.Len() > m { 305 t.Logf("WARNING: Msgsize() for %v is inaccurate", v) 306 } 307 308 vn := Struct{} 309 err := msgp.Decode(&buf, &vn) 310 if err != nil { 311 t.Error(err) 312 } 313 314 buf.Reset() 315 msgp.Encode(&buf, &v) 316 err = msgp.NewReader(&buf).Skip() 317 if err != nil { 318 t.Error(err) 319 } 320 } 321 322 func BenchmarkEncodeStruct(b *testing.B) { 323 v := Struct{} 324 var buf bytes.Buffer 325 msgp.Encode(&buf, &v) 326 b.SetBytes(int64(buf.Len())) 327 en := msgp.NewWriter(msgp.Nowhere) 328 b.ReportAllocs() 329 b.ResetTimer() 330 for i := 0; i < b.N; i++ { 331 v.EncodeMsg(en) 332 } 333 en.Flush() 334 } 335 336 func BenchmarkDecodeStruct(b *testing.B) { 337 v := Struct{} 338 var buf bytes.Buffer 339 msgp.Encode(&buf, &v) 340 b.SetBytes(int64(buf.Len())) 341 rd := msgp.NewEndlessReader(buf.Bytes(), b) 342 dc := msgp.NewReader(rd) 343 b.ReportAllocs() 344 b.ResetTimer() 345 for i := 0; i < b.N; i++ { 346 err := v.DecodeMsg(dc) 347 if err != nil { 348 b.Fatal(err) 349 } 350 } 351 } 352 353 func TestMarshalUnmarshalZtype(t *testing.T) { 354 v := Ztype{} 355 bts, err := v.MarshalMsg(nil) 356 if err != nil { 357 t.Fatal(err) 358 } 359 left, err := v.UnmarshalMsg(bts) 360 if err != nil { 361 t.Fatal(err) 362 } 363 if len(left) > 0 { 364 t.Errorf("%d bytes left over after UnmarshalMsg(): %q", len(left), left) 365 } 366 367 left, err = msgp.Skip(bts) 368 if err != nil { 369 t.Fatal(err) 370 } 371 if len(left) > 0 { 372 t.Errorf("%d bytes left over after Skip(): %q", len(left), left) 373 } 374 } 375 376 func BenchmarkMarshalMsgZtype(b *testing.B) { 377 v := Ztype{} 378 b.ReportAllocs() 379 b.ResetTimer() 380 for i := 0; i < b.N; i++ { 381 v.MarshalMsg(nil) 382 } 383 } 384 385 func BenchmarkAppendMsgZtype(b *testing.B) { 386 v := Ztype{} 387 bts := make([]byte, 0, v.Msgsize()) 388 bts, _ = v.MarshalMsg(bts[0:0]) 389 b.SetBytes(int64(len(bts))) 390 b.ReportAllocs() 391 b.ResetTimer() 392 for i := 0; i < b.N; i++ { 393 bts, _ = v.MarshalMsg(bts[0:0]) 394 } 395 } 396 397 func BenchmarkUnmarshalZtype(b *testing.B) { 398 v := Ztype{} 399 bts, _ := v.MarshalMsg(nil) 400 b.ReportAllocs() 401 b.SetBytes(int64(len(bts))) 402 b.ResetTimer() 403 for i := 0; i < b.N; i++ { 404 _, err := v.UnmarshalMsg(bts) 405 if err != nil { 406 b.Fatal(err) 407 } 408 } 409 } 410 411 func TestEncodeDecodeZtype(t *testing.T) { 412 v := Ztype{} 413 var buf bytes.Buffer 414 msgp.Encode(&buf, &v) 415 416 m := v.Msgsize() 417 if buf.Len() > m { 418 t.Logf("WARNING: Msgsize() for %v is inaccurate", v) 419 } 420 421 vn := Ztype{} 422 err := msgp.Decode(&buf, &vn) 423 if err != nil { 424 t.Error(err) 425 } 426 427 buf.Reset() 428 msgp.Encode(&buf, &v) 429 err = msgp.NewReader(&buf).Skip() 430 if err != nil { 431 t.Error(err) 432 } 433 } 434 435 func BenchmarkEncodeZtype(b *testing.B) { 436 v := Ztype{} 437 var buf bytes.Buffer 438 msgp.Encode(&buf, &v) 439 b.SetBytes(int64(buf.Len())) 440 en := msgp.NewWriter(msgp.Nowhere) 441 b.ReportAllocs() 442 b.ResetTimer() 443 for i := 0; i < b.N; i++ { 444 v.EncodeMsg(en) 445 } 446 en.Flush() 447 } 448 449 func BenchmarkDecodeZtype(b *testing.B) { 450 v := Ztype{} 451 var buf bytes.Buffer 452 msgp.Encode(&buf, &v) 453 b.SetBytes(int64(buf.Len())) 454 rd := msgp.NewEndlessReader(buf.Bytes(), b) 455 dc := msgp.NewReader(rd) 456 b.ReportAllocs() 457 b.ResetTimer() 458 for i := 0; i < b.N; i++ { 459 err := v.DecodeMsg(dc) 460 if err != nil { 461 b.Fatal(err) 462 } 463 } 464 }