summaryrefslogtreecommitdiff
path: root/test/win32ole
diff options
context:
space:
mode:
authorsuke <suke@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-12-22 12:31:45 +0000
committersuke <suke@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-12-22 12:31:45 +0000
commit14c5bd12ad50bb98481b404e83f9cc916c4f70e5 (patch)
treef86084d5f1dc39ee05a06877ea0ec63a4df1ddb1 /test/win32ole
parent1634ac4d641fa81bbb6a2af8f8fd93be3baca820 (diff)
* 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
Diffstat (limited to 'test/win32ole')
-rw-r--r--test/win32ole/test_win32ole_event.rb124
1 files changed, 72 insertions, 52 deletions
diff --git a/test/win32ole/test_win32ole_event.rb b/test/win32ole/test_win32ole_event.rb
index 3ab7654..e08442b 100644
--- a/test/win32ole/test_win32ole_event.rb
+++ b/test/win32ole/test_win32ole_event.rb
@@ -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)