win 0.1.0 → 0.1.2

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.
data/lib/win/gui.rb CHANGED
@@ -2,7 +2,7 @@ require 'win/gui/window'
2
2
  require 'win/gui/input'
3
3
  require 'win/gui/message'
4
4
  require 'win/gui/dialog'
5
- require 'win/gui/convenience'
5
+ require 'win/gui/window/window'
6
6
 
7
7
  module Win
8
8
  # Contains several modules defining Win32 API functions and constants related to Windows GUI (Graphical User Interface)
@@ -12,6 +12,5 @@ module Win
12
12
  include Win::Gui::Input
13
13
  include Win::Gui::Message
14
14
  include Win::Gui::Dialog
15
- include Win::Gui::Convenience
16
15
  end
17
16
  end
data/lib/win/library.rb CHANGED
@@ -364,7 +364,6 @@ module Win
364
364
  ##
365
365
  # Generates possible effective names for function in Win32 dll (name+A/W),
366
366
  # Rubyesque name and aliases for method(s) defined based on function name,
367
- # sets boolean flag for test functions (Is...)
368
367
  #
369
368
  def generate_names(name, options={})
370
369
  name = name.to_s
@@ -375,7 +374,6 @@ module Win
375
374
  case method_name
376
375
  when /^is_/
377
376
  aliases << method_name.sub(/^is_/, '') + '?'
378
- options[:boolean] = true
379
377
  when /^set_/
380
378
  aliases << method_name.sub(/^set_/, '')+ '='
381
379
  when /^get_/
data/spec/spec_helper.rb CHANGED
@@ -47,7 +47,7 @@ module WinTest
47
47
  TEST_KEY_DELAY = 0.001
48
48
  TEST_IMPOSSIBLE = 'Impossible'
49
49
  TEST_CONVERSION_ERROR = /Can.t convert/
50
- TEST_SLEEP_DELAY = 0.01
50
+ TEST_SLEEP_DELAY = 0.02
51
51
  TEST_APP_PATH = File.join(File.dirname(__FILE__), "test_apps/locknote/LockNote.exe" )
52
52
  TEST_APP_START = 'start "" "' + TEST_APP_PATH + '"'
53
53
  TEST_WIN_TITLE = 'LockNote - Steganos LockNote'
@@ -69,13 +69,13 @@ module WinTestApp
69
69
 
70
70
  include WinTest
71
71
  include Win::Gui
72
- include Win::Gui::Convenience
72
+ #include Win::Gui::Convenience
73
73
 
74
74
  def launch_test_app
75
75
  system TEST_APP_START
76
76
  sleep TEST_SLEEP_DELAY until (handle = find_window(nil, TEST_WIN_TITLE))
77
77
 
78
- @launched_test_app = WrapWindow.new handle
78
+ @launched_test_app = Window::Window.new handle
79
79
  # app = "Test app" #need to get rid of Window for JRuby
80
80
  # class << app; self; end.send( :define_method, :handle, &lambda {handle})
81
81
  # @launched_test_app = app
@@ -94,7 +94,7 @@ module WinTestApp
94
94
  app = launch_test_app
95
95
 
96
96
  def app.textarea #define singleton method retrieving app's text area
97
- WrapWindow.new find_window_ex(self.handle, 0, TEST_TEXTAREA_CLASS, nil)
97
+ Window::Window.new find_window_ex(self.handle, 0, TEST_TEXTAREA_CLASS, nil)
98
98
  end
99
99
 
100
100
  yield app
@@ -11,13 +11,6 @@ module WinWindowTest
11
11
 
12
12
  describe '#get_dlg_item' do
13
13
  spec{ use{ control_handle = get_dlg_item(handle = 0, item_id = 1) }}
14
- # handle (L) - Handle of the dialog box that contains the control.
15
- # item_id (I) - Specifies the identifier of the control to be retrieved.
16
- # Returns (L) - handle of the specified control if success or nil for invalid dialog box handle or a nonexistent control.
17
- # To get extended error information, call GetLastError.
18
- # You can use the GetDlgItem function with any parent-child window pair, not just with dialog boxes. As long as the handle
19
- # parameter specifies a parent window and the child window has a unique id (as specified by the hMenu parameter in the
20
- # CreateWindow or CreateWindowEx function that created the child window), GetDlgItem returns a valid handle to the child window.
21
14
 
22
15
  it 'returns handle to correctly specified control'
23
16
 
@@ -37,6 +30,28 @@ module WinWindowTest
37
30
  end
38
31
  end
39
32
 
