2006-05-01 13:05:08 +04:00
|
|
|
#
|
|
|
|
# This script check that Win32OLE can execute InvokeVerb method of FolderItem2.
|
|
|
|
#
|
|
|
|
|
|
|
|
begin
|
|
|
|
require 'win32ole'
|
2006-05-07 03:40:08 +04:00
|
|
|
rescue LoadError
|
2006-05-01 13:05:08 +04:00
|
|
|
end
|
|
|
|
require 'test/unit'
|
|
|
|
|
|
|
|
if defined?(WIN32OLE)
|
|
|
|
class TestInvokeVerb < Test::Unit::TestCase
|
|
|
|
def setup
|
2010-10-14 18:23:03 +04:00
|
|
|
# make dummy file for InvokeVerb test.
|
2006-05-01 13:05:08 +04:00
|
|
|
@fso = WIN32OLE.new('Scripting.FileSystemObject')
|
2010-10-14 18:23:03 +04:00
|
|
|
dummy_file = @fso.GetTempName
|
2006-05-01 13:05:08 +04:00
|
|
|
@cfolder = @fso.getFolder(".")
|
2010-10-14 18:23:03 +04:00
|
|
|
f = @cfolder.CreateTextFile(dummy_file)
|
2006-05-01 13:05:08 +04:00
|
|
|
f.close
|
2010-10-14 18:23:03 +04:00
|
|
|
@dummy_path = @cfolder.path + "\\" + dummy_file
|
2006-05-01 13:05:08 +04:00
|
|
|
|
2010-10-14 18:23:03 +04:00
|
|
|
shell=WIN32OLE.new('Shell.Application')
|
|
|
|
@nsp = shell.NameSpace(@cfolder.path)
|
|
|
|
@fi2 = @nsp.parseName(dummy_file)
|
2006-05-01 13:05:08 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def find_link(path)
|
|
|
|
arlink = []
|
|
|
|
@cfolder.files.each do |f|
|
|
|
|
if /\.lnk$/ =~ f.path
|
2006-12-26 15:09:57 +03:00
|
|
|
linkinfo = @nsp.parseName(f.name).getLink
|
2006-05-01 13:05:08 +04:00
|
|
|
arlink.push f if linkinfo.path == path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
arlink
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_invokeverb
|
2010-10-03 15:45:17 +04:00
|
|
|
# in Windows Vista (not tested), Windows 7
|
|
|
|
# The verb must be in English.
|
|
|
|
# Creating Shortcut is "Link"
|
2010-10-14 18:23:03 +04:00
|
|
|
links = find_link(@dummy_path)
|
|
|
|
assert_equal(0, links.size)
|
2006-05-01 13:05:08 +04:00
|
|
|
|
2010-10-14 18:23:03 +04:00
|
|
|
# Now create shortcut to @dummy_path
|
|
|
|
arg = WIN32OLE_VARIANT.new("Link")
|
|
|
|
@fi2.InvokeVerb(arg)
|
2006-12-26 15:09:57 +03:00
|
|
|
|
2010-10-14 18:23:03 +04:00
|
|
|
# Now search shortcut to @dummy_path
|
|
|
|
links = find_link(@dummy_path)
|
|
|
|
assert_equal(1, links.size)
|
|
|
|
@lpath = links[0].path
|
2006-05-01 13:05:08 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
|
|
|
if @lpath
|
|
|
|
@fso.deleteFile(@lpath)
|
|
|
|
end
|
|
|
|
if @dummy_path
|
|
|
|
@fso.deleteFile(@dummy_path)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|