* test/win32ole/test_win32ole_event.rb: some tests are

executed on standard Windows OS without ADO.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48921 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
suke 2014-12-22 12:31:45 +00:00
Родитель 1634ac4d64
Коммит 14c5bd12ad
2 изменённых файлов: 77 добавлений и 52 удалений

Просмотреть файл

@ -1,3 +1,8 @@
Mon Dec 22 21:30:16 2014 Masaki Suketa <masaki.suketa@nifty.ne.jp>
* 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@ruby-lang.org>
* signal.c (received_signal): fix condition to define.

Просмотреть файл

@ -41,6 +41,12 @@ if defined?(WIN32OLE_EVENT)
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)
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)
@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)
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)
}
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)