33
+ describe Win::Gui::Dialog, ' defines convenience/service methods on top of Windows API' do
34
+ describe 'dialog' do
35
+ spec{ use{ dialog( title ='Dialog Title', timeout_sec = 0.001, &any_block) }}
36
+
37
+ it 'finds top-level dialog window by title' do
38
+ pending 'Some problems (?with timeouts?) leave window open ~half of the runs'
39
+ test_app do |app|
40
+ keystroke(VK_ALT, 'F'.ord, 'A'.ord)
41
+ @found = false
42
+ dialog('Save As', 0.5) do |dialog_window|
43
+ @found = true
44
+ keystroke(VK_ESCAPE)
45
+ dialog_window
46
+ end
47
+ @found.should == true
48
+ end
49
+ end
50
+
51
+ it 'yields found dialog window to a given block'
52
+
53
+ end
54
+ end
40
55
  end
41
56
  end
42
57
 
@@ -28,12 +28,42 @@ module WinWindowTest
28
28
  end
29
29
 
30
30
  describe '#mouse_event' do
31
+ spec { use {mouse_event( flags = MOUSEEVENTF_ABSOLUTE , dx = 0, dy = 0, data=0, extra_info=0 )}}
31
32
  it 'Emulates Mouse clicks'
32
33
  end
33
34
 
34
35
  describe '#set_cursor_pos' do
36
+ spec { use {success = set_cursor_pos(x=0, y=0)}}
35
37
  it 'how to test set_cursor_pos?'
36
38
  end
37
39
  end
40
+
41
+ describe Win::Gui::Input, ' defines convenience/service methods on top of Windows API' do
42
+ describe '#keystroke' do
43
+ spec{ use{ keystroke( vkey = 30, vkey = 30) }}
44
+
45
+ it 'emulates combinations of keys pressed (Ctrl+Alt+P+M, etc)' do
46
+ test_app do |app|
47
+ keystroke(VK_CONTROL, 'A'.ord)
48
+ keystroke(VK_SPACE)
49
+ app.textarea.text.should == ' '
50
+ 2.times {keystroke(VK_CONTROL, 'Z'.ord)} # dirty hack!
51
+ end
52
+ end
53
+ end
54
+
55
+ describe '#type_in' do
56
+ spec{ use{ type_in(message = '') }}
57
+
58
+ it 'types text message into the window holding the focus' do
59
+ test_app do |app|
60
+ text = '12 34'
61
+ type_in(text)
62
+ app.textarea.text.should =~ Regexp.new(text)
63
+ 5.times {keystroke(VK_CONTROL, 'Z'.ord)} # dirty hack!
64
+ end
65
+ end
66
+ end
67
+ end
38
68
  end
39
69
 
@@ -11,13 +11,6 @@ module WinGuiMessageTest
11
11
 
12
12
  describe '#post_message' do
13
13
  spec{ use{ success = post_message(handle = 0, msg = 0, w_param = 0, l_param = 0) }}
14
- # handle (L) - Handle to the window whose window procedure will receive the message.
15
- # If this parameter is HWND_BROADCAST, the message is sent to all top-level windows in the system, including disabled or
16
- # invisible unowned windows, overlapped windows, and pop-up windows; but the message is not sent to child windows.
17
- # msg (L) - Specifies the message to be posted.
18
- # w_param (L) - Specifies additional message-specific information.
19
- # l_param (L) - Specifies additional message-specific information.
20
- # returns (L) - Nonzero if success, zero if function failed. To get extended error information, call GetLastError.
21
14
 
22
15
  it 'places (posts) a message in the message queue associated with the thread that created the specified window'
23
16
  it 'returns without waiting for the thread to process the message'
@@ -1,72 +1,24 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
- require 'win/gui/convenience'
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
2
+ require 'win/gui/window'
3
+ require 'win/gui/window/window'
3
4
 
4
5
  module WinGuiTest
5
6
  include WinTestApp
6
7
  include Win::Gui::Window
7
- include Win::Gui::Input
8
- include Win::Gui::Convenience
9
-
10
- describe Win::Gui::Convenience, ' defines convenience/service methods on top of Windows API' do
11
- describe '#keystroke' do
12
- spec{ use{ keystroke( vkey = 30, vkey = 30) }}
13
-
14
- it 'emulates combinations of keys pressed (Ctrl+Alt+P+M, etc)' do
15
- test_app do |app|
16
- keystroke(VK_CONTROL, 'A'.ord)
17
- keystroke(VK_SPACE)
18
- app.textarea.text.should == ' '
19
- 2.times {keystroke(VK_CONTROL, 'Z'.ord)} # dirty hack!
20
- end
21
- end
22
- end
23
-
24
- describe '#type_in' do
25
- spec{ use{ type_in(message = '') }}
26
-
27
- it 'types text message into the window holding the focus' do
28
- test_app do |app|
29
- text = '12 34'
30
- type_in(text)
31
- app.textarea.text.should =~ Regexp.new(text)
32
- 5.times {keystroke(VK_CONTROL, 'Z'.ord)} # dirty hack!
33
- end
34
- end
35
- end
36
-
37
- describe 'dialog' do
38
- spec{ use{ dialog( title ='Dialog Title', timeout_sec = 0.001, &any_block) }}
39
-
40
- it 'finds top-level dialog window by title' do
41
- pending 'Some problems (?with timeouts?) leave window open ~half of the runs'
42
- test_app do |app|
43
- keystroke(VK_ALT, 'F'.ord, 'A'.ord)
44
- @found = false
45
- dialog('Save As', 0.5) do |dialog_window|
46
- @found = true
47
- keystroke(VK_ESCAPE)
48
- dialog_window
49
- end
50
- @found.should == true
51
- end
52
- end
53
- it 'yields found dialog window to a given block'
54
- end
55
-
56
- end
8
+ include Win::Gui::Input
57
9
 
