win32-clipboard 0.6.3 → 0.6.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/CHANGES +112 -105
- data/MANIFEST +31 -12
- data/README +106 -112
- data/Rakefile +4 -7
- data/certs/djberg96_pub.pem +21 -0
- data/examples/clipboard_test.rb +28 -28
- data/lib/win32-clipboard.rb +1 -0
- data/lib/win32/clipboard.rb +447 -447
- data/lib/win32/html_clipboard.rb +232 -232
- data/lib/win32/windows/constants.rb +14 -14
- data/lib/win32/windows/functions.rb +66 -66
- data/lib/win32/windows/structs.rb +43 -43
- data/test/lock.rb +18 -18
- data/test/notify.rb +27 -27
- data/test/test_clipboard.rb +176 -176
- data/test/test_clipboard_chain.rb +137 -137
- data/test/test_html_clipboard.rb +50 -50
- data/test/test_image_clipboard.rb +51 -51
- data/win32-clipboard.gemspec +26 -26
- metadata +37 -13
- metadata.gz.sig +0 -0
@@ -1,14 +1,14 @@
|
|
1
|
-
module Windows
|
2
|
-
module Constants
|
3
|
-
GHND = 0x0042
|
4
|
-
WM_DESTROY = 0x0002
|
5
|
-
WM_CLOSE = 0x0010
|
6
|
-
WM_DRAWCLIPBOARD = 0x0308
|
7
|
-
WM_CHANGECBCHAIN = 0x030D
|
8
|
-
GWL_USERDATA = -21
|
9
|
-
GWL_WNDPROC = -4
|
10
|
-
CF_TEXT = 1
|
11
|
-
BI_RGB = 0
|
12
|
-
BI_BITFIELDS = 3
|
13
|
-
end
|
14
|
-
end
|
1
|
+
module Windows
|
2
|
+
module Constants
|
3
|
+
GHND = 0x0042
|
4
|
+
WM_DESTROY = 0x0002
|
5
|
+
WM_CLOSE = 0x0010
|
6
|
+
WM_DRAWCLIPBOARD = 0x0308
|
7
|
+
WM_CHANGECBCHAIN = 0x030D
|
8
|
+
GWL_USERDATA = -21
|
9
|
+
GWL_WNDPROC = -4
|
10
|
+
CF_TEXT = 1
|
11
|
+
BI_RGB = 0
|
12
|
+
BI_BITFIELDS = 3
|
13
|
+
end
|
14
|
+
end
|
@@ -1,66 +1,66 @@
|
|
1
|
-
require 'ffi'
|
2
|
-
|
3
|
-
module Windows
|
4
|
-
module Functions
|
5
|
-
extend FFI::Library
|
6
|
-
|
7
|
-
typedef :uintptr_t, :hglobal
|
8
|
-
typedef :uintptr_t, :hwnd
|
9
|
-
typedef :uintptr_t, :handle
|
10
|
-
typedef :uintptr_t, :hmenu
|
11
|
-
typedef :uintptr_t, :hdrop
|
12
|
-
typedef :uintptr_t, :hinstance
|
13
|
-
typedef :ulong, :dword
|
14
|
-
|
15
|
-
callback :wnd_proc, [:hwnd, :uint, :long, :long], :long
|
16
|
-
|
17
|
-
ffi_lib :kernel32
|
18
|
-
|
19
|
-
attach_function :GlobalAlloc, [:uint, :size_t], :hglobal
|
20
|
-
attach_function :GlobalFree, [:hglobal], :hglobal
|
21
|
-
attach_function :GlobalLock, [:hglobal], :pointer
|
22
|
-
attach_function :GlobalSize, [:hglobal], :size_t
|
23
|
-
attach_function :GlobalUnlock, [:hglobal], :bool
|
24
|
-
|
25
|
-
ffi_lib :user32
|
26
|
-
|
27
|
-
attach_function :ChangeClipboardChain, [:hwnd, :hwnd], :bool
|
28
|
-
attach_function :CloseClipboard, [], :bool
|
29
|
-
attach_function :CountClipboardFormats, [], :int
|
30
|
-
attach_function :CreateWindowEx, :CreateWindowExA, [:dword, :string, :string, :dword, :int, :int, :int, :int, :hwnd, :hmenu, :hinstance, :pointer], :hwnd
|
31
|
-
attach_function :DefWindowProc, :DefWindowProcA, [:hwnd, :uint, :uint, :uint], :long
|
32
|
-
attach_function :DispatchMessage, :DispatchMessageA, [:pointer], :uint
|
33
|
-
attach_function :EmptyClipboard, [], :bool
|
34
|
-
attach_function :EnumClipboardFormats, [:uint], :uint
|
35
|
-
attach_function :GetClipboardData, [:uint], :handle
|
36
|
-
attach_function :GetClipboardFormatName, :GetClipboardFormatNameA, [:uint, :pointer, :int], :int
|
37
|
-
attach_function :IsClipboardFormatAvailable, [:uint], :bool
|
38
|
-
attach_function :OpenClipboard, [:hwnd], :bool
|
39
|
-
attach_function :PeekMessage, :PeekMessageA, [:pointer, :hwnd, :uint, :uint, :uint], :bool
|
40
|
-
attach_function :PostMessage, :PostMessageA, [:hwnd, :uint, :uintptr_t, :uintptr_t], :bool
|
41
|
-
attach_function :PostQuitMessage, :PostQuitMessage, [:uint], :void
|
42
|
-
attach_function :RegisterClipboardFormat, :RegisterClipboardFormatA, [:string], :uint
|
43
|
-
attach_function :SetClipboardData, [:uint, :handle], :handle
|
44
|
-
attach_function :SetClipboardViewer, [:hwnd], :hwnd
|
45
|
-
attach_function :SendMessage, :SendMessageA, [:hwnd, :uint, :uintptr_t, :uintptr_t], :bool
|
46
|
-
attach_function :TranslateMessage, [:pointer], :bool
|
47
|
-
|
48
|
-
# Use Long on 32-bit Ruby, LongPtr on 64-bit Ruby
|
49
|
-
begin
|
50
|
-
attach_function :GetWindowLongPtr, :GetWindowLongPtrA, [:hwnd, :int], :long
|
51
|
-
attach_function :SetWindowLongPtr, :SetWindowLongPtrA, [:hwnd, :int, :uintptr_t], :long
|
52
|
-
rescue FFI::NotFoundError
|
53
|
-
attach_function :GetWindowLongPtr, :GetWindowLongA, [:hwnd, :int], :long
|
54
|
-
attach_function :SetWindowLongPtr, :SetWindowLongA, [:hwnd, :int, :uintptr_t], :long
|
55
|
-
end
|
56
|
-
|
57
|
-
ffi_lib :shell32
|
58
|
-
|
59
|
-
attach_function :DragQueryFileA, [:hdrop, :uint, :pointer, :uint], :uint
|
60
|
-
|
61
|
-
ffi_lib :gdi32
|
62
|
-
|
63
|
-
attach_function :GetEnhMetaFileBits, [:handle, :uint, :pointer], :uint
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
1
|
+
require 'ffi'
|
2
|
+
|
3
|
+
module Windows
|
4
|
+
module Functions
|
5
|
+
extend FFI::Library
|
6
|
+
|
7
|
+
typedef :uintptr_t, :hglobal
|
8
|
+
typedef :uintptr_t, :hwnd
|
9
|
+
typedef :uintptr_t, :handle
|
10
|
+
typedef :uintptr_t, :hmenu
|
11
|
+
typedef :uintptr_t, :hdrop
|
12
|
+
typedef :uintptr_t, :hinstance
|
13
|
+
typedef :ulong, :dword
|
14
|
+
|
15
|
+
callback :wnd_proc, [:hwnd, :uint, :long, :long], :long
|
16
|
+
|
17
|
+
ffi_lib :kernel32
|
18
|
+
|
19
|
+
attach_function :GlobalAlloc, [:uint, :size_t], :hglobal
|
20
|
+
attach_function :GlobalFree, [:hglobal], :hglobal
|
21
|
+
attach_function :GlobalLock, [:hglobal], :pointer
|
22
|
+
attach_function :GlobalSize, [:hglobal], :size_t
|
23
|
+
attach_function :GlobalUnlock, [:hglobal], :bool
|
24
|
+
|
25
|
+
ffi_lib :user32
|
26
|
+
|
27
|
+
attach_function :ChangeClipboardChain, [:hwnd, :hwnd], :bool
|
28
|
+
attach_function :CloseClipboard, [], :bool
|
29
|
+
attach_function :CountClipboardFormats, [], :int
|
30
|
+
attach_function :CreateWindowEx, :CreateWindowExA, [:dword, :string, :string, :dword, :int, :int, :int, :int, :hwnd, :hmenu, :hinstance, :pointer], :hwnd
|
31
|
+
attach_function :DefWindowProc, :DefWindowProcA, [:hwnd, :uint, :uint, :uint], :long
|
32
|
+
attach_function :DispatchMessage, :DispatchMessageA, [:pointer], :uint
|
33
|
+
attach_function :EmptyClipboard, [], :bool
|
34
|
+
attach_function :EnumClipboardFormats, [:uint], :uint
|
35
|
+
attach_function :GetClipboardData, [:uint], :handle
|
36
|
+
attach_function :GetClipboardFormatName, :GetClipboardFormatNameA, [:uint, :pointer, :int], :int
|
37
|
+
attach_function :IsClipboardFormatAvailable, [:uint], :bool
|
38
|
+
attach_function :OpenClipboard, [:hwnd], :bool
|
39
|
+
attach_function :PeekMessage, :PeekMessageA, [:pointer, :hwnd, :uint, :uint, :uint], :bool
|
40
|
+
attach_function :PostMessage, :PostMessageA, [:hwnd, :uint, :uintptr_t, :uintptr_t], :bool
|
41
|
+
attach_function :PostQuitMessage, :PostQuitMessage, [:uint], :void
|
42
|
+
attach_function :RegisterClipboardFormat, :RegisterClipboardFormatA, [:string], :uint
|
43
|
+
attach_function :SetClipboardData, [:uint, :handle], :handle
|
44
|
+
attach_function :SetClipboardViewer, [:hwnd], :hwnd
|
45
|
+
attach_function :SendMessage, :SendMessageA, [:hwnd, :uint, :uintptr_t, :uintptr_t], :bool
|
46
|
+
attach_function :TranslateMessage, [:pointer], :bool
|
47
|
+
|
48
|
+
# Use Long on 32-bit Ruby, LongPtr on 64-bit Ruby
|
49
|
+
begin
|
50
|
+
attach_function :GetWindowLongPtr, :GetWindowLongPtrA, [:hwnd, :int], :long
|
51
|
+
attach_function :SetWindowLongPtr, :SetWindowLongPtrA, [:hwnd, :int, :uintptr_t], :long
|
52
|
+
rescue FFI::NotFoundError
|
53
|
+
attach_function :GetWindowLongPtr, :GetWindowLongA, [:hwnd, :int], :long
|
54
|
+
attach_function :SetWindowLongPtr, :SetWindowLongA, [:hwnd, :int, :uintptr_t], :long
|
55
|
+
end
|
56
|
+
|
57
|
+
ffi_lib :shell32
|
58
|
+
|
59
|
+
attach_function :DragQueryFileA, [:hdrop, :uint, :pointer, :uint], :uint
|
60
|
+
|
61
|
+
ffi_lib :gdi32
|
62
|
+
|
63
|
+
attach_function :GetEnhMetaFileBits, [:handle, :uint, :pointer], :uint
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
@@ -1,43 +1,43 @@
|
|
1
|
-
require 'ffi'
|
2
|
-
|
3
|
-
module Windows
|
4
|
-
module Structs
|
5
|
-
extend FFI::Library
|
6
|
-
|
7
|
-
typedef :uchar, :byte
|
8
|
-
typedef :ulong, :dword
|
9
|
-
typedef :ushort, :word
|
10
|
-
|
11
|
-
class RGBQUAD < FFI::Struct
|
12
|
-
layout(
|
13
|
-
:rgbBlue, :byte,
|
14
|
-
:rgbGreen, :byte,
|
15
|
-
:rgbRed, :byte,
|
16
|
-
:rgbReserved, :byte,
|
17
|
-
)
|
18
|
-
end
|
19
|
-
|
20
|
-
class BITMAPINFOHEADER < FFI::Struct
|
21
|
-
layout(
|
22
|
-
:biSize, :dword,
|
23
|
-
:biWidth, :long,
|
24
|
-
:biHeight, :long,
|
25
|
-
:biPlanes, :word,
|
26
|
-
:biBitCount, :word,
|
27
|
-
:biCompression, :dword,
|
28
|
-
:biSizeImage, :dword,
|
29
|
-
:biXPelsPerMeter, :long,
|
30
|
-
:biYPelsPerMeter, :long,
|
31
|
-
:biClrUsed, :dword,
|
32
|
-
:biClrImportant, :dword
|
33
|
-
)
|
34
|
-
end
|
35
|
-
|
36
|
-
class BITMAPINFO < FFI::Struct
|
37
|
-
layout(
|
38
|
-
:bmiHeader, BITMAPINFOHEADER,
|
39
|
-
:bmiColor, [RGBQUAD, 1]
|
40
|
-
)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
1
|
+
require 'ffi'
|
2
|
+
|
3
|
+
module Windows
|
4
|
+
module Structs
|
5
|
+
extend FFI::Library
|
6
|
+
|
7
|
+
typedef :uchar, :byte
|
8
|
+
typedef :ulong, :dword
|
9
|
+
typedef :ushort, :word
|
10
|
+
|
11
|
+
class RGBQUAD < FFI::Struct
|
12
|
+
layout(
|
13
|
+
:rgbBlue, :byte,
|
14
|
+
:rgbGreen, :byte,
|
15
|
+
:rgbRed, :byte,
|
16
|
+
:rgbReserved, :byte,
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
class BITMAPINFOHEADER < FFI::Struct
|
21
|
+
layout(
|
22
|
+
:biSize, :dword,
|
23
|
+
:biWidth, :long,
|
24
|
+
:biHeight, :long,
|
25
|
+
:biPlanes, :word,
|
26
|
+
:biBitCount, :word,
|
27
|
+
:biCompression, :dword,
|
28
|
+
:biSizeImage, :dword,
|
29
|
+
:biXPelsPerMeter, :long,
|
30
|
+
:biYPelsPerMeter, :long,
|
31
|
+
:biClrUsed, :dword,
|
32
|
+
:biClrImportant, :dword
|
33
|
+
)
|
34
|
+
end
|
35
|
+
|
36
|
+
class BITMAPINFO < FFI::Struct
|
37
|
+
layout(
|
38
|
+
:bmiHeader, BITMAPINFOHEADER,
|
39
|
+
:bmiColor, [RGBQUAD, 1]
|
40
|
+
)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/test/lock.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
|
-
require 'timeout'
|
2
|
-
require 'tmpdir'
|
3
|
-
|
4
|
-
def lock(&block)
|
5
|
-
Timeout::timeout(5) do
|
6
|
-
open(File.join(Dir.tmpdir, 'ruby-win32-clipboard.lock'), 'w') do |f|
|
7
|
-
begin
|
8
|
-
f.flock(File::LOCK_EX)
|
9
|
-
yield
|
10
|
-
ensure
|
11
|
-
f.flock(File::LOCK_UN)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
rescue Timeout::Error
|
16
|
-
raise 'Lock(timeout)'
|
17
|
-
end
|
18
|
-
|
1
|
+
require 'timeout'
|
2
|
+
require 'tmpdir'
|
3
|
+
|
4
|
+
def lock(&block)
|
5
|
+
Timeout::timeout(5) do
|
6
|
+
open(File.join(Dir.tmpdir, 'ruby-win32-clipboard.lock'), 'w') do |f|
|
7
|
+
begin
|
8
|
+
f.flock(File::LOCK_EX)
|
9
|
+
yield
|
10
|
+
ensure
|
11
|
+
f.flock(File::LOCK_UN)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
rescue Timeout::Error
|
16
|
+
raise 'Lock(timeout)'
|
17
|
+
end
|
18
|
+
|
data/test/notify.rb
CHANGED
@@ -1,27 +1,27 @@
|
|
1
|
-
require 'win32/clipboard'
|
2
|
-
require File.join(File.dirname(__FILE__), 'lock')
|
3
|
-
|
4
|
-
include Win32
|
5
|
-
|
6
|
-
timeout = ARGV[1].to_i
|
7
|
-
|
8
|
-
def write
|
9
|
-
data = ''
|
10
|
-
lock do
|
11
|
-
data = Clipboard.data
|
12
|
-
end
|
13
|
-
|
14
|
-
begin
|
15
|
-
STDOUT.puts data
|
16
|
-
STDOUT.flush
|
17
|
-
rescue => e
|
18
|
-
puts $!
|
19
|
-
end
|
20
|
-
if data == ARGV[0]
|
21
|
-
exit
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
Timeout::timeout(timeout) do
|
26
|
-
Clipboard.notify_change {write}
|
27
|
-
end
|
1
|
+
require 'win32/clipboard'
|
2
|
+
require File.join(File.dirname(__FILE__), 'lock')
|
3
|
+
|
4
|
+
include Win32
|
5
|
+
|
6
|
+
timeout = ARGV[1].to_i
|
7
|
+
|
8
|
+
def write
|
9
|
+
data = ''
|
10
|
+
lock do
|
11
|
+
data = Clipboard.data
|
12
|
+
end
|
13
|
+
|
14
|
+
begin
|
15
|
+
STDOUT.puts data
|
16
|
+
STDOUT.flush
|
17
|
+
rescue => e
|
18
|
+
puts $!
|
19
|
+
end
|
20
|
+
if data == ARGV[0]
|
21
|
+
exit
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
Timeout::timeout(timeout) do
|
26
|
+
Clipboard.notify_change {write}
|
27
|
+
end
|
data/test/test_clipboard.rb
CHANGED
@@ -1,176 +1,176 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
###########################################################################
|
3
|
-
# test_clipboard.rb
|
4
|
-
#
|
5
|
-
# Test suite for the win32-clipboard library. This will copy and remove
|
6
|
-
# data from your clipboard. If your current clipboard data is crucial to
|
7
|
-
# you, please save it first.
|
8
|
-
#
|
9
|
-
# You should run this test case via the 'rake test' task.
|
10
|
-
###########################################################################
|
11
|
-
require 'test-unit'
|
12
|
-
require 'win32/clipboard'
|
13
|
-
require 'timeout'
|
14
|
-
include Win32
|
15
|
-
|
16
|
-
class TC_Win32_ClipBoard < Test::Unit::TestCase
|
17
|
-
test "version is set to expected value" do
|
18
|
-
assert_equal('0.6.
|
19
|
-
end
|
20
|
-
|
21
|
-
test "data method basic functionality" do
|
22
|
-
assert_respond_to(Clipboard, :data)
|
23
|
-
assert_nothing_raised{ Clipboard.data }
|
24
|
-
assert_kind_of(String, Clipboard.data)
|
25
|
-
end
|
26
|
-
|
27
|
-
test "data method requires proper format" do
|
28
|
-
assert_raise(TypeError){ Clipboard.data('test') }
|
29
|
-
assert_raise(NameError){ Clipboard.data(CF_FOO) }
|
30
|
-
end
|
31
|
-
|
32
|
-
test "get_data is an alias for data" do
|
33
|
-
assert_respond_to(Clipboard, :get_data)
|
34
|
-
assert_alias_method(Clipboard, :data, :get_data)
|
35
|
-
end
|
36
|
-
|
37
|
-
test "set_data basic functionality" do
|
38
|
-
assert_respond_to(Clipboard, :set_data)
|
39
|
-
assert_nothing_raised{ Clipboard.set_data('foo') }
|
40
|
-
end
|
41
|
-
|
42
|
-
test "set_data works with unicode text" do
|
43
|
-
assert_nothing_raised{
|
44
|
-
Clipboard.set_data('Ηελλας', Clipboard::UNICODETEXT)
|
45
|
-
}
|
46
|
-
end
|
47
|
-
|
48
|
-
test "set_data requires at least one argument" do
|
49
|
-
assert_raise(ArgumentError){ Clipboard.set_data }
|
50
|
-
end
|
51
|
-
|
52
|
-
test "set_data requires a valid data format" do
|
53
|
-
assert_raise(NameError){ Clipboard.set_data('foo', CF_FOO) }
|
54
|
-
end
|
55
|
-
|
56
|
-
test "set and get ascii data as expected" do
|
57
|
-
assert_nothing_raised{ Clipboard.set_data('foobar') }
|
58
|
-
assert_equal('foobar', Clipboard.data)
|
59
|
-
end
|
60
|
-
|
61
|
-
test "set and get unicode data as expected" do
|
62
|
-
assert_nothing_raised{
|
63
|
-
Clipboard.set_data('Ηελλας', Clipboard::UNICODETEXT)
|
64
|
-
}
|
65
|
-
assert_equal('Ηελλας', Clipboard.data(Clipboard::UNICODETEXT))
|
66
|
-
end
|
67
|
-
|
68
|
-
test "empty method basic functionality" do
|
69
|
-
assert_respond_to(Clipboard, :empty)
|
70
|
-
assert_nothing_raised{ Clipboard.empty }
|
71
|
-
end
|
72
|
-
|
73
|
-
test "clear is an alias for empty" do
|
74
|
-
assert_respond_to(Clipboard, :clear)
|
75
|
-
assert_alias_method(Clipboard, :clear, :empty)
|
76
|
-
end
|
77
|
-
|
78
|
-
test "num_formats basic functionality" do
|
79
|
-
assert_respond_to(Clipboard, :num_formats)
|
80
|
-
assert_nothing_raised{ Clipboard.num_formats }
|
81
|
-
assert_kind_of(Fixnum, Clipboard.num_formats)
|
82
|
-
end
|
83
|
-
|
84
|
-
test "num_formats returns an expected value" do
|
85
|
-
assert_true(Clipboard.num_formats >= 0)
|
86
|
-
assert_true(Clipboard.num_formats < 1000)
|
87
|
-
end
|
88
|
-
|
89
|
-
test "num_formats does not accept any arguments" do
|
90
|
-
assert_raise(ArgumentError){ Clipboard.num_formats(true) }
|
91
|
-
end
|
92
|
-
|
93
|
-
test "register_format basic functionality" do
|
94
|
-
assert_respond_to(Clipboard, :register_format)
|
95
|
-
assert_nothing_raised{ Clipboard.register_format('Ruby') }
|
96
|
-
assert_kind_of(Integer, Clipboard.register_format('Ruby'))
|
97
|
-
end
|
98
|
-
|
99
|
-
test "register_format requires a string argument" do
|
100
|
-
assert_raises(TypeError){ Clipboard.register_format(1) }
|
101
|
-
end
|
102
|
-
|
103
|
-
test "formats method basic functionality" do
|
104
|
-
assert_respond_to(Clipboard, :formats)
|
105
|
-
assert_nothing_raised{ Clipboard.formats }
|
106
|
-
assert_kind_of(Hash, Clipboard.formats)
|
107
|
-
end
|
108
|
-
|
109
|
-
# TODO: Why do these fail?
|
110
|
-
#test "formats result contains expected values" do
|
111
|
-
# assert_true(Clipboard.formats.size > 0)
|
112
|
-
# assert_true(Clipboard.formats.include?(1))
|
113
|
-
#end
|
114
|
-
|
115
|
-
test "formats method does not accept any arguments" do
|
116
|
-
assert_raise(ArgumentError){ Clipboard.formats(true) }
|
117
|
-
end
|
118
|
-
|
119
|
-
test "format_available basic functionality" do
|
120
|
-
assert_respond_to(Clipboard, :format_available?)
|
121
|
-
assert_nothing_raised{ Clipboard.format_available?(1) }
|
122
|
-
end
|
123
|
-
|
124
|
-
test "format_available returns a boolean value" do
|
125
|
-
assert_boolean(Clipboard.format_available?(1))
|
126
|
-
end
|
127
|
-
|
128
|
-
test "format_name basic functionality" do
|
129
|
-
assert_respond_to(Clipboard, :format_name)
|
130
|
-
assert_nothing_raised{ Clipboard.format_name(1) }
|
131
|
-
end
|
132
|
-
|
133
|
-
test "format_name returns expected value" do
|
134
|
-
format = Clipboard.register_format('HTML Format')
|
135
|
-
assert_equal('HTML Format', Clipboard.format_name(format))
|
136
|
-
assert_nil(Clipboard.format_name(9999999))
|
137
|
-
end
|
138
|
-
|
139
|
-
test "format_name requires a numeric argument" do
|
140
|
-
assert_raise(TypeError){ Clipboard.format_name('foo') }
|
141
|
-
end
|
142
|
-
|
143
|
-
test "notify_change basic functionality" do
|
144
|
-
assert_respond_to(Clipboard, :notify_change)
|
145
|
-
def wait(&block)
|
146
|
-
Timeout::timeout(5) do
|
147
|
-
while @count == 0
|
148
|
-
yield if block
|
149
|
-
sleep(0.1)
|
150
|
-
end
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
@count = 0
|
155
|
-
t = Thread.start do
|
156
|
-
Clipboard.notify_change {@count += 1}
|
157
|
-
end
|
158
|
-
wait {Clipboard.set_data('ready')}
|
159
|
-
@count = 0
|
160
|
-
|
161
|
-
Clipboard.set_data('foo')
|
162
|
-
wait
|
163
|
-
assert_equal(@count, 1)
|
164
|
-
t.kill
|
165
|
-
end
|
166
|
-
|
167
|
-
test "expected constants are defined" do
|
168
|
-
assert_not_nil(Clipboard::TEXT)
|
169
|
-
assert_not_nil(Clipboard::OEMTEXT)
|
170
|
-
assert_not_nil(Clipboard::UNICODETEXT)
|
171
|
-
assert_not_nil(Clipboard::BITMAP)
|
172
|
-
assert_not_nil(Clipboard::DIB)
|
173
|
-
assert_not_nil(Clipboard::HDROP)
|
174
|
-
assert_not_nil(Clipboard::ENHMETAFILE)
|
175
|
-
end
|
176
|
-
end
|
1
|
+
# encoding: utf-8
|
2
|
+
###########################################################################
|
3
|
+
# test_clipboard.rb
|
4
|
+
#
|
5
|
+
# Test suite for the win32-clipboard library. This will copy and remove
|
6
|
+
# data from your clipboard. If your current clipboard data is crucial to
|
7
|
+
# you, please save it first.
|
8
|
+
#
|
9
|
+
# You should run this test case via the 'rake test' task.
|
10
|
+
###########################################################################
|
11
|
+
require 'test-unit'
|
12
|
+
require 'win32/clipboard'
|
13
|
+
require 'timeout'
|
14
|
+
include Win32
|
15
|
+
|
16
|
+
class TC_Win32_ClipBoard < Test::Unit::TestCase
|
17
|
+
test "version is set to expected value" do
|
18
|
+
assert_equal('0.6.4', Clipboard::VERSION)
|
19
|
+
end
|
20
|
+
|
21
|
+
test "data method basic functionality" do
|
22
|
+
assert_respond_to(Clipboard, :data)
|
23
|
+
assert_nothing_raised{ Clipboard.data }
|
24
|
+
assert_kind_of(String, Clipboard.data)
|
25
|
+
end
|
26
|
+
|
27
|
+
test "data method requires proper format" do
|
28
|
+
assert_raise(TypeError){ Clipboard.data('test') }
|
29
|
+
assert_raise(NameError){ Clipboard.data(CF_FOO) }
|
30
|
+
end
|
31
|
+
|
32
|
+
test "get_data is an alias for data" do
|
33
|
+
assert_respond_to(Clipboard, :get_data)
|
34
|
+
assert_alias_method(Clipboard, :data, :get_data)
|
35
|
+
end
|
36
|
+
|
37
|
+
test "set_data basic functionality" do
|
38
|
+
assert_respond_to(Clipboard, :set_data)
|
39
|
+
assert_nothing_raised{ Clipboard.set_data('foo') }
|
40
|
+
end
|
41
|
+
|
42
|
+
test "set_data works with unicode text" do
|
43
|
+
assert_nothing_raised{
|
44
|
+
Clipboard.set_data('Ηελλας', Clipboard::UNICODETEXT)
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
test "set_data requires at least one argument" do
|
49
|
+
assert_raise(ArgumentError){ Clipboard.set_data }
|
50
|
+
end
|
51
|
+
|
52
|
+
test "set_data requires a valid data format" do
|
53
|
+
assert_raise(NameError){ Clipboard.set_data('foo', CF_FOO) }
|
54
|
+
end
|
55
|
+
|
56
|
+
test "set and get ascii data as expected" do
|
57
|
+
assert_nothing_raised{ Clipboard.set_data('foobar') }
|
58
|
+
assert_equal('foobar', Clipboard.data)
|
59
|
+
end
|
60
|
+
|
61
|
+
test "set and get unicode data as expected" do
|
62
|
+
assert_nothing_raised{
|
63
|
+
Clipboard.set_data('Ηελλας', Clipboard::UNICODETEXT)
|
64
|
+
}
|
65
|
+
assert_equal('Ηελλας', Clipboard.data(Clipboard::UNICODETEXT))
|
66
|
+
end
|
67
|
+
|
68
|
+
test "empty method basic functionality" do
|
69
|
+
assert_respond_to(Clipboard, :empty)
|
70
|
+
assert_nothing_raised{ Clipboard.empty }
|
71
|
+
end
|
72
|
+
|
73
|
+
test "clear is an alias for empty" do
|
74
|
+
assert_respond_to(Clipboard, :clear)
|
75
|
+
assert_alias_method(Clipboard, :clear, :empty)
|
76
|
+
end
|
77
|
+
|
78
|
+
test "num_formats basic functionality" do
|
79
|
+
assert_respond_to(Clipboard, :num_formats)
|
80
|
+
assert_nothing_raised{ Clipboard.num_formats }
|
81
|
+
assert_kind_of(Fixnum, Clipboard.num_formats)
|
82
|
+
end
|
83
|
+
|
84
|
+
test "num_formats returns an expected value" do
|
85
|
+
assert_true(Clipboard.num_formats >= 0)
|
86
|
+
assert_true(Clipboard.num_formats < 1000)
|
87
|
+
end
|
88
|
+
|
89
|
+
test "num_formats does not accept any arguments" do
|
90
|
+
assert_raise(ArgumentError){ Clipboard.num_formats(true) }
|
91
|
+
end
|
92
|
+
|
93
|
+
test "register_format basic functionality" do
|
94
|
+
assert_respond_to(Clipboard, :register_format)
|
95
|
+
assert_nothing_raised{ Clipboard.register_format('Ruby') }
|
96
|
+
assert_kind_of(Integer, Clipboard.register_format('Ruby'))
|
97
|
+
end
|
98
|
+
|
99
|
+
test "register_format requires a string argument" do
|
100
|
+
assert_raises(TypeError){ Clipboard.register_format(1) }
|
101
|
+
end
|
102
|
+
|
103
|
+
test "formats method basic functionality" do
|
104
|
+
assert_respond_to(Clipboard, :formats)
|
105
|
+
assert_nothing_raised{ Clipboard.formats }
|
106
|
+
assert_kind_of(Hash, Clipboard.formats)
|
107
|
+
end
|
108
|
+
|
109
|
+
# TODO: Why do these fail?
|
110
|
+
#test "formats result contains expected values" do
|
111
|
+
# assert_true(Clipboard.formats.size > 0)
|
112
|
+
# assert_true(Clipboard.formats.include?(1))
|
113
|
+
#end
|
114
|
+
|
115
|
+
test "formats method does not accept any arguments" do
|
116
|
+
assert_raise(ArgumentError){ Clipboard.formats(true) }
|
117
|
+
end
|
118
|
+
|
119
|
+
test "format_available basic functionality" do
|
120
|
+
assert_respond_to(Clipboard, :format_available?)
|
121
|
+
assert_nothing_raised{ Clipboard.format_available?(1) }
|
122
|
+
end
|
123
|
+
|
124
|
+
test "format_available returns a boolean value" do
|
125
|
+
assert_boolean(Clipboard.format_available?(1))
|
126
|
+
end
|
127
|
+
|
128
|
+
test "format_name basic functionality" do
|
129
|
+
assert_respond_to(Clipboard, :format_name)
|
130
|
+
assert_nothing_raised{ Clipboard.format_name(1) }
|
131
|
+
end
|
132
|
+
|
133
|
+
test "format_name returns expected value" do
|
134
|
+
format = Clipboard.register_format('HTML Format')
|
135
|
+
assert_equal('HTML Format', Clipboard.format_name(format))
|
136
|
+
assert_nil(Clipboard.format_name(9999999))
|
137
|
+
end
|
138
|
+
|
139
|
+
test "format_name requires a numeric argument" do
|
140
|
+
assert_raise(TypeError){ Clipboard.format_name('foo') }
|
141
|
+
end
|
142
|
+
|
143
|
+
test "notify_change basic functionality" do
|
144
|
+
assert_respond_to(Clipboard, :notify_change)
|
145
|
+
def wait(&block)
|
146
|
+
Timeout::timeout(5) do
|
147
|
+
while @count == 0
|
148
|
+
yield if block
|
149
|
+
sleep(0.1)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
@count = 0
|
155
|
+
t = Thread.start do
|
156
|
+
Clipboard.notify_change {@count += 1}
|
157
|
+
end
|
158
|
+
wait {Clipboard.set_data('ready')}
|
159
|
+
@count = 0
|
160
|
+
|
161
|
+
Clipboard.set_data('foo')
|
162
|
+
wait
|
163
|
+
assert_equal(@count, 1)
|
164
|
+
t.kill
|
165
|
+
end
|
166
|
+
|
167
|
+
test "expected constants are defined" do
|
168
|
+
assert_not_nil(Clipboard::TEXT)
|
169
|
+
assert_not_nil(Clipboard::OEMTEXT)
|
170
|
+
assert_not_nil(Clipboard::UNICODETEXT)
|
171
|
+
assert_not_nil(Clipboard::BITMAP)
|
172
|
+
assert_not_nil(Clipboard::DIB)
|
173
|
+
assert_not_nil(Clipboard::HDROP)
|
174
|
+
assert_not_nil(Clipboard::ENHMETAFILE)
|
175
|
+
end
|
176
|
+
end
|