summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsuke <suke@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-05-01 09:05:08 +0000
committersuke <suke@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-05-01 09:05:08 +0000
commit2bdd9d6eba7f2088e017ae80e0029c236eeb47e0 (patch)
tree495cb40485a055756292d2f34e0e04f1ffa14a0c
parent0cf4abaa278e338f3aa6e4633f06ef2da934ccf8 (diff)
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
-rw-r--r--ChangeLog5
-rw-r--r--ext/win32ole/tests/testINVOKEVERB.rb68
-rw-r--r--ext/win32ole/tests/testNIL2VTEMPTY.rb28
-rw-r--r--ext/win32ole/tests/testOLEEVENT.rb91
-rw-r--r--ext/win32ole/tests/testall.rb3
-rw-r--r--ext/win32ole/win32ole.c7
-rw-r--r--test/win32ole/test_folderitem2_invokeverb.rb80
-rw-r--r--test/win32ole/test_nil2vtempty.rb32
-rw-r--r--test/win32ole/test_win32ole_event.rb98
9 files changed, 218 insertions, 194 deletions
diff --git a/ChangeLog b/ChangeLog
index e91ed71f4d..1ed1cc9a71 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
diff --git a/ext/win32ole/tests/testINVOKEVERB.rb b/ext/win32ole/tests/testINVOKEVERB.rb
deleted file mode 100644
index 96b3e2f88f..0000000000
--- a/ext/win32ole/tests/testINVOKEVERB.rb
+++ /dev/null
@@ -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
-
diff --git a/ext/win32ole/tests/testNIL2VTEMPTY.rb b/ext/win32ole/tests/testNIL2VTEMPTY.rb
deleted file mode 100644
index 555d35fbf3..0000000000
--- a/ext/win32ole/tests/testNIL2VTEMPTY.rb
+++ /dev/null
@@ -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
-
diff --git a/ext/win32ole/tests/testOLEEVENT.rb b/ext/win32ole/tests/testOLEEVENT.rb
deleted file mode 100644
index 0901158642..0000000000
--- a/ext/win32ole/tests/testOLEEVENT.rb
+++ /dev/null
@@ -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
-
diff --git a/ext/win32ole/tests/testall.rb b/ext/win32ole/tests/testall.rb
index e5dad78684..12e97e3913 100644
--- a/ext/win32ole/tests/testall.rb
+++ b/ext/win32ole/tests/testall.rb
@@ -2,6 +2,3 @@ require 'test/unit'
require 'win32ole'
puts "Now Test Win32OLE version #{WIN32OLE::VERSION}"
require "testWIN32OLE"
-require "testOLEEVENT"
-require "testNIL2VTEMPTY"
-require "testINVOKEVERB"
diff --git a/ext/win32ole/win32ole.c b/ext/win32ole/win32ole.c
index 2a89dfb8a6..ba4fc4b921 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.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);
diff --git a/test/win32ole/test_folderitem2_invokeverb.rb b/test/win32ole/test_folderitem2_invokeverb.rb
new file mode 100644
index 0000000000..0707684681
--- /dev/null
+++ b/test/win32ole/test_folderitem2_invokeverb.rb
@@ -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
diff --git a/test/win32ole/test_nil2vtempty.rb b/test/win32ole/test_nil2vtempty.rb
new file mode 100644
index 0000000000..2576415a8d
--- /dev/null
+++ b/test/win32ole/test_nil2vtempty.rb
@@ -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
diff --git a/test/win32ole/test_win32ole_event.rb b/test/win32ole/test_win32ole_event.rb
new file mode 100644
index 0000000000..1b0285cb58
--- /dev/null
+++ b/test/win32ole/test_win32ole_event.rb
@@ -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