AXElements 0.6.0beta2 → 0.7.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.yardopts +1 -2
- data/README.markdown +152 -88
- data/Rakefile +8 -103
- data/docs/Debugging.markdown +9 -2
- data/docs/KeyboardEvents.markdown +114 -49
- data/docs/Setting.markdown +1 -0
- data/docs/images/next_version.png +0 -0
- data/ext/accessibility/key_coder/extconf.rb +22 -0
- data/ext/accessibility/key_coder/key_coder.c +113 -0
- data/lib/AXElements.rb +2 -0
- data/lib/accessibility/core.rb +897 -0
- data/lib/accessibility/debug.rb +168 -0
- data/lib/accessibility/dsl.rb +697 -0
- data/lib/accessibility/enumerators.rb +104 -0
- data/lib/accessibility/errors.rb +32 -0
- data/lib/accessibility/factory.rb +153 -0
- data/lib/accessibility/graph.rb +150 -0
- data/lib/{ax_elements/inspector.rb → accessibility/pp_inspector.rb} +39 -28
- data/lib/accessibility/qualifier.rb +158 -0
- data/lib/accessibility/string.rb +494 -0
- data/lib/accessibility/translator.rb +178 -0
- data/lib/accessibility/version.rb +7 -0
- data/lib/accessibility.rb +79 -0
- data/lib/ax/application.rb +234 -0
- data/lib/{ax_elements/elements → ax}/button.rb +2 -0
- data/lib/ax/element.rb +518 -0
- data/lib/{ax_elements/elements → ax}/radio_button.rb +2 -0
- data/lib/ax/row.rb +37 -0
- data/lib/{ax_elements/elements → ax}/static_text.rb +2 -0
- data/lib/ax/systemwide.rb +86 -0
- data/lib/ax_elements/awesome_print.rb +25 -0
- data/lib/ax_elements/exception_workaround.rb +8 -0
- data/lib/ax_elements/nsarray_compat.rb +64 -0
- data/lib/ax_elements/vendor/inflection_data.rb +65 -0
- data/lib/ax_elements/vendor/inflections.rb +172 -0
- data/lib/ax_elements/vendor/inflector.rb +306 -0
- data/lib/ax_elements.rb +14 -25
- data/lib/minitest/ax_elements.rb +112 -12
- data/lib/mouse.rb +72 -46
- data/lib/rspec/expectations/ax_elements.rb +133 -6
- data/rakelib/doc.rake +13 -0
- data/rakelib/ext.rake +61 -0
- data/rakelib/gem.rake +28 -0
- data/rakelib/test.rake +53 -0
- data/test/helper.rb +11 -97
- data/test/integration/accessibility/test_core.rb +18 -0
- data/test/integration/accessibility/test_debug.rb +44 -0
- data/test/integration/accessibility/test_dsl.rb +225 -0
- data/test/integration/accessibility/test_enumerators.rb +122 -0
- data/test/integration/accessibility/test_errors.rb +38 -0
- data/test/integration/accessibility/test_notifications.rb +22 -0
- data/test/integration/accessibility/test_qualifier.rb +148 -0
- data/test/integration/ax/test_application.rb +56 -0
- data/test/integration/ax/test_element.rb +46 -0
- data/test/integration/ax/test_row.rb +23 -0
- data/test/integration/ax_elements/test_nsarray_compat.rb +43 -0
- data/test/integration/minitest/test_ax_elements.rb +98 -0
- data/test/integration/rspec/expectations/test_ax_elements.rb +58 -0
- data/test/integration/test_mouse.rb +35 -0
- data/test/sanity/accessibility/test_core.rb +553 -0
- data/test/sanity/accessibility/test_debug.rb +63 -0
- data/test/sanity/accessibility/test_dsl.rb +75 -0
- data/test/sanity/accessibility/test_errors.rb +10 -0
- data/test/sanity/accessibility/test_factory.rb +88 -0
- data/test/sanity/accessibility/test_pp_inspector.rb +110 -0
- data/test/sanity/accessibility/test_qualifier.rb +13 -0
- data/test/sanity/accessibility/test_string.rb +238 -0
- data/test/sanity/accessibility/test_translator.rb +145 -0
- data/test/sanity/ax/test_application.rb +90 -0
- data/test/sanity/ax/test_element.rb +80 -0
- data/test/sanity/ax/test_systemwide.rb +66 -0
- data/test/sanity/ax_elements/test_nsarray_compat.rb +16 -0
- data/test/sanity/ax_elements/test_nsobject_inspect.rb +11 -0
- data/test/sanity/minitest/test_ax_elements.rb +15 -0
- data/test/sanity/rspec/expectations/test_ax_elements.rb +12 -0
- data/test/sanity/test_ax_elements.rb +10 -0
- data/test/sanity/test_mouse.rb +19 -0
- metadata +111 -93
- data/LICENSE.txt +0 -25
- data/ext/key_coder/extconf.rb +0 -6
- data/ext/key_coder/key_coder.m +0 -77
- data/lib/ax_elements/accessibility/enumerators.rb +0 -104
- data/lib/ax_elements/accessibility/graph.rb +0 -118
- data/lib/ax_elements/accessibility/language.rb +0 -347
- data/lib/ax_elements/accessibility/qualifier.rb +0 -73
- data/lib/ax_elements/accessibility.rb +0 -166
- data/lib/ax_elements/core.rb +0 -541
- data/lib/ax_elements/element.rb +0 -593
- data/lib/ax_elements/elements/application.rb +0 -88
- data/lib/ax_elements/elements/row.rb +0 -30
- data/lib/ax_elements/elements/systemwide.rb +0 -46
- data/lib/ax_elements/macruby_extensions.rb +0 -255
- data/lib/ax_elements/notification.rb +0 -37
- data/lib/ax_elements/version.rb +0 -9
- data/test/elements/test_application.rb +0 -72
- data/test/elements/test_row.rb +0 -27
- data/test/elements/test_systemwide.rb +0 -38
- data/test/test_accessibility.rb +0 -127
- data/test/test_blankness.rb +0 -26
- data/test/test_core.rb +0 -448
- data/test/test_element.rb +0 -939
- data/test/test_enumerators.rb +0 -81
- data/test/test_inspector.rb +0 -130
- data/test/test_language.rb +0 -157
- data/test/test_macruby_extensions.rb +0 -303
- data/test/test_mouse.rb +0 -5
- data/test/test_search_semantics.rb +0 -143
data/test/test_enumerators.rb
DELETED
@@ -1,81 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
|
3
|
-
class TestAccessibilityBFEnumerator < TestAX
|
4
|
-
|
5
|
-
APP = AX::Application.new REF, AX.attrs_of_element(REF)
|
6
|
-
|
7
|
-
def test_each_iterates_in_correct_order
|
8
|
-
tab_group = APP.main_window.children.find { |x| x.class == AX::TabGroup }
|
9
|
-
enum = Accessibility::BFEnumerator.new(tab_group)
|
10
|
-
actual = enum.map &:class
|
11
|
-
expected = [
|
12
|
-
AX::RadioButton, AX::RadioButton, AX::TabGroup,
|
13
|
-
AX::RadioButton, AX::RadioButton, AX::TabGroup,
|
14
|
-
AX::RadioButton, AX::RadioButton, AX::TabGroup,
|
15
|
-
AX::RadioButton, AX::RadioButton, AX::Group,
|
16
|
-
AX::TextField, AX::TextField,
|
17
|
-
AX::StaticText, AX::StaticText
|
18
|
-
]
|
19
|
-
assert_equal expected, actual
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_first_element_is_first_child # not the root
|
23
|
-
enum = Accessibility::BFEnumerator.new(APP)
|
24
|
-
def enum.first
|
25
|
-
each { |x| return x }
|
26
|
-
end
|
27
|
-
assert_instance_of AX::StandardWindow, enum.first
|
28
|
-
end
|
29
|
-
|
30
|
-
# this was a "bug", so we should make sure it doesn't come back
|
31
|
-
def test_find_returns_immediately_after_finding
|
32
|
-
tree = Accessibility::BFEnumerator.new(APP.attribute(:main_window))
|
33
|
-
cache = []
|
34
|
-
tree.find do |element|
|
35
|
-
cache << element.class.to_s
|
36
|
-
element.class == AX::Slider
|
37
|
-
end
|
38
|
-
refute_includes cache, 'AX::ValueIndicator'
|
39
|
-
refute_includes cache, 'AX::IncrementArrow'
|
40
|
-
assert_includes cache, 'AX::Slider'
|
41
|
-
end
|
42
|
-
|
43
|
-
end
|
44
|
-
|
45
|
-
|
46
|
-
class TestAccessibilityDFEnumerator < TestAX
|
47
|
-
|
48
|
-
APP = AX::Application.new REF, AX.attrs_of_element(REF)
|
49
|
-
|
50
|
-
def test_each_iterates_in_correct_order
|
51
|
-
tab_group = APP.main_window.children.find { |x| x.class == AX::TabGroup }
|
52
|
-
enum = Accessibility::DFEnumerator.new tab_group
|
53
|
-
actual = enum.map &:class
|
54
|
-
expected = [
|
55
|
-
AX::RadioButton, AX::RadioButton, AX::TabGroup,
|
56
|
-
AX::RadioButton, AX::RadioButton, AX::TabGroup,
|
57
|
-
AX::RadioButton, AX::RadioButton, AX::TabGroup,
|
58
|
-
AX::RadioButton, AX::RadioButton, AX::Group,
|
59
|
-
AX::TextField, AX::StaticText,
|
60
|
-
AX::TextField, AX::StaticText
|
61
|
-
]
|
62
|
-
assert_equal expected, actual
|
63
|
-
end
|
64
|
-
|
65
|
-
# since we have a different implementation, we should also verify order here...
|
66
|
-
def test_each_with_height_has_correct_height
|
67
|
-
enum = Accessibility::DFEnumerator.new APP.attribute(:main_window)
|
68
|
-
enum.each_with_height do |element, height|
|
69
|
-
# msg = element.inspect # for debugging, otherwise makes test too intense for MacRuby
|
70
|
-
case element.class.to_s
|
71
|
-
when 'AX::CloseButton','AX::ZoomButton','AX::Slider','AX::RadioGroup','AX::ScrollArea','AX::CheckBox','AX::Incrementor','AX::SearchField'
|
72
|
-
assert_equal 1, height
|
73
|
-
when 'AX::WebArea','AX::Table','AX::ScrollBar'
|
74
|
-
assert_equal 2, height
|
75
|
-
when 'AX::SortButton'
|
76
|
-
assert_equal 4, height
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
end
|
data/test/test_inspector.rb
DELETED
@@ -1,130 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
|
3
|
-
class TestPPInspector < MiniTest::Unit::TestCase
|
4
|
-
include Accessibility::PPInspector
|
5
|
-
|
6
|
-
# expected API for PPInspector module
|
7
|
-
def attributes ; @attributes end
|
8
|
-
def attribute attr; @attribute end
|
9
|
-
def size_of attr; @size_of end
|
10
|
-
|
11
|
-
# trivial but important for backwards compat with Snow Leopard
|
12
|
-
def test_identifier_const
|
13
|
-
assert Accessibility::PPInspector.const_defined? :KAXIdentifierAttribute
|
14
|
-
assert_equal 'AXIdentifier', KAXIdentifierAttribute
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_identifier_using_value
|
18
|
-
@attributes = [KAXValueAttribute]
|
19
|
-
|
20
|
-
@attribute = 'cake'
|
21
|
-
assert_match /cake/, pp_identifier
|
22
|
-
|
23
|
-
@attribute = 3.14
|
24
|
-
assert_match /value=3.14/, pp_identifier
|
25
|
-
|
26
|
-
@attribute = ''
|
27
|
-
assert_match ::EMPTY_STRING, pp_identifier
|
28
|
-
|
29
|
-
@attribute = nil
|
30
|
-
assert_match ::EMPTY_STRING, pp_identifier
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_identifier_using_title
|
34
|
-
@attributes = [KAXTitleAttribute]
|
35
|
-
@attribute = 'My Title'
|
36
|
-
assert_match /"My Title"/, pp_identifier
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_identifier_using_title_ui_element
|
40
|
-
@attributes = [KAXTitleUIElementAttribute]
|
41
|
-
@attribute = 'hey'
|
42
|
-
assert_match /"hey"/, pp_identifier
|
43
|
-
end
|
44
|
-
|
45
|
-
# hmmm...
|
46
|
-
def test_identifier_using_description
|
47
|
-
@attributes = [KAXDescriptionAttribute]
|
48
|
-
|
49
|
-
@attribute = 'roflcopter'
|
50
|
-
assert_match /roflcopter/, pp_identifier
|
51
|
-
|
52
|
-
@attribute = NSString.string
|
53
|
-
assert_equal NSString.string, pp_identifier
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_identifier_using_identifier
|
57
|
-
@attributes = [KAXIdentifierAttribute]
|
58
|
-
|
59
|
-
@attribute = '_NS:151'
|
60
|
-
assert_match /_NS:151/, pp_identifier
|
61
|
-
|
62
|
-
@attribute = 'contact table'
|
63
|
-
assert_match /contact table/, pp_identifier
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_identifier_empty_string_as_final_fallback
|
67
|
-
@attributes = NSArray.array
|
68
|
-
assert_equal NSString.string, pp_identifier
|
69
|
-
end
|
70
|
-
|
71
|
-
def test_position
|
72
|
-
@attribute = CGPointZero
|
73
|
-
assert_match /\(0\.0, 0\.0\)/, pp_position
|
74
|
-
|
75
|
-
@attribute = CGPoint.new(3.14, -5)
|
76
|
-
assert_match /\(3\.14, -5\.0\)/, pp_position
|
77
|
-
end
|
78
|
-
|
79
|
-
# this sometimes happens, even though it shouldn't
|
80
|
-
def test_position_is_nil
|
81
|
-
@attribute = nil
|
82
|
-
assert_equal ::EMPTY_STRING, pp_position
|
83
|
-
end
|
84
|
-
|
85
|
-
def test_children_pluralizes_properly
|
86
|
-
@size_of = 2
|
87
|
-
assert_match /2 children/, pp_children
|
88
|
-
|
89
|
-
@size_of = 9001
|
90
|
-
assert_match /9001 children/, pp_children
|
91
|
-
|
92
|
-
@size_of = 3.14
|
93
|
-
assert_match /3.14 children/, pp_children
|
94
|
-
end
|
95
|
-
|
96
|
-
def test_children_count
|
97
|
-
@size_of = 1
|
98
|
-
assert_match /1 child/, pp_children
|
99
|
-
end
|
100
|
-
|
101
|
-
def test_children_void_if_none
|
102
|
-
@size_of = 0
|
103
|
-
assert_equal NSString.string, pp_children
|
104
|
-
end
|
105
|
-
|
106
|
-
def test_checkbox_includes_attribute_name_and_box
|
107
|
-
@attribute = true
|
108
|
-
assert_match /thing\[.\]/, pp_checkbox(:thing)
|
109
|
-
assert_match /cake\[.\]/, pp_checkbox(:cake)
|
110
|
-
assert_match /pie\[.\]/, pp_checkbox(:pie)
|
111
|
-
end
|
112
|
-
|
113
|
-
def test_checkbox_uses_checks_properly
|
114
|
-
check = /✔/
|
115
|
-
cross = /✘/
|
116
|
-
|
117
|
-
@attribute = true
|
118
|
-
assert_match check, pp_checkbox(:a)
|
119
|
-
|
120
|
-
@attribute = :cake
|
121
|
-
assert_match check, pp_checkbox(:a)
|
122
|
-
|
123
|
-
@attribute = false
|
124
|
-
assert_match cross, pp_checkbox(:a)
|
125
|
-
|
126
|
-
@attribute = nil
|
127
|
-
assert_match cross, pp_checkbox(:a)
|
128
|
-
end
|
129
|
-
|
130
|
-
end
|
data/test/test_language.rb
DELETED
@@ -1,157 +0,0 @@
|
|
1
|
-
class TestAccessibilityLanguageActions < TestAX
|
2
|
-
|
3
|
-
# LSP FTW
|
4
|
-
class Language
|
5
|
-
include Accessibility::Language
|
6
|
-
end
|
7
|
-
|
8
|
-
# mocking like a pro
|
9
|
-
class LanguageTest < AX::Element
|
10
|
-
attr_reader :called_action
|
11
|
-
def perform_action name
|
12
|
-
@called_action = name
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def setup
|
17
|
-
@language = Language.new
|
18
|
-
@element = LanguageTest.new REF, AX.attrs_of_element(REF)
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_static_actions_forward
|
22
|
-
@language.cancel @element
|
23
|
-
assert_equal :cancel, @element.called_action
|
24
|
-
|
25
|
-
@language.confirm @element
|
26
|
-
assert_equal :confirm, @element.called_action
|
27
|
-
|
28
|
-
@language.decrement @element
|
29
|
-
assert_equal :decrement, @element.called_action
|
30
|
-
|
31
|
-
@language.delete @element
|
32
|
-
assert_equal :delete, @element.called_action
|
33
|
-
|
34
|
-
@language.increment @element
|
35
|
-
assert_equal :increment, @element.called_action
|
36
|
-
|
37
|
-
@language.pick @element
|
38
|
-
assert_equal :pick, @element.called_action
|
39
|
-
|
40
|
-
@language.press @element
|
41
|
-
assert_equal :press, @element.called_action
|
42
|
-
|
43
|
-
@language.cancel @element
|
44
|
-
assert_equal :cancel, @element.called_action
|
45
|
-
|
46
|
-
@language.raise @element
|
47
|
-
assert_equal :raise, @element.called_action
|
48
|
-
|
49
|
-
@language.show_menu @element
|
50
|
-
assert_equal :show_menu, @element.called_action
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_method_missing_forwards
|
54
|
-
@language.zomg_method @element
|
55
|
-
assert_equal :zomg_method, @element.called_action
|
56
|
-
|
57
|
-
assert_raises NoMethodError do
|
58
|
-
@language.zomg_method 'bacon'
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def test_raise_can_still_raise_exceptions
|
63
|
-
assert_raises ArgumentError do
|
64
|
-
@language.raise ArgumentError
|
65
|
-
end
|
66
|
-
assert_raises NoMethodError do
|
67
|
-
@language.raise NoMethodError
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
end
|
72
|
-
|
73
|
-
class TestAccessibilityLanguage < TestAX
|
74
|
-
|
75
|
-
def test_set_focus
|
76
|
-
window = attribute_for(REF, KAXMainWindowAttribute)
|
77
|
-
group = children_for(window).find do |element|
|
78
|
-
attribute_for(element,KAXRoleAttribute) == KAXRadioGroupRole
|
79
|
-
end
|
80
|
-
buttons = children_for group
|
81
|
-
# @todo swich focus between radio buttons in the radio group
|
82
|
-
end
|
83
|
-
|
84
|
-
# def test_set_arbitrary_attribute
|
85
|
-
# end
|
86
|
-
|
87
|
-
# def test_set_value
|
88
|
-
# end
|
89
|
-
|
90
|
-
# def test_type_sends_to_system_by_default
|
91
|
-
# end
|
92
|
-
|
93
|
-
# def test_type_can_send_to_arbitrary_applications
|
94
|
-
# end
|
95
|
-
|
96
|
-
# def test_register_for_notification_forwards_to_element
|
97
|
-
# end
|
98
|
-
|
99
|
-
# def test_wait_for_notification_forwards
|
100
|
-
# end
|
101
|
-
|
102
|
-
# def test_wait_for_notification_has_default
|
103
|
-
# end
|
104
|
-
|
105
|
-
# def test_move_mouse_to_accepts_many_inputs_but_forwards_cgpoint
|
106
|
-
# end
|
107
|
-
|
108
|
-
# def test_drag_mouse_accepts_many_inputs_but_forwards_cgpoint
|
109
|
-
# end
|
110
|
-
|
111
|
-
# def test_scroll_moves_mouse_to_object_first_if_given
|
112
|
-
# end
|
113
|
-
|
114
|
-
# def test_scroll_forwards_properly
|
115
|
-
# end
|
116
|
-
|
117
|
-
# def test_click_moves_mouse_to_object_first
|
118
|
-
# end
|
119
|
-
|
120
|
-
# def test_click_forwards
|
121
|
-
# end
|
122
|
-
|
123
|
-
# def test_right_click_moves_mouse_to_object_first
|
124
|
-
# end
|
125
|
-
|
126
|
-
# def test_right_click_forwards
|
127
|
-
# end
|
128
|
-
|
129
|
-
# def test_right_click_alias
|
130
|
-
# end
|
131
|
-
|
132
|
-
# def test_double_click_moves_mouse_to_object_first
|
133
|
-
# end
|
134
|
-
|
135
|
-
# def test_double_click_forwards
|
136
|
-
# end
|
137
|
-
|
138
|
-
# def test_show_about_window_for
|
139
|
-
# end
|
140
|
-
|
141
|
-
# def test_preferences_window_for
|
142
|
-
# end
|
143
|
-
|
144
|
-
def test_language_is_available_everywhere
|
145
|
-
assert_includes Object.new.class.ancestors, Accessibility::Language
|
146
|
-
assert_includes TopLevel.ancestors, Accessibility::Language
|
147
|
-
end
|
148
|
-
|
149
|
-
def test_callbacks_are_unregistered_when_a_timeout_occurs
|
150
|
-
skip
|
151
|
-
AX.register_for_notif
|
152
|
-
refute_empty AX.notifs.keys
|
153
|
-
AX.wait_for_notification short_timeout
|
154
|
-
assert_empty AX.notifs.keys
|
155
|
-
end
|
156
|
-
|
157
|
-
end
|
@@ -1,303 +0,0 @@
|
|
1
|
-
class TestNSArrayAccessors < MiniTest::Unit::TestCase
|
2
|
-
|
3
|
-
def test_second_returns_second_from_array
|
4
|
-
[[1,2],[:one,:two]].each { |array|
|
5
|
-
assert_equal array.last, NSArray.arrayWithArray(array).second
|
6
|
-
assert_equal array.last, array.second
|
7
|
-
}
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_second_returns_nil_from_array_of_one
|
11
|
-
[[1], [:one]].each { |array|
|
12
|
-
assert_nil NSArray.arrayWithArray(array).second
|
13
|
-
assert_nil array.second
|
14
|
-
}
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_second_returns_second_from_array
|
18
|
-
[[1,2,3],[:one,:two,:three]].each { |array|
|
19
|
-
assert_equal array.last, NSArray.arrayWithArray(array).third
|
20
|
-
assert_equal array.last, array.third
|
21
|
-
}
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_second_returns_nil_from_array_of_two
|
25
|
-
[[1,2], [:one,:two]].each { |array|
|
26
|
-
assert_nil NSArray.arrayWithArray(array).third
|
27
|
-
assert_nil array.third
|
28
|
-
}
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
32
|
-
|
33
|
-
|
34
|
-
class TestNSArrayToPoint < MiniTest::Unit::TestCase
|
35
|
-
|
36
|
-
def test_makes_a_point
|
37
|
-
assert_instance_of CGPoint, [1, 1].to_point
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_uses_first_two_elements
|
41
|
-
assert_equal CGPoint.new(1,2), NSArray.arrayWithArray([1, 2, 3]).to_point
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
|
-
|
47
|
-
class TestNSArrayToSize < MiniTest::Unit::TestCase
|
48
|
-
|
49
|
-
def test_makes_a_point
|
50
|
-
assert_instance_of CGSize, [1, 1].to_size
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_uses_first_two_elements
|
54
|
-
assert_equal CGSize.new(1,2), NSArray.arrayWithArray([1, 2, 3]).to_size
|
55
|
-
end
|
56
|
-
|
57
|
-
end
|
58
|
-
|
59
|
-
|
60
|
-
class TestNSArrayToRect < MiniTest::Unit::TestCase
|
61
|
-
|
62
|
-
def test_makes_a_rect
|
63
|
-
assert_instance_of CGRect, [1, 1, 1, 1].to_rect
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_uses_first_two_elements
|
67
|
-
expected = CGRect.new(CGPoint.new(4,3),CGSize.new(2,5))
|
68
|
-
actual = NSArray.arrayWithArray([4, 3, 2, 5, 7]).to_rect
|
69
|
-
assert_equal expected, actual
|
70
|
-
end
|
71
|
-
|
72
|
-
end
|
73
|
-
|
74
|
-
|
75
|
-
class TestNSStringCamelize < MiniTest::Unit::TestCase
|
76
|
-
|
77
|
-
def test_takes_snake_case_string_and_makes_it_camel_case
|
78
|
-
assert_equal 'AMethodName', 'a_method_name'.camelize
|
79
|
-
assert_equal 'MethodName', 'method_name'.camelize
|
80
|
-
assert_equal 'Name', 'name'.camelize
|
81
|
-
end
|
82
|
-
|
83
|
-
def test_takes_camel_case_and_does_nothing
|
84
|
-
assert_equal 'AMethodName', 'AMethodName'.camelize
|
85
|
-
assert_equal 'MethodName', 'MethodName'.camelize
|
86
|
-
assert_equal 'Name', 'Name'.camelize
|
87
|
-
end
|
88
|
-
|
89
|
-
end
|
90
|
-
|
91
|
-
|
92
|
-
class TestNSStringPredicate < MiniTest::Unit::TestCase
|
93
|
-
|
94
|
-
def test_true_if_string_ends_with_a_question_mark
|
95
|
-
assert 'test?'.predicate?
|
96
|
-
end
|
97
|
-
|
98
|
-
def test_false_if_the_string_does_not_end_with_a_question_mark
|
99
|
-
refute 'tes?t'.predicate?
|
100
|
-
refute 'te?st'.predicate?
|
101
|
-
refute 't?est'.predicate?
|
102
|
-
refute '?test'.predicate?
|
103
|
-
end
|
104
|
-
|
105
|
-
def test_false_if_the_string_has_no_question_mark
|
106
|
-
refute 'test'.predicate?
|
107
|
-
end
|
108
|
-
|
109
|
-
end
|
110
|
-
|
111
|
-
|
112
|
-
class TestNSStringSingularize < MiniTest::Unit::TestCase
|
113
|
-
|
114
|
-
# a better test might be to take the method and bind it into a
|
115
|
-
# different context where ActiveSupport::Inflector resolved to
|
116
|
-
# a mock class with a mocked version #singularize
|
117
|
-
def test_calls_active_support
|
118
|
-
assert_equal 'octopus', NSString.alloc.initWithString('octopi').singularize
|
119
|
-
assert_equal 'ox', NSString.alloc.initWithString('oxen').singularize
|
120
|
-
assert_equal 'box', NSString.alloc.initWithString('boxes').singularize
|
121
|
-
assert_equal 'box', NSString.alloc.initWithString('box').singularize
|
122
|
-
end
|
123
|
-
|
124
|
-
end
|
125
|
-
|
126
|
-
|
127
|
-
class TestNSArrayMethodMissing < MiniTest::Unit::TestCase
|
128
|
-
|
129
|
-
ELEMENTS = AX::DOCK.list.application_dock_items
|
130
|
-
|
131
|
-
def test_delegates_up_if_array_is_not_composed_of_elements
|
132
|
-
assert_raises NoMethodError do [1].title_ui_element end
|
133
|
-
end
|
134
|
-
|
135
|
-
def test_simple_attribute
|
136
|
-
refute_empty ELEMENTS.url.compact
|
137
|
-
end
|
138
|
-
|
139
|
-
def test_artificially_plural_attribute
|
140
|
-
refute_empty ELEMENTS.urls.compact
|
141
|
-
end
|
142
|
-
|
143
|
-
def test_naturally_plural_attribute
|
144
|
-
refute_empty ELEMENTS.children.compact
|
145
|
-
end
|
146
|
-
|
147
|
-
def test_predicate_method
|
148
|
-
refute_empty ELEMENTS.application_running?.compact
|
149
|
-
end
|
150
|
-
|
151
|
-
end
|
152
|
-
|
153
|
-
|
154
|
-
class TestCGPointExtensions < MiniTest::Unit::TestCase
|
155
|
-
SCREENS = NSScreen.screens
|
156
|
-
MAIN_SCREEN = NSScreen.mainScreen
|
157
|
-
end
|
158
|
-
|
159
|
-
|
160
|
-
class TestCGPointCenterOfRect < TestCGPointExtensions
|
161
|
-
|
162
|
-
def test_unaltered_with_cgrectzero
|
163
|
-
assert_equal CGPointZero, CGPoint.center_of_rect(CGRectZero)
|
164
|
-
end
|
165
|
-
|
166
|
-
def test_middle_of_screen
|
167
|
-
frame = MAIN_SCREEN.frame
|
168
|
-
point = frame.origin.dup
|
169
|
-
point.x = frame.size.width / 2
|
170
|
-
point.y = frame.size.height / 2
|
171
|
-
assert_equal point, CGPoint.center_of_rect(frame)
|
172
|
-
end
|
173
|
-
|
174
|
-
def center_of_rect origin_x, origin_y, width, height
|
175
|
-
rect = CGRect.new(CGPoint.new(origin_x,origin_y), CGSize.new(width,height))
|
176
|
-
CGPoint.center_of_rect(rect)
|
177
|
-
end
|
178
|
-
|
179
|
-
def test_simple_square_with_origin_at_zero
|
180
|
-
point = center_of_rect(0.0, 0.0, 2.0, 2.0)
|
181
|
-
assert_equal 1, point.x
|
182
|
-
assert_equal 1, point.y
|
183
|
-
end
|
184
|
-
|
185
|
-
def test_simple_square_in_positive_positive_quadrant
|
186
|
-
point = center_of_rect(1.0, 1.0, 6.0, 6.0)
|
187
|
-
assert_equal 4, point.x
|
188
|
-
assert_equal 4, point.y
|
189
|
-
end
|
190
|
-
|
191
|
-
def test_rect_in_positive_positive_quadrant
|
192
|
-
point = center_of_rect(1.0, 2.0, 6.0, 10.0)
|
193
|
-
assert_equal 4, point.x
|
194
|
-
assert_equal 7, point.y
|
195
|
-
end
|
196
|
-
|
197
|
-
def test_rect_in_negative_positive_quadrant
|
198
|
-
point = center_of_rect(-123.0, 25.0, 6.0, 10.0)
|
199
|
-
assert_equal -120, point.x
|
200
|
-
assert_equal 30, point.y
|
201
|
-
end
|
202
|
-
|
203
|
-
def test_rect_starts_in_negative_positive_quadrant_but_is_in_positive_positive
|
204
|
-
point = center_of_rect(-10.0, 70.0, 20.0, 42.0)
|
205
|
-
assert_equal 0, point.x
|
206
|
-
assert_equal 91, point.y
|
207
|
-
end
|
208
|
-
|
209
|
-
end
|
210
|
-
|
211
|
-
|
212
|
-
class TestCGPointCenter < TestCGPointExtensions
|
213
|
-
|
214
|
-
def test_unaltered_with_cgrectzero
|
215
|
-
assert_equal CGPointZero, CGPointZero.center(CGSizeZero)
|
216
|
-
end
|
217
|
-
|
218
|
-
def center origin_x, origin_y, width, height
|
219
|
-
CGPoint.new(origin_x,origin_y).center CGSize.new(width,height)
|
220
|
-
end
|
221
|
-
|
222
|
-
def test_simple_square_with_origin_at_zero
|
223
|
-
point = center(0.0, 0.0, 2.0, 2.0)
|
224
|
-
assert_equal 1, point.x
|
225
|
-
assert_equal 1, point.y
|
226
|
-
end
|
227
|
-
|
228
|
-
def test_simple_square_in_positive_positive_quadrant
|
229
|
-
point = center(1.0, 1.0, 6.0, 6.0)
|
230
|
-
assert_equal 4, point.x
|
231
|
-
assert_equal 4, point.y
|
232
|
-
end
|
233
|
-
|
234
|
-
def test_rect_in_positive_positive_quadrant
|
235
|
-
point = center(1.0, 2.0, 6.0, 10.0)
|
236
|
-
assert_equal 4, point.x
|
237
|
-
assert_equal 7, point.y
|
238
|
-
end
|
239
|
-
|
240
|
-
def test_rect_in_negative_positive_quadrant
|
241
|
-
point = center(-123.0, 25.0, 6.0, 10.0)
|
242
|
-
assert_equal -120, point.x
|
243
|
-
assert_equal 30, point.y
|
244
|
-
end
|
245
|
-
|
246
|
-
def test_rect_starts_in_negative_positive_quadrant_but_is_in_positive_positive
|
247
|
-
point = center(-10.0, 70.0, 20.0, 42.0)
|
248
|
-
assert_equal 0, point.x
|
249
|
-
assert_equal 91, point.y
|
250
|
-
end
|
251
|
-
|
252
|
-
end
|
253
|
-
|
254
|
-
|
255
|
-
class TestCGPointToPoint < MiniTest::Unit::TestCase
|
256
|
-
|
257
|
-
def test_returns_self
|
258
|
-
assert_equal CGPointZero, CGPointZero.to_point
|
259
|
-
point = CGPoint.new(1, 1)
|
260
|
-
assert_equal point, point.to_point
|
261
|
-
end
|
262
|
-
|
263
|
-
end
|
264
|
-
|
265
|
-
|
266
|
-
class TestBoxedToAXValue < MiniTest::Unit::TestCase
|
267
|
-
|
268
|
-
def test_point_makes_a_value
|
269
|
-
value = CGPointZero.to_axvalue
|
270
|
-
ptr = Pointer.new CGPoint.type
|
271
|
-
AXValueGetValue(value, 1, ptr)
|
272
|
-
assert_equal CGPointZero, ptr[0]
|
273
|
-
end
|
274
|
-
|
275
|
-
def test_size_makes_a_value
|
276
|
-
value = CGSizeZero.to_axvalue
|
277
|
-
ptr = Pointer.new CGSize.type
|
278
|
-
AXValueGetValue(value, 2, ptr)
|
279
|
-
assert_equal CGSizeZero, ptr[0]
|
280
|
-
end
|
281
|
-
|
282
|
-
def test_rect_makes_a_value
|
283
|
-
value = CGRectZero.to_axvalue
|
284
|
-
ptr = Pointer.new CGRect.type
|
285
|
-
AXValueGetValue(value, 3, ptr)
|
286
|
-
assert_equal CGRectZero, ptr[0]
|
287
|
-
end
|
288
|
-
|
289
|
-
def test_range_makes_a_value
|
290
|
-
range = CFRange.new(5, 4)
|
291
|
-
value = range.to_axvalue
|
292
|
-
ptr = Pointer.new CFRange.type
|
293
|
-
AXValueGetValue(value, 4, ptr)
|
294
|
-
assert_equal range, ptr[0]
|
295
|
-
end
|
296
|
-
|
297
|
-
def test_values
|
298
|
-
[[CGPoint, 1], [CGSize, 2], [CGRect, 3], [CFRange, 4]].each do |klass, value|
|
299
|
-
assert_equal value, klass.instance_variable_get(:@ax_value)
|
300
|
-
end
|
301
|
-
end
|
302
|
-
|
303
|
-
end
|