win 0.1.13 → 0.1.16

Sign up to get free protection for your applications and to get access to all the features.
data/win.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{win}
8
- s.version = "0.1.13"
8
+ s.version = "0.1.16"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["arvicco"]
12
- s.date = %q{2010-02-20}
12
+ s.date = %q{2010-02-25}
13
13
  s.description = %q{Rubyesque interfaces and wrappers for Windows API functions pre-defined using FFI }
14
14
  s.email = %q{arvitallian@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -27,23 +27,23 @@ Gem::Specification.new do |s|
27
27
  "features/support/env.rb",
28
28
  "features/win.feature",
29
29
  "lib/win/dde.rb",
30
+ "lib/win/error.rb",
30
31
  "lib/win/extensions.rb",
31
32
  "lib/win/gui.rb",
32
33
  "lib/win/gui/dialog.rb",
33
34
  "lib/win/gui/input.rb",
34
35
  "lib/win/gui/message.rb",
35
36
  "lib/win/gui/window.rb",
36
- "lib/win/gui/window/window.rb",
37
37
  "lib/win/library.rb",
38
38
  "spec/spec.opts",
39
39
  "spec/spec_helper.rb",
40
40
  "spec/test_apps/locknote/LockNote.exe",
41
41
  "spec/win/dde_spec.rb",
42
+ "spec/win/error_spec.rb",
42
43
  "spec/win/extensions_spec.rb",
43
44
  "spec/win/gui/dialog_spec.rb",
44
45
  "spec/win/gui/input_spec.rb",
45
46
  "spec/win/gui/message_spec.rb",
46
- "spec/win/gui/window/window_spec.rb",
47
47
  "spec/win/gui/window_spec.rb",
48
48
  "spec/win/library_spec.rb",
49
49
  "win.gemspec"
@@ -56,11 +56,11 @@ Gem::Specification.new do |s|
56
56
  s.test_files = [
57
57
  "spec/spec_helper.rb",
58
58
  "spec/win/dde_spec.rb",
59
+ "spec/win/error_spec.rb",
59
60
  "spec/win/extensions_spec.rb",
60
61
  "spec/win/gui/dialog_spec.rb",
61
62
  "spec/win/gui/input_spec.rb",
62
63
  "spec/win/gui/message_spec.rb",
63
- "spec/win/gui/window/window_spec.rb",
64
64
  "spec/win/gui/window_spec.rb",
65
65
  "spec/win/library_spec.rb"
66
66
  ]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: win
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.13
4
+ version: 0.1.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - arvicco
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-20 00:00:00 +03:00
12
+ date: 2010-02-25 00:00:00 +03:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -62,23 +62,23 @@ files:
62
62
  - features/support/env.rb
63
63
  - features/win.feature
64
64
  - lib/win/dde.rb
65
+ - lib/win/error.rb
65
66
  - lib/win/extensions.rb
66
67
  - lib/win/gui.rb
67
68
  - lib/win/gui/dialog.rb
68
69
  - lib/win/gui/input.rb
69
70
  - lib/win/gui/message.rb
70
71
  - lib/win/gui/window.rb
71
- - lib/win/gui/window/window.rb
72
72
  - lib/win/library.rb
73
73
  - spec/spec.opts
74
74
  - spec/spec_helper.rb
75
75
  - spec/test_apps/locknote/LockNote.exe
76
76
  - spec/win/dde_spec.rb
77
+ - spec/win/error_spec.rb
77
78
  - spec/win/extensions_spec.rb
78
79
  - spec/win/gui/dialog_spec.rb
79
80
  - spec/win/gui/input_spec.rb
80
81
  - spec/win/gui/message_spec.rb
81
- - spec/win/gui/window/window_spec.rb
82
82
  - spec/win/gui/window_spec.rb
83
83
  - spec/win/library_spec.rb
84
84
  - win.gemspec
@@ -113,10 +113,10 @@ summary: Rubyesque interfaces and wrappers for Windows API functions pre-defined
113
113
  test_files:
114
114
  - spec/spec_helper.rb
115
115
  - spec/win/dde_spec.rb
116
+ - spec/win/error_spec.rb
116
117
  - spec/win/extensions_spec.rb
117
118
  - spec/win/gui/dialog_spec.rb
118
119
  - spec/win/gui/input_spec.rb
119
120
  - spec/win/gui/message_spec.rb
120
- - spec/win/gui/window/window_spec.rb
121
121
  - spec/win/gui/window_spec.rb
122
122
  - spec/win/library_spec.rb
@@ -1,88 +0,0 @@
1
- require 'win/library'
2
- require 'win/gui/window'
3
- require 'win/gui/message'
4
- require 'win/gui/input'
5
-
6
- module Win
7
- module GUI
8
- module Window
9
- # This class is a thin wrapper around window handle
10
- # It should be probably moved out of this lib since it's supposed to be "close to metal"
11
- class Window
12
- # Wait delay
13
- SLEEP_DELAY = 0.001
14
- # Timeout waiting for Window to be closed
15
- CLOSE_TIMEOUT = 1
16
-
17
- include Win::GUI::Window
18
- extend Win::GUI::Window
19
- include Win::GUI::Message
20
- include Win::GUI::Input
21
-
22
- attr_reader :handle
23
-
24
- # find top level window by title, return wrapped Window object
25
- def self.top_level(title, seconds=3)
26
- @handle = timeout(seconds) do
27
- sleep SLEEP_DELAY while (h = find_window nil, title) == nil; h
28
- end
29
- Window.new @handle
30
- end
31
-
32
- def initialize(handle)
33
- @handle = handle
34
- end
35
-
36
- # find child window (control) by title, window class, or control ID:
37
- def child(id)
38
- result = case id
39
- when String
40
- by_title = find_window_ex @handle, 0, nil, id.gsub('_', '&' )
41
- by_class = find_window_ex @handle, 0, id, nil
42
- by_title ? by_title : by_class
43
- when Fixnum
44
- get_dlg_item @handle, id
45
- when nil
46
- find_window_ex @handle, 0, nil, nil
47
- else
48
- nil
49
- end
50
- raise "Control '#{id}' not found" unless result
51
- Window.new result
52
- end
53
-
54
- def children
55
- enum_child_windows(@handle).map{|child_handle| Window.new child_handle}
56
- end
57
-
58
- # emulate click of the control identified by id
59
- def click(id)
60
- h = child(id).handle
61
- rectangle = [0, 0, 0, 0].pack 'LLLL'
62
- get_window_rect h, rectangle
63
- left, top, right, bottom = rectangle.unpack 'LLLL'
64
- center = [(left + right) / 2, (top + bottom) / 2]
65
- set_cursor_pos *center
66
- mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
67
- mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
68
- end
69
-
70
- def close
71
- post_message @handle, WM_SYSCOMMAND, SC_CLOSE, 0
72
- end
73
-
74
- def wait_for_close
75
- timeout(CLOSE_TIMEOUT) do
76
- sleep SLEEP_DELAY while window_visible?(@handle)
77
- end
78
- end
79
-
80
- def text
81
- buffer = "\x0" * 2048
82
- length = send_message @handle, WM_GETTEXT, buffer.length, buffer
83
- length == 0 ? '' : buffer[0..length - 1]
84
- end
85
- end
86
- end
87
- end
88
- end
@@ -1,129 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
2
- require 'win/gui/window'
3
- require 'win/gui/window/window'
4
-
5
- module WinGUITest
6
- include WinTestApp
7
- include Win::GUI::Window
8
- include Win::GUI::Input
9
-
10
- describe Win::GUI::Window::Window, ' thin wrapper class around window handle' do
11
- before(:each) { @app = launch_test_app }
12
- after(:each){ close_test_app }
13
-
14
- context 'creating' do
15
- it 'can be wrapped around any existing window' do
16
- any_handle = find_window(nil, nil)
17
- use{ Window::Window.new any_handle }
18
- end
19
-
20
- it 'can be wrapped around specific window' do
21
- use{ Window::Window.new @app.handle }
22
- end
23
- end
24
-
25
- context 'manipulating' do
26
-
27
- it 'has handle property equal to underlying window handle' do
28
- any_handle = find_window(nil, nil)
29
- any = Window::Window.new any_handle
30
- any.handle.should == any_handle
31
- end
32
-
33
- it 'has text property equal to underlying window text(title)' do
34
- @app.text.should == TEST_WIN_TITLE
35
- end
36
-
37
- it 'closes when asked nicely' do
38
- @app.close
39
- sleep TEST_SLEEP_DELAY # needed to ensure window had enough time to close down
40
- find_window(nil, TEST_WIN_TITLE).should == nil #!!!!!!
41
- end
42
-
43
- it 'waits f0r window to disappear (NB: this happens before handle is released!)' do
44
- start = Time.now
45
- @app.close
46
- @app.wait_for_close
47
- (Time.now - start).should be <= Win::GUI::Window::Window::CLOSE_TIMEOUT
48
- window_visible?(@app.handle).should be false
49
- end
50
- end
51
-
52
- context '.top_level class method' do
53
- it 'finds any top-level window (title = nil) and wraps it in a Window object' do
54
- use { @win = Window::Window.top_level(title = nil, timeout_sec = 3) }
55
- @win.should be_a_kind_of Window
56
- end
57
-
58
- it 'finds top-level window by title and wraps it in a Window object' do
59
- win = Window::Window.top_level( TEST_WIN_TITLE, 1)
60
- win.handle.should == @app.handle
61
- end
62
- end
63
-
64
- context '#child' do
65
- spec { use { @control = @app.child(title_class_id = nil) }}
66
-
67
- it 'finds any child window(control) if given nil' do
68
- @app.child(nil).should_not == nil
69
- end
70
-
71
- it 'finds child window(control) by class' do
72
- @app.child(TEST_TEXTAREA_CLASS).should_not == nil
73
- end
74
-
75
- it 'finds child window(control) by name' do
76
- pending 'Need to find control with short name'
77
- @app.child(TEST_TEXTAREA_TEXT).should_not == nil
78
- end
79
-
80
- it 'finds child window(control) by control ID' do
81
- pending 'Need to find some control ID'
82
- @app.child(TEST_TEXTAREA_ID).should_not == nil
83
- end
84
-
85
- it 'raises error if wrong control is given' do
86
- expect { @app.child('Impossible Control')}.to raise_error "Control 'Impossible Control' not found"
87
- end
88
- it 'substitutes & for _ when searching by title ("&Yes" type controls)'
89
-
90
- end
91
-
92
- context '#children' do
93
- spec { use { children = @app.children }}
94
-
95
- it 'returns an array' do
96
- @app.children.should be_a_kind_of(Array)
97
- end
98
-
99
- it 'returns an array of all child windows to the given window ' do
100
- children = @app.children
101
- children.should be_a_kind_of Array
102
- children.should_not be_empty
103
- children.should have(2).elements
104
- children.each{|child| child?(@app.handle, child.handle).should == true }
105
- get_class_name(children.last.handle).should == TEST_TEXTAREA_CLASS
106
- end
107
-
108
- # it 'finds child window(control) by name' do
109
- # pending 'Need to find control with short name'
110
- # @app.child(TEST_TEXTAREA_TEXT).should_not == nil
111
- # end
112
- #
113
- # it 'finds child window(control) by control ID' do
114
- # pending 'Need to find some control ID'
115
- # @app.child(TEST_TEXTAREA_ID).should_not == nil
116
- # end
117
- #
118
- # it 'raises error if wrong control is given' do
119
- # expect { @app.child('Impossible Control')}.to raise_error "Control 'Impossible Control' not found"
120
- # end
121
- # it 'substitutes & for _ when searching by title ("&Yes" type controls)'
122
-
123
- end
124
-
125
- context '#click' do
126
- it 'emulates clicking of the control identified by id'
127
- end
128
- end
129
- end