ruby-changes:36840
From: suke <ko1@a...>
Date: Mon, 22 Dec 2014 21:31:59 +0900 (JST)
Subject: [ruby-changes:36840] suke:r48921 (trunk): * test/win32ole/test_win32ole_event.rb: some tests are
suke 2014-12-22 21:31:45 +0900 (Mon, 22 Dec 2014) New Revision: 48921 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=48921 Log: * test/win32ole/test_win32ole_event.rb: some tests are executed on standard Windows OS without ADO. Modified files: trunk/ChangeLog trunk/test/win32ole/test_win32ole_event.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 48920) +++ ChangeLog (revision 48921) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Mon Dec 22 21:30:16 2014 Masaki Suketa <masaki.suketa@n...> + + * test/win32ole/test_win32ole_event.rb: some tests are + executed on standard Windows OS without ADO. + Mon Dec 22 14:08:31 2014 Nobuyoshi Nakada <nobu@r...> * signal.c (received_signal): fix condition to define. Index: test/win32ole/test_win32ole_event.rb =================================================================== --- test/win32ole/test_win32ole_event.rb (revision 48920) +++ test/win32ole/test_win32ole_event.rb (revision 48921) @@ -41,6 +41,12 @@ if defined?(WIN32OLE_EVENT) https://github.com/ruby/ruby/blob/trunk/test/win32ole/test_win32ole_event.rb#L41 WIN32OLE_EVENT.new("A") } end + def test_s_new_non_exist_event + dict = WIN32OLE.new('Scripting.Dictionary') + assert_raise(RuntimeError) { + WIN32OLE_EVENT.new(dict) + } + end end class TestWIN32OLE_EVENT_SWbemSink < Test::Unit::TestCase @@ -49,6 +55,72 @@ if defined?(WIN32OLE_EVENT) https://github.com/ruby/ruby/blob/trunk/test/win32ole/test_win32ole_event.rb#L55 skip "'WbemScripting.SWbemSink' is not available" end else + def setup + @wmi = WIN32OLE.connect('winmgmts://localhost/root/cimv2') + @sws = WIN32OLE.new('WbemScripting.SWbemSink') + @event = @event1 = @event2 = "" + @sql = "SELECT * FROM __InstanceModificationEvent WITHIN 1 WHERE TargetInstance ISA 'Win32_LocalTime'" + end + + def message_loop + 2.times do + WIN32OLE_EVENT.message_loop + sleep 1 + end + end + + def default_handler(event, *args) + @event += event + end + + def handler1 + @event1 = "handler1" + end + + def test_s_new_non_exist_event + assert_raise(RuntimeError) { + WIN32OLE_EVENT.new(@sws, 'XXXXX') + } + end + + def test_s_new + obj = WIN32OLE_EVENT.new(@sws, 'ISWbemSinkEvents') + assert_instance_of(WIN32OLE_EVENT, obj) + obj = WIN32OLE_EVENT.new(@sws) + assert_instance_of(WIN32OLE_EVENT, obj) + end + + def test_s_new_loop + @wmi.ExecNotificationQueryAsync(@sws, @sql) + ev = WIN32OLE_EVENT.new(@sws) + ev.on_event {|*args| default_handler(*args)} + message_loop + 10.times do |i| + WIN32OLE_EVENT.new(@sws) + message_loop + GC.start + end + assert_match(/OnObjectReady/, @event) + end + + def test_on_event + @wmi.ExecNotificationQueryAsync(@sws, @sql) + ev = WIN32OLE_EVENT.new(@sws, 'ISWbemSinkEvents') + ev.on_event {|*args| default_handler(*args)} + message_loop + assert_match(/OnObjectReady/, @event) + end + + def test_on_event_symbol + @wmi.ExecNotificationQueryAsync(@sws, @sql) + ev = WIN32OLE_EVENT.new(@sws) + ev.on_event(:OnObjectReady) {|*args| + handler1 + } + message_loop + assert_equal("handler1", @event1) + end + end end @@ -80,40 +152,6 @@ if defined?(WIN32OLE_EVENT) https://github.com/ruby/ruby/blob/trunk/test/win32ole/test_win32ole_event.rb#L152 @event3 = "" 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_on_event - ev = WIN32OLE_EVENT.new(@db, 'ConnectionEvents') - ev.on_event {|*args| default_handler(*args)} - @db.open - message_loop - assert_match(/WillConnect/, @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_event2 ev = WIN32OLE_EVENT.new(@db, 'ConnectionEvents') ev.on_event('WillConnect') {|*args| handler1} @@ -123,15 +161,6 @@ if defined?(WIN32OLE_EVENT) https://github.com/ruby/ruby/blob/trunk/test/win32ole/test_win32ole_event.rb#L161 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_event4 ev = WIN32OLE_EVENT.new(@db, 'ConnectionEvents') ev.on_event{|*args| handler1} @@ -171,15 +200,6 @@ if defined?(WIN32OLE_EVENT) https://github.com/ruby/ruby/blob/trunk/test/win32ole/test_win32ole_event.rb#L200 } end - def test_non_exist_event - assert_raise(RuntimeError) { - WIN32OLE_EVENT.new(@db, 'XXXX') - } - dict = WIN32OLE.new('Scripting.Dictionary') - assert_raise(RuntimeError) { - WIN32OLE_EVENT.new(dict) - } - end def test_on_event_with_outargs ev = WIN32OLE_EVENT.new(@db) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/