From b432bbd3aea2ed2f0a0b42232e5ee6afb7a91edb Mon Sep 17 00:00:00 2001 From: Alexey Verkhovsky Date: Fri, 6 May 2005 03:18:14 +0000 Subject: [PATCH] Slightly improved start/stop code in Watir test --- test/watir/e2e.rb | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/test/watir/e2e.rb b/test/watir/e2e.rb index af8ee4a4..d7732497 100644 --- a/test/watir/e2e.rb +++ b/test/watir/e2e.rb @@ -8,20 +8,31 @@ require(File.expand_path(File.dirname(__FILE__) + "/../../config/environment")) INSTIKI_PORT = 2501 HOME = "http://localhost:#{INSTIKI_PORT}" +class Win32API +# FIXME this should raise an error whenever an API call returns an error +# alias __original_call call +# def call(*args) +# __original_call(*args) +# last_error = Win32API.new('kernel32.dll', 'GetLastError', '', 'L').__original_call() +# raise "Win32API call to #{args.inspect} has failed with error code #{last_error}" if last_error +# end +end + class E2EInstikiTest < Test::Unit::TestCase def startup - createProcess = Win32API.new('kernel32.dll', 'CreateProcess', 'pplllllppp', 'L') - startupinfo = [ 68 ].pack('lx64') - @@instiki = [ 0,0,0,0 ].pack('llll') - createProcess.call(nil, + createProcess = + startup_info = [68].pack('lx64') + @@instiki = [0, 0, 0, 0].pack('llll') + Win32API.new('kernel32.dll', 'CreateProcess', 'pplllllppp', 'L').call( + nil, "ruby #{RAILS_ROOT}/instiki.rb --storage #{prepare_storage} " + " --port #{INSTIKI_PORT} --environment development", - 0, 0, 1, 0, 0, "c:\\", startupinfo, @@instiki) + 0, 0, 1, 0, 0, '.', startup_info, @@instiki) sleep 5 - @@ie = Watir::IE.start("http://localhost:2501") + @@ie = Watir::IE.start(HOME) setup_web setup_home_page @@ -30,16 +41,12 @@ class E2EInstikiTest < Test::Unit::TestCase end def self.shutdown + process_id = @@instiki.unpack('llll')[2] + right_to_terminate_process = 1 + handle = Win32API.new('kernel32.dll', 'OpenProcess', 'lil', 'l').call( + right_to_terminate_process, 0, process_id) + Win32API.new('kernel32.dll', 'TerminateProcess', 'll', 'L').call(handle, 0) - processid = @@instiki.unpack('llll')[2] - - openProcess = Win32API.new('kernel32.dll', 'OpenProcess', 'lil', 'l') - handle = openProcess.call(1, 0, processid) - - terminateProcess = Win32API.new('kernel32.dll', 'TerminateProcess', 'll', 'L') - terminateProcess.call(handle, 0) - - # todo this doesn't actually shut down anything @@ie.close if defined? @@ie end