1 Star 0 Fork 2

mickelfeng/openp2p

forked from 柔情铁憨/openp2p 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
common_test.go 2.15 KB
一键复制 编辑 原始数据 按行查看 历史
柔情铁憨 提交于 2022-04-27 23:34 +08:00 . 1.5.5
package main
import (
"log"
"testing"
)
func TestAESCBC(t *testing.T) {
for packetSize := 1; packetSize <= 8192; packetSize++ {
log.Println("test packetSize=", packetSize)
data := make([]byte, packetSize)
for i := 0; i < packetSize; i++ {
data[i] = byte('0' + i%10)
}
p2pEncryptBuf := make([]byte, len(data)+PaddingSize)
inBuf := make([]byte, len(data)+PaddingSize)
copy(inBuf, data)
cryptKey := []byte("0123456789ABCDEF")
sendBuf, err := encryptBytes(cryptKey, p2pEncryptBuf, inBuf, len(data))
if err != nil {
t.Errorf("encrypt packet failed:%s", err)
}
log.Printf("encrypt data len=%d\n", len(sendBuf))
decryptBuf := make([]byte, len(sendBuf))
outBuf, err := decryptBytes(cryptKey, decryptBuf, sendBuf, len(sendBuf))
if err != nil {
t.Errorf("decrypt packet failed:%s", err)
}
// log.Printf("len=%d,content=%s\n", len(outBuf), outBuf)
log.Printf("decrypt data len=%d\n", len(outBuf))
log.Println("validate")
for i := 0; i < len(outBuf); i++ {
if outBuf[i] != byte('0'+i%10) {
t.Error("validate failed")
}
}
log.Println("validate ok")
}
}
func TestNetInfo(t *testing.T) {
log.Println(netInfo())
}
func assertCompareVersion(t *testing.T, v1 string, v2 string, result int) {
if compareVersion(v1, v2) != result {
t.Errorf("compare version %s %s fail\n", v1, v2)
}
}
func TestCompareVersion(t *testing.T) {
// test =
assertCompareVersion(t, "0.98.0", "0.98.0", EQUAL)
assertCompareVersion(t, "0.98", "0.98", EQUAL)
assertCompareVersion(t, "1.4.0", "1.4.0", EQUAL)
assertCompareVersion(t, "1.5.0", "1.5.0", EQUAL)
// test >
assertCompareVersion(t, "0.98.0.22345", "0.98.0.12345", GREATER)
assertCompareVersion(t, "1.98.0.12345", "0.98", GREATER)
assertCompareVersion(t, "10.98.0.12345", "9.98.0.12345", GREATER)
assertCompareVersion(t, "1.4.0", "0.98.0.12345", GREATER)
assertCompareVersion(t, "1.4", "0.98.0.12345", GREATER)
assertCompareVersion(t, "1", "0.98.0.12345", GREATER)
// test <
assertCompareVersion(t, "0.98.0.12345", "0.98.0.12346", LESS)
assertCompareVersion(t, "9.98.0.12345", "10.98.0.12345", LESS)
assertCompareVersion(t, "1.4.2", "1.5.0", LESS)
assertCompareVersion(t, "", "1.5.0", LESS)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mickelfeng/openp2p.git
git@gitee.com:mickelfeng/openp2p.git
mickelfeng
openp2p
openp2p
master

搜索帮助