blob: 96b3e2f88fe9a478f5e95a2b6c9165f17924f5f8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
#
# This script check that Win32OLE can execute InvokeVerb method of FolderItem2.
#
require 'test/unit'
require 'win32ole'
class TestInvokeVerb < Test::Unit::TestCase
def setup
#
# make dummy.txt file for InvokeVerb test.
#
ofs = open('dummy.txt', 'w')
ofs.write('this is test')
ofs.close
@fso = WIN32OLE.new('Scripting.FileSystemObject')
@dummy_path = @fso.GetAbsolutePathName('dummy.txt')
@shell=WIN32OLE.new('Shell.Application')
@fi2 = @shell.NameSpace(@dummy_path).ParentFolder.ParseName(@shell.NameSpace(@dummy_path).Title)
@shortcut = nil
#
# Search the 'Create Shortcut (&S)' string.
# Yes, I know the string in the Windows 2000 Japanese Edition.
# But I do not know about the string in any other Windows.
#
verbs = @fi2.verbs
verbs.extend(Enumerable)
@shortcut = verbs.collect{|verb|
verb.name
}.find {|name|
/.*\(\&S\)$/ =~ name
}
end
def test_invokeverb
# We expect there is no shortcut in this folder.
link = Dir["*.lnk"].find {|f| true}
assert(!link)
# Now create shortcut to "dummy.txt"
assert(@shortcut)
arg = WIN32OLE_VARIANT.new(@shortcut)
@fi2.InvokeVerb(arg)
# We expect there is shortcut in this folder
link = Dir["*.lnk"].find {|f| true}
assert(link)
# The shortcut is to the "dummy.txt"
@lpath = @fso.GetAbsolutePathName(link)
linkinfo = @shell.NameSpace(@lpath).Self.GetLink
assert_equal(@dummy_path, linkinfo.path)
end
def teardown
if @lpath
@fso.deleteFile(@lpath)
end
if @dummy_path
@fso.deleteFile(@dummy_path)
end
end
end
|