Permalink
Browse files

merge revision(s) 17827,17846:17848:

	* gc.c: add rb_during_gc(). based on a patch from arton <artonx AT
	  yahoo.co.jp> at [ruby-dev:35313].   
	* intern.h: ditto.
	* ext/win32ole/win32ole.c: avoid creating Ruby object during
	  GC. thanks to arton <artonx AT yahoo.co.jp>. [ruby-dev:35313]
	* ext/win32ole/tests: add test_win32ole_event.rb, remove
	  testOLEEVENT.rb
	* ext/win32ole/tests/testWIN32OLE.rb(test_convert_bignum):
	  fix test.


git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8_6@17924 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information...
1 parent ab62001 commit f87853336ce86ab9afc2069773cd13fe845f3ae7 @shyouhei shyouhei committed Jul 7, 2008
View
@@ -1,3 +1,21 @@
+Mon Jul 7 12:07:28 2008 Masaki Suketa <masaki.suketa@nifty.ne.jp>
+
+ * ext/win32ole/win32ole.c: avoid creating Ruby object during
+ GC. thanks to arton <artonx AT yahoo.co.jp>. [ruby-dev:35313]
+
+ * ext/win32ole/tests: add test_win32ole_event.rb, remove
+ testOLEEVENT.rb
+
+ * ext/win32ole/tests/testWIN32OLE.rb(test_convert_bignum):
+ fix test.
+
+Mon Jul 7 12:07:28 2008 Masaki Suketa <masaki.suketa@nifty.ne.jp>
+
+ * gc.c: add rb_during_gc(). based on a patch from arton <artonx AT
+ yahoo.co.jp> at [ruby-dev:35313].
+
+ * intern.h: ditto.
+
Thu Jul 3 17:15:04 2008 URABE Shyouhei <shyouhei@ruby-lang.org>
* win32/win32.c: revert r17290, requested by NAKAMURA Usaku
@@ -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
-
@@ -156,7 +156,8 @@ def test_convert_bignum
sheet.range("A3").value = "=A1*10 + 9"
assert_equal(9999999999, sheet.range("A2").value)
assert_equal(9999999999, sheet.range("A3").value)
-
+ sheet.range("A4").value = "2008/03/04"
+ assert_equal("2008/03/04 00:00:00", sheet.range("A4").value)
ensure
book.saved = true
end
@@ -0,0 +1,133 @@
+begin
+ require 'win32ole'
+rescue LoadError
+end
+require 'test/unit'
+
+if defined?(WIN32OLE_EVENT)
+ class TestWIN32OLE_EVENT < 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
+ @ie = WIN32OLE.new("InternetExplorer.Application")
+ @ie.visible = true
+ @event = ""
+ @event2 = ""
+ @event3 = ""
+ @f = create_temp_html
+ 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.navigate("file:///#{@f}")
+ while @ie.busy
+ WIN32OLE_EVENT.new(@ie, 'DWebBrowserEvents')
+ GC.start
+ sleep 0.1
+ 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.navigate("file:///#{@f}")
+ while @ie.busy
+ sleep 0.1
+ end
+ 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}")
+ while @ie.busy
+ sleep 0.1
+ end
+ assert_equal("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}")
+ while @ie.busy
+ sleep 0.1
+ 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.navigate("file:///#{@f}")
+ while @ie.busy
+ sleep 0.1
+ end
+ 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}")
+ while @ie.busy
+ sleep 0.1
+ end
+ assert_match(/BeforeNavigate/, @event)
+ ev.unadvise
+ @event = ""
+ @ie.navigate("file:///#{@f}")
+ while @ie.busy
+ sleep 0.1
+ end
+ assert_equal("", @event);
+ assert_raise(WIN32OLERuntimeError) {
+ ev.on_event {|*args| default_handler(*args)}
+ }
+ end
+
+ def handler1
+ @event2 = "handler1"
+ end
+
+ def handler2
+ @event2 = "handler2"
+ end
+
+ def handler3(url)
+ @event3 += url
+ end
+
+ def teardown
+ @ie.quit
+ @ie = nil
+ File.unlink(@f)
+ GC.start
+ end
+ end
+end
@@ -12,4 +12,5 @@
require "test_ole_methods.rb"
require "test_propertyputref.rb"
require "test_word.rb"
+require "test_win32ole_event.rb"
# require "testOLEEVENT"
Oops, something went wrong.

0 comments on commit f878533

Please sign in to comment.