58
- describe Win::Gui::Convenience::WrapWindow, ' thin wrapper class around window handle' do
10
+ describe Win::Gui::Window::Window, ' thin wrapper class around window handle' do
59
11
  before(:each) { @app = launch_test_app }
60
12
  after(:each){ close_test_app }
61
13
 
62
14
  context 'creating' do
63
15
  it 'can be wrapped around any existing window' do
64
16
  any_handle = find_window(nil, nil)
65
- use{ WrapWindow.new any_handle }
17
+ use{ Window::Window.new any_handle }
66
18
  end
67
19
 
68
20
  it 'can be wrapped around specific window' do
69
- use{ WrapWindow.new @app.handle }
21
+ use{ Window::Window.new @app.handle }
70
22
  end
71
23
  end
72
24
 
@@ -74,7 +26,7 @@ module WinGuiTest
74
26
 
75
27
  it 'has handle property equal to underlying window handle' do
76
28
  any_handle = find_window(nil, nil)
77
- any = WrapWindow.new any_handle
29
+ any = Window::Window.new any_handle
78
30
  any.handle.should == any_handle
79
31
  end
80
32
 
@@ -85,26 +37,26 @@ module WinGuiTest
85
37
  it 'closes when asked nicely' do
86
38
  @app.close
87
39
  sleep TEST_SLEEP_DELAY # needed to ensure window had enough time to close down
88
- find_window(nil, TEST_WIN_TITLE).should == nil #!!!!!
40
+ find_window(nil, TEST_WIN_TITLE).should == nil #!!!!!!
89
41
  end
90
42
 
91
43
  it 'waits f0r window to disappear (NB: this happens before handle is released!)' do
92
44
  start = Time.now
93
45
  @app.close
94
46
  @app.wait_for_close
95
- (Time.now - start).should be <= Win::Gui::Convenience::CLOSE_TIMEOUT
47
+ (Time.now - start).should be <= Win::Gui::Window::Window::CLOSE_TIMEOUT
96
48
  window_visible?(@app.handle).should be false
97
49
  end
98
50
  end
99
51
 
100
52
  context '.top_level class method' do
101
53
  it 'finds any top-level window (title = nil) and wraps it in a Window object' do
102
- use { @win = WrapWindow.top_level(title = nil, timeout_sec = 3) }
103
- @win.should be_a_kind_of WrapWindow
54
+ use { @win = Window::Window.top_level(title = nil, timeout_sec = 3) }
55
+ @win.should be_a_kind_of Window
104
56
  end
105
57
 
106
58
  it 'finds top-level window by title and wraps it in a Window object' do
107
- win = WrapWindow.top_level( TEST_WIN_TITLE, 1)
59
+ win = Window::Window.top_level( TEST_WIN_TITLE, 1)
108
60
  win.handle.should == @app.handle
109
61
  end
110
62
  end
@@ -266,9 +266,9 @@ module WinWindowTest
266
266
  it 'returns correct window class name' do
267
267
  test_app do |app|
268
268
  get_class_name(app.handle).should == TEST_WIN_CLASS
269
- get_class_name_w(app.handle).should == TEST_WIN_CLASS #!!!! nil?
270
- class_name_w(app.handle).should == TEST_WIN_CLASS #!!!!!!! nil?
271
269
  class_name(app.handle).should == TEST_WIN_CLASS
270
+ class_name_w(app.handle).should == TEST_WIN_CLASS #!!!!!!!!! nil?
271
+ get_class_name_w(app.handle).should == TEST_WIN_CLASS #!!!!!! nil?
272
272
  end
273
273
  end
274
274
  end
@@ -408,6 +408,17 @@ module WinWindowTest
408
408
  end
409
409
  end
410
410
 
411
+ describe '#enum_desktop_windows' do
412
+ before(:all){@app = launch_test_app}
413
+ after(:all){close_test_app}
414
+
415
+ spec{ use{ handles = enum_desktop_windows(0, value = 13) }}
416
+ spec{ use{ enum_desktop_windows(0) do |handle, message|
417
+ end }}
418
+
419
+ it 'iterates through all the top-level windows for a given desktop'
420
+ end
421
+
411
422
  describe '#enum_child_windows' do
