gitee.com/quant1x/gox@v1.21.2/encoding/binary/cstruct/tests/array_test.go (about) 1 package tests 2 3 import ( 4 "gitee.com/quant1x/gox/encoding/binary/cstruct" 5 "testing" 6 ) 7 8 type mystruct6 struct { 9 F37 uint16 10 F38 [5]int32 11 } 12 13 type mystruct5 struct { 14 F32 [5]int8 15 F33 [6]byte 16 F34 [7]uint8 17 F35 [4]bool 18 F36 [5]int16 19 F37 [5]uint16 20 F38 [5]int32 21 F39 [5]uint32 22 F40 [5]float32 23 F41 [5]int64 24 F42 [5]uint64 25 F43 [5]float64 26 F44 [3]mystruct6 27 } 28 29 func Test_LE111(t *testing.T) { 30 a := &mystruct5{} 31 a.F32 = [5]int8{0, -128, 2, 127, 4} 32 a.F33 = [6]byte{'h', 'e', 'l', 'l', 'o', '1'} 33 a.F34 = [7]uint8{0, 1, 2, 3, 255, 5, 6} 34 a.F35 = [4]bool{true, false, false, true} 35 a.F36 = [5]int16{1, -1, 0, 32767, -32768} 36 a.F37 = [5]uint16{0, 1, 2, 32767, 65535} 37 a.F38 = [5]int32{1, -1, 0, 2147483647, -2147483648} 38 a.F39 = [5]uint32{0, 1, 2, 2147483647, 4294967295} 39 a.F40 = [5]float32{0.98, -1, 0, -0.98, 999.9} 40 a.F41 = [5]int64{1, -1, 0, 9223372036854775807, -9223372036854775808} 41 a.F42 = [5]uint64{0, 1, 2, 9223372036854775807, 18446744073709551615} 42 a.F43 = [5]float64{0, 999888888.777, 2, -999888888.777, 99999999.99} 43 44 b1 := mystruct6{} 45 b1.F37 = 65535 46 b1.F38 = [5]int32{1, -1, 0, 2147483647, -2147483648} 47 b2 := mystruct6{} 48 b2.F37 = 1 49 b2.F38 = [5]int32{1, -1, 0, 1, -2} 50 b3 := mystruct6{} 51 b3.F37 = 65535 52 b3.F38 = [5]int32{3, -3, 0, 3, -3} 53 a.F44 = [3]mystruct6{b1, b2, b3} 54 55 test111(t, a) 56 } 57 58 func test111(t *testing.T, a *mystruct5) { 59 buf_l, _ := cstruct.Pack(a) 60 b := &mystruct5{} 61 if err := cstruct.Unpack(buf_l, b); err != nil { 62 t.Log(err) 63 t.Error("出错啦!") 64 return 65 } 66 67 t.Log(b.F32) 68 t.Log(b.F33) 69 t.Log(b.F34) 70 t.Log(b.F35) 71 t.Log(b.F36) 72 t.Log(b.F37) 73 t.Log(b.F38) 74 t.Log(b.F39) 75 t.Log(b.F40) 76 t.Log(b.F41) 77 t.Log(b.F42) 78 t.Log(b.F43) 79 t.Log(b.F44) 80 }