uia 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,3 +1,7 @@
1
+ === Version 0.3.3 / 2014-05-13
2
+ * Enhancements
3
+ * MenuItems#has_menu_item?
4
+
1
5
  === Version 0.3.2 / 2014-05-13
2
6
  * Enhancements
3
7
  * added #with method to extend an Element based on ControlPatterns
@@ -1,27 +1,60 @@
1
1
  #include "Stdafx.h"
2
2
 
3
3
  extern "C" {
4
+ public ref class MenuItemNotFound : Exception {
5
+ public:
6
+ MenuItemNotFound(String^ message) : Exception(message) {}
7
+ };
8
+
9
+ void SelectMenuItemPath(ElementInformationPtr, char*, const int, list<const char*>&);
10
+ bool HasMenuItemPath(ElementInformationPtr, char*, const int, list<const char*>&);
11
+ InvokePattern^ MenuItemPath(ElementInformationPtr, list<const char*>&);
12
+
13
+ __declspec(dllexport) bool MenuItem_HasPath(ElementInformationPtr element, char* errorInfo, const int errorInfoLength, const int n, const char* arg0, ...) {
14
+ GRAB_VARARGS(menuItems, const char*, n);
15
+ return HasMenuItemPath(element, errorInfo, errorInfoLength, menuItems);
16
+ }
17
+
18
+ __declspec(dllexport) void MenuItem_SelectPath(ElementInformationPtr element, char* errorInfo, const int errorInfoLength, const int n, const char* arg0, ...) {
19
+ GRAB_VARARGS(menuItems, const char*, n);
20
+ SelectMenuItemPath(element, errorInfo, errorInfoLength, menuItems);
21
+ }
22
+
4
23
  void SelectMenuItemPath(ElementInformationPtr element, char* errorInfo, const int errorInfoLength, list<const char*>& items) {
5
24
  try {
6
- auto current = ElementFrom(element);
25
+ MenuItemPath(element, items)->Invoke();
26
+ } catch(Exception^ e) {
27
+ StringHelper::CopyToUnmanagedString(e->Message, errorInfo, errorInfoLength);
28
+ }
29
+ }
7
30
 
8
- for(auto item = items.begin(); item != items.end(); ++item) {
9
- auto name = gcnew String(*item);
31
+ bool HasMenuItemPath(ElementInformationPtr element, char* errorInfo, const int errorInfoLength, list<const char*>& items) {
32
+ try {
33
+ return nullptr != MenuItemPath(element, items);
34
+ } catch(MenuItemNotFound^) {
35
+ return false;
36
+ } catch(Exception^ e) {
37
+ StringHelper::CopyToUnmanagedString(e->Message, errorInfo, errorInfoLength);
38
+ return false;
39
+ }
40
+ }
10
41
 
11
- current = current->MenuItem(name);
12
- if( nullptr == current) {
13
- throw gcnew Exception(String::Format("the menu item \"{0}\" was not found", name));
14
- }
42
+ InvokePattern^ MenuItemPath(ElementInformationPtr element, list<const char*>& items) {
43
+ auto current = ElementFrom(element);
44
+
45
+ for(auto item = items.begin(); item != items.end(); ++item) {
46
+ auto name = gcnew String(*item);
47
+
48
+ current = current->MenuItem(name);
49
+ if( nullptr == current) {
50
+ throw gcnew MenuItemNotFound(String::Format("the menu item \"{0}\" was not found", name));
51
+ }
15
52
 
53
+ if( *item != items.back() ) {
16
54
  current->As<InvokePattern^>(InvokePattern::Pattern)->Invoke();
17
55
  }
18
- } catch(Exception^ e) {
19
- StringHelper::CopyToUnmanagedString(e->Message, errorInfo, errorInfoLength);
20
56
  }
21
- }
22
57
 
23
- __declspec(dllexport) void MenuItem_SelectPath(ElementInformationPtr element, char* errorInfo, const int errorInfoLength, const int n, const char* arg0, ...) {
24
- GRAB_VARARGS(menuItems, const char*, n);
25
- SelectMenuItemPath(element, errorInfo, errorInfoLength, menuItems);
58
+ return current->As<InvokePattern^>(InvokePattern::Pattern);
26
59
  }
27
60
  }
@@ -5,6 +5,10 @@ module Uia
5
5
  Library.select_menu_path @element, *path
6
6
  end
7
7
  alias_method :select_menu_item, :select_menu_path
8
+
9
+ def has_menu_item?(*path)
10
+ Library.has_menu_item @element, *path
11
+ end
8
12
  end
9
13
  end
10
14
  end
data/lib/uia/library.rb CHANGED
@@ -153,10 +153,16 @@ module Uia
153
153
 
154
154
  # MenuItem methods
155
155
  attach_function :MenuItem_SelectPath, [:pointer, :pointer, :int, :int, :varargs], :void
156
+ attach_function :MenuItem_HasPath, [:pointer, :pointer, :int, :int, :varargs], :bool
157
+
156
158
  def self.select_menu_path(element, *path)
157
159
  try_catch {|s, n| MenuItem_SelectPath element, s, n, path.count, *path.to_var_args(:string) }
158
160
  end
159
161
 
162
+ def self.has_menu_item(element, *path)
163
+ try_catch {|s, n| MenuItem_HasPath element, s, n, path.count, *path.to_var_args(:string) }
164
+ end
165
+
160
166
  def self.find_by_runtime_id(id)
161
167
  p = FFI::MemoryPointer.new :int, id.count
162
168
  p.write_array_of_int(id)
data/lib/uia/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Uia
2
- VERSION = '0.3.2'
2
+ VERSION = '0.3.3'
3
3
  end
@@ -1,13 +1,21 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Uia::ControlTypes::MenuItems do
4
- Given(:main) { Uia.find_element(title: 'MainFormWindow').with(:menu_items) }
4
+ Given(:main) { Uia.find_element(title: 'MainFormWindow').with(:menu_items) }
5
5
 
6
6
  after(:each) do
7
7
  about = Uia.find_element(title: 'About')
8
8
  about.send_keys [:alt, :f4] if about
9
9
  end
10
10
 
11
+ context 'existence' do
12
+ Then { expect(main).not_to have_menu_item 'non-existent' }
13
+ Then { expect(main).not_to have_menu_item 'File', 'Roundabout Way', 'To', 'Not There' }
14
+
15
+ Then { expect(main).to have_menu_item 'File' }
16
+ Then { expect(main).to have_menu_item 'File', 'Roundabout Way', 'To' }
17
+ end
18
+
11
19
  context 'selecting individually' do
12
20
  When { main.select_menu_item 'About' }
13
21
  Then { Uia.find_element(title: 'About') != nil }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uia
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-05-13 00:00:00.000000000 Z
12
+ date: 2014-05-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ffi
@@ -261,7 +261,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
261
261
  version: '0'
262
262
  segments:
263
263
  - 0
264
- hash: 59019763
264
+ hash: -227578093
265
265
  required_rubygems_version: !ruby/object:Gem::Requirement
266
266
  none: false
267
267
  requirements:
@@ -270,7 +270,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
270
270
  version: '0'
271
271
  segments:
272
272
  - 0
273
- hash: 59019763
273
+ hash: -227578093
274
274
  requirements: []
275
275
  rubyforge_project:
276
276
  rubygems_version: 1.8.28