github.com/suiyunonghen/dxcommonlib@v0.0.0-20190612012041-7f8547a81a67/bits_test.go (about)

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