accept hash argument of Symbol key.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10750 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
suke 2006-08-19 07:53:27 +00:00
Родитель ddf79e9b6d
Коммит 0c2571d621
3 изменённых файлов: 61 добавлений и 6 удалений

Просмотреть файл

@ -1,3 +1,11 @@
Sat Aug 19 16:47:51 2006 Masaki Suketa <masaki.suketa@nifty.ne.jp>
* 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 <nobu@ruby-lang.org>
* file.c (rb_file_s_rename): use errno if set properly.

Просмотреть файл

@ -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 <method name>, so "index + 1" */

Просмотреть файл

@ -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