1#!/usr/bin/env ruby 2 3require "minitest" 4require "./xdo_test_helper" 5 6class XdotoolMouseMoveTests < MiniTest::Test 7 include XdoTestHelper 8 9 def test_mousemove_should_have_no_output 10 status, lines = xdotool_ok "mousemove 0 0" 11 assert_equal(0, lines.length, "mousemove should have no output") 12 end # def test_mousemove_should_have_no_output 13 14 def test_mousemove_flags 15 xdotool_ok "mousemove -c 0 0" 16 xdotool_ok "mousemove --clearmodifiers 0 0" 17 xdotool_ok "mousemove -p 0 0" 18 xdotool_ok "mousemove --polar 0 0" 19 xdotool_ok "mousemove --screen 0 0 0" 20 xdotool_ok "mousemove --sync 0 0" 21 xdotool_ok "mousemove -w #{@wid} 0 0" 22 xdotool_ok "mousemove --window #{@wid} 0 0" 23 end # def test_mousemove_flags 24 25 def test_mousemove 26 x_list = [0, 1, 100, 200, 400] 27 y_list = [0, 1, 100, 200, 400] 28 29 x_list.each do |x| 30 y_list.each do |y| 31 status, lines = xdotool_ok "mousemove #{x} #{y}" 32 try do 33 assert_mouse_position(x, y) 34 end 35 end # x_list.each 36 end # y_list.each 37 end # def test_mousemove 38 39 def test_mousemove_with_sync 40 x_list = [0, 200, 400] 41 y_list = [0, 200, 400] 42 43 x_list.each do |x| 44 y_list.each do |y| 45 status, lines = xdotool_ok "mousemove --sync #{x} #{y}" 46 assert_mouse_position(x, y) 47 end # x_list.each 48 end # y_list.each 49 end # def test_mousemove 50 51 def test_mousemove_polar 52 dimensions = %x{xdpyinfo}.split("\n").grep(/dimensions:/).first.split[1] 53 w, h = dimensions.split("x").collect { |v| v.to_i } 54 55 center_x = (w/2).to_i 56 center_y = (h/2).to_i 57 58 xdotool_ok "mousemove --sync --polar 0 100" 59 assert_mouse_position_near(center_x, center_y - 100); 60 61 xdotool_ok "mousemove --sync --polar 90 100" 62 assert_mouse_position_near(center_x + 100, center_y); 63 64 xdotool_ok "mousemove --sync --polar 180 100" 65 assert_mouse_position_near(center_x, center_y + 100); 66 67 xdotool_ok "mousemove --sync --polar 270 100" 68 assert_mouse_position_near(center_x - 100, center_y); 69 end 70 71 def test_mousemove_relative 72 start_x = 300 73 start_y = 200 74 75 xdotool_ok "mousemove --sync #{start_x} #{start_y}" 76 77 x_list = [-100, -50, -10, -5, -1, 0,1,20,50,100] 78 y_list = [-100, -50, -10, -5, -1, 0,1,20,50,100] 79 80 x_list.each do |x| 81 y_list.each do |y| 82 xdotool_ok "mousemove --sync #{start_x} #{start_y}" 83 status, lines = xdotool_ok "mousemove_relative --sync -- #{x} #{y}" 84 assert_mouse_position_near(start_x + x, start_y + y) 85 end # x_list.each 86 end # y_list.each 87 end 88 89 def test_mousemove_relative_polar 90 start_x = 300 91 start_y = 200; 92 93 xdotool_ok "mousemove --sync #{start_x} #{start_y}" 94 xdotool_ok "mousemove_relative --sync --polar 0 100" 95 assert_mouse_position_near(start_x, start_y - 100); 96 97 xdotool_ok "mousemove --sync #{start_x} #{start_y}" 98 xdotool_ok "mousemove_relative --sync --polar 90 100" 99 assert_mouse_position_near(start_x + 100, start_y); 100 101 xdotool_ok "mousemove --sync #{start_x} #{start_y}" 102 xdotool_ok "mousemove_relative --sync --polar 180 100" 103 assert_mouse_position_near(start_x, start_y + 100); 104 105 xdotool_ok "mousemove --sync #{start_x} #{start_y}" 106 xdotool_ok "mousemove_relative --sync --polar 270 100" 107 assert_mouse_position_near(start_x - 100, start_y); 108 end 109 110 # https://github.com/jordansissel/xdotool/issues/64 111 def test_mousemove_same_position_of_the_other_window 112 move_x = 100 113 move_y = 200 114 115 # It seems window wid located at (0, 0) at first. 116 xdotool_ok "windowmove --sync #{@wid} 400 400" 117 118 status, xwininfo_output = runcmd "xwininfo -id #{@wid}" 119 the_other_window_x = xwininfo_output.grep(/ Absolute upper-left X:/).first[/[0-9]+/].to_i 120 the_other_window_y = xwininfo_output.grep(/ Absolute upper-left Y:/).first[/[0-9]+/].to_i 121 122 xdotool_ok "mousemove --sync #{move_x} #{move_y}" 123 xdotool_ok "mousemove --sync --window #{@wid} #{move_x} #{move_y}" 124 125 assert_mouse_position_near(the_other_window_x + move_x, 126 the_other_window_y + move_y) 127 end 128end # XdotoolMouseMoveTests 129