Fix compile errors on macOS and add some tests

This commit is contained in:
xl000
2023-05-21 20:24:25 +08:00
parent 3d6d57d199
commit af69301e52
9 changed files with 85 additions and 6 deletions

27
tests/cmd_test.go Normal file
View File

@@ -0,0 +1,27 @@
package tests
import (
"hk4e/protocol/cmd"
"hk4e/protocol/proto"
"reflect"
"testing"
"github.com/stretchr/testify/assert"
)
func TestCmd(t *testing.T) {
t.Log("TestCmd")
pbm := cmd.NewCmdProtoMap()
ping_req1 := pbm.GetProtoObjByCmdId(cmd.PingReq)
t1 := reflect.TypeOf(ping_req1)
t.Log(t1, t1.Elem(), t1.Elem().Name())
ping_req2 := new(proto.PingReq)
t2 := reflect.TypeOf(ping_req2)
t.Log(t2, t2.Elem(), t2.Elem().Name())
assert.Equal(t, t1.Elem().Name(), t2.Elem().Name())
assert.Equal(t, pbm.GetCmdNameByCmdId(cmd.PingReq), "PingReq")
assert.Equal(t, int(pbm.GetCmdIdByCmdName("PingReq")), cmd.PingReq)
assert.Equal(t, int(pbm.GetCmdIdByProtoObj(ping_req1)), cmd.PingReq)
assert.Equal(t, int(pbm.GetCmdIdByProtoObj(ping_req2)), cmd.PingReq)
}