io_test.go 643 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package kcp_test
  2. import (
  3. "testing"
  4. . "v2ray.com/core/transport/internet/kcp"
  5. )
  6. func TestKCPPacketReader(t *testing.T) {
  7. reader := KCPPacketReader{
  8. Security: &SimpleAuthenticator{},
  9. }
  10. testCases := []struct {
  11. Input []byte
  12. Output []Segment
  13. }{
  14. {
  15. Input: []byte{},
  16. Output: nil,
  17. },
  18. {
  19. Input: []byte{1},
  20. Output: nil,
  21. },
  22. }
  23. for _, testCase := range testCases {
  24. seg := reader.Read(testCase.Input)
  25. if testCase.Output == nil && seg != nil {
  26. t.Errorf("Expect nothing returned, but actually %v", seg)
  27. } else if testCase.Output != nil && seg == nil {
  28. t.Errorf("Expect some output, but got nil")
  29. }
  30. }
  31. }