mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
ext/win32ole/win32ole.c (add_event_call_back): should not
delete event handler when the event name is not entried. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10125 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
0cf4abaa27
commit
2bdd9d6eba
9 changed files with 218 additions and 194 deletions
|
@ -1,3 +1,8 @@
|
|||
Mon May 1 17:58:16 2006 Masaki Suketa <masaki.suketa@nifty.ne.jp>
|
||||
|
||||
* ext/win32ole/win32ole.c (add_event_call_back): should not
|
||||
delete event handler when the event name is not entried.
|
||||
|
||||
Mon May 1 08:32:10 2006 Masaki Suketa <masaki.suketa@nifty.ne.jp>
|
||||
|
||||
* ext/win32ole/win32ole.c (ole_param_ole_type): should return
|
||||
|
|
|
@ -1,68 +0,0 @@
|
|||
#
|
||||
# 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.
|
||||
#
|
||||
verbs = @fi2.verbs
|
||||
verbs.extend(Enumerable)
|
||||
@shortcut = verbs.collect{|verb|
|
||||
verb.name
|
||||
}.find {|name|
|
||||
/.*\(\&S\)$/ =~ name
|
||||
}
|
||||
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
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
# This is test script to check that WIN32OLE should convert nil to VT_EMPTY in second try.
|
||||
# [ruby-talk:137054]
|
||||
|
||||
require 'win32ole'
|
||||
require 'test/unit'
|
||||
|
||||
class TestNIL2VT_EMPTY < Test::Unit::TestCase
|
||||
def setup
|
||||
fs = WIN32OLE.new('Scripting.FileSystemObject')
|
||||
@path = fs.GetFolder(".").path
|
||||
end
|
||||
def test_openSchema
|
||||
con = nil
|
||||
begin
|
||||
con = WIN32OLE.new('ADODB.Connection')
|
||||
con.connectionString = "Provider=MSDASQL;Extended Properties="
|
||||
con.connectionString +="\"DRIVER={Microsoft Text Driver (*.txt; *.csv)};DBQ=#{@path}\""
|
||||
con.open
|
||||
rescue
|
||||
con = nil
|
||||
end
|
||||
if con
|
||||
rs = con.openSchema(4, [nil,nil,"DUMMY", "TABLE"])
|
||||
assert(rs)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,91 +0,0 @@
|
|||
require 'rubyunit'
|
||||
require 'win32ole'
|
||||
|
||||
class TestWIN32OLE_EVENT < RUNIT::TestCase
|
||||
def setup
|
||||
@excel = WIN32OLE.new("Excel.Application")
|
||||
@excel.visible = true
|
||||
@event = ""
|
||||
@event2 = ""
|
||||
end
|
||||
def test_on_event
|
||||
book = @excel.workbooks.Add
|
||||
value = ""
|
||||
begin
|
||||
ev = WIN32OLE_EVENT.new(book, 'WorkbookEvents')
|
||||
ev.on_event('SheetChange'){|arg1, arg2|
|
||||
begin
|
||||
value = arg1.value
|
||||
rescue
|
||||
value = $!.message
|
||||
end
|
||||
}
|
||||
book.Worksheets(1).Range("A1").value = "OK"
|
||||
ensure
|
||||
book.saved = true
|
||||
end
|
||||
assert_equal("OK", value)
|
||||
end
|
||||
|
||||
def handler1
|
||||
@event += "handler1"
|
||||
end
|
||||
def handler2
|
||||
@event += "handler2"
|
||||
end
|
||||
|
||||
def handler3
|
||||
@event += "handler3"
|
||||
end
|
||||
|
||||
def test_on_event2
|
||||
book = @excel.workbooks.Add
|
||||
begin
|
||||
ev = WIN32OLE_EVENT.new(book, 'WorkbookEvents')
|
||||
ev.on_event('SheetChange'){|arg1, arg2|
|
||||
handler1
|
||||
}
|
||||
ev.on_event('SheetChange'){|arg1, arg2|
|
||||
handler2
|
||||
}
|
||||
book.Worksheets(1).Range("A1").value = "OK"
|
||||
ensure
|
||||
book.saved = true
|
||||
end
|
||||
assert_equal("handler2", @event)
|
||||
end
|
||||
|
||||
def test_on_event3
|
||||
book = @excel.workbooks.Add
|
||||
begin
|
||||
ev = WIN32OLE_EVENT.new(book, 'WorkbookEvents')
|
||||
ev.on_event{ handler1 }
|
||||
ev.on_event{ handler2 }
|
||||
book.Worksheets(1).Range("A1").value = "OK"
|
||||
ensure
|
||||
book.saved = true
|
||||
end
|
||||
assert_equal("handler2", @event)
|
||||
end
|
||||
|
||||
def test_on_event4
|
||||
book = @excel.workbooks.Add
|
||||
begin
|
||||
ev = WIN32OLE_EVENT.new(book, 'WorkbookEvents')
|
||||
ev.on_event{ handler1 }
|
||||
ev.on_event{ handler2 }
|
||||
ev.on_event('SheetChange'){|arg1, arg2| handler3 }
|
||||
book.Worksheets(1).Range("A1").value = "OK"
|
||||
ensure
|
||||
book.saved = true
|
||||
end
|
||||
assert_equal("handler3", @event)
|
||||
end
|
||||
|
||||
def teardown
|
||||
@excel.quit
|
||||
@excel = nil
|
||||
GC.start
|
||||
end
|
||||
end
|
||||
|
|
@ -2,6 +2,3 @@ require 'test/unit'
|
|||
require 'win32ole'
|
||||
puts "Now Test Win32OLE version #{WIN32OLE::VERSION}"
|
||||
require "testWIN32OLE"
|
||||
require "testOLEEVENT"
|
||||
require "testNIL2VTEMPTY"
|
||||
require "testINVOKEVERB"
|
||||
|
|
|
@ -79,7 +79,7 @@
|
|||
|
||||
#define WC2VSTR(x) ole_wc2vstr((x), TRUE)
|
||||
|
||||
#define WIN32OLE_VERSION "0.7.6"
|
||||
#define WIN32OLE_VERSION "0.7.7"
|
||||
|
||||
typedef HRESULT (STDAPICALLTYPE FNCOCREATEINSTANCEEX)
|
||||
(REFCLSID, IUnknown*, DWORD, COSERVERINFO*, DWORD, MULTI_QI*);
|
||||
|
@ -6352,7 +6352,6 @@ STDMETHODIMP EVENTSINK_Invoke(
|
|||
else {
|
||||
result = rb_apply(handler, rb_intern("call"), args);
|
||||
}
|
||||
|
||||
if (pvarResult) {
|
||||
ole_val2variant(result, pvarResult);
|
||||
}
|
||||
|
@ -6739,14 +6738,14 @@ fev_s_msg_loop(VALUE klass)
|
|||
static void
|
||||
add_event_call_back(VALUE obj, VALUE event, VALUE data)
|
||||
{
|
||||
long at;
|
||||
long at = -1;
|
||||
VALUE events = rb_ivar_get(obj, id_events);
|
||||
if (NIL_P(events) || TYPE(events) != T_ARRAY) {
|
||||
events = rb_ary_new();
|
||||
rb_ivar_set(obj, id_events, events);
|
||||
}
|
||||
at = ole_search_event_at(events, event);
|
||||
if (at >= -1) {
|
||||
if (at >= 0) {
|
||||
rb_ary_delete_at(events, at);
|
||||
}
|
||||
rb_ary_push(events, data);
|
||||
|
|
80
test/win32ole/test_folderitem2_invokeverb.rb
Normal file
80
test/win32ole/test_folderitem2_invokeverb.rb
Normal file
|
@ -0,0 +1,80 @@
|
|||
#
|
||||
# This script check that Win32OLE can execute InvokeVerb method of FolderItem2.
|
||||
#
|
||||
|
||||
begin
|
||||
require 'win32ole'
|
||||
rescue
|
||||
end
|
||||
|
||||
require 'test/unit'
|
||||
|
||||
if defined?(WIN32OLE)
|
||||
class TestInvokeVerb < Test::Unit::TestCase
|
||||
def setup
|
||||
#
|
||||
# make dummy.txt file for InvokeVerb test.
|
||||
#
|
||||
|
||||
@fso = WIN32OLE.new('Scripting.FileSystemObject')
|
||||
@dummy_path = @fso.GetTempName
|
||||
@cfolder = @fso.getFolder(".")
|
||||
f = @cfolder.CreateTextFile(@dummy_path)
|
||||
f.close
|
||||
@dummy_path = @cfolder.path + "\\" + @dummy_path
|
||||
|
||||
@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.
|
||||
#
|
||||
verbs = @fi2.verbs
|
||||
verbs.extend(Enumerable)
|
||||
@shortcut = verbs.collect{|verb|
|
||||
verb.name
|
||||
}.find {|name|
|
||||
/.*\(\&S\)$/ =~ name
|
||||
}
|
||||
end
|
||||
|
||||
def find_link(path)
|
||||
arlink = []
|
||||
@cfolder.files.each do |f|
|
||||
if /\.lnk$/ =~ f.path
|
||||
linkinfo = @shell.NameSpace(f.path).self.getlink
|
||||
arlink.push f if linkinfo.path == path
|
||||
end
|
||||
end
|
||||
arlink
|
||||
end
|
||||
|
||||
def test_invokeverb
|
||||
links = find_link(@dummy_path)
|
||||
assert(0, links.size)
|
||||
|
||||
# Now create shortcut to @dummy_path
|
||||
assert(@shortcut)
|
||||
arg = WIN32OLE_VARIANT.new(@shortcut)
|
||||
@fi2.InvokeVerb(arg)
|
||||
|
||||
# Now search shortcut to @dummy_path
|
||||
links = find_link(@dummy_path)
|
||||
assert(1, links.size)
|
||||
@lpath = links[0].path
|
||||
end
|
||||
|
||||
def teardown
|
||||
if @lpath
|
||||
@fso.deleteFile(@lpath)
|
||||
end
|
||||
if @dummy_path
|
||||
@fso.deleteFile(@dummy_path)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
32
test/win32ole/test_nil2vtempty.rb
Normal file
32
test/win32ole/test_nil2vtempty.rb
Normal file
|
@ -0,0 +1,32 @@
|
|||
# This is test script to check that WIN32OLE should convert nil to VT_EMPTY in second try.
|
||||
# [ruby-talk:137054]
|
||||
begin
|
||||
require 'win32ole'
|
||||
rescue LoadError
|
||||
end
|
||||
|
||||
require 'test/unit'
|
||||
if defined?(WIN32OLE)
|
||||
class TestNIL2VT_EMPTY < Test::Unit::TestCase
|
||||
def setup
|
||||
fs = WIN32OLE.new('Scripting.FileSystemObject')
|
||||
@path = fs.GetFolder(".").path
|
||||
end
|
||||
def test_openSchema
|
||||
con = nil
|
||||
begin
|
||||
con = WIN32OLE.new('ADODB.Connection')
|
||||
con.connectionString = "Provider=MSDASQL;Extended Properties="
|
||||
con.connectionString +="\"DRIVER={Microsoft Text Driver (*.txt; *.csv)};DBQ=#{@path}\""
|
||||
con.open
|
||||
rescue
|
||||
con = nil
|
||||
end
|
||||
if con
|
||||
rs = con.openSchema(4, [nil,nil,"DUMMY", "TABLE"])
|
||||
assert(rs)
|
||||
assert_equal("_Recordset", rs.ole_type.name)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
98
test/win32ole/test_win32ole_event.rb
Normal file
98
test/win32ole/test_win32ole_event.rb
Normal file
|
@ -0,0 +1,98 @@
|
|||
begin
|
||||
require 'win32ole'
|
||||
rescue
|
||||
end
|
||||
require 'test/unit'
|
||||
if defined?(WIN32OLE_EVENT)
|
||||
class TestWIN32OLE_EVENT < Test::Unit::TestCase
|
||||
def setup
|
||||
@ie = WIN32OLE.new("InternetExplorer.Application")
|
||||
@ie.visible = true
|
||||
@event = ""
|
||||
@event2 = ""
|
||||
@event3 = ""
|
||||
end
|
||||
|
||||
def default_handler(event, *args)
|
||||
@event += event
|
||||
end
|
||||
|
||||
def test_on_event
|
||||
ev = WIN32OLE_EVENT.new(@ie, 'DWebBrowserEvents')
|
||||
ev.on_event {|*args| default_handler(*args)}
|
||||
@ie.gohome
|
||||
while @ie.busy
|
||||
WIN32OLE_EVENT.message_loop
|
||||
end
|
||||
assert_match(/BeforeNavigate/, @event)
|
||||
assert_match(/NavigateComplete/, @event)
|
||||
end
|
||||
|
||||
def test_on_event2
|
||||
ev = WIN32OLE_EVENT.new(@ie, 'DWebBrowserEvents')
|
||||
ev.on_event('BeforeNavigate') {|*args| handler1}
|
||||
ev.on_event('BeforeNavigate') {|*args| handler2}
|
||||
@ie.gohome
|
||||
while @ie.busy
|
||||
WIN32OLE_EVENT.message_loop
|
||||
end
|
||||
assert_equal("handler2", @event2)
|
||||
end
|
||||
|
||||
def test_on_event3
|
||||
ev = WIN32OLE_EVENT.new(@ie, 'DWebBrowserEvents')
|
||||
ev.on_event {handler1}
|
||||
ev.on_event {handler2}
|
||||
@ie.gohome
|
||||
while @ie.busy
|
||||
WIN32OLE_EVENT.message_loop
|
||||
end
|
||||
assert_equal("handler2", @event2)
|
||||
end
|
||||
|
||||
def test_on_event4
|
||||
ev = WIN32OLE_EVENT.new(@ie, 'DWebBrowserEvents')
|
||||
ev.on_event{handler1}
|
||||
ev.on_event{handler2}
|
||||
ev.on_event('NavigateComplete'){|*args| handler3(*args)}
|
||||
@ie.gohome
|
||||
while @ie.busy
|
||||
WIN32OLE_EVENT.message_loop
|
||||
end
|
||||
assert(@event3!="")
|
||||
assert("handler2", @event2)
|
||||
end
|
||||
|
||||
def test_on_event5
|
||||
ev = WIN32OLE_EVENT.new(@ie, 'DWebBrowserEvents')
|
||||
ev.on_event {|*args| default_handler(*args)}
|
||||
ev.on_event('NavigateComplete'){|*args| handler3(*args)}
|
||||
@ie.gohome
|
||||
while @ie.busy
|
||||
WIN32OLE_EVENT.message_loop
|
||||
end
|
||||
assert_match(/BeforeNavigate/, @event)
|
||||
assert(/NavigateComplete/ !~ @event)
|
||||
assert(@event!="")
|
||||
end
|
||||
|
||||
def handler1
|
||||
@event2 = "handler1"
|
||||
end
|
||||
|
||||
def handler2
|
||||
@event2 = "handler2"
|
||||
end
|
||||
|
||||
def handler3(url)
|
||||
@event3 += url
|
||||
end
|
||||
|
||||
def teardown
|
||||
@ie.quit
|
||||
@ie = nil
|
||||
GC.start
|
||||
sleep 1
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue