win32-clipboard 0.6.3 → 0.6.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,137 +1,137 @@
1
- # encoding: utf-8
2
- ###########################################################################
3
- # test_clipboard_chain.rb
4
- #
5
- # Test suite for the win32-clipboard library(only clipboard chain).
6
- ###########################################################################
7
- require 'test-unit'
8
- require 'win32/clipboard'
9
- require 'timeout'
10
- require File.join(File.dirname(__FILE__), 'lock')
11
-
12
- include Win32
13
-
14
- class TC_Clipboard_Chain < Test::Unit::TestCase
15
- test "clipboard viewer chain" do
16
- begin
17
- # Add clipboard viewer 1-3
18
- # clipboard viewer chain: cv3 -> cv2 -> cv1
19
- cv1 = ClipboardViewer.new('1')
20
- puts 'Added clipboard viewer 1'
21
-
22
- cv2 = ClipboardViewer.new('2')
23
- puts 'Added clipboard viewer 2'
24
-
25
- cv3 = ClipboardViewer.new('3')
26
- puts 'Added clipboard viewer 3'
27
-
28
- lock do
29
- Clipboard.set_data('foo')
30
- end
31
-
32
- result = Clipboard.data
33
- assert_equal(result, cv1.result)
34
- assert_equal(result, cv2.result)
35
- assert_equal(result, cv3.result)
36
-
37
- # Remove clipboard viewer 2
38
- # clipboard viewer chain: cv3 -> cv1
39
- assert_not_nil(cv2.remove)
40
-
41
- cv1.clear
42
- cv3.clear
43
- Clipboard.set_data('bar')
44
-
45
- result = Clipboard.data
46
- assert_equal(result, cv1.result)
47
- assert_equal(result, cv3.result)
48
-
49
- # Remove clipboard viewer 3
50
- assert_not_nil(cv3.remove)
51
-
52
- cv1.clear
53
- Clipboard.set_data('foobar')
54
-
55
- result = Clipboard.data
56
- assert_equal(result, cv1.result)
57
- assert_not_nil(cv1.remove)
58
- ensure
59
- cv1.exit
60
- cv2.exit
61
- cv3.exit
62
- end
63
- end
64
-
65
- class ClipboardViewer
66
- NOTIFY_TIMEOUT = 20
67
- def initialize(key)
68
- @key = key
69
- load_path = File.join(File.join(File.dirname(__FILE__), '..'), 'lib')
70
- @pipe = IO.popen("#{RbConfig.ruby} -I #{load_path} #{File.join(File.dirname(__FILE__), "notify.rb")} #{key} #{NOTIFY_TIMEOUT}")
71
- @result = nil
72
- is_ready = false
73
-
74
- @t = Thread.start do
75
- begin
76
- while true
77
- result = @pipe.gets.chomp
78
-
79
- if result == 'ready'
80
- is_ready = true
81
- else
82
- @result = result
83
- end
84
-
85
- if @result == @key.chop
86
- break
87
- end
88
- end
89
- rescue => e
90
- puts $!
91
- puts e.backtrace
92
- end
93
- end
94
-
95
- Timeout::timeout(5) do
96
- until is_ready
97
- lock do
98
- Clipboard.set_data('ready')
99
- end
100
- sleep(0.1)
101
- end
102
- end
103
- end
104
-
105
- def clear
106
- @result = nil
107
- end
108
-
109
- def result
110
- Timeout::timeout(5) do
111
- until @result
112
- sleep(0.1)
113
- end
114
- end
115
- @result
116
- rescue Timeout::Error
117
- raise 'Cannot get result.(Timeout)'
118
- end
119
-
120
- def remove
121
- return unless @t.alive?
122
- lock do
123
- Clipboard.set_data(@key)
124
- end
125
- ret = @t.join(3)
126
- if ret
127
- @pipe.close
128
- end
129
- ret
130
- end
131
-
132
- def exit
133
- return unless @t.alive?
134
- Process.kill('KILL', @pipe.pid)
135
- end
136
- end
137
- end
1
+ # encoding: utf-8
2
+ ###########################################################################
3
+ # test_clipboard_chain.rb
4
+ #
5
+ # Test suite for the win32-clipboard library(only clipboard chain).
6
+ ###########################################################################
7
+ require 'test-unit'
8
+ require 'win32/clipboard'
9
+ require 'timeout'
10
+ require File.join(File.dirname(__FILE__), 'lock')
11
+
12
+ include Win32
13
+
14
+ class TC_Clipboard_Chain < Test::Unit::TestCase
15
+ test "clipboard viewer chain" do
16
+ begin
17
+ # Add clipboard viewer 1-3
18
+ # clipboard viewer chain: cv3 -> cv2 -> cv1
19
+ cv1 = ClipboardViewer.new('1')
20
+ puts 'Added clipboard viewer 1'
21
+
22
+ cv2 = ClipboardViewer.new('2')
23
+ puts 'Added clipboard viewer 2'
24
+
25
+ cv3 = ClipboardViewer.new('3')
26
+ puts 'Added clipboard viewer 3'
27
+
28
+ lock do
29
+ Clipboard.set_data('foo')
30
+ end
31
+
32
+ result = Clipboard.data
33
+ assert_equal(result, cv1.result)
34
+ assert_equal(result, cv2.result)
35
+ assert_equal(result, cv3.result)
36
+
37
+ # Remove clipboard viewer 2
38
+ # clipboard viewer chain: cv3 -> cv1
39
+ assert_not_nil(cv2.remove)
40
+
41
+ cv1.clear
42
+ cv3.clear
43
+ Clipboard.set_data('bar')
44
+
45
+ result = Clipboard.data
46
+ assert_equal(result, cv1.result)
47
+ assert_equal(result, cv3.result)
48
+
49
+ # Remove clipboard viewer 3
50
+ assert_not_nil(cv3.remove)
51
+
52
+ cv1.clear
53
+ Clipboard.set_data('foobar')
54
+
55
+ result = Clipboard.data
56
+ assert_equal(result, cv1.result)
57
+ assert_not_nil(cv1.remove)
58
+ ensure
59
+ cv1.exit
60
+ cv2.exit
61
+ cv3.exit
62
+ end
63
+ end
64
+
65
+ class ClipboardViewer
66
+ NOTIFY_TIMEOUT = 20
67
+ def initialize(key)
68
+ @key = key
69
+ load_path = File.join(File.join(File.dirname(__FILE__), '..'), 'lib')
70
+ @pipe = IO.popen("#{RbConfig.ruby} -I #{load_path} #{File.join(File.dirname(__FILE__), "notify.rb")} #{key} #{NOTIFY_TIMEOUT}")
71
+ @result = nil
72
+ is_ready = false
73
+
74
+ @t = Thread.start do
75
+ begin
76
+ while true
77
+ result = @pipe.gets.chomp
78
+
79
+ if result == 'ready'
80
+ is_ready = true
81
+ else
82
+ @result = result
83
+ end
84
+
85
+ if @result == @key.chop
86
+ break
87
+ end
88
+ end
89
+ rescue => e
90
+ puts $!
91
+ puts e.backtrace
92
+ end
93
+ end
94
+
95
+ Timeout::timeout(5) do
96
+ until is_ready
97
+ lock do
98
+ Clipboard.set_data('ready')
99
+ end
100
+ sleep(0.1)
101
+ end
102
+ end
103
+ end
104
+
105
+ def clear
106
+ @result = nil
107
+ end
108
+
109
+ def result
110
+ Timeout::timeout(5) do
111
+ until @result
112
+ sleep(0.1)
113
+ end
114
+ end
115
+ @result
116
+ rescue Timeout::Error
117
+ raise 'Cannot get result.(Timeout)'
118
+ end
119
+
120
+ def remove
121
+ return unless @t.alive?
122
+ lock do
123
+ Clipboard.set_data(@key)
124
+ end
125
+ ret = @t.join(3)
126
+ if ret
127
+ @pipe.close
128
+ end
129
+ ret
130
+ end
131
+
132
+ def exit
133
+ return unless @t.alive?
134
+ Process.kill('KILL', @pipe.pid)
135
+ end
136
+ end
137
+ end
@@ -1,50 +1,50 @@
1
- ########################################################################
2
- # test_html_clipboard.rb
3
- #
4
- # Test suite for the HtmlClipboard class.
5
- ########################################################################
6
- require 'test-unit'
7
- require 'win32/clipboard'
8
- require 'win32/html_clipboard'
9
- include Win32
10
-
11
- class TC_Html_Clipboard < Test::Unit::TestCase
12
- def setup
13
- @html_str = "Writing to the <i>clipboard</i> is <b>easy</b> with this code"
14
- @plain_str = "Writing to the clipboard is easy with this code"
15
- end
16
-
17
- test "CF_HTML constant is defined" do
18
- assert_not_nil(HtmlClipboard::CF_HTML)
19
- assert_kind_of(Integer, HtmlClipboard::CF_HTML)
20
- end
21
-
22
- test "get_data basic functionality" do
23
- assert_respond_to(HtmlClipboard, :get_data)
24
- end
25
-
26
- test "set_data basic functionality" do
27
- assert_respond_to(HtmlClipboard, :set_data)
28
- end
29
-
30
- test "getting html data returns a plain string" do
31
- assert_nothing_raised{ HtmlClipboard.set_data(@html_str) }
32
- assert_equal(@plain_str, HtmlClipboard.get_data)
33
- end
34
-
35
- test "html_format basic functionality" do
36
- assert_respond_to(HtmlClipboard, :html_format?)
37
- assert_boolean(HtmlClipboard.html_format?)
38
- end
39
-
40
- test "data details basic functionality" do
41
- assert_respond_to(HtmlClipboard, :data_details)
42
- assert_nothing_raised{ HtmlClipboard.data_details }
43
- assert_kind_of(String, HtmlClipboard.data_details)
44
- end
45
-
46
- def teardown
47
- @html_str = nil
48
- @plain_str = nil
49
- end
50
- end
1
+ ########################################################################
2
+ # test_html_clipboard.rb
3
+ #
4
+ # Test suite for the HtmlClipboard class.
5
+ ########################################################################
6
+ require 'test-unit'
7
+ require 'win32/clipboard'
8
+ require 'win32/html_clipboard'
9
+ include Win32
10
+
11
+ class TC_Html_Clipboard < Test::Unit::TestCase
12
+ def setup
13
+ @html_str = "Writing to the <i>clipboard</i> is <b>easy</b> with this code"
14
+ @plain_str = "Writing to the clipboard is easy with this code"
15
+ end
16
+
17
+ test "CF_HTML constant is defined" do
18
+ assert_not_nil(HtmlClipboard::CF_HTML)
19
+ assert_kind_of(Integer, HtmlClipboard::CF_HTML)
20
+ end
21
+
22
+ test "get_data basic functionality" do
23
+ assert_respond_to(HtmlClipboard, :get_data)
24
+ end
25
+
26
+ test "set_data basic functionality" do
27
+ assert_respond_to(HtmlClipboard, :set_data)
28
+ end
29
+
30
+ test "getting html data returns a plain string" do
31
+ assert_nothing_raised{ HtmlClipboard.set_data(@html_str) }
32
+ assert_equal(@plain_str, HtmlClipboard.get_data)
33
+ end
34
+
35
+ test "html_format basic functionality" do
36
+ assert_respond_to(HtmlClipboard, :html_format?)
37
+ assert_boolean(HtmlClipboard.html_format?)
38
+ end
39
+
40
+ test "data details basic functionality" do
41
+ assert_respond_to(HtmlClipboard, :data_details)
42
+ assert_nothing_raised{ HtmlClipboard.data_details }
43
+ assert_kind_of(String, HtmlClipboard.data_details)
44
+ end
45
+
46
+ def teardown
47
+ @html_str = nil
48
+ @plain_str = nil
49
+ end
50
+ end
@@ -1,51 +1,51 @@
1
- # encoding: utf-8
2
- ###########################################################################
3
- # test_image_clipboard.rb
4
- #
5
- # Test suite for the win32-clipboard library(only get_image_data).
6
- ###########################################################################
7
- require 'test-unit'
8
- require 'win32/clipboard'
9
- include Win32
10
-
11
- class TC_Image_ClipBoard < Test::Unit::TestCase
12
- class << self
13
- def startup
14
- $is_ready = false
15
- @t = Thread.new do
16
- begin
17
- Win32::Clipboard.notify_change {$is_ready = true}
18
- rescue => e
19
- puts $!
20
- puts e.backtrace
21
- end
22
- end
23
- # wait for notify_change running
24
- until $is_ready
25
- Clipboard.set_data('foo')
26
- sleep 0.1
27
- end
28
- end
29
-
30
- def shutdown
31
- @t.kill
32
- end
33
- end
34
-
35
- dir = File.join(File.dirname(__FILE__), 'img')
36
- Dir.glob("#{dir}/*.bmp") do |file|
37
- test "get_image_data file: " + File.basename(file) do
38
- $is_ready = false
39
-
40
- bmp = File.open(file, "rb").read
41
- Clipboard.set_data(bmp, Clipboard::DIB)
42
-
43
- until $is_ready
44
- sleep 0.1
45
- end
46
-
47
- assert_equal(Clipboard.data(Clipboard::DIB), bmp)
48
- end
49
- end
50
-
51
- end
1
+ # encoding: utf-8
2
+ ###########################################################################
3
+ # test_image_clipboard.rb
4
+ #
5
+ # Test suite for the win32-clipboard library(only get_image_data).
6
+ ###########################################################################
7
+ require 'test-unit'
8
+ require 'win32/clipboard'
9
+ include Win32
10
+
11
+ class TC_Image_ClipBoard < Test::Unit::TestCase
12
+ class << self
13
+ def startup
14
+ $is_ready = false
15
+ @t = Thread.new do
16
+ begin
17
+ Win32::Clipboard.notify_change {$is_ready = true}
18
+ rescue => e
19
+ puts $!
20
+ puts e.backtrace
21
+ end
22
+ end
23
+ # wait for notify_change running
24
+ until $is_ready
25
+ Clipboard.set_data('foo')
26
+ sleep 0.1
27
+ end
28
+ end
29
+
30
+ def shutdown
31
+ @t.kill
32
+ end
33
+ end
34
+
35
+ dir = File.join(File.dirname(__FILE__), 'img')
36
+ Dir.glob("#{dir}/*.bmp") do |file|
37
+ test "get_image_data file: " + File.basename(file) do
38
+ $is_ready = false
39
+
40
+ bmp = File.open(file, "rb").read
41
+ Clipboard.set_data(bmp, Clipboard::DIB)
42
+
43
+ until $is_ready
44
+ sleep 0.1
45
+ end
46
+
47
+ assert_equal(Clipboard.data(Clipboard::DIB), bmp)
48
+ end
49
+ end
50
+
51
+ end