github.com/qjfoidnh/BaiduPCS-Go@v0.0.0-20231011165705-caa18a3765f3/pcsutil/checksum/checksum_test.go (about)

     1  package checksum_test
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/qjfoidnh/BaiduPCS-Go/pcsutil/checksum"
     6  	"testing"
     7  )
     8  
     9  var (
    10  	flagList = []int{
    11  		checksum.CHECKSUM_MD5 | 000000000000000000000000000 | 00000000000000000000000,
    12  		000000000000000000000 | checksum.CHECKSUM_SLICE_MD5 | 00000000000000000000000,
    13  		000000000000000000000 | 000000000000000000000000000 | checksum.CHECKSUM_CRC32,
    14  		checksum.CHECKSUM_MD5 | checksum.CHECKSUM_SLICE_MD5 | 00000000000000000000000,
    15  		000000000000000000000 | checksum.CHECKSUM_SLICE_MD5 | checksum.CHECKSUM_CRC32,
    16  		checksum.CHECKSUM_MD5 | 000000000000000000000000000 | checksum.CHECKSUM_CRC32,
    17  		checksum.CHECKSUM_MD5 | checksum.CHECKSUM_SLICE_MD5 | checksum.CHECKSUM_CRC32,
    18  	}
    19  )
    20  
    21  func printFileMeta(meta *checksum.LocalFileMeta) {
    22  	fmt.Printf("slicemd5: %x, md5: %x, crc32: %x %d\n", meta.SliceMD5, meta.MD5, meta.CRC32, meta.CRC32)
    23  }
    24  
    25  func TestChecksum(t *testing.T) {
    26  	fmt.Println("--- file.go")
    27  	for _, flag := range flagList {
    28  		lf, err := checksum.GetFileSum("file.go", flag)
    29  		if err != nil {
    30  			t.Fatal(err)
    31  		}
    32  		printFileMeta(&lf.LocalFileMeta)
    33  	}
    34  
    35  	fmt.Println("--- /Users/syy/go/src/github.com/qjfoidnh/BaiduPCS-Go/BaiduPCS-Go")
    36  	for _, flag := range flagList {
    37  		lf := checksum.NewLocalFileChecksumWithBufSize("/Users/syy/go/src/github.com/qjfoidnh/BaiduPCS-Go/BaiduPCS-Go", checksum.DefaultBufSize-3, checksum.DefaultBufSize)
    38  		err := lf.OpenPath()
    39  		if err != nil {
    40  			t.Fatal(err)
    41  		}
    42  		lf.Sum(flag)
    43  		printFileMeta(&lf.LocalFileMeta)
    44  	}
    45  }