package video_decrypt

import (
	"bytes"
	"fmt"
	"testing"
	"time"
)

func TestGetSortTable(t *testing.T) {
	sortTable := getSortTable(12345667)
	fmt.Println(sortTable)
}

func TestGetSortTableCheck(t *testing.T) {
	sortTable := getSortTable(12345667)

	//检查长度
	if len(sortTable) != 256 {
		fmt.Println("长度不对")
		return
	}

	//检查是否有所有元素
	for i := 0; i <= 0xff; i++ {
		if !bytes.Contains(sortTable, []byte{byte(i)}) {
			fmt.Printf("不包含元素:%d", i)
			return
		}
	}

	fmt.Println("ok")
}

func TestEncryptData(t *testing.T) {
	dataStr := []byte{2, 3, 4, 5, 6}
	key := "11111111111111"

	encData, err := EncryptData([]byte(dataStr), key)
	if err != nil {
		fmt.Println("err:", err)
		return
	}

	fmt.Println((encData))
}

func TestDecryptData(t *testing.T) {
	dataStr := []byte{2, 3, 4, 5, 6}
	key := "11111111111111"

	encData, err := EncryptData(dataStr, key)
	if err != nil {
		fmt.Println("err:", err)
		return
	}

	decData, err := decryptData(encData, key)
	fmt.Println(decData)
}

func TestHandle_ServeHTTP(t *testing.T) {
	//https://video-up.oss-accelerate.aliyuncs.com/2021126qXJsenyTcZoe.mp4
	err := StartServer("https://video-up.oss-accelerate.aliyuncs.com/2021126qXJsenyTcZoe.mp4", "video-up.oss-accelerate.aliyuncs.com")
	if err != nil {
		t.Error(err)
		return
	}

	hostPath := GetHostPath()
	dataUrl := hostPath + "/2021126qXJsenyTcZoe.mp4"

	fmt.Println(dataUrl)

	time.Sleep(1000 * time.Hour)
}

func TestSortTable(t *testing.T) {
	key := "ab11cke22y123"
	fmt.Println([]byte(key))
	mapTable := getSortTableV2(key)
	fmt.Println(mapTable)
}