412
423
  before(:all){@app = launch_test_app}
413
424
  after(:all){close_test_app}
@@ -449,6 +460,21 @@ module WinWindowTest
449
460
  end
450
461
  end
451
462
  end
452
- end
453
- end
454
463
 
464
+ describe Win::Gui::Window, ' defines convenience/service methods on top of Windows API' do
465
+ describe '#foreground' do
466
+ spec{ use{ foreground?( any_handle) }}
467
+ end
468
+ describe '#hide_window' do
469
+ spec{ use{ hide_window(any_handle) }}
470
+
471
+ end
472
+ it 'hides window: same as show_window(handle, SW_HIDE)' do
473
+ test_app do |app|
474
+ hide_window(app.handle)
475
+ visible?(app.handle).should == false
476
+ end
477
+ end
478
+ end
479
+ end
480
+ end
@@ -162,33 +162,6 @@ module WinLibraryTest
162
162
  end
163
163
  end
164
164
 
165
- context 'auto-defining Ruby-like boolean methods if API function name starts with "Is_"' do
166
- before(:each) {MyLib.function 'IsWindow', 'L', 'L'}
167
-
168
- it 'defines new instance method name dropping Is_ and adding ?' do
169
- respond_to?(:window?).should be_true
170
- respond_to?(:is_window).should be_true
171
- respond_to?(:IsWindow).should be_true
172
- end
173
-
174
- it 'defined CamelCase method returns zero/non-zero as expected' do
175
- IsWindow(any_handle).should_not == true
176
- IsWindow(any_handle).should_not == 0
177
- IsWindow(not_a_handle).should == 0
178
- end
179
-
180
- it 'defined snake_case method returns false/true instead of zero/non-zero' do
181
- window?(any_handle).should == true
182
- window?(not_a_handle).should == false
183
- is_window(any_handle).should == true
184
- is_window(not_a_handle).should == false
185
- end
186
-
187
- it 'defined methods enforce the argument count' do
188
- should_count_args :window?, :is_window, :IsWindow, [not_a_handle], [nil, not_a_handle, any_handle]
189
- end
190
- end
191
-
192
165
  context 'defining API with :boolean option converts result to boolean' do
193
166
  before(:each) { MyLib.function 'FindWindow', 'PP', 'L', :boolean => true }
194
167
 
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.0"
8
+ s.version = "0.1.2"
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-15}
12
+ s.date = %q{2010-02-16}
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 = [
@@ -29,21 +29,21 @@ Gem::Specification.new do |s|
29
29
  "lib/win/dde.rb",
30
30
  "lib/win/extensions.rb",
31
31
  "lib/win/gui.rb",
32
- "lib/win/gui/convenience.rb",
33
32
  "lib/win/gui/dialog.rb",
34
33
  "lib/win/gui/input.rb",
35
34
  "lib/win/gui/message.rb",
36
35
  "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
42
  "spec/win/extensions_spec.rb",
43
- "spec/win/gui/convenience_spec.rb",
44
43
  "spec/win/gui/dialog_spec.rb",
45
44
  "spec/win/gui/input_spec.rb",
46
45
  "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"
@@ -57,10 +57,10 @@ Gem::Specification.new do |s|
57
57
  "spec/spec_helper.rb",
58
58
  "spec/win/dde_spec.rb",
59
59
  "spec/win/extensions_spec.rb",
60
- "spec/win/gui/convenience_spec.rb",
61
60
  "spec/win/gui/dialog_spec.rb",
62
61
  "spec/win/gui/input_spec.rb",
63
62
  "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.0
4
+ version: 0.1.2
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-15 00:00:00 +03:00
12
+ date: 2010-02-16 00:00:00 +03:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -64,21 +64,21 @@ files:
64
64
  - lib/win/dde.rb
65
65
  - lib/win/extensions.rb
66
66
  - lib/win/gui.rb
67
- - lib/win/gui/convenience.rb
68
67
  - lib/win/gui/dialog.rb
69
68
  - lib/win/gui/input.rb
70
69
  - lib/win/gui/message.rb
71
70
  - 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
77
  - spec/win/extensions_spec.rb
78
- - spec/win/gui/convenience_spec.rb
79
78
  - spec/win/gui/dialog_spec.rb
80
79
  - spec/win/gui/input_spec.rb
81
80
  - 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
@@ -114,9 +114,9 @@ test_files:
114
114
  - spec/spec_helper.rb
115
115
  - spec/win/dde_spec.rb
116
116
  - spec/win/extensions_spec.rb
117
- - spec/win/gui/convenience_spec.rb
118
117
  - spec/win/gui/dialog_spec.rb
119
118
  - spec/win/gui/input_spec.rb
120
119
  - 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