rb-scpt 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/rb-scpt-1.0.1.gem +0 -0
- data/extconf.rb +12 -12
- data/rb-scpt.gemspec +10 -10
- data/sample/AB_export_vcard.rb +16 -16
- data/sample/AB_list_people_with_emails.rb +4 -4
- data/sample/Add_iCal_event.rb +12 -12
- data/sample/Create_daily_iCal_todos.rb +28 -28
- data/sample/Export_Address_Book_phone_numbers.rb +52 -52
- data/sample/Hello_world.rb +10 -10
- data/sample/List_iTunes_playlist_names.rb +3 -3
- data/sample/Make_Mail_message.rb +24 -24
- data/sample/Open_file_in_TextEdit.rb +5 -5
- data/sample/Organize_Mail_messages.rb +46 -46
- data/sample/Print_folder_tree.rb +5 -5
- data/sample/Select_all_HTML_files.rb +6 -6
- data/sample/Set_iChat_status.rb +12 -12
- data/sample/Simple_Finder_GUI_Scripting.rb +6 -6
- data/sample/Stagger_Finder_windows.rb +9 -9
- data/sample/TextEdit_demo.rb +71 -71
- data/sample/iTunes_top40_to_html.rb +28 -30
- data/src/SendThreadSafe.c +293 -293
- data/src/SendThreadSafe.h +108 -108
- data/src/lib/_aem/aemreference.rb +997 -998
- data/src/lib/_aem/codecs.rb +609 -610
- data/src/lib/_aem/connect.rb +197 -197
- data/src/lib/_aem/encodingsupport.rb +67 -67
- data/src/lib/_aem/findapp.rb +75 -75
- data/src/lib/_aem/mactypes.rb +241 -242
- data/src/lib/_aem/send.rb +268 -268
- data/src/lib/_aem/typewrappers.rb +52 -52
- data/src/lib/_appscript/defaultterminology.rb +266 -266
- data/src/lib/_appscript/referencerenderer.rb +230 -233
- data/src/lib/_appscript/reservedkeywords.rb +106 -106
- data/src/lib/_appscript/safeobject.rb +125 -125
- data/src/lib/_appscript/terminology.rb +448 -449
- data/src/lib/aem.rb +238 -238
- data/src/lib/kae.rb +1487 -1487
- data/src/lib/osax.rb +647 -647
- data/src/lib/rb-scpt.rb +1065 -1065
- data/src/rbae.c +595 -595
- data/test/test_aemreference.rb +104 -107
- data/test/test_appscriptcommands.rb +131 -134
- data/test/test_appscriptreference.rb +96 -99
- data/test/test_codecs.rb +166 -168
- data/test/test_findapp.rb +13 -16
- data/test/test_mactypes.rb +70 -72
- data/test/test_osax.rb +46 -48
- data/test/testall.sh +4 -4
- metadata +8 -7
data/test/test_aemreference.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
#!/usr/bin/ruby -w
|
2
2
|
|
3
|
-
begin; require 'rubygems'; rescue LoadError; end
|
4
|
-
|
5
3
|
require 'test/unit'
|
6
4
|
require "_aem/aemreference"
|
7
5
|
require "_aem/typewrappers"
|
@@ -10,109 +8,108 @@ require "_aem/codecs"
|
|
10
8
|
|
11
9
|
class TC_AEMReferences < Test::Unit::TestCase
|
12
10
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
[AEMReference::Its.elements('cwor').ne([]),
|
55
|
-
'AEM.its.elements("cwor").ne([])',
|
56
|
-
AEMReference::Its.elements("cwor").eq([]).not], # i.e. there isn't a KAENotEqual operator, so not-equal tests are actually packed as an equal test followed by not test
|
57
|
-
|
58
|
-
[AEMReference::Its.elements('cwor').eq(nil), 'AEM.its.elements("cwor").eq(nil)', nil],
|
59
|
-
[AEMReference::Its.elements('cwor').property('leng').gt(0),
|
60
|
-
'AEM.its.elements("cwor").property("leng").gt(0)', nil],
|
61
|
-
[AEMReference::Its.elements('cwor').le(''), 'AEM.its.elements("cwor").le("")', nil],
|
62
|
-
[AEMReference::Its.elements('cwor').begins_with('foo').not,
|
63
|
-
'AEM.its.elements("cwor").begins_with("foo").not', nil],
|
64
|
-
|
65
|
-
|
66
|
-
[AEMReference::Its.elements('cwor').contains('foo'), 'AEM.its.elements("cwor").contains("foo")', nil],
|
67
|
-
[AEMReference::Its.elements('cwor').is_in('foo'), 'AEM.its.elements("cwor").is_in("foo")', nil],
|
68
|
-
|
69
|
-
[AEMReference::App.elements('docu').by_filter(AEMReference::Its.property('size').ge(42)),
|
70
|
-
'AEM.app.elements("docu").by_filter(AEM.its.property("size").ge(42))', nil],
|
71
|
-
|
72
|
-
[AEMReference::App.elements('docu').by_index(1).property('ctxt') \
|
73
|
-
.elements('cpar').elements('cha ').by_range(
|
74
|
-
AEMReference::Con.elements('cha ').by_index(3),
|
75
|
-
AEMReference::Con.elements('cha ').by_index(55)
|
76
|
-
).next('cha ').after,
|
77
|
-
'AEM.app.elements("docu").by_index(1).property("ctxt").elements("cpar").elements("cha ")' +
|
78
|
-
'.by_range(AEM.con.elements("cha ").by_index(3), AEM.con.elements("cha ").by_index(55))' +
|
79
|
-
'.next("cha ").after', nil],
|
80
|
-
|
81
|
-
[AEMReference::Its.property('pnam').ne('foo').and(AEMReference::Its.elements('cfol').eq([])).not,
|
82
|
-
'AEM.its.property("pnam").ne("foo").and(AEM.its.elements("cfol").eq([])).not',
|
83
|
-
AEMReference::Its.property('pnam').eq('foo').not.and(AEMReference::Its.elements('cfol').eq([])).not],
|
84
|
-
|
85
|
-
[AEMReference::App.elements('docu').beginning, 'AEM.app.elements("docu").beginning', nil],
|
86
|
-
[AEMReference::App.elements('docu').end, 'AEM.app.elements("docu").end', nil],
|
87
|
-
[AEMReference::App.elements('docu').by_index(3).before, 'AEM.app.elements("docu").by_index(3).before', nil],
|
88
|
-
[AEMReference::App.elements('docu').by_name('foo').after, 'AEM.app.elements("docu").by_name("foo").after', nil],
|
89
|
-
|
90
|
-
].each do |val, res, unpacked_version|
|
91
|
-
begin
|
92
|
-
assert_equal(res, val.to_s)
|
93
|
-
d = DefaultCodecs.pack(val)
|
94
|
-
val = unpacked_version ? unpacked_version : val
|
95
|
-
val2 = DefaultCodecs.unpack(d)
|
96
|
-
assert_equal(val, val2)
|
97
|
-
val2 = DefaultCodecs.unpack(d)
|
98
|
-
assert_block { val.eql?(val2) }
|
99
|
-
val2 = DefaultCodecs.unpack(d)
|
100
|
-
assert_equal(val2, val)
|
101
|
-
val2 = DefaultCodecs.unpack(d)
|
102
|
-
assert_block { val2.eql?(val) }
|
103
|
-
rescue
|
104
|
-
puts 'EXPECTED: ' + res
|
105
|
-
raise
|
106
|
-
end
|
107
|
-
end
|
108
|
-
assert_not_equal(AEMReference::App.property('ctxt').property('ctxt'), AEMReference::Con.property('ctxt').property('ctxt'))
|
109
|
-
assert_not_equal(AEMReference::App.property('foob').property('ctxt'), AEMReference::App.property('ctxt').property('ctxt'))
|
110
|
-
assert_not_equal(AEMReference::App.elements('ctxt').property('ctxt'), AEMReference::App.property('ctxt').property('ctxt'))
|
111
|
-
assert_not_equal(AEMReference::App.elements('ctxt').property('ctxt'), 333)
|
112
|
-
assert_not_equal(333, AEMReference::App.property('ctxt').property('ctxt'))
|
113
|
-
# # by-filter references do basic type checking to ensure an its-based reference is given
|
114
|
-
assert_raises(TypeError) { AEMReference::App.elements('docu').by_filter(1) }
|
115
|
-
|
116
|
-
end
|
117
|
-
end
|
11
|
+
def test_reference_forms
|
12
|
+
[
|
13
|
+
[AEMReference::App.property('ctxt'), 'AEM.app.property("ctxt")', nil],
|
14
|
+
|
15
|
+
[AEMReference::App.elements('docu'), 'AEM.app.elements("docu")', nil],
|
16
|
+
|
17
|
+
[AEMReference::App.elements('docu').by_index(1),
|
18
|
+
'AEM.app.elements("docu").by_index(1)', nil],
|
19
|
+
[AEMReference::App.elements('docu').by_name('foo'),
|
20
|
+
'AEM.app.elements("docu").by_name("foo")', nil],
|
21
|
+
[AEMReference::App.elements('docu').by_id(300),
|
22
|
+
'AEM.app.elements("docu").by_id(300)', nil],
|
23
|
+
|
24
|
+
[AEMReference::App.elements('docu').next('docu'),
|
25
|
+
'AEM.app.elements("docu").next("docu")', nil],
|
26
|
+
[AEMReference::App.elements('docu').previous('docu'),
|
27
|
+
'AEM.app.elements("docu").previous("docu")', nil],
|
28
|
+
|
29
|
+
[AEMReference::App.elements('docu').first, 'AEM.app.elements("docu").first', nil],
|
30
|
+
[AEMReference::App.elements('docu').middle, 'AEM.app.elements("docu").middle', nil],
|
31
|
+
[AEMReference::App.elements('docu').last, 'AEM.app.elements("docu").last', nil],
|
32
|
+
[AEMReference::App.elements('docu').any, 'AEM.app.elements("docu").any', nil],
|
33
|
+
|
34
|
+
[AEMReference::Con.elements("docu").by_index(3), 'AEM.con.elements("docu").by_index(3)', nil],
|
35
|
+
|
36
|
+
[AEMReference::App.elements('docu').by_range(
|
37
|
+
AEMReference::Con.elements('docu').by_index(3),
|
38
|
+
AEMReference::Con.elements('docu').by_name('foo')),
|
39
|
+
'AEM.app.elements("docu").by_range(' +
|
40
|
+
'AEM.con.elements("docu").by_index(3), ' +
|
41
|
+
'AEM.con.elements("docu").by_name("foo"))', nil],
|
42
|
+
|
43
|
+
[AEMReference::App.elements('docu').by_range(1, 'foo'),
|
44
|
+
'AEM.app.elements("docu").by_range(1, "foo")',
|
45
|
+
AEMReference::App.elements("docu").by_range(
|
46
|
+
AEMReference::Con.elements("docu").by_index(1),
|
47
|
+
AEMReference::Con.elements("docu").by_name("foo"))],
|
48
|
+
|
49
|
+
[AEMReference::Its.property('name').eq('foo').and(AEMReference::Its.elements('cwor').eq([])),
|
50
|
+
'AEM.its.property("name").eq("foo").and(AEM.its.elements("cwor").eq([]))', nil],
|
118
51
|
|
52
|
+
[AEMReference::Its.elements('cwor').ne([]),
|
53
|
+
'AEM.its.elements("cwor").ne([])',
|
54
|
+
AEMReference::Its.elements("cwor").eq([]).not], # i.e. there isn't a KAENotEqual operator, so not-equal tests are actually packed as an equal test followed by not test
|
55
|
+
|
56
|
+
[AEMReference::Its.elements('cwor').eq(nil), 'AEM.its.elements("cwor").eq(nil)', nil],
|
57
|
+
[AEMReference::Its.elements('cwor').property('leng').gt(0),
|
58
|
+
'AEM.its.elements("cwor").property("leng").gt(0)', nil],
|
59
|
+
[AEMReference::Its.elements('cwor').le(''), 'AEM.its.elements("cwor").le("")', nil],
|
60
|
+
[AEMReference::Its.elements('cwor').begins_with('foo').not,
|
61
|
+
'AEM.its.elements("cwor").begins_with("foo").not', nil],
|
62
|
+
|
63
|
+
|
64
|
+
[AEMReference::Its.elements('cwor').contains('foo'), 'AEM.its.elements("cwor").contains("foo")', nil],
|
65
|
+
[AEMReference::Its.elements('cwor').is_in('foo'), 'AEM.its.elements("cwor").is_in("foo")', nil],
|
66
|
+
|
67
|
+
[AEMReference::App.elements('docu').by_filter(AEMReference::Its.property('size').ge(42)),
|
68
|
+
'AEM.app.elements("docu").by_filter(AEM.its.property("size").ge(42))', nil],
|
69
|
+
|
70
|
+
[AEMReference::App.elements('docu').by_index(1).property('ctxt') \
|
71
|
+
.elements('cpar').elements('cha ').by_range(
|
72
|
+
AEMReference::Con.elements('cha ').by_index(3),
|
73
|
+
AEMReference::Con.elements('cha ').by_index(55)
|
74
|
+
).next('cha ').after,
|
75
|
+
'AEM.app.elements("docu").by_index(1).property("ctxt").elements("cpar").elements("cha ")' +
|
76
|
+
'.by_range(AEM.con.elements("cha ").by_index(3), AEM.con.elements("cha ").by_index(55))' +
|
77
|
+
'.next("cha ").after', nil],
|
78
|
+
|
79
|
+
[AEMReference::Its.property('pnam').ne('foo').and(AEMReference::Its.elements('cfol').eq([])).not,
|
80
|
+
'AEM.its.property("pnam").ne("foo").and(AEM.its.elements("cfol").eq([])).not',
|
81
|
+
AEMReference::Its.property('pnam').eq('foo').not.and(AEMReference::Its.elements('cfol').eq([])).not],
|
82
|
+
|
83
|
+
[AEMReference::App.elements('docu').beginning, 'AEM.app.elements("docu").beginning', nil],
|
84
|
+
[AEMReference::App.elements('docu').end, 'AEM.app.elements("docu").end', nil],
|
85
|
+
[AEMReference::App.elements('docu').by_index(3).before, 'AEM.app.elements("docu").by_index(3).before', nil],
|
86
|
+
[AEMReference::App.elements('docu').by_name('foo').after, 'AEM.app.elements("docu").by_name("foo").after', nil],
|
87
|
+
|
88
|
+
].each do |val, res, unpacked_version|
|
89
|
+
begin
|
90
|
+
assert_equal(res, val.to_s)
|
91
|
+
d = DefaultCodecs.pack(val)
|
92
|
+
val = unpacked_version ? unpacked_version : val
|
93
|
+
val2 = DefaultCodecs.unpack(d)
|
94
|
+
assert_equal(val, val2)
|
95
|
+
val2 = DefaultCodecs.unpack(d)
|
96
|
+
assert_block { val.eql?(val2) }
|
97
|
+
val2 = DefaultCodecs.unpack(d)
|
98
|
+
assert_equal(val2, val)
|
99
|
+
val2 = DefaultCodecs.unpack(d)
|
100
|
+
assert_block { val2.eql?(val) }
|
101
|
+
rescue
|
102
|
+
puts 'EXPECTED: ' + res
|
103
|
+
raise
|
104
|
+
end
|
105
|
+
end
|
106
|
+
assert_not_equal(AEMReference::App.property('ctxt').property('ctxt'), AEMReference::Con.property('ctxt').property('ctxt'))
|
107
|
+
assert_not_equal(AEMReference::App.property('foob').property('ctxt'), AEMReference::App.property('ctxt').property('ctxt'))
|
108
|
+
assert_not_equal(AEMReference::App.elements('ctxt').property('ctxt'), AEMReference::App.property('ctxt').property('ctxt'))
|
109
|
+
assert_not_equal(AEMReference::App.elements('ctxt').property('ctxt'), 333)
|
110
|
+
assert_not_equal(333, AEMReference::App.property('ctxt').property('ctxt'))
|
111
|
+
# # by-filter references do basic type checking to ensure an its-based reference is given
|
112
|
+
assert_raises(TypeError) { AEMReference::App.elements('docu').by_filter(1) }
|
113
|
+
|
114
|
+
end
|
115
|
+
end
|
@@ -1,6 +1,4 @@
|
|
1
|
-
#!/usr/bin/ruby -w
|
2
|
-
|
3
|
-
begin; require 'rubygems'; rescue LoadError; end
|
1
|
+
#!/usr/local/bin/ruby -w
|
4
2
|
|
5
3
|
require 'test/unit'
|
6
4
|
require 'rb-scpt'
|
@@ -13,140 +11,139 @@ require 'rb-scpt'
|
|
13
11
|
|
14
12
|
class TC_AppscriptNewApp < Test::Unit::TestCase
|
15
13
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
14
|
+
def test_by_name
|
15
|
+
[
|
16
|
+
'/Applications/TextEdit.app',
|
17
|
+
'Finder.app',
|
18
|
+
'System Events'
|
19
|
+
].each do |name|
|
20
|
+
a = Appscript.app(name)
|
21
|
+
assert_not_nil(a)
|
22
|
+
assert_instance_of(Appscript::Application, a)
|
23
|
+
assert_instance_of(Appscript::Reference, a.name)
|
24
|
+
end
|
25
|
+
assert_equal('app("/Applications/TextEdit.app")', Appscript.app('TextEdit').to_s)
|
26
|
+
assert_equal('app("/Applications/TextEdit.app")', Appscript.app.by_name('TextEdit').to_s)
|
27
|
+
|
28
|
+
assert_raises(Appscript::ApplicationNotFoundError) { Appscript.app('/non-existent/app') }
|
29
|
+
assert_raises(Appscript::ApplicationNotFoundError) { Appscript.app('non-existent.app') }
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_by_id
|
33
|
+
[
|
34
|
+
'com.apple.textedit',
|
35
|
+
'com.apple.finder',
|
36
|
+
].each do |name|
|
37
|
+
a = Appscript.app.by_id(name)
|
38
|
+
assert_not_nil(a)
|
39
|
+
assert_instance_of(Appscript::Application, a)
|
40
|
+
assert_instance_of(Appscript::Reference, a.name)
|
41
|
+
end
|
42
|
+
assert_equal('app("/Applications/TextEdit.app")', Appscript.app.by_id('com.apple.textedit').to_s)
|
43
|
+
|
44
|
+
assert_raises(Appscript::ApplicationNotFoundError) { Appscript.app.by_id('non.existent.app') }
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_by_creator
|
48
|
+
a = Appscript.app.by_creator('ttxt')
|
49
|
+
assert_instance_of(Appscript::Reference, a.name)
|
50
|
+
assert_equal('app("/Applications/TextEdit.app")', a.to_s)
|
51
|
+
assert_raises(Appscript::ApplicationNotFoundError) { Appscript.app.by_id('!@$o') }
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_by_pid
|
55
|
+
pid = `top -l1 | grep Finder | awk '{ print $1 }'`.to_i # note: this line will return a bad result if more than one user is logged in
|
56
|
+
a = Appscript.app.by_pid(pid)
|
57
|
+
assert_instance_of(Appscript::Reference, a.name)
|
58
|
+
assert_equal("app.by_pid(#{pid})", a.to_s)
|
59
|
+
assert_equal('Finder', a.name.get)
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_by_aem_app
|
63
|
+
a = Appscript.app.by_aem_app(AEM::Application.by_path('/Applications/TextEdit.app'))
|
64
|
+
assert_instance_of(Appscript::Reference, a.name)
|
65
|
+
assert_equal('app.by_aem_app(AEM::Application.by_path("/Applications/TextEdit.app"))', a.to_s)
|
66
|
+
end
|
69
67
|
end
|
70
68
|
|
71
69
|
|
72
70
|
class TC_AppscriptCommands < Test::Unit::TestCase
|
73
71
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
d.text.set("\302\251 M. Lef\303\250vre")
|
104
|
-
assert_equal("\302\251 M. Lef\303\250vre", d.text.get)
|
105
|
-
|
106
|
-
d.close(:saving=>:no)
|
107
|
-
end
|
108
|
-
|
109
|
-
def test_commands_2
|
110
|
-
d = @te.make(:new=>:document, :at=>@te.documents.end)
|
111
|
-
|
112
|
-
@te.set(d.text, :to=> 'test1')
|
113
|
-
assert_equal('test1', d.text.get)
|
114
|
-
|
115
|
-
@te.set(d.text, :to=> 'test2')
|
116
|
-
@te.make(:new=>:word, :at=>Appscript.app.documents[1].paragraphs.end, :with_data=>' test3')
|
117
|
-
assert_equal('test2 test3', d.text.get)
|
118
|
-
|
119
|
-
d.close(:saving=>:no)
|
120
|
-
|
121
|
-
assert_raises(Appscript::CommandError) { @te.documents[10000].get }
|
122
|
-
|
123
|
-
assert_instance_of(Fixnum, @te.documents.count)
|
124
|
-
assert_equal(@te.documents.count, @te.count(:each=>:document))
|
125
|
-
end
|
126
|
-
|
127
|
-
def test_commands_3
|
128
|
-
assert_equal('Finder', @f.name.get)
|
129
|
-
val = @f.home.folders['Desktop'].get(:result_type=>:alias)
|
130
|
-
assert_instance_of(MacTypes::Alias, val)
|
131
|
-
assert_equal(val, @f.desktop.get(:result_type=>:alias))
|
132
|
-
assert_instance_of(Array, @f.disks.get)
|
133
|
-
|
134
|
-
r = @f.home.get
|
135
|
-
f = r.get(:result_type=>:file_ref)
|
136
|
-
assert_equal(r, @f.items[f].get)
|
137
|
-
|
138
|
-
assert_equal(@f.home.items.get, @f.home.items.get)
|
139
|
-
assert_not_equal(@f.disks['non-existent'], @f.disks[1].get)
|
140
|
-
end
|
141
|
-
|
142
|
-
def test_command_error
|
143
|
-
begin
|
144
|
-
@f.items[10000].get
|
145
|
-
rescue Appscript::CommandError => e
|
146
|
-
assert_equal(-1728, e.to_i)
|
147
|
-
assert_equal("CommandError\n\t\tOSERROR: -1728\n\t\tMESSAGE: Can't get reference.\n\t\tOFFENDING OBJECT: app(\"/System/Library/CoreServices/Finder.app\").items[10000]\n\t\tCOMMAND: app(\"/System/Library/CoreServices/Finder.app\").items[10000].get()\n", e.to_s)
|
148
|
-
assert_instance_of(AEM::EventError, e.real_error)
|
149
|
-
end
|
150
|
-
end
|
151
|
-
end
|
72
|
+
def setup
|
73
|
+
@te = Appscript.app('TextEdit')
|
74
|
+
@f = Appscript.app('Finder')
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_commands_1
|
78
|
+
assert_equal('TextEdit', @te.name.get)
|
79
|
+
d = @te.make(:new=>:document, :with_properties=>{:text=>'test test_commands'})
|
80
|
+
assert_instance_of(Appscript::Reference, d)
|
81
|
+
d.text.end.make(:new=>:word, :with_data=>' test2')
|
82
|
+
assert_equal('test test_commands test2', d.text.get)
|
83
|
+
assert_instance_of(String,
|
84
|
+
d.text.get(:ignore=>[:diacriticals, :punctuation, :whitespace, :expansion], :timeout=>10))
|
85
|
+
assert_nil(d.get(:wait_reply=>false))
|
86
|
+
|
87
|
+
|
88
|
+
# test Ruby 1.9+ String Encoding support
|
89
|
+
version, sub_version = RUBY_VERSION.split('.').collect {|n| n.to_i} [0, 2]
|
90
|
+
if version >= 1 and sub_version >= 9
|
91
|
+
|
92
|
+
print "(check Encoding support)"
|
93
|
+
s = "\302\251 M. Lef\303\250vre"
|
94
|
+
s.force_encoding('utf-8')
|
95
|
+
d.text.set(s)
|
96
|
+
assert_equal(s, d.text.get)
|
97
|
+
|
98
|
+
@te.AS_app_data.use_ascii_8bit
|
99
|
+
end
|
152
100
|
|
101
|
+
d.text.set("\302\251 M. Lef\303\250vre")
|
102
|
+
assert_equal("\302\251 M. Lef\303\250vre", d.text.get)
|
103
|
+
|
104
|
+
d.close(:saving=>:no)
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_commands_2
|
108
|
+
d = @te.make(:new=>:document, :at=>@te.documents.end)
|
109
|
+
|
110
|
+
@te.set(d.text, :to=> 'test1')
|
111
|
+
assert_equal('test1', d.text.get)
|
112
|
+
|
113
|
+
@te.set(d.text, :to=> 'test2')
|
114
|
+
@te.make(:new=>:word, :at=>Appscript.app.documents[1].paragraphs.end, :with_data=>' test3')
|
115
|
+
assert_equal('test2 test3', d.text.get)
|
116
|
+
|
117
|
+
d.close(:saving=>:no)
|
118
|
+
|
119
|
+
assert_raises(Appscript::CommandError) { @te.documents[10000].get }
|
120
|
+
|
121
|
+
assert_instance_of(Fixnum, @te.documents.count)
|
122
|
+
assert_equal(@te.documents.count, @te.count(:each=>:document))
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_commands_3
|
126
|
+
assert_equal('Finder', @f.name.get)
|
127
|
+
val = @f.home.folders['Desktop'].get(:result_type=>:alias)
|
128
|
+
assert_instance_of(MacTypes::Alias, val)
|
129
|
+
assert_equal(val, @f.desktop.get(:result_type=>:alias))
|
130
|
+
assert_instance_of(Array, @f.disks.get)
|
131
|
+
|
132
|
+
r = @f.home.get
|
133
|
+
f = r.get(:result_type=>:file_ref)
|
134
|
+
assert_equal(r, @f.items[f].get)
|
135
|
+
|
136
|
+
assert_equal(@f.home.items.get, @f.home.items.get)
|
137
|
+
assert_not_equal(@f.disks['non-existent'], @f.disks[1].get)
|
138
|
+
end
|
139
|
+
|
140
|
+
def test_command_error
|
141
|
+
begin
|
142
|
+
@f.items[10000].get
|
143
|
+
rescue Appscript::CommandError => e
|
144
|
+
assert_equal(-1728, e.to_i)
|
145
|
+
assert_equal("CommandError\n\t\tOSERROR: -1728\n\t\tMESSAGE: Can't get reference.\n\t\tOFFENDING OBJECT: app(\"/System/Library/CoreServices/Finder.app\").items[10000]\n\t\tCOMMAND: app(\"/System/Library/CoreServices/Finder.app\").items[10000].get()\n", e.to_s)
|
146
|
+
assert_instance_of(AEM::EventError, e.real_error)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|