gitee.com/quant1x/gox@v1.21.2/encoding/binary/cstruct/tests/slice_struct_test.go (about) 1 package tests 2 3 import ( 4 "gitee.com/quant1x/gox/encoding/binary/cstruct" 5 "testing" 6 ) 7 8 type mystruct12 struct { 9 F1 int8 10 } 11 12 type mystruct10 struct { 13 F2 []mystruct12 14 F1 int32 15 F3 []mystruct12 16 } 17 18 type mystruct9 struct { 19 F90 []mystruct10 20 } 21 22 func Test_LE9(t *testing.T) { 23 b1 := []mystruct12{mystruct12{1}, mystruct12{2}, mystruct12{3}, mystruct12{4}} 24 b2 := []mystruct12{} 25 b3 := []mystruct12{mystruct12{1}, mystruct12{2}} 26 { 27 a := &mystruct9{} 28 a.F90 = []mystruct10{mystruct10{nil, 1, nil}, mystruct10{nil, 2, nil}, mystruct10{b3, 3, b1}} 29 test9(t, a) 30 } 31 { 32 a := &mystruct9{} 33 a.F90 = []mystruct10{mystruct10{b1, 1, b3}} 34 test9(t, a) 35 } 36 { 37 a := &mystruct9{} 38 a.F90 = []mystruct10{} 39 test9(t, a) 40 } 41 { 42 a := &mystruct9{} 43 a.F90 = []mystruct10{mystruct10{b1, 1, b2}} 44 test9(t, a) 45 46 } 47 { 48 a := &mystruct9{} 49 a.F90 = []mystruct10{mystruct10{b2, 1, b1}} 50 test9(t, a) 51 } 52 { 53 a := &mystruct9{} 54 a.F90 = []mystruct10{mystruct10{b1, 1, b2}, mystruct10{b2, 1, b1}, mystruct10{b2, 1, b1}, mystruct10{b2, 1, b1}} 55 test9(t, a) 56 57 } 58 } 59 60 func test9(t *testing.T, a *mystruct9) { 61 buf_l, _ := cstruct.Pack(a) 62 b := &mystruct9{} 63 t.Log(buf_l) 64 if err := cstruct.Unpack(buf_l, b); err != nil { 65 t.Log(err) 66 t.Error("出错啦!") 67 return 68 } 69 t.Log(b) 70 }