ruby-changes:8560
From: suke <ko1@a...>
Date: Mon, 3 Nov 2008 06:52:24 +0900 (JST)
Subject: [ruby-changes:8560] Ruby:r20093 (ruby_1_9_1): * ext/win32ole/win32ole.c (ole_event_free): invoke IConnectionPoint::Unadvise
suke 2008-11-03 06:52:04 +0900 (Mon, 03 Nov 2008) New Revision: 20093 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=20093 Log: * ext/win32ole/win32ole.c (ole_event_free): invoke IConnectionPoint::Unadvise before invoking IConnectionPoint::Release. * test/win32ole/test_win32ole_event.rb, test/win32ole/err_in_callback.rb, test/win32ole/test_err_in_callback.rb, test/win32ole/test_win32ole_variant_outarg.rb, test/win32ole/orig_data.csv: Use ActiveX Data Object Library instead of InternetExplorer. remove test/win32ole/test_win32ole_variant_with_ie.rb. Added files: branches/ruby_1_9_1/test/win32ole/orig_data.csv branches/ruby_1_9_1/test/win32ole/test_win32ole_variant_outarg.rb Removed files: branches/ruby_1_9_1/test/win32ole/test_win32ole_variant_with_ie.rb Modified files: branches/ruby_1_9_1/ChangeLog branches/ruby_1_9_1/ext/win32ole/win32ole.c branches/ruby_1_9_1/test/win32ole/err_in_callback.rb branches/ruby_1_9_1/test/win32ole/test_err_in_callback.rb branches/ruby_1_9_1/test/win32ole/test_win32ole_event.rb Index: ruby_1_9_1/ChangeLog =================================================================== --- ruby_1_9_1/ChangeLog (revision 20092) +++ ruby_1_9_1/ChangeLog (revision 20093) @@ -1,3 +1,15 @@ +Mon Nov 3 06:41:19 2008 Masaki Suketa <masaki.suketa@n...> + + * ext/win32ole/win32ole.c (ole_event_free): invoke IConnectionPoint::Unadvise + before invoking IConnectionPoint::Release. + + * test/win32ole/test_win32ole_event.rb, test/win32ole/err_in_callback.rb, + test/win32ole/test_err_in_callback.rb, + test/win32ole/test_win32ole_variant_outarg.rb, + test/win32ole/orig_data.csv: Use ActiveX Data Object + Library instead of InternetExplorer. + remove test/win32ole/test_win32ole_variant_with_ie.rb. + Sun Nov 2 16:41:52 2008 Nobuyoshi Nakada <nobu@r...> * ext/zlib/zlib.c (Init_zlib): defines readbyte instead redefining Index: ruby_1_9_1/ext/win32ole/win32ole.c =================================================================== --- ruby_1_9_1/ext/win32ole/win32ole.c (revision 20092) +++ ruby_1_9_1/ext/win32ole/win32ole.c (revision 20093) @@ -128,7 +128,7 @@ #define WC2VSTR(x) ole_wc2vstr((x), TRUE) -#define WIN32OLE_VERSION "1.3.7" +#define WIN32OLE_VERSION "1.3.8" typedef HRESULT (STDAPICALLTYPE FNCOCREATEINSTANCEEX) (REFCLSID, IUnknown*, DWORD, COSERVERINFO*, DWORD, MULTI_QI*); @@ -8124,7 +8124,11 @@ static void ole_event_free(struct oleeventdata *poleev) { - OLE_FREE(poleev->pConnectionPoint); + if (poleev->pConnectionPoint) { + poleev->pConnectionPoint->lpVtbl->Unadvise(poleev->pConnectionPoint, poleev->dwCookie); + OLE_RELEASE(poleev->pConnectionPoint); + poleev->pConnectionPoint = NULL; + } free(poleev); } Index: ruby_1_9_1/test/win32ole/test_win32ole_variant_with_ie.rb =================================================================== --- ruby_1_9_1/test/win32ole/test_win32ole_variant_with_ie.rb (revision 20092) +++ ruby_1_9_1/test/win32ole/test_win32ole_variant_with_ie.rb (revision 20093) @@ -1,53 +0,0 @@ -# This is test script to check WIN32OLE_VARIANT using Internet Explorer -begin - require 'win32ole' -rescue LoadError -end -require 'test/unit' - -if defined?(WIN32OLE) - class TestWIN32OLE_VARIANT_WITH_IE < Test::Unit::TestCase - def create_temp_html - fso = WIN32OLE.new('Scripting.FileSystemObject') - dummy_file = fso.GetTempName + ".html" - cfolder = fso.getFolder(".") - f = cfolder.CreateTextFile(dummy_file) - f.writeLine("<html><body>This is test HTML file for Win32OLE.</body></html>") - f.close - dummy_path = cfolder.path + "\\" + dummy_file - dummy_path - end - def setup - @f = create_temp_html - @ie = WIN32OLE.new('InternetExplorer.Application') - @ie.visible = true - @ie.navigate("file:///#{@f}") - while @ie.busy - sleep 0.5 - end - end - def test_variant_ref_and_argv - @ie.execWB(19, 0, nil, -1) - size = WIN32OLE::ARGV[3] - assert(size >= 0) - - obj = WIN32OLE_VARIANT.new(nil, WIN32OLE::VARIANT::VT_VARIANT|WIN32OLE::VARIANT::VT_BYREF) - @ie.execWb(19, 0, nil, obj) - assert_equal(size, obj.value) - assert_equal(size, WIN32OLE::ARGV[3]) - - obj = WIN32OLE_VARIANT.new(-1, WIN32OLE::VARIANT::VT_VARIANT|WIN32OLE::VARIANT::VT_BYREF) - @ie.execWb(19, 0, nil, obj) - assert_equal(size, obj.value) - assert_equal(size, WIN32OLE::ARGV[3]) - end - - def teardown - File.unlink(@f) - if @ie - @ie.quit - @ie = nil - end - end - end -end Index: ruby_1_9_1/test/win32ole/orig_data.csv =================================================================== --- ruby_1_9_1/test/win32ole/orig_data.csv (revision 0) +++ ruby_1_9_1/test/win32ole/orig_data.csv (revision 20093) @@ -0,0 +1,5 @@ +ID,VALUE +1,"A" +2,"B" +3,"C" +4,"B" Index: ruby_1_9_1/test/win32ole/test_err_in_callback.rb =================================================================== --- ruby_1_9_1/test/win32ole/test_err_in_callback.rb (revision 20092) +++ ruby_1_9_1/test/win32ole/test_err_in_callback.rb (revision 20093) @@ -21,27 +21,12 @@ " -I " + e }.join("") @script = File.dirname(__FILE__) + "/err_in_callback.rb" - @param = create_temp_html - @param = "file:///" + @param.gsub(/\\/, '/') end end - def create_temp_html - fso = WIN32OLE.new('Scripting.FileSystemObject') - @dummy_file = fso.GetTempName + ".html" - cfolder = fso.getFolder(".") - @str = "This is test HTML file for Win32OLE (#{Time.now})" - f = cfolder.CreateTextFile(@dummy_file) - f.writeLine("<html><body><div id='str'>#{@str}</div></body></html>") - f.close - @f = @dummy_file - dummy_path = cfolder.path + "\\" + @dummy_file - dummy_path - end - def test_err_in_callback if @ruby - cmd = "#{@ruby} -v #{@iopt} #{@script} #{@param} > test_err_in_callback.log 2>&1" + cmd = "#{@ruby} -v #{@iopt} #{@script} > test_err_in_callback.log 2>&1" system(cmd) str = "" open("test_err_in_callback.log") {|ifs| @@ -51,34 +36,9 @@ end end - def ie_quit - WIN32OLE_EVENT.message_loop - sh = WIN32OLE.new('Shell.Application') - sh.windows.each do |w| - i = 0 - begin - i = i + 1 - next if i > 100 - WIN32OLE_EVENT.message_loop - sleep 0.1 - next if /#{@dummy_file}/ !~ w.locationURL - e = w.document.all.item("str") - if e && e.innerHTML == @str - w.quit - WIN32OLE_EVENT.message_loop - sleep 0.2 - break - end - rescue - retry - end - end - end - def teardown - ie_quit - File.unlink(@f) File.unlink("test_err_in_callback.log") end + end end Index: ruby_1_9_1/test/win32ole/err_in_callback.rb =================================================================== --- ruby_1_9_1/test/win32ole/err_in_callback.rb (revision 20092) +++ ruby_1_9_1/test/win32ole/err_in_callback.rb (revision 20093) @@ -1,15 +1,9 @@ require 'win32ole' -ie = WIN32OLE.new('InternetExplorer.Application') -ie.visible = true -WIN32OLE_EVENT.message_loop -sleep 0.2 -ev = WIN32OLE_EVENT.new(ie) - -ev.on_event('NavigateComplete2') {|*args| +db = WIN32OLE.new('ADODB.Connection') +db.connectionString = "Driver={Microsoft Text Driver (*.txt; *.csv)};DefaultDir=.;" +ev = WIN32OLE_EVENT.new(db) +ev.on_event('WillConnect') {|*args| foo } -ie.navigate(ARGV.shift) -while ie.readystate != 4 - WIN32OLE_EVENT.message_loop - sleep 0.2 -end +db.open +WIN32OLE_EVENT.message_loop Index: ruby_1_9_1/test/win32ole/test_win32ole_event.rb =================================================================== --- ruby_1_9_1/test/win32ole/test_win32ole_event.rb (revision 20092) +++ ruby_1_9_1/test/win32ole/test_win32ole_event.rb (revision 20093) @@ -4,330 +4,331 @@ end require 'test/unit' -if defined?(WIN32OLE_EVENT) - class TestWIN32OLE_EVENT < Test::Unit::TestCase - module IE +def ado_installed? + installed = false + if defined?(WIN32OLE) + db = nil + begin + db = WIN32OLE.new('ADODB.Connection') + db.connectionString = "Driver={Microsoft Text Driver (*.txt; *.csv)};DefaultDir=.;" + db.open + db.close + db = nil + installed = true + rescue end - def create_temp_html - fso = WIN32OLE.new('Scripting.FileSystemObject') - dummy_file = fso.GetTempName + ".html" - cfolder = fso.getFolder(".") - f = cfolder.CreateTextFile(dummy_file) - f.writeLine("<html><body>This is test HTML file for Win32OLE.</body></html>") - f.close - dummy_path = cfolder.path + "\\" + dummy_file - dummy_path - end + end + installed +end - def message_loop - WIN32OLE_EVENT.message_loop - sleep 0.1 - end +if defined?(WIN32OLE_EVENT) + dotest = ado_installed? + if !dotest + STDERR.puts("\n#{__FILE__} skipped(ActiveX Data Object Library not found.)") + end + if dotest + class TestWIN32OLE_EVENT < Test::Unit::TestCase + CONNSTR="Driver={Microsoft Text Driver (*.txt; *.csv)};DefaultDir=.;" + module ADO + end + def message_loop + WIN32OLE_EVENT.message_loop + end - def wait_ie - while @ie.readyState != IE::READYSTATE_COMPLETE - message_loop + def default_handler(event, *args) + @event += event end - end - def setup - WIN32OLE_EVENT.message_loop - @ie = WIN32OLE.new("InternetExplorer.Application") - if !defined?(IE::READYSTATE_COMPLETE) - WIN32OLE.const_load(@ie, IE) + def setup + @db = WIN32OLE.new('ADODB.Connection') + if !defined?(ADO::AdStateOpen) + WIN32OLE.const_load(@db, ADO) + end + @db.connectionString = CONNSTR + @event = "" + @event2 = "" + @event3 = "" end - @ie.visible = true - message_loop - @event = "" - @event2 = "" - @event3 = "" - @f = create_temp_html - end - def default_handler(event, *args) - @event += event - end + def test_s_new + assert_raise(TypeError) { + ev = WIN32OLE_EVENT.new("A") + } + end - def test_s_new - assert_raise(TypeError) { - ev = WIN32OLE_EVENT.new("A") - } - end + def test_s_new_without_itf + ev = WIN32OLE_EVENT.new(@db) + ev.on_event {|*args| default_handler(*args)} + @db.open + @db.close + 10.times do |i| + WIN32OLE_EVENT.new(@db) + GC.start + message_loop + @db.open + message_loop + @db.close + end + assert_match(/WillConnect/, @event) + end - def test_s_new_without_itf - ev = WIN32OLE_EVENT.new(@ie) - ev.on_event {|*args| default_handler(*args)} - @ie.navigate("file:///#{@f}") - while @ie.busy - WIN32OLE_EVENT.new(@ie) - GC.start + def test_on_event + ev = WIN32OLE_EVENT.new(@db, 'ConnectionEvents') + ev.on_event {|*args| default_handler(*args)} + @db.open message_loop + assert_match(/WillConnect/, @event) end - assert_match(/BeforeNavigate/, @event) - assert_match(/NavigateComplete/, @event) - end - def test_on_event - ev = WIN32OLE_EVENT.new(@ie, 'DWebBrowserEvents') - ev.on_event {|*args| default_handler(*args)} - @ie.navigate("file:///#{@f}") - wait_ie - assert_match(/BeforeNavigate/, @event) - assert_match(/NavigateComplete/, @event) - end + def test_on_event_symbol + ev = WIN32OLE_EVENT.new(@db) + ev.on_event(:WillConnect) {|*args| + handler1 + } + @db.open + message_loop + assert_equal("handler1", @event2) + 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(@db, 'ConnectionEvents') + ev.on_event('WillConnect') {|*args| handler1} + ev.on_event('WillConnect') {|*args| handler2} + @db.open + message_loop + assert_equal("handler2", @event2) + end - def test_on_event2 - ev = WIN32OLE_EVENT.new(@ie, 'DWebBrowserEvents') - ev.on_event('BeforeNavigate') {|*args| handler1} - ev.on_event('BeforeNavigate') {|*args| handler2} - @ie.navigate("file:///#{@f}") - wait_ie - assert_equal("handler2", @event2) - end + def test_on_event3 + ev = WIN32OLE_EVENT.new(@db, 'ConnectionEvents') + ev.on_event('WillConnect') {|*args| handler1} + ev.on_event('WillConnect') {|*args| handler2} + @db.open + message_loop + assert_equal("handler2", @event2) + end - def test_on_event3 - ev = WIN32OLE_EVENT.new(@ie, 'DWebBrowserEvents') - ev.on_event {|*args| handler1} - ev.on_event {|*args| handler2} - @ie.navigate("file:///#{@f}") - wait_ie - assert_equal("handler2", @event2) - end + def test_on_event4 + ev = WIN32OLE_EVENT.new(@db, 'ConnectionEvents') + ev.on_event{|*args| handler1} + ev.on_event{|*args| handler2} + ev.on_event('WillConnect'){|*args| handler3(*args)} + @db.open + message_loop + assert_equal(CONNSTR, @event3) + assert("handler2", @event2) + end - def test_on_event4 - ev = WIN32OLE_EVENT.new(@ie, 'DWebBrowserEvents') - ev.on_event{|*args| handler1} - ev.on_event{|*args| handler2} - ev.on_event('NavigateComplete'){|*args| handler3(*args)} - @ie.navigate("file:///#{@f}") - wait_ie - assert(@event3!="") - assert("handler2", @event2) - end + def test_on_event5 + ev = WIN32OLE_EVENT.new(@db, 'ConnectionEvents') + ev.on_event {|*args| default_handler(*args)} + ev.on_event('WillConnect'){|*args| handler3(*args)} + @db.open + message_loop + assert_match(/ConnectComplete/, @event) + assert(/WillConnect/ !~ @event) + assert_equal(CONNSTR, @event3) + 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.navigate("file:///#{@f}") - wait_ie - assert_match(/BeforeNavigate/, @event) - assert(/NavigateComplete/ !~ @event) - assert(@event!="") - end - - def test_unadvise - ev = WIN32OLE_EVENT.new(@ie, 'DWebBrowserEvents') - ev.on_event {|*args| default_handler(*args)} - @ie.navigate("file:///#{@f}") - wait_ie - assert_match(/BeforeNavigate/, @event) - ev.unadvise - @event = "" - @ie.navigate("file:///#{@f}") - wait_ie - assert_equal("", @event); - assert_raise(WIN32OLERuntimeError) { + def test_unadvise + ev = WIN32OLE_EVENT.new(@db, 'ConnectionEvents') ev.on_event {|*args| default_handler(*args)} - } - end + @db.open + message_loop + assert_match(/WillConnect/, @event) + ev.unadvise + @event = "" + @db.close + @db.open + message_loop + assert_equal("", @event); + assert_raise(WIN32OLERuntimeError) { + ev.on_event {|*args| default_handler(*args)} + } + end - def test_non_exist_event - assert_raise(RuntimeError) { - ev = WIN32OLE_EVENT.new(@ie, 'XXXX') - } - dict = WIN32OLE.new('Scripting.Dictionary') - assert_raise(RuntimeError) { - ev = WIN32OLE_EVENT.new(dict) - } - end + def test_non_exist_event + assert_raise(RuntimeError) { + ev = WIN32OLE_EVENT.new(@db, 'XXXX') + } + dict = WIN32OLE.new('Scripting.Dictionary') + assert_raise(RuntimeError) { + ev = WIN32OLE_EVENT.new(dict) + } + end - def test_on_event_with_outargs - ev = WIN32OLE_EVENT.new(@ie) - # ev.on_event_with_outargs('BeforeNavigate'){|*args| - # args.last[5] = true # Cancel = true - # } - ev.on_event_with_outargs('BeforeNavigate2'){|*args| - args.last[6] = true # Cancel = true - } - bl = @ie.locationURL - @ie.navigate("file:///#{@f}") - wait_ie - assert_equal(bl, @ie.locationURL) - end + def test_on_event_with_outargs + ev = WIN32OLE_EVENT.new(@db) + @db.connectionString = 'XXX' # set illegal connection string + assert_raise(WIN32OLERuntimeError) { + @db.open + } + ev.on_event_with_outargs('WillConnect'){|*args| + args.last[0] = CONNSTR # ConnectionString = CONNSTR + } + @db.open + message_loop + assert(true) + end - def test_on_event_hash_return - ev = WIN32OLE_EVENT.new(@ie) - ev.on_event('BeforeNavigate2'){|*args| - {:return => 1, :Cancel => true} - } - bl = @ie.locationURL - @ie.navigate("file:///#{@f}") - wait_ie - assert_equal(bl, @ie.locationURL) - end + def test_on_event_hash_return + ev = WIN32OLE_EVENT.new(@db) + ev.on_event('WillConnect'){|*args| + {:return => 1, :ConnectionString => CONNSTR} + } + @db.connectionString = 'XXX' + @db.open + assert(true) + end - def test_on_event_hash_return2 - ev = WIN32OLE_EVENT.new(@ie) - ev.on_event('BeforeNavigate2'){|*args| - {:Cancel => true} - } - bl = @ie.locationURL - @ie.navigate("file:///#{@f}") - wait_ie - assert_equal(bl, @ie.locationURL) - end + def test_on_event_hash_return2 + ev = WIN32OLE_EVENT.new(@db) + ev.on_event('WillConnect'){|*args| + {:ConnectionString => CONNSTR} + } + @db.connectionString = 'XXX' + @db.open + assert(true) + end - def test_on_event_hash_return3 - ev = WIN32OLE_EVENT.new(@ie) - ev.on_event('BeforeNavigate2'){|*args| - {'Cancel' => true} - } - bl = @ie.locationURL - @ie.navigate("file:///#{@f}") - wait_ie - assert_equal(bl, @ie.locationURL) - end - - def test_on_event_hash_return4 - ev = WIN32OLE_EVENT.new(@ie) - ev.on_event('BeforeNavigate2'){|*args| - {'return' => 2, 'Cancel' => true} - } - bl = @ie.locationURL - @ie.navigate("file:///#{@f}") - wait_ie - assert_equal(bl, @ie.locationURL) - end + def test_on_event_hash_return3 + ev = WIN32OLE_EVENT.new(@db) + ev.on_event('WillConnect'){|*args| + {'ConnectionString' => CONNSTR} + } + @db.connectionString = 'XXX' + @db.open + assert(true) + end - def test_on_event_hash_return5 - ev = WIN32OLE_EVENT.new(@ie) - ev.on_event('BeforeNavigate2'){|*args| - {6 => true} - } - bl = @ie.locationURL - @ie.navigate("file:///#{@f}") - wait_ie - assert_equal(bl, @ie.locationURL) - end + def test_on_event_hash_return4 + ev = WIN32OLE_EVENT.new(@db) + ev.on_event('WillConnect'){|*args| + {'return' => 1, 'ConnectionString' => CONNSTR} + } + @db.connectionString = 'XXX' + @db.open + assert(true) + end - def test_off_event - ev = WIN32OLE_EVENT.new(@ie) - ev.on_event{handler1} - ev.off_event - @ie.navigate("file:///#{@f}") - wait_ie - assert_equal("", @event2) - end + def test_on_event_hash_return5 + ev = WIN32OLE_EVENT.new(@db) + ev.on_event('WillConnect'){|*args| + {0 => CONNSTR} + } + @db.connectionString = 'XXX' + @db.open + assert(true) + end - def test_off_event_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 test_off_event + ev = WIN32OLE_EVENT.new(@db) + ev.on_event{handler1} + ev.off_event + @db.open + message_loop + 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 test_off_event_arg + ev = WIN32OLE_EVENT.new(@db) + ev.on_event('WillConnect'){handler1} + ev.off_event('WillConnect') + @db.open + message_loop + assert_equal("", @event2) + end - def handler1 - @event2 = "handler1" - end + def test_off_event_arg2 + ev = WIN32OLE_EVENT.new(@db) + ev.on_event('WillConnect'){handler1} + ev.on_event('ConnectComplete'){handler1} + ev.off_event('WillConnect') + @db.open + message_loop + assert_equal("handler1", @event2) + end - def handler2 - @event2 = "handler2" - end - - def handler3(url) - @event3 += url - end - - def teardown - @ie.quit - message_loop - @ie = nil - i = 0 - begin - i += 1 - File.unlink(@f) if i < 10 - rescue Errno::EACCES + def test_off_event_sym_arg + ev = WIN32OLE_EVENT.new(@db) + ev.on_event('WillConnect'){handler1} + ev.off_event(:WillConnect) + @db.open message_loop - retry + assert_equal("", @event2) end - message_loop - GC.start - message_loop - end - class Handler1 - attr_reader :val1, :val2, :val3, :val4 - def initialize - @val1 = nil - @val2 = nil - @val3 = nil - @val4 = nil + def handler1 + @event2 = "handler1" end - def onStatusTextChange(t) - @val1 = t + + def handler2 + @event2 = "handler2" end - def onProgressChange(p, pmax) - @val2 = p - @val3 = pmax + + def handler3(*arg) + @event3 += arg[0] end - def onPropertyChange(p) - @val4 = p + + def teardown + if @db && @db.state == ADO::AdStateOpen + @db.close + end + message_loop + @db = nil end - end - class Handler2 - attr_reader :ev - def initialize - @ev = "" + class Handler1 + attr_reader :val1, :val2, :val3, :val4 + def initialize + @val1 = nil + @val2 = nil + @val3 = nil + @val4 = nil + end + def onWillConnect(conn, uid, pwd, opts, stat, pconn) + @val1 = conn + end + def onConnectComplete(err, stat, pconn) + @val2 = err + @val3 = stat + end + def onInfoMessage(err, stat, pconn) + @val4 = stat + end end - def method_missing(ev, *arg) - @ev += ev + + class Handler2 + attr_reader :ev + def initialize + @ev = "" + end + def method_missing(ev, *arg) + @ev += ev + end end - end - def test_handler1 - ev = WIN32OLE_EVENT.new(@ie) - h1 = Handler1.new - ev.handler = h1 - @ie.navigate("file:///#{@f}") - wait_ie - assert(h1.val1) - assert_equal(h1.val1, ev.handler.val1) - assert(h1.val2) - assert(h1.val3) - assert(h1.val4) - end + def test_handler1 + ev = WIN32OLE_EVENT.new(@db) + h1 = Handler1.new + ev.handler = h1 + @db.open + message_loop + assert_equal(CONNSTR, h1.val1) + assert_equal(h1.val1, ev.handler.val1) + assert_equal(nil, h1.val2) + assert_equal(ADO::AdStateOpen, h1.val3) + assert_equal(ADO::AdStateOpen, h1.val4) + end - def test_handler2 - ev = WIN32OLE_EVENT.new(@ie) - h2 = Handler2.new - ev.handler = h2 - @ie.navigate("file:///#{@f}") - wait_ie - assert(h2.ev != "") + def test_handler2 + ev = WIN32OLE_EVENT.new(@db) + h2 = Handler2.new + ev.handler = h2 + @db.open + message_loop + assert(h2.ev != "") + end end - end end Index: ruby_1_9_1/test/win32ole/test_win32ole_variant_outarg.rb =================================================================== --- ruby_1_9_1/test/win32ole/test_win32ole_variant_outarg.rb (revision 0) +++ ruby_1_9_1/test/win32ole/test_win32ole_variant_outarg.rb (revision 20093) @@ -0,0 +1,69 @@ +begin + require 'win32ole' +rescue LoadError +end +require 'test/unit' +require 'fileutils' + +def ado_csv_installed? + installed = false + if defined?(WIN32OLE) + db = nil + begin + db = WIN32OLE.new('ADODB.Connection') + db.connectionString = "Driver={Microsoft Text Driver (*.txt; *.csv)};DefaultDir=.;" + db.open + db.close + db = nil + installed = true + rescue + end + end + installed +end + +if defined?(WIN32OLE_VARIANT) + dotest = ado_csv_installed? + if !dotest + STDERR.puts("\n#{__FILE__} skipped(ActiveX Data Object Library not found.)") + end + if dotest + class TestWIN32OLE_VARIANT_OUTARG < Test::Unit::TestCase + module ADO + end + CONNSTR="Driver={Microsoft Text Driver (*.txt; *.csv)};DefaultDir=.;" + def setup + FileUtils.cp(File.dirname(__FILE__) + '/orig_data.csv', './data.csv') + @db = WIN32OLE.new('ADODB.Connection') + if !defined?(ADO::AdStateOpen) + WIN32OLE.const_load(@db, ADO) + end + @db.connectionString = CONNSTR + @db.open + end + + def test_variant_ref_and_argv + sql = "INSERT INTO data.csv VALUES (5, 'E')" + @db.execute(sql, -1) + c = WIN32OLE::ARGV[1] + assert_equal(1, WIN32OLE::ARGV[1]) + obj = WIN32OLE_VARIANT.new(nil, WIN32OLE::VARIANT::VT_VARIANT|WIN32OLE::VARIANT::VT_BYREF) + assert_equal(nil, obj.value) + @db.execute(sql , obj) + assert_equal(1, obj.value) + obj = WIN32OLE_VARIANT.new(-100, WIN32OLE::VARIANT::VT_VARIANT|WIN32OLE::VARIANT::VT_BYREF) + assert_equal(-100, obj.value) + @db.execute(sql, obj) + assert_equal(1, obj.value) + end + + def teardown + if @db && @db.state == ADO::AdStateOpen + @db.close + end + File.unlink("data.csv") + end + + end + end +end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/