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