github.com/kayoticsully/syncthing@v0.8.9-0.20140724133906-c45a2fdc03f8/xdr/encdec_test.go (about) 1 // Copyright (C) 2014 Jakob Borg and Contributors (see the CONTRIBUTORS file). 2 // All rights reserved. Use of this source code is governed by an MIT-style 3 // license that can be found in the LICENSE file. 4 5 package xdr_test 6 7 import ( 8 "bytes" 9 "testing" 10 "testing/quick" 11 ) 12 13 // Contains all supported types 14 type TestStruct struct { 15 I int 16 I16 int16 17 UI16 uint16 18 I32 int32 19 UI32 uint32 20 I64 int64 21 UI64 uint64 22 BS []byte 23 S string 24 } 25 26 func TestEncDec(t *testing.T) { 27 fn := func(t0 TestStruct) bool { 28 bs := t0.MarshalXDR() 29 var t1 TestStruct 30 err := t1.UnmarshalXDR(bs) 31 if err != nil { 32 t.Fatal(err) 33 } 34 35 // Not comparing with DeepEqual since we'll unmarshal nil slices as empty 36 if t0.I != t1.I || 37 t0.I16 != t1.I16 || t0.UI16 != t1.UI16 || 38 t0.I32 != t1.I32 || t0.UI32 != t1.UI32 || 39 t0.I64 != t1.I64 || t0.UI64 != t1.UI64 || 40 bytes.Compare(t0.BS, t1.BS) != 0 || 41 t0.S != t1.S { 42 t.Logf("%#v", t0) 43 t.Logf("%#v", t1) 44 return false 45 } 46 return true 47 } 48 if err := quick.Check(fn, nil); err != nil { 49 t.Error(err) 50 } 51 }