ftc_test.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // License: GPLv3 Copyright: 2023, Kovid Goyal, <kovid at kovidgoyal.net>
  2. package transfer
  3. import (
  4. "fmt"
  5. "strings"
  6. "testing"
  7. "time"
  8. "github.com/google/go-cmp/cmp"
  9. )
  10. var _ = fmt.Print
  11. func TestFTCSerialization(t *testing.T) {
  12. ftc := FileTransmissionCommand{}
  13. q := func(expected string) {
  14. actual := ftc.Serialize()
  15. ad := make(map[string]bool)
  16. for _, x := range strings.Split(actual, ";") {
  17. ad[x] = true
  18. }
  19. ed := make(map[string]bool)
  20. for _, x := range strings.Split(expected, ";") {
  21. ed[x] = true
  22. }
  23. if diff := cmp.Diff(ed, ad); diff != "" {
  24. t.Fatalf("Failed to Serialize:\n%s", diff)
  25. }
  26. }
  27. q("")
  28. ftc.Action = Action_send
  29. q("ac=send")
  30. ftc.File_id = "fid"
  31. ftc.Name = "moose"
  32. ftc.Mtime = time.Second
  33. ftc.Permissions = 0o600
  34. ftc.Data = []byte("moose")
  35. q("ac=send;fid=fid;n=bW9vc2U;mod=1000000000;prm=384;d=bW9vc2U")
  36. n, err := NewFileTransmissionCommand(ftc.Serialize())
  37. if err != nil {
  38. t.Fatal(err)
  39. }
  40. q(n.Serialize())
  41. unsafe := "moo\x1b;;[?*.-se1"
  42. if safe_string(unsafe) != "moo.-se1" {
  43. t.Fatalf("safe_string() failed for %#v yielding: %#v", unsafe, safe_string(unsafe))
  44. }
  45. }