instruction_test.go 4.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package guac
  15. import (
  16. "testing"
  17. "yunion.io/x/log"
  18. )
  19. // 4.args,13.VERSION_1_5_0,8.hostname,4.port,6.domain,8.username,8.password,5.width,6.height,3.dpi,15.initial-program,11.color-depth,13.disable-audio,15.enable-printing,12.printer-name,12.enable-drive,10.drive-name,10.drive-path,17.create-drive-path,16.disable-download,14.disable-upload,7.console,13.console-audio,13.server-layout,8.security,11.ignore-cert,12.disable-auth,10.remote-app,14.remote-app-dir,15.remote-app-args,15.static-channels,11.client-name,16.enable-wallpaper,14.enable-theming,21.enable-font-smoothing,23.enable-full-window-drag,26.enable-desktop-composition,22.enable-menu-animations,22.disable-bitmap-caching,25.disable-offscreen-caching,21.disable-glyph-caching,16.preconnection-id,18.preconnection-blob,8.timezone,11.enable-sftp,13.sftp-hostname,13.sftp-host-key,9.sftp-port,13.sftp-username,13.sftp-password,16.sftp-private-key,15.sftp-passphrase,14.sftp-directory,19.sftp-root-directory,26.sftp-server-alive-interval,21.sftp-disable-download,19.sftp-disable-upload,14.recording-path,14.recording-name,24.recording-exclude-output,23.recording-exclude-mouse,23.recording-exclude-touch,22.recording-include-keys,21.create-recording-path,13.resize-method,18.enable-audio-input,12.enable-touch,9.read-only,16.gateway-hostname,12.gateway-port,14.gateway-domain,16.gateway-username,16.gateway-password,17.load-balance-info,12.disable-copy,13.disable-paste,15.wol-send-packet,12.wol-mac-addr,18.wol-broadcast-addr,12.wol-udp-port,13.wol-wait-time,14.force-lossless,19.normalize-clipboard;
  20. func TestInstruction(t *testing.T) {
  21. cases := []struct {
  22. instructionStr string
  23. left string
  24. want []*Instruction
  25. }{
  26. {"5.ready,37.$59a9eff3-ef1a-4758-8be2-0f1d06b4c8be;", "", []*Instruction{NewInstruction("ready", "$59a9eff3-ef1a-4758-8be2-0f1d06b4c8be")}},
  27. {"5.audio,1.1,31.audio/L16;rate=44100,channels=2;4.size,1.0,4.1648,3.991;4.size,2.-1,2.11,2.16;3.img,1.3,2.12,2.-1,9.image/png,1.0,1.0;4.blob,1.3,232.iVBORw0KGgoAAAANSUhEUgAAAAsAAAAQCAYAAADAvYV+AAAABmJLR0QA/wD/AP+gvaeTAAAAYklEQVQokY2RQQ4AIQgDW+L/v9y9qCEsIJ4QZggoJAnDYwAwFQwASI4EO8FEMH95CRYTnfCDOyGFK6GEM6GFo7AqKI4sSSsCJH1X+roFkKdjueABX/On77lz2uGtr6pj9okfTeJQAYVaxnMAAAAASUVORK5CYII=;3.end,1.3;6.cursor,1.0,1.0,2.-1,1.0,1.0,2.11,2.16;", "", []*Instruction{
  28. NewInstruction("audio", "1", "audio/L16;rate=44100,channels=2"),
  29. NewInstruction("size", "0", "1648", "991"),
  30. NewInstruction("size", "-1", "11", "16"),
  31. NewInstruction("img", "3", "12", "-1", "image/png", "0", "0"),
  32. NewInstruction("blob", "3", "iVBORw0KGgoAAAANSUhEUgAAAAsAAAAQCAYAAADAvYV+AAAABmJLR0QA/wD/AP+gvaeTAAAAYklEQVQokY2RQQ4AIQgDW+L/v9y9qCEsIJ4QZggoJAnDYwAwFQwASI4EO8FEMH95CRYTnfCDOyGFK6GEM6GFo7AqKI4sSSsCJH1X+roFkKdjueABX/On77lz2uGtr6pj9okfTeJQAYVaxnMAAAAASUVORK5CYII="),
  33. NewInstruction("end", "3"),
  34. NewInstruction("cursor", "0", "0", "-1", "0", "0", "11", "16"),
  35. }},
  36. {"4.copy,2.-2,1.0,1.0,2.64,2.64,2.14,1.0,3.640,3.576;4.copy,2.-2,1.0,1.0,2.64,2.64,2.14,1.0,3.704,3.576;4.copy,2.-2,1.0,1.0,2.64,2.64,2.14,1.0,3.7",
  37. "4.copy,2.-2,1.0,1.0,2.64,2.64,2.14,1.0,3.7",
  38. []*Instruction{
  39. NewInstruction("copy", "-2", "0", "0", "64", "64", "14", "0", "640", "576"),
  40. NewInstruction("copy", "-2", "0", "0", "64", "64", "14", "0", "704", "576"),
  41. }},
  42. {"4.copy,2.-6,1.0,1.0,2.64,2.64,2.14,1.0,3.640,3.576;4.copy,2.-6,1", "4.copy,2.-6,1", []*Instruction{
  43. NewInstruction("copy", "-6", "0", "0", "64", "64", "14", "0", "640", "576"),
  44. }},
  45. }
  46. for _, c := range cases {
  47. t.Run("test instruction", func(t *testing.T) {
  48. instructions, left, err := parse([]byte(c.instructionStr))
  49. if err != nil {
  50. t.Fatalf("parse %s error: %v", c.instructionStr, err)
  51. }
  52. if c.left != string(left) {
  53. log.Fatalf("want %s left, got %s", c.left, string(left))
  54. }
  55. if len(instructions) != len(c.want) {
  56. log.Fatalf("want %d instructions, parse %d", len(c.want), len(instructions))
  57. }
  58. for i := range instructions {
  59. if instructions[i].String() != c.want[i].String() {
  60. log.Fatalf("%s not equals %s", instructions[i].String(), c.want[i].String())
  61. }
  62. }
  63. })
  64. }
  65. }