From ad4ef9cf0ae0caca0c5f2f968b1757300991a84d Mon Sep 17 00:00:00 2001 From: suke Date: Sat, 20 Aug 2005 07:34:34 +0000 Subject: [PATCH] add test script to check WIN32OLE can invoke InvokeVerb of FolderItem2 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9007 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/win32ole/tests/testINVOKEVERB.rb | 70 ++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 ext/win32ole/tests/testINVOKEVERB.rb diff --git a/ext/win32ole/tests/testINVOKEVERB.rb b/ext/win32ole/tests/testINVOKEVERB.rb new file mode 100644 index 0000000000..3510b9057c --- /dev/null +++ b/ext/win32ole/tests/testINVOKEVERB.rb @@ -0,0 +1,70 @@ +# +# 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. + # + @fi2.verbs.each do |v| + # + # We expect the 'Create Shortcut' string is end with '(&S)'. + # + if /.*\(\&S\)$/ =~ v.name + @shortcut = v.name + break + end + end + 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 +