1# 2# This script check that Win32OLE can execute InvokeVerb method of FolderItem2. 3# 4 5begin 6 require 'win32ole' 7rescue LoadError 8end 9require 'test/unit' 10 11if defined?(WIN32OLE) 12 class TestInvokeVerb < Test::Unit::TestCase 13 def setup 14 # make dummy file for InvokeVerb test. 15 @fso = WIN32OLE.new('Scripting.FileSystemObject') 16 dummy_file = @fso.GetTempName 17 @cfolder = @fso.getFolder(".") 18 f = @cfolder.CreateTextFile(dummy_file) 19 f.close 20 @dummy_path = @cfolder.path + "\\" + dummy_file 21 22 shell=WIN32OLE.new('Shell.Application') 23 @nsp = shell.NameSpace(@cfolder.path) 24 @fi2 = @nsp.parseName(dummy_file) 25 end 26 27 def find_link(path) 28 arlink = [] 29 @cfolder.files.each do |f| 30 if /\.lnk$/ =~ f.path 31 linkinfo = @nsp.parseName(f.name).getLink 32 arlink.push f if linkinfo.path == path 33 end 34 end 35 arlink 36 end 37 38 def test_invokeverb 39 # in Windows Vista (not tested), Windows 7 40 # The verb must be in English. 41 # Creating Shortcut is "Link" 42 links = find_link(@dummy_path) 43 assert_equal(0, links.size) 44 45 # Now create shortcut to @dummy_path 46 arg = WIN32OLE_VARIANT.new("Link") 47 @fi2.InvokeVerb(arg) 48 49 # Now search shortcut to @dummy_path 50 links = find_link(@dummy_path) 51 assert_equal(1, links.size) 52 @lpath = links[0].path 53 end 54 55 def teardown 56 if @lpath 57 @fso.deleteFile(@lpath) 58 end 59 if @dummy_path 60 @fso.deleteFile(@dummy_path) 61 end 62 end 63 64 end 65end 66