imitator_x 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/ext/xwindow.h ADDED
@@ -0,0 +1,38 @@
1
+ /*********************************************************************************
2
+ Imitator for X is a library allowing you to fake input to systems using X11.
3
+ Copyright � 2010 Marvin G�lker
4
+
5
+ This file is part of Imitator for X.
6
+
7
+ Imitator for X is free software: you can redistribute it and/or modify
8
+ it under the terms of the GNU Lesser General Public License as published by
9
+ the Free Software Foundation, either version 3 of the License, or
10
+ (at your option) any later version.
11
+
12
+ Imitator for X is distributed in the hope that it will be useful,
13
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ GNU Lesser General Public License for more details.
16
+
17
+ You should have received a copy of the GNU Lesser General Public License
18
+ along with Imitator for X. If not, see <http://www.gnu.org/licenses/>.
19
+ *********************************************************************************/
20
+ #ifndef IMITATOR_XWINDOW_HEADER
21
+ #define IMITATOR_XWINDOW_HEADER
22
+
23
+ /*Gets the window ID of self and converts it to a Window. A Window is just a long. */
24
+ #define GET_WINDOW (Window) NUM2LONG(rb_ivar_get(self, rb_intern("@window_id")))
25
+
26
+ /*Converts a string returned by a X function (cp), a char *, to a ruby string
27
+ *(encoded in ISO-88591; I couldn't find out how to get the locale encoding out of X,
28
+ *so you may have to change this if ISO-8859-1 isn't your X Server's locale) and then
29
+ *to an UTF-8-encoded string. */
30
+ #define XSTR_TO_RSTR(cp) rb_str_export_to_enc(rb_enc_str_new(cp, strlen(cp), rb_enc_find("ISO-8859-1")), rb_utf8_encoding())
31
+
32
+ /*Imitator::X::XWindow*/
33
+ VALUE XWindow;
34
+
35
+ /*XWindow initialization function*/
36
+ void Init_xwindow(void);
37
+
38
+ #endif
@@ -0,0 +1,179 @@
1
+ #!/usr/bin/env ruby
2
+ #Encoding: UTF-8
3
+ =begin
4
+ --
5
+ Imitator for X is a library allowing you to fake input to systems using X11.
6
+ Copyright © 2010 Marvin Gülker
7
+
8
+ This file is part of Imitator for X.
9
+
10
+ Imitator for X is free software: you can redistribute it and/or modify
11
+ it under the terms of the GNU Lesser General Public License as published by
12
+ the Free Software Foundation, either version 3 of the License, or
13
+ (at your option) any later version.
14
+
15
+ Imitator for X is distributed in the hope that it will be useful,
16
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
+ GNU Lesser General Public License for more details.
19
+
20
+ You should have received a copy of the GNU Lesser General Public License
21
+ along with Imitator for X. If not, see <http://www.gnu.org/licenses/>.
22
+ ++
23
+ =end
24
+
25
+ module Imitator
26
+
27
+ module X
28
+
29
+ #This class wraps CD/DVD devices. After creating an object of this class
30
+ #you can open or close your drives. Also, you're able to lock and unlock them.
31
+ class XDrive
32
+ include Open3
33
+
34
+ #The +eject+ command.
35
+ EJECT = "eject"
36
+
37
+ #Returns the mount point of the default drive.
38
+ #===Return value
39
+ #A string describing the default drive.
40
+ #===Raises
41
+ #[XError] +eject+ command failed.
42
+ #===Example
43
+ # p Imitator::X::Drive.default #=> "cdrom"
44
+ def self.default
45
+ err = ""
46
+ out = ""
47
+ Open3.popen3("#{EJECT} -d") do |stdin, stdout, stderr|
48
+ stdin.close_write
49
+ out << stdout.read.chomp
50
+ err << stderr.read.chomp
51
+ end
52
+ raise(XError, err) unless err.empty?
53
+ out.match(/`(.*)'/)[1]
54
+ end
55
+
56
+ #Creates a new XDrive object.
57
+ #===Parameters
58
+ #[+drive+] (<tt>XDrive.default()</tt>) The drive to wrap. Either a device file like <tt>/dev/scd1</tt> or a mount point like <tt>cdrom1</tt>.
59
+ #===Return value
60
+ #The newly created object.
61
+ #===Raises
62
+ #[ArgumentError] Invalid drive.
63
+ #===Example
64
+ # #Get a handle to the default drive
65
+ # drive = Imitator::X::XDrive.new
66
+ # #By device file
67
+ # drive = Imitator::X::XDrive.new("/dev/scd1")
68
+ # #By mount point
69
+ # drive = Imitator::X::Drive.new("cdrom1")
70
+ def initialize(drive = XDrive.default)
71
+ @drive = drive
72
+ @locked = false
73
+ raise(ArgumentError, "No such drive: '#{@drive}'!") unless system("#{EJECT} -n #{@drive} > /dev/null 2>&1")
74
+ end
75
+
76
+ #call-seq:
77
+ # eject() ==> nil
78
+ # open() ==> nil
79
+ #
80
+ #Opens a drive.
81
+ #===Return value
82
+ #nil.
83
+ #===Raises
84
+ #[XError] +eject+ command failed.
85
+ #===Example
86
+ # drive.eject
87
+ def eject
88
+ err = ""
89
+ popen3(EJECT + " " + @drive) do |stdin, stdout, stderr|
90
+ #stdin.close_write
91
+ err << stderr.read.chomp
92
+ end
93
+ raise(XError, err) unless err.empty?
94
+ nil
95
+ end
96
+ alias open eject
97
+
98
+ #Closes a drive.
99
+ #===Return value
100
+ #nil.
101
+ #===Raises
102
+ #[XError] +eject+ command failed.
103
+ #===Example
104
+ # #The drive should be opened first, otherwise this has no effect
105
+ # drive.eject
106
+ # drive.close
107
+ #===Remarks
108
+ #Laptop devices usually can't be closed. If you try this, you'll
109
+ #get an XError saying that an Input/Output error occured.
110
+ def close
111
+ err = ""
112
+ popen3("eject -t #{@drive}") do |stdin, stdout, stderr|
113
+ stdin.close_write
114
+ err << stderr.read.chomp
115
+ end
116
+ raise(XError, err) unless err.empty?
117
+ nil
118
+ end
119
+
120
+ #Locks a drive. That means, it can't be opened by
121
+ #using the eject button.
122
+ #===Return value
123
+ #nil.
124
+ #===Example
125
+ # Imitator::X::Drive.lock!
126
+ def lock!
127
+ err = ""
128
+ popen3("#{EJECT} -i on #{@drive}") do |stdin, stdout, stderr|
129
+ stdin.close_write
130
+ err << stderr.read.chomp
131
+ end
132
+ raise(XError, err) unless err.empty?
133
+ @locked = true
134
+ nil
135
+ end
136
+
137
+ #Unlocks a drive. That means, it can be opened by the eject
138
+ #button.
139
+ #===Return value
140
+ #nil.
141
+ #===Raises
142
+ #[XError] +eject+ command failed.
143
+ #===Example
144
+ # #First, we have to lock a drive.
145
+ # Imitator::X::Drive.lock!
146
+ # Imitator::X::Drive.release!
147
+ def release!
148
+ err = ""
149
+ popen3("#{EJECT} -i off #{@drive}") do |stdin, stdout, stderr|
150
+ stdin.close_write
151
+ err << stderr.read.chomp
152
+ end
153
+ raise(XError, err) unless err.empty?
154
+ @locked = false
155
+ nil
156
+ end
157
+
158
+ #Checks wheather or not we locked a drive.
159
+ #===Return value
160
+ #true or false
161
+ #===Example
162
+ # puts drive.locked?#=> false
163
+ # drive.lock!
164
+ # puts drive.locked? #=> true
165
+ # drive.release!
166
+ # puts drive.locked? #=> false
167
+ #===Remarks
168
+ #This method works only within one Ruby application - if the drive is locked
169
+ #from outside, for example by the user typing "eject -i on cdrom1" that won't be
170
+ #recognized by this method.
171
+ def locked?
172
+ @locked
173
+ end
174
+
175
+ end
176
+
177
+ end
178
+
179
+ end
data/lib/imitator/x.rb ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ #Encoding: UTF-8
3
+ =begin
4
+ --
5
+ Imitator for X is a library allowing you to fake input to systems using X11.
6
+ Copyright © 2010 Marvin Gülker
7
+
8
+ This file is part of Imitator for X.
9
+
10
+ Imitator for X is free software: you can redistribute it and/or modify
11
+ it under the terms of the GNU Lesser General Public License as published by
12
+ the Free Software Foundation, either version 3 of the License, or
13
+ (at your option) any later version.
14
+
15
+ Imitator for X is distributed in the hope that it will be useful,
16
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
+ GNU Lesser General Public License for more details.
19
+
20
+ You should have received a copy of the GNU Lesser General Public License
21
+ along with Imitator for X. If not, see <http://www.gnu.org/licenses/>.
22
+ ++
23
+ =end
24
+
25
+ require "yaml"
26
+ require "open3"
27
+ require "strscan"
28
+ require_relative "../../ext/x"
29
+ require_relative "x/drive"
@@ -0,0 +1,179 @@
1
+ #Encoding: UTF-8
2
+ ################################################
3
+ #Imitator for X is a library allowing you to fake input to systems using X11.
4
+ #Copyright © 2010 Marvin Gülker
5
+ #
6
+ #This file is part of Imitator for X.
7
+ #
8
+ #Imitator for X is free software: you can redistribute it and/or modify
9
+ #it under the terms of the GNU Lesser General Public License as published by
10
+ #the Free Software Foundation, either version 3 of the License, or
11
+ #(at your option) any later version.
12
+ #
13
+ #Imitator for X is distributed in the hope that it will be useful,
14
+ #but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ #GNU Lesser General Public License for more details.
17
+ #
18
+ #You should have received a copy of the GNU Lesser General Public License
19
+ #along with Imitator for X. If not, see <http://www.gnu.org/licenses/>.
20
+ ################################################
21
+ #
22
+ #This file instructs Imitator for X how to simulate characters
23
+ #that can't be faked just by pressing one key, i.e. those keys
24
+ #that need modifier keys like the [SHIFT], [ALT], [ALT_GR] keys pressed.
25
+ #Beside the regular key upcase combinations which are just
26
+ #simulated by pressing the [SHIFT] key and than hitting the wanted letter key
27
+ #before releasing the [SHIFT] key again it's highly keyboard and locale-dependant
28
+ #how a special character is created. For example, to create an @ character on
29
+ #a German keyboard you'd press [ALT_GR] + [Q]. In Switzerland, it's [ALT_GR] + [2].
30
+ #Another one is the backslash - on my German keyboard I create one via [ALT_GR] + [ß],
31
+ #an american keyboard doesn't need a modifier key at all - it's there where on my keyboard the
32
+ #[Ä] or [Ü] key resides.
33
+ #
34
+ #Since it's likely that the mappings in this file don't represent your keybaord,
35
+ #you can change them. Just look for the character that isn't simulated correctly,
36
+ #and change the key sequence to the one belonging to your keyboard.
37
+ #In order to do this correctly, you should use the keysym names shown to you
38
+ #when you manually press this key while running the "xev" program.
39
+ #( I reccomand using "xev | grep keysym").
40
+ #
41
+ #Also, if you change this file, you may want to email me at sutniuq<>gmx<>net,
42
+ #in the future I may then be able to code some kind of locale selector that automatically
43
+ #chooses the correct key combinations.
44
+ ---
45
+ #=========Regular key upcase mappings==========
46
+ #You won't change these, won't you?
47
+ A: Shift_L+a
48
+ B: Shift_L+b
49
+ C: Shift_L+c
50
+ D: Shift_L+d
51
+ E: Shift_L+e
52
+ F: Shift_L+f
53
+ G: Shift_L+g
54
+ H: Shift_L+h
55
+ I: Shift_L+i
56
+ J: Shift_L+j
57
+ K: Shift_L+k
58
+ L: Shift_L+l
59
+ M: Shift_L+m
60
+ N: Shift_L+n
61
+ O: Shift_L+o
62
+ P: Shift_L+p
63
+ Q: Shift_L+q
64
+ R: Shift_L+r
65
+ S: Shift_L+s
66
+ T: Shift_L+t
67
+ U: Shift_L+u
68
+ V: Shift_L+v
69
+ W: Shift_L+w
70
+ X: Shift_L+x
71
+ Y: Shift_L+y
72
+ Z: Shift_L+z
73
+ #==========Special letter mappings===========
74
+ #Characters that are letters, but not defined in ASCII.
75
+ #Use this section for those parts of your local alphabet that
76
+ #isn't covered by ASCII.
77
+ Ä: Shift_L+adiaeresis
78
+ Ö: Shift_L+odiaeresis
79
+ Ü: Shift_L+udiaeresis
80
+ ẞ: ISO_Level3_Shift+Shift+s
81
+ á: dead_acute+a
82
+ é: dead_acute+e
83
+ #==========Special sign mappings=============
84
+ #Non-letter chracters.
85
+ #Put in here those keys that doesn't have literal meaning in
86
+ #your language.
87
+ ;: Shift_L+semicolon
88
+ ":": Shift_L+colon
89
+ "_": Shift_L+underscore
90
+ "'": Shift_L+apostrophe
91
+ "*": Shift_L+asterisk
92
+ ">": Shift_L+greater
93
+ "!": Shift_L+exclam
94
+ "\"": Shift_L+quotedbl
95
+ §: Shift_L+section
96
+ $: Shift_L+dollar
97
+ %: Shift_L+percent
98
+ &: Shift_L+ampersand
99
+ /: Shift_L+slash
100
+ (: Shift_L+parenleft
101
+ ): Shift_L+parenright
102
+ "=": Shift_L+equal
103
+ "?": Shift_L+question
104
+ °: Shift_L+degree
105
+ ¹: ISO_Level3_Shift+onesuperior
106
+ ²: ISO_Level3_Shift+twosuperior
107
+ ³: ISO_Level3_Shift+threesuperior
108
+ ¼: ISO_Level3_Shift+onequarter
109
+ ½: ISO_Level3_Shift+onehalf
110
+ ¬: ISO_Level3_Shift+notsign
111
+ "{": ISO_Level3_Shift+braceleft
112
+ "[": ISO_Level3_Shift+bracketleft
113
+ "]": ISO_Level3_Shift+bracketright
114
+ "}": ISO_Level3_Shift+braceright
115
+ \: ISO_Level3_Shift+backslash
116
+ @: ISO_Level3_Shift+at
117
+ ł: ISO_Level3_Shift+lstroke
118
+ €: ISO_Level3_Shift+EuroSign
119
+ ¶: ISO_Level3_Shift+paragraph
120
+ ŧ: ISO_Level3_Shift+tslash
121
+ ←: ISO_Level3_Shift+leftarrow
122
+ ↓: ISO_Level3_Shift+downarrow
123
+ →: ISO_Level3_Shift+rightarrow
124
+ ø: ISO_Level3_Shift+oslash
125
+ þ: ISO_Level3_Shift+thorn
126
+ æ: ISO_Level3_Shift+ae
127
+ ſ: ISO_Level3_Shift+U017F
128
+ ð: ISO_Level3_Shift+eth
129
+ đ: ISO_Level3_Shift+dstroke
130
+ ŋ: ISO_Level3_Shift+eng
131
+ ħ: ISO_Level3_Shift+hstroke
132
+ ĸ: ISO_Level3_Shift+kra
133
+ ł: ISO_Level3_Shift+lstroke
134
+ |: ISO_Level3_Shift+bar
135
+ »: ISO_Level3_Shift+guillemotright
136
+ «: ISO_Level3_Shift+guillemotleft
137
+ ¢: ISO_Level3_Shift+cent
138
+ „: ISO_Level3_Shift+doublelowquotemark
139
+ “: ISO_Level3_Shift+leftdoublequotemark
140
+ ”: ISO_Level3_Shift+rightdoublequotemark
141
+ µ: ISO_Level3_Shift+mu
142
+ ·: ISO_Level3_Shift+periodcentered
143
+ …: ISO_Level3_Shift+U2026
144
+ –: ISO_Level3_Shift+endash
145
+ ¡: ISO_Level3_Shift+Shift+exclamdown
146
+ ⅛: ISO_Level3_Shift+Shift+oneeigth
147
+ £: ISO_Level3_Shift+Shift+sterling
148
+ ¤: ISO_Level3_Shift+Shift+currency
149
+ ⅜: ISO_Level3_Shift+Shift+threeeights
150
+ ⅝: ISO_Level3_Shift+Shift+fiveeights
151
+ ⅞: ISO_Level3_Shift+Shift+seveneights
152
+ ™: ISO_Level3_Shift+Shift+trademark
153
+ ±: ISO_Level3_Shift+Shift+plusminus
154
+ ¿: ISO_Level3_Shift+Shift+questiondown
155
+ Ω: ISO_Level3_Shift+Shift+Greek_OMEGA
156
+ Ł: ISO_Level3_Shift+Shift+Lstroke
157
+ ®: ISO_Level3_Shift+Shift+registered
158
+ Ŧ: ISO_Level3_Shift+Shift+Tslash
159
+ ¥: ISO_Level3_Shift+Shift+yen
160
+ ↑: ISO_Level3_Shift+Shift+uparrow
161
+ ı: ISO_Level3_Shift+Shift+idotless
162
+ Ø: ISO_Level3_Shift+Shift+Oslash
163
+ Þ: ISO_Level3_Shift+Shift+THORN
164
+ Æ: ISO_Level3_Shift+Shift+AE
165
+ Ð: ISO_Level3_Shift+Shift+ETH
166
+ ª: ISO_Level3_Shift+Shift+ordfeminine
167
+ Ŋ: ISO_Level3_Shift+Shift+ENG
168
+ Ħ: ISO_Level3_Shift+Shift+Hstroke
169
+ ¦: ISO_Level3_Shift+Shift+brokenbar
170
+ ›: ISO_Level3_Shift+Shift+U203A
171
+ ‹: ISO_Level3_Shift+Shift+U2039
172
+ ©: ISO_Level3_Shift+Shift+copyright
173
+ ‚: ISO_Level3_Shift+Shift+singlelowquotemark
174
+ ‘: ISO_Level3_Shift+Shift+leftsinglequotemark
175
+ ’: ISO_Level3_Shift+Shift+rightsinglequotemark
176
+ º: ISO_Level3_Shift+Shift+masculine
177
+ ×: ISO_Level3_Shift+Shift+multiply
178
+ ÷: ISO_Level3_Shift+Shift+division
179
+ —: ISO_Level3_Shift+Shift+emdash
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env ruby
2
+ #Encoding: UTF-8
3
+ =begin
4
+ --
5
+ Imitator for X is a library allowing you to fake input to systems using X11.
6
+ Copyright © 2010 Marvin Gülker
7
+
8
+ This file is part of Imitator for X.
9
+
10
+ Imitator for X is free software: you can redistribute it and/or modify
11
+ it under the terms of the GNU Lesser General Public License as published by
12
+ the Free Software Foundation, either version 3 of the License, or
13
+ (at your option) any later version.
14
+
15
+ Imitator for X is distributed in the hope that it will be useful,
16
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
+ GNU Lesser General Public License for more details.
19
+
20
+ You should have received a copy of the GNU Lesser General Public License
21
+ along with Imitator for X. If not, see <http://www.gnu.org/licenses/>.
22
+ ++
23
+ =end
24
+
25
+ #Ensure we use the correct key combinations file
26
+ $imitator_x_charfile_path = File.join(File.expand_path(File.dirname(__FILE__)), "..", "lib", "imitator_x_special_chars.yml")
27
+
28
+ require "test/unit"
29
+ require_relative "../lib/imitator/x"
30
+
31
+ class ClipboardTest < Test::Unit::TestCase
32
+
33
+ TEST_TEXT = "This is my\ntest test\t with special chars like ä!"
34
+
35
+ def test_read_write
36
+ Imitator::X::Clipboard.write(TEST_TEXT)
37
+ assert_equal(TEST_TEXT, Imitator::X::Clipboard.read(:clipboard))
38
+ end
39
+
40
+ def test_clear
41
+ Imitator::X::Clipboard.write(TEST_TEXT)
42
+ Imitator::X::Clipboard.clear(:clipboard)
43
+ assert_equal("", Imitator::X::Clipboard.read(:clipboard))
44
+ end
45
+
46
+ end
@@ -0,0 +1,117 @@
1
+ #!/usr/bin/env ruby
2
+ #Encoding: UTF-8
3
+ =begin
4
+ --
5
+ Imitator for X is a library allowing you to fake input to systems using X11.
6
+ Copyright © 2010 Marvin Gülker
7
+
8
+ This file is part of Imitator for X.
9
+
10
+ Imitator for X is free software: you can redistribute it and/or modify
11
+ it under the terms of the GNU Lesser General Public License as published by
12
+ the Free Software Foundation, either version 3 of the License, or
13
+ (at your option) any later version.
14
+
15
+ Imitator for X is distributed in the hope that it will be useful,
16
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
+ GNU Lesser General Public License for more details.
19
+
20
+ You should have received a copy of the GNU Lesser General Public License
21
+ along with Imitator for X. If not, see <http://www.gnu.org/licenses/>.
22
+ ++
23
+ =end
24
+
25
+ #Ensure we use the correct key combinations file
26
+ $imitator_x_charfile_path = File.join(File.expand_path(File.dirname(__FILE__)), "..", "lib", "imitator_x_special_chars.yml")
27
+
28
+ require "test/unit"
29
+ require_relative "../lib/imitator/x"
30
+
31
+ class KeyboardTest < Test::Unit::TestCase
32
+
33
+ ASCII_STRING = "The quick brown fox jumped over the lazy dog"
34
+ UTF8_STRING = "ÄÖÜä@öüßabc"
35
+ ESCAPE_STRING = "This has\t2 escseqs: {Tab}!"
36
+ INVALID_STRING = "Incorrect escape: {Nosuchkey}"
37
+
38
+ EDITOR = ["gedit", "kwrite", "mousepad", "kate"].find{|cmd| `which '#{cmd}'`; $?.exitstatus == 0}
39
+ raise("No editor found!") if EDITOR.nil?
40
+ puts "Chosen editor: '#{EDITOR}'." if $VERBOSE
41
+
42
+ def self.startup
43
+ @win_proc = spawn(EDITOR)
44
+ sleep 2
45
+ end
46
+
47
+ def self.shutdown
48
+ Process.kill("SIGKILL", @win_proc)
49
+ end
50
+
51
+ def teardown
52
+ Imitator::X::Keyboard.ctrl_a
53
+ Imitator::X::Keyboard.delete
54
+ end
55
+
56
+ def setup
57
+ sleep 0.5
58
+ end
59
+
60
+ def test_delete
61
+ Imitator::X::Keyboard.simulate(ASCII_STRING)
62
+ sleep 1
63
+ Imitator::X::Keyboard.ctrl_a
64
+ Imitator::X::Keyboard.delete
65
+ assert_equal("", get_text)
66
+ Imitator::X::Keyboard.simulate(ASCII_STRING)
67
+ sleep 1
68
+ Imitator::X::Keyboard.ctrl_a
69
+ Imitator::X::Keyboard.delete(true)
70
+ assert_equal("", get_text)
71
+ end
72
+
73
+ def test_ascii
74
+ Imitator::X::Keyboard.simulate(ASCII_STRING)
75
+ assert_equal(ASCII_STRING, get_text)
76
+ Imitator::X::Keyboard.delete
77
+ Imitator::X::Keyboard.simulate(ASCII_STRING, true)
78
+ assert_equal(ASCII_STRING, get_text)
79
+ end
80
+
81
+ def test_utf8
82
+ Imitator::X::Keyboard.simulate(UTF8_STRING)
83
+ assert_equal(UTF8_STRING, get_text)
84
+ Imitator::X::Keyboard.delete
85
+ Imitator::X::Keyboard.simulate(UTF8_STRING, true)
86
+ assert_equal(UTF8_STRING, get_text)
87
+ end
88
+
89
+ def test_escape
90
+ Imitator::X::Keyboard.simulate(ESCAPE_STRING)
91
+ assert_equal(ESCAPE_STRING.gsub("{Tab}", "\t"), get_text)
92
+ Imitator::X::Keyboard.delete
93
+ assert_raise(Imitator::X::XError){Imitator::X::Keyboard.simulate(INVALID_STRING)}
94
+ end
95
+
96
+ def test_hold
97
+ Imitator::X::Keyboard.down("a")
98
+ sleep 1
99
+ Imitator::X::Keyboard.up("a")
100
+ assert_block{get_text.size > 1}
101
+ end
102
+
103
+ def test_key
104
+ Imitator::X::Keyboard.key("Shift+a")
105
+ assert_equal("A", get_text)
106
+ end
107
+
108
+ private
109
+
110
+ def get_text
111
+ sleep 1
112
+ Imitator::X::Keyboard.ctrl_a
113
+ sleep 1
114
+ Imitator::X::Clipboard.read(:primary)
115
+ end
116
+
117
+ end
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env ruby
2
+ #Encoding: UTF-8
3
+ =begin
4
+ --
5
+ Imitator for X is a library allowing you to fake input to systems using X11.
6
+ Copyright © 2010 Marvin Gülker
7
+
8
+ This file is part of Imitator for X.
9
+
10
+ Imitator for X is free software: you can redistribute it and/or modify
11
+ it under the terms of the GNU Lesser General Public License as published by
12
+ the Free Software Foundation, either version 3 of the License, or
13
+ (at your option) any later version.
14
+
15
+ Imitator for X is distributed in the hope that it will be useful,
16
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
+ GNU Lesser General Public License for more details.
19
+
20
+ You should have received a copy of the GNU Lesser General Public License
21
+ along with Imitator for X. If not, see <http://www.gnu.org/licenses/>.
22
+ ++
23
+ =end
24
+
25
+ #Ensure we use the correct key combinations file
26
+ $imitator_x_charfile_path = File.join(File.expand_path(File.dirname(__FILE__)), "..", "lib", "imitator_x_special_chars.yml")
27
+
28
+ require "test/unit"
29
+ require_relative "../lib/imitator/x"
30
+
31
+ class MouseTest < Test::Unit::TestCase
32
+
33
+ def test_move
34
+ Imitator::X::Mouse.move(100, 100)
35
+ assert_equal([100, 100], Imitator::X::Mouse.pos)
36
+ assert_equal([100, 100], Imitator::X::Mouse.position)
37
+
38
+ end
39
+
40
+ end
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env ruby
2
+ #Encoding: UTF-8
3
+ =begin
4
+ --
5
+ Imitator for X is a library allowing you to fake input to systems using X11.
6
+ Copyright © 2010 Marvin Gülker
7
+
8
+ This file is part of Imitator for X.
9
+
10
+ Imitator for X is free software: you can redistribute it and/or modify
11
+ it under the terms of the GNU Lesser General Public License as published by
12
+ the Free Software Foundation, either version 3 of the License, or
13
+ (at your option) any later version.
14
+
15
+ Imitator for X is distributed in the hope that it will be useful,
16
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
+ GNU Lesser General Public License for more details.
19
+
20
+ You should have received a copy of the GNU Lesser General Public License
21
+ along with Imitator for X. If not, see <http://www.gnu.org/licenses/>.
22
+ ++
23
+ =end
24
+
25
+ #Ensure we use the correct key combinations file
26
+ $imitator_x_charfile_path = File.join(File.expand_path(File.dirname(__FILE__)), "..", "lib", "imitator_x_special_chars.yml")
27
+
28
+ require "test/unit"
29
+ require_relative "../lib/imitator/x"
30
+
31
+ class DriveTest < Test::Unit::TestCase
32
+
33
+ def test_default
34
+ assert_equal(`eject -d`.match(/`(.*?)'/)[1], Imitator::X::XDrive.default)
35
+ end
36
+
37
+ def test_eject_close
38
+ drive = Imitator::X::XDrive.new
39
+ drive.open
40
+ begin
41
+ drive.close
42
+ rescue Imitator::X::XError
43
+ notify "Coldn't close your CD-ROM drive. Are you using a laptop?"
44
+ end
45
+ end
46
+
47
+ end