1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* ext/win32ole/win32ole.c (hash2named_arg): refactoring.

* ext/win32ole/win32ole.c (ole_invoke, fole_respond_to, ev_on_event,
  fev_off_event): accepts Symbol argument.

* test/win32ole/test_win32ole.rb: ditto.

* test/win32ole/test_win32ole_event.rb: ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18324 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
suke 2008-08-03 10:43:44 +00:00
parent da4d9e0362
commit e231d67ee1
4 changed files with 63 additions and 5 deletions

View file

@ -1,3 +1,14 @@
Sun Aug 3 19:32:52 2008 Masaki Suketa <masaki.suketa@nifty.ne.jp>
* ext/win32ole/win32ole.c (hash2named_arg): refactoring.
* ext/win32ole/win32ole.c (ole_invoke, fole_respond_to, ev_on_event,
fev_off_event): accepts Symbol argument.
* test/win32ole/test_win32ole.rb: ditto.
* test/win32ole/test_win32ole_event.rb: ditto.
Sun Aug 3 10:41:54 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
* string.c (rb_str_shared_replace): fixed memory leak. a patch from

View file

@ -118,7 +118,7 @@
#define WC2VSTR(x) ole_wc2vstr((x), TRUE)
#define WIN32OLE_VERSION "1.3.0"
#define WIN32OLE_VERSION "1.3.1"
typedef HRESULT (STDAPICALLTYPE FNCOCREATEINSTANCEEX)
(REFCLSID, IUnknown*, DWORD, COSERVERINFO*, DWORD, MULTI_QI*);
@ -3162,7 +3162,7 @@ hash2named_arg(VALUE pair, struct oleparam* pOp)
rb_raise(rb_eTypeError, "wrong argument type (expected String or Symbol)");
}
if (TYPE(key) == T_SYMBOL) {
key = rb_str_new2(rb_id2name(SYM2ID(key)));
key = rb_sym_to_s(key);
}
/* pNamedArgs[0] is <method name>, so "index + 1" */
@ -3225,6 +3225,12 @@ ole_invoke(int argc, VALUE *argv, VALUE self, USHORT wFlags, BOOL is_bracket)
op.dp.cArgs = 0;
rb_scan_args(argc, argv, "1*", &cmd, &paramS);
if(TYPE(cmd) != T_STRING && TYPE(cmd) != T_SYMBOL) {
rb_raise(rb_eTypeError, "method is wrong type (expected String or Symbol)");
}
if (TYPE(cmd) == T_SYMBOL) {
cmd = rb_sym_to_s(cmd);
}
OLEData_Get_Struct(self, pole);
if(!pole->pDispatch) {
rb_raise(rb_eRuntimeError, "failed to get dispatch interface");
@ -4417,7 +4423,12 @@ fole_respond_to(VALUE self, VALUE method)
DISPID DispID;
HRESULT hr;
rb_secure(4);
Check_SafeStr(method);
if(TYPE(method) != T_STRING && TYPE(method) != T_SYMBOL) {
rb_raise(rb_eTypeError, "wrong argument type (expected String or Symbol)");
}
if (TYPE(method) == T_SYMBOL) {
method = rb_sym_to_s(method);
}
OLEData_Get_Struct(self, pole);
wcmdname = ole_vstr2wc(method);
hr = pole->pDispatch->lpVtbl->GetIDsOfNames( pole->pDispatch, &IID_NULL,
@ -8143,7 +8154,12 @@ ev_on_event(int argc, VALUE *argv, VALUE self, VALUE is_ary_arg)
}
rb_scan_args(argc, argv, "01*", &event, &args);
if(!NIL_P(event)) {
Check_SafeStr(event);
if(TYPE(event) != T_STRING && TYPE(event) != T_SYMBOL) {
rb_raise(rb_eTypeError, "wrong argument type (expected String or Symbol)");
}
if (TYPE(event) == T_SYMBOL) {
event = rb_sym_to_s(event);
}
}
data = rb_ary_new3(4, rb_block_proc(), event, args, is_ary_arg);
add_event_call_back(self, event, data);
@ -8229,7 +8245,12 @@ fev_off_event(int argc, VALUE *argv, VALUE self)
rb_secure(4);
rb_scan_args(argc, argv, "01", &event);
if(!NIL_P(event)) {
Check_SafeStr(event);
if(TYPE(event) != T_STRING && TYPE(event) != T_SYMBOL) {
rb_raise(rb_eTypeError, "wrong argument type (expected String or Symbol)");
}
if (TYPE(event) == T_SYMBOL) {
event = rb_sym_to_s(event);
}
}
events = rb_ivar_get(self, id_events);
if (NIL_P(events)) {

View file

@ -250,12 +250,19 @@ if defined?(WIN32OLE)
fso = WIN32OLE.new('Scripting.FileSystemObject')
assert(fso.ole_respond_to?('getFolder'))
assert(fso.ole_respond_to?('GETFOLDER'))
assert(fso.ole_respond_to?(:getFolder))
assert(!fso.ole_respond_to?('XXXXX'))
assert_raise(TypeError) {
assert_raise(fso.ole_respond_to?(1))
}
end
def test_invoke
fso = WIN32OLE.new('Scripting.FileSystemObject')
assert(fso.invoke(:getFolder, "."))
assert(fso.invoke('getFolder', "."))
end
def test_s_const_load
assert(!defined?(CONST1::SsfWINDOWS))
shell=WIN32OLE.new('Shell.Application')

View file

@ -76,6 +76,16 @@ if defined?(WIN32OLE_EVENT)
assert_match(/NavigateComplete/, @event)
end
def test_on_event_symbol
ev = WIN32OLE_EVENT.new(@ie)
ev.on_event(:BeforeNavigate2) {|*args|
handler1
}
@ie.navigate("file:///#{@f}")
wait_ie
assert_equal("handler1", @event2)
end
def test_on_event2
ev = WIN32OLE_EVENT.new(@ie, 'DWebBrowserEvents')
ev.on_event('BeforeNavigate') {|*args| handler1}
@ -229,6 +239,15 @@ if defined?(WIN32OLE_EVENT)
assert_equal("", @event2)
end
def test_off_event_sym_arg
ev = WIN32OLE_EVENT.new(@ie)
ev.on_event('BeforeNavigate2'){handler1}
ev.off_event(:BeforeNavigate2)
@ie.navigate("file:///#{@f}")
wait_ie
assert_equal("", @event2)
end
def handler1
@event2 = "handler1"
end