From 0c2571d62116fb79263627d056387e88afbcc34a Mon Sep 17 00:00:00 2001 From: suke Date: Sat, 19 Aug 2006 07:53:27 +0000 Subject: [PATCH] accept hash argument of Symbol key. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10750 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 8 +++++++ ext/win32ole/win32ole.c | 15 +++++++----- test/win32ole/test_win32ole.rb | 44 ++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 6 deletions(-) create mode 100644 test/win32ole/test_win32ole.rb diff --git a/ChangeLog b/ChangeLog index d77c8852e1..a9f0f7f70f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Sat Aug 19 16:47:51 2006 Masaki Suketa + + * ext/win32ole/win32ole.c (hash2named_arg): accept hash argument + of symbol key. + + * test/win32ole/test_win32ole.rb + ditto. + Sat Aug 19 11:28:08 2006 Nobuyoshi Nakada * file.c (rb_file_s_rename): use errno if set properly. diff --git a/ext/win32ole/win32ole.c b/ext/win32ole/win32ole.c index 0381bb2003..8778d70305 100644 --- a/ext/win32ole/win32ole.c +++ b/ext/win32ole/win32ole.c @@ -79,7 +79,7 @@ #define WC2VSTR(x) ole_wc2vstr((x), TRUE) -#define WIN32OLE_VERSION "0.7.9" +#define WIN32OLE_VERSION "0.8.0" typedef HRESULT (STDAPICALLTYPE FNCOCREATEINSTANCEEX) (REFCLSID, IUnknown*, DWORD, COSERVERINFO*, DWORD, MULTI_QI*); @@ -2228,11 +2228,11 @@ hash2named_arg(VALUE pair, struct oleparam* pOp) VALUE key, value; index = pOp->dp.cNamedArgs; - /*------------------------------------- - the data-type of key must be String - ---------------------------------------*/ + /*--------------------------------------------- + the data-type of key must be String or Symbol + -----------------------------------------------*/ key = rb_ary_entry(pair, 0); - if(TYPE(key) != T_STRING) { + if(TYPE(key) != T_STRING && TYPE(key) != T_SYMBOL) { /* clear name of dispatch parameters */ for(i = 1; i < index + 1; i++) { SysFreeString(pOp->pNamedArgs[i]); @@ -2242,7 +2242,10 @@ hash2named_arg(VALUE pair, struct oleparam* pOp) VariantClear(&(pOp->dp.rgvarg[i])); } /* raise an exception */ - Check_Type(key, T_STRING); + rb_raise(rb_eTypeError, "wrong argument type (expected String or Symbol)"); + } + if (TYPE(key) == T_SYMBOL) { + key = rb_str_new2(rb_id2name(SYM2ID(key))); } /* pNamedArgs[0] is , so "index + 1" */ diff --git a/test/win32ole/test_win32ole.rb b/test/win32ole/test_win32ole.rb new file mode 100644 index 0000000000..f1bdb2c208 --- /dev/null +++ b/test/win32ole/test_win32ole.rb @@ -0,0 +1,44 @@ +# +# This script check that Win32OLE can execute InvokeVerb method of FolderItem2. +# + +begin + require 'win32ole' +rescue LoadError +end +require 'test/unit' + +if defined?(WIN32OLE) + class TestWin32OLE < Test::Unit::TestCase + def test_invoke_accept_symbol_hash_key + fso = WIN32OLE.new('Scripting.FileSystemObject') + afolder = fso.getFolder(".") + bfolder = fso.getFolder({"FolderPath" => "."}) + cfolder = fso.getFolder({:FolderPath => "."}) + assert_equal(afolder.path, bfolder.path) + assert_equal(afolder.path, cfolder.path) + fso = nil + end + def test_invoke_hash_key_non_str_sym + fso = WIN32OLE.new('Scripting.FileSystemObject') + begin + bfolder = fso.getFolder({1 => "."}) + assert(false) + rescue TypeError + assert(true) + end + fso = nil + end + def test_invoke_accept_multi_hash_key + shell = WIN32OLE.new('Shell.Application') + folder = shell.nameSpace(0) + item = folder.items.item(0) + name = folder.getDetailsOf(item, 0) + assert_equal(item.name, name) + name = folder.getDetailsOf({:vItem => item, :iColumn => 0}) + assert_equal(item.name, name) + name = folder.getDetailsOf({"vItem" => item, :iColumn => 0}) + assert_equal(item.name, name) + end + end +end