2008-07-25 18:49:53 +04:00
|
|
|
#
|
|
|
|
# test Win32OLE avoids cfp consistency error when the exception raised
|
|
|
|
# in WIN32OLE_EVENT handler block. [ruby-dev:35450]
|
|
|
|
#
|
|
|
|
|
|
|
|
begin
|
|
|
|
require 'win32ole'
|
|
|
|
rescue LoadError
|
|
|
|
end
|
|
|
|
require 'rbconfig'
|
|
|
|
if defined?(WIN32OLE)
|
2008-08-12 08:35:13 +04:00
|
|
|
require 'mkmf'
|
|
|
|
require 'test/unit'
|
2008-07-25 18:49:53 +04:00
|
|
|
class TestErrInCallBack < Test::Unit::TestCase
|
|
|
|
def setup
|
|
|
|
@ruby = nil
|
|
|
|
if File.exist?("./" + CONFIG["RUBY_INSTALL_NAME"] + CONFIG["EXEEXT"])
|
2008-08-02 17:59:43 +04:00
|
|
|
sep = File::ALT_SEPARATOR || "/"
|
|
|
|
@ruby = "." + sep + CONFIG["RUBY_INSTALL_NAME"]
|
2008-07-25 18:49:53 +04:00
|
|
|
@iopt = $:.map {|e|
|
|
|
|
" -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')
|
2008-09-10 16:15:04 +04:00
|
|
|
@dummy_file = fso.GetTempName + ".html"
|
2008-07-25 18:49:53 +04:00
|
|
|
cfolder = fso.getFolder(".")
|
|
|
|
@str = "This is test HTML file for Win32OLE (#{Time.now})"
|
2008-09-10 16:15:04 +04:00
|
|
|
f = cfolder.CreateTextFile(@dummy_file)
|
2008-07-25 18:49:53 +04:00
|
|
|
f.writeLine("<html><body><div id='str'>#{@str}</div></body></html>")
|
|
|
|
f.close
|
2008-09-10 16:15:04 +04:00
|
|
|
@f = @dummy_file
|
|
|
|
dummy_path = cfolder.path + "\\" + @dummy_file
|
2008-07-25 18:49:53 +04:00
|
|
|
dummy_path
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_err_in_callback
|
|
|
|
if @ruby
|
2008-08-02 17:59:43 +04:00
|
|
|
cmd = "#{@ruby} -v #{@iopt} #{@script} #{@param} > test_err_in_callback.log 2>&1"
|
|
|
|
system(cmd)
|
|
|
|
str = ""
|
|
|
|
open("test_err_in_callback.log") {|ifs|
|
|
|
|
str = ifs.read
|
|
|
|
}
|
|
|
|
assert_match(/NameError/, str)
|
2008-07-25 18:49:53 +04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def ie_quit
|
2008-09-11 15:15:43 +04:00
|
|
|
WIN32OLE_EVENT.message_loop
|
2008-07-25 18:49:53 +04:00
|
|
|
sh = WIN32OLE.new('Shell.Application')
|
|
|
|
sh.windows.each do |w|
|
2008-09-10 16:15:04 +04:00
|
|
|
i = 0
|
|
|
|
begin
|
|
|
|
i = i + 1
|
2008-09-11 15:15:43 +04:00
|
|
|
next if i > 100
|
2008-09-10 16:15:04 +04:00
|
|
|
WIN32OLE_EVENT.message_loop
|
|
|
|
sleep 0.1
|
2008-09-11 15:15:43 +04:00
|
|
|
next if /#{@dummy_file}/ !~ w.locationURL
|
2008-09-10 16:15:04 +04:00
|
|
|
e = w.document.all.item("str")
|
2008-07-25 18:49:53 +04:00
|
|
|
if e && e.innerHTML == @str
|
|
|
|
w.quit
|
|
|
|
WIN32OLE_EVENT.message_loop
|
|
|
|
sleep 0.2
|
2008-09-10 16:15:04 +04:00
|
|
|
break
|
2008-07-25 18:49:53 +04:00
|
|
|
end
|
2008-09-10 16:15:04 +04:00
|
|
|
rescue
|
|
|
|
retry
|
2008-07-25 18:49:53 +04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
|
|
|
ie_quit
|
2008-08-02 17:59:43 +04:00
|
|
|
File.unlink(@f)
|
|
|
|
File.unlink("test_err_in_callback.log")
|
2008-07-25 18:49:53 +04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|