PageRenderTime 62ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/xdotool-2.20110530.1/t/test_typing.rb

#
Ruby | 140 lines | 103 code | 25 blank | 12 comment | 4 complexity | 86dee6fbf08ded346935343a25d25a55 MD5 | raw file
  1. #!/usr/bin/env ruby
  2. #
  3. require "test/unit"
  4. require "tempfile"
  5. require "xdo_test_helper"
  6. class XdotoolTypingTests < Test::Unit::TestCase
  7. include XdoTestHelper
  8. SYMBOLS = "`12345678990-=~ !@\#$%^&*()_+[]\{}|;':\",./<>?"
  9. LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
  10. # override XdoTestHelper#setup
  11. def setup
  12. @xdotool = "../xdotool"
  13. @title = "#{self.class.name}_#{rand}"
  14. setup_ensure_x_is_healthy
  15. @file = Tempfile.new("xdotool-test")
  16. setup_launch_xterm("cat >> #{@file.path}")
  17. ready = false
  18. while !ready
  19. #puts "Waiting for focus"
  20. xdotool "windowfocus #{@wid}"
  21. status, lines = xdotool "getwindowfocus -f"
  22. if status == 0 and lines.first.to_i == @wid
  23. ready = true
  24. end
  25. sleep 0.2
  26. end
  27. #puts "Window #{@wid} has focus"
  28. end # def setup
  29. def readfile
  30. # gedit and other editors don't truncate the file, they simply
  31. # create a new file and overwrite it. This is observable by
  32. # noting the inode number changing on the file. At any rate, this
  33. # requires us to open the file by name instead of using the existing
  34. # @file.
  35. file = File.open(@file.path, "r")
  36. return file.read.chomp
  37. end
  38. def type(input)
  39. #status, lines = xdotool "type --window #{@wid} --clearmodifiers '#{input}'"
  40. #_xdotool "key ctrl+s ctrl+q"
  41. input.gsub!(/'/, "\\'")
  42. status, lines = xdotool "type --clearmodifiers '#{input}'"
  43. xdotool "key ctrl+d ctrl+d"
  44. Process.wait(@launchpid) rescue nil
  45. return readfile
  46. end
  47. def _test_typing(input)
  48. data = type(input)
  49. assert_equal(input, data)
  50. end
  51. def test_us_simple_typing
  52. system("setxkbmap us")
  53. _test_typing(LETTERS)
  54. end
  55. def test_us_symbol_typing
  56. system("setxkbmap us")
  57. _test_typing(SYMBOLS)
  58. end
  59. def test_us_se_simple_typing
  60. system("setxkbmap -option grp:switch,grp:shifts_toggle us,se")
  61. _test_typing(LETTERS)
  62. end
  63. def test_us_se_symbol_typing
  64. system("setxkbmap -option grp:switch,grp:shifts_toggle us,se")
  65. _test_typing(SYMBOLS)
  66. end
  67. def test_se_us_simple_typing
  68. system("setxkbmap -option grp:switch,grp:shifts_toggle se,us")
  69. _test_typing(LETTERS)
  70. end
  71. def test_se_us_symbol_typing
  72. system("setxkbmap -option grp:switch,grp:shifts_toggle se,us")
  73. _test_typing(SYMBOLS)
  74. end
  75. def test_us_dvorak_simple_typing
  76. system("setxkbmap us dvorak")
  77. _test_typing(LETTERS)
  78. end
  79. def test_us_dvorak_symbol_typing
  80. system("setxkbmap us dvorak")
  81. _test_typing(SYMBOLS)
  82. end
  83. def test_se_simple_typing
  84. system("setxkbmap se")
  85. _test_typing(LETTERS)
  86. end
  87. def test_se_symbol_typing
  88. system("setxkbmap se")
  89. _test_typing(SYMBOLS)
  90. end
  91. def test_de_simple_typing
  92. system("setxkbmap de")
  93. _test_typing(LETTERS)
  94. end
  95. def test_de_symbol_typing
  96. system("setxkbmap de")
  97. _test_typing(SYMBOLS)
  98. end
  99. def test_terminator
  100. input = %w{hello world}
  101. status, lines = xdotool "type --clearmodifiers --terminator FIZZLE #{input.join(" ")} FIZZLE"
  102. xdotool "key ctrl+d ctrl+d"
  103. Process.wait(@launchpid) rescue nil
  104. data = readfile
  105. assert_equal(input.join(""), data)
  106. end # def test_terminator
  107. def test_arity
  108. input = %w{hello world}
  109. status, lines = xdotool "type --clearmodifiers --args 2 #{input.join(" ")}"
  110. xdotool "key ctrl+d ctrl+d"
  111. Process.wait(@launchpid) rescue nil
  112. data = readfile
  113. assert_equal(input.join(""), data)
  114. end # def test_terminator
  115. end # class XdotoolTypingTests