github.com/suiyunonghen/DxCommonLib@v0.5.3/bits_test.go (about) 1 package DxCommonLib 2 3 import ( 4 "encoding/binary" 5 "os" 6 "testing" 7 "fmt" 8 "unsafe" 9 ) 10 11 12 13 14 func TestMemMove(t *testing.T) { 15 m := ([]byte)("12345678") 16 b := make([]byte,20) 17 CopyMemory(unsafe.Pointer(&b[0]),unsafe.Pointer(&m[0]),uintptr(len(m))) 18 19 fmt.Println(string(b)) 20 fmt.Println(b) 21 fmt.Println(m) 22 if CompareMem(unsafe.Pointer(&m[0]),unsafe.Pointer(&b[0]),len(m)){ 23 ZeroMemory(unsafe.Pointer(&m[0]),uintptr(len(m))) 24 fmt.Println("内存相等") 25 } 26 fmt.Println(m) 27 } 28 func TestTDxBits_Bits(t *testing.T) { 29 bits := DxBits{} 30 bits.ReSetByInt32(255) 31 fmt.Println(bits.Bits(3)) 32 fmt.Println(bits.AsInt32()) 33 bits.SetBits(3,true) 34 fmt.Println(bits.AsInt32()) 35 fmt.Println(bits.Bits(3)) 36 37 bits.ReSetByInt32(-1) 38 bits.NotBits(-1) 39 fmt.Println(bits.AsInt32()) 40 } 41 42 43 func TestBitLitten(t *testing.T) { 44 var b [8]byte 45 binary.BigEndian.PutUint64(b[:],189234) 46 fmt.Println(b) 47 file,err := os.OpenFile(`d:\1.bin`,int(FMCreate),0660) 48 if err==nil{ 49 file.Write(b[:]) 50 file.Close() 51 } 52 } 53 54 func TestGFileStream_Read(t *testing.T) { 55 stream,_ := NewFileStream(`E:\Delphi\Controls\UI\Skin\DXScene v4.42\dx_vgcore.pas`,FMOpenRead,4096) 56 mb := make([]byte,4096*2+100) 57 a,_ := stream.Read(mb) 58 fmt.Println(a) 59 fmt.Println(string(mb)) 60 fmt.Println(stream.FilePosition()) 61 fmt.Println(stream.Position()) 62 63 stream.Read(mb) 64 fmt.Println(stream.FilePosition()) 65 66 fmt.Println(string(mb)) 67 stream.Read(mb) 68 fmt.Println(string(mb)) 69 stream.Read(mb) 70 fmt.Println(string(mb)) 71 } 72 73 func TestGFileStream_Write(t *testing.T) { 74 stream,_ := NewFileStream(`E:\1.txt`,FMOpenReadWrite,4096) 75 stream.Write([]byte("测试不得闲")) 76 stream.Close() 77 }