summaryrefslogtreecommitdiff
path: root/ruby_1_8_6/ext/win32ole/tests
diff options
context:
space:
mode:
Diffstat (limited to 'ruby_1_8_6/ext/win32ole/tests')
-rw-r--r--ruby_1_8_6/ext/win32ole/tests/oleserver.rb10
-rw-r--r--ruby_1_8_6/ext/win32ole/tests/testNIL2VTEMPTY.rb28
-rw-r--r--ruby_1_8_6/ext/win32ole/tests/testOLEEVENT.rb91
-rw-r--r--ruby_1_8_6/ext/win32ole/tests/testOLEMETHOD.rb92
-rw-r--r--ruby_1_8_6/ext/win32ole/tests/testOLEPARAM.rb65
-rw-r--r--ruby_1_8_6/ext/win32ole/tests/testOLETYPE.rb96
-rw-r--r--ruby_1_8_6/ext/win32ole/tests/testOLEVARIABLE.rb49
-rw-r--r--ruby_1_8_6/ext/win32ole/tests/testVARIANT.rb32
-rw-r--r--ruby_1_8_6/ext/win32ole/tests/testWIN32OLE.rb372
-rw-r--r--ruby_1_8_6/ext/win32ole/tests/test_ole_methods.rb36
-rw-r--r--ruby_1_8_6/ext/win32ole/tests/test_propertyputref.rb19
-rw-r--r--ruby_1_8_6/ext/win32ole/tests/test_word.rb37
-rw-r--r--ruby_1_8_6/ext/win32ole/tests/testall.rb15
13 files changed, 942 insertions, 0 deletions
diff --git a/ruby_1_8_6/ext/win32ole/tests/oleserver.rb b/ruby_1_8_6/ext/win32ole/tests/oleserver.rb
new file mode 100644
index 0000000000..bf721373e5
--- /dev/null
+++ b/ruby_1_8_6/ext/win32ole/tests/oleserver.rb
@@ -0,0 +1,10 @@
+require 'win32ole'
+def oletypelib_name(pat)
+ WIN32OLE_TYPE.typelibs.each do |lib|
+ return lib if pat =~ lib
+ end
+end
+module OLESERVER
+ MS_EXCEL_TYPELIB = oletypelib_name(/^Microsoft Excel .* Object Library$/)
+ MS_XML_TYPELIB = oletypelib_name(/^Microsoft XML/)
+end
diff --git a/ruby_1_8_6/ext/win32ole/tests/testNIL2VTEMPTY.rb b/ruby_1_8_6/ext/win32ole/tests/testNIL2VTEMPTY.rb
new file mode 100644
index 0000000000..555d35fbf3
--- /dev/null
+++ b/ruby_1_8_6/ext/win32ole/tests/testNIL2VTEMPTY.rb
@@ -0,0 +1,28 @@
+# This is test script to check that WIN32OLE should convert nil to VT_EMPTY in second try.
+# [ruby-talk:137054]
+
+require 'win32ole'
+require 'test/unit'
+
+class TestNIL2VT_EMPTY < Test::Unit::TestCase
+ def setup
+ fs = WIN32OLE.new('Scripting.FileSystemObject')
+ @path = fs.GetFolder(".").path
+ end
+ def test_openSchema
+ con = nil
+ begin
+ con = WIN32OLE.new('ADODB.Connection')
+ con.connectionString = "Provider=MSDASQL;Extended Properties="
+ con.connectionString +="\"DRIVER={Microsoft Text Driver (*.txt; *.csv)};DBQ=#{@path}\""
+ con.open
+ rescue
+ con = nil
+ end
+ if con
+ rs = con.openSchema(4, [nil,nil,"DUMMY", "TABLE"])
+ assert(rs)
+ end
+ end
+end
+
diff --git a/ruby_1_8_6/ext/win32ole/tests/testOLEEVENT.rb b/ruby_1_8_6/ext/win32ole/tests/testOLEEVENT.rb
new file mode 100644
index 0000000000..0901158642
--- /dev/null
+++ b/ruby_1_8_6/ext/win32ole/tests/testOLEEVENT.rb
@@ -0,0 +1,91 @@
+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
+
diff --git a/ruby_1_8_6/ext/win32ole/tests/testOLEMETHOD.rb b/ruby_1_8_6/ext/win32ole/tests/testOLEMETHOD.rb
new file mode 100644
index 0000000000..390c9999f8
--- /dev/null
+++ b/ruby_1_8_6/ext/win32ole/tests/testOLEMETHOD.rb
@@ -0,0 +1,92 @@
+# You need RubyUnit and MS Excel and MSI to run this test script
+
+require 'rubyunit'
+
+require 'win32ole'
+require 'oleserver'
+
+class TestOLEMETHOD < RUNIT::TestCase
+ include OLESERVER
+ def setup
+ @excel_app = WIN32OLE_TYPE.new(MS_EXCEL_TYPELIB, 'Application')
+ end
+ def test_s_new
+ m = WIN32OLE_METHOD.new(@excel_app, 'Quit')
+ assert_instance_of(WIN32OLE_METHOD, m)
+ m = WIN32OLE_METHOD.new(@excel_app, 'WorkbookOpen')
+ assert_instance_of(WIN32OLE_METHOD, m)
+ m = WIN32OLE_METHOD.new(@excel_app, 'workbookopen')
+ assert_instance_of(WIN32OLE_METHOD, m)
+ end
+ def test_name
+ m = WIN32OLE_METHOD.new(@excel_app, 'Quit')
+ assert_equal('Quit', m.name)
+ end
+ def test_to_s
+ m = WIN32OLE_METHOD.new(@excel_app, 'Quit')
+ assert_equal('Quit', "#{m}")
+ end
+ def test_return_type
+ m = WIN32OLE_METHOD.new(@excel_app, 'ActiveCell')
+ assert_equal('Range', m.return_type)
+ m = WIN32OLE_METHOD.new(@excel_app, 'ActivePrinter')
+ assert_equal('BSTR', m.return_type)
+ end
+ def test_return_vtype
+ m = WIN32OLE_METHOD.new(@excel_app, 'ActiveCell')
+ assert_equal(WIN32OLE::VARIANT::VT_PTR, m.return_vtype)
+ m = WIN32OLE_METHOD.new(@excel_app, 'ActivePrinter')
+ assert_equal(WIN32OLE::VARIANT::VT_BSTR, m.return_vtype)
+ end
+ def test_return_type_detail
+ m = WIN32OLE_METHOD.new(@excel_app, 'ActiveCell')
+ assert_equal(['PTR', 'USERDEFINED', 'Range'], m.return_type_detail)
+ m = WIN32OLE_METHOD.new(@excel_app, 'ActivePrinter')
+ assert_equal(['BSTR'], m.return_type_detail)
+ end
+
+ def test_invoke_kind
+ m = WIN32OLE_METHOD.new(@excel_app, 'ActiveCell')
+ assert_equal('PROPERTYGET', m.invoke_kind)
+ end
+ def test_visible
+ m = WIN32OLE_METHOD.new(@excel_app, 'ActiveCell')
+ assert(m.visible?)
+ m = WIN32OLE_METHOD.new(@excel_app, 'AddRef')
+ assert(!m.visible?)
+ end
+ def test_event
+ m = WIN32OLE_METHOD.new(@excel_app, 'WorkbookOpen')
+ assert(m.event?)
+ m = WIN32OLE_METHOD.new(@excel_app, 'ActiveCell')
+ assert(!m.event?)
+ end
+ def test_event_interface
+ m = WIN32OLE_METHOD.new(@excel_app, 'WorkbookOpen')
+ assert_equal('AppEvents', m.event_interface)
+ m = WIN32OLE_METHOD.new(@excel_app, 'ActiveCell')
+ assert_nil(m.event_interface)
+ end
+ def test_helpstring
+ domdoc = WIN32OLE_TYPE.new(MS_XML_TYPELIB, 'DOMDocument')
+ m = WIN32OLE_METHOD.new(domdoc, 'abort')
+ assert_equal('abort an asynchronous download', m.helpstring)
+ end
+ def test_helpfile
+ m = WIN32OLE_METHOD.new(@excel_app, 'ActiveCell')
+ assert_match(/VBAXL.*\.(HLP|CHM)$/i, m.helpfile)
+ end
+ def test_helpcontext
+ m = WIN32OLE_METHOD.new(@excel_app, 'ActiveCell')
+ assert(m.helpcontext > 0)
+ end
+ def test_offset_vtbl
+ m = WIN32OLE_METHOD.new(@excel_app, 'QueryInterface')
+ assert_equal(0, m.offset_vtbl)
+ end
+ def test_dispid
+ tobj = WIN32OLE_TYPE.new('Microsoft Shell Controls And Automation', 'FolderItem2')
+ method = WIN32OLE_METHOD.new(tobj, 'InvokeVerb')
+ assert_equal(1610743824, method.dispid)
+ end
+end
diff --git a/ruby_1_8_6/ext/win32ole/tests/testOLEPARAM.rb b/ruby_1_8_6/ext/win32ole/tests/testOLEPARAM.rb
new file mode 100644
index 0000000000..4014fadbfc
--- /dev/null
+++ b/ruby_1_8_6/ext/win32ole/tests/testOLEPARAM.rb
@@ -0,0 +1,65 @@
+# You need RubyUnit and MS Excel and MSI to run this test script
+
+require 'rubyunit'
+
+require 'win32ole'
+require 'oleserver'
+
+class TestOLEPARAM < RUNIT::TestCase
+ include OLESERVER
+ def test_name
+ classes = WIN32OLE_TYPE.ole_classes(MS_EXCEL_TYPELIB)
+ sh = classes.find {|c| c.name == 'Worksheet'}
+ saveas = sh.ole_methods.find {|m| m.name == 'SaveAs'}
+ param_names = saveas.params.collect{|p| p.name}
+ assert(param_names.size > 0)
+ assert(param_names.include?('Filename'))
+ end
+ def test_to_s
+ classes = WIN32OLE_TYPE.ole_classes(MS_EXCEL_TYPELIB)
+ sh = classes.find {|c| c.name == 'Worksheet'}
+ saveas = sh.ole_methods.find {|m| m.name == 'SaveAs'}
+ param_names = saveas.params.collect{|p| "#{p}"}
+ assert(param_names.include?('Filename'))
+ end
+ def test_ole_type
+ classes = WIN32OLE_TYPE.ole_classes(MS_EXCEL_TYPELIB)
+ methods = classes.find {|c| c.name == 'Worksheet'}.ole_methods
+ f = methods.find {|m| m.name == 'SaveAs'}
+ assert_equal('BSTR', f.params[0].ole_type)
+ methods = classes.find {|c| c.name == 'Workbook'}.ole_methods
+ f = methods.find {|m| m.name == 'SaveAs'}
+ assert_equal('XlSaveAsAccessMode', f.params[6].ole_type)
+ end
+ def test_ole_type_detail
+ classes = WIN32OLE_TYPE.ole_classes(MS_EXCEL_TYPELIB)
+ methods = classes.find {|c| c.name == 'Worksheet'}.ole_methods
+ f = methods.find {|m| m.name == 'SaveAs'}
+ assert_equal(['BSTR'], f.params[0].ole_type_detail)
+ methods = classes.find {|c| c.name == 'Workbook'}.ole_methods
+ f = methods.find {|m| m.name == 'SaveAs'}
+ assert_equal(['USERDEFINED', 'XlSaveAsAccessMode'], f.params[6].ole_type_detail)
+ end
+ def test_input
+ classes = WIN32OLE_TYPE.ole_classes(MS_EXCEL_TYPELIB)
+ methods = classes.find {|c| c.name == 'Worksheet'}.ole_methods
+ f = methods.find {|m| m.name == 'SaveAs'}
+ assert(f.params[0].input?)
+ end
+
+ def test_output
+ classes = WIN32OLE_TYPE.ole_classes(MS_EXCEL_TYPELIB)
+ methods = classes.find {|c| c.name == 'Worksheet'}.ole_methods
+ f = methods.find {|m| m.name == 'SaveAs'}
+ assert(!f.params[0].output?)
+ end
+ def test_optional
+ classes = WIN32OLE_TYPE.ole_classes(MS_EXCEL_TYPELIB)
+ methods = classes.find {|c| c.name == 'Worksheet'}.ole_methods
+ f = methods.find {|m| m.name == 'SaveAs'}
+ assert(!f.params[0].optional?)
+ methods = classes.find {|c| c.name == 'Workbook'}.ole_methods
+ f = methods.find {|m| m.name == 'SaveAs'}
+ assert(f.params[0].optional?)
+ end
+end
diff --git a/ruby_1_8_6/ext/win32ole/tests/testOLETYPE.rb b/ruby_1_8_6/ext/win32ole/tests/testOLETYPE.rb
new file mode 100644
index 0000000000..d4eb1146e1
--- /dev/null
+++ b/ruby_1_8_6/ext/win32ole/tests/testOLETYPE.rb
@@ -0,0 +1,96 @@
+# You need RubyUnit and MS Excel and MSI to run this test script
+
+require 'rubyunit'
+
+require 'win32ole'
+require 'oleserver'
+
+class TestOLETYPE < RUNIT::TestCase
+ include OLESERVER
+ def test_s_new
+ type = WIN32OLE_TYPE.new(MS_EXCEL_TYPELIB, 'Application')
+ assert_instance_of(WIN32OLE_TYPE, type)
+ end
+ def test_s_ole_classes
+ classes = WIN32OLE_TYPE.ole_classes(MS_EXCEL_TYPELIB)
+ assert(classes.size > 0)
+ end
+ def test_s_typelibs
+ libs = WIN32OLE_TYPE.typelibs
+ assert(libs.include?(MS_EXCEL_TYPELIB))
+ assert(libs.include?(MS_XML_TYPELIB))
+ end
+ def test_s_progids
+ progids = WIN32OLE_TYPE.progids
+ assert(progids.include?('Excel.Application'))
+ end
+ def test_name
+ classes = WIN32OLE_TYPE.ole_classes(MS_EXCEL_TYPELIB)
+ class_names = classes.collect{|c|
+ c.name
+ }
+ assert(class_names.include?('Application'))
+ end
+
+ def test_class_to_s
+ classes = WIN32OLE_TYPE.ole_classes(MS_EXCEL_TYPELIB)
+ class_names = classes.collect{|c|
+ "#{c}"
+ }
+ assert(class_names.include?('Application'))
+ end
+
+ def test_ole_type
+ classes = WIN32OLE_TYPE.ole_classes(MS_EXCEL_TYPELIB)
+ app = classes.find {|c| c.name == 'Application'}
+ assert_equal('Class', app.ole_type)
+ app = classes.find {|c| c.name == '_Application'}
+ assert_equal('Dispatch', app.ole_type)
+ end
+ def test_typekind
+ classes = WIN32OLE_TYPE.ole_classes(MS_EXCEL_TYPELIB)
+ app = classes.find {|c| c.name == 'Application'}
+ assert_equal(5, app.typekind)
+ end
+ def test_visible
+ classes = WIN32OLE_TYPE.ole_classes(MS_EXCEL_TYPELIB)
+ app = classes.find {|c| c.name == 'Application'}
+ assert(app.visible?)
+ app = classes.find {|c| c.name == 'IAppEvents'}
+ assert(!app.visible?)
+ end
+ def test_src_type
+ classes = WIN32OLE_TYPE.ole_classes(MS_XML_TYPELIB)
+ domnode = classes.find {|c| c.name == 'DOMNodeType'}
+ assert_equal('tagDOMNodeType', domnode.src_type)
+ end
+ def test_helpstring
+ classes = WIN32OLE_TYPE.ole_classes(MS_XML_TYPELIB)
+ domdoc = classes.find {|c| c.name == 'DOMDocument'}
+ assert_equal('W3C-DOM XML Document', domdoc.helpstring)
+ end
+ def test_variables
+ classes = WIN32OLE_TYPE.ole_classes(MS_EXCEL_TYPELIB)
+ xlchart = classes.find {|c| c.name == 'XlChartType'}
+ assert(xlchart.variables.size > 0)
+ end
+ def test_ole_methods
+ classes = WIN32OLE_TYPE.ole_classes(MS_EXCEL_TYPELIB)
+ worksheet = classes.find {|c| c.name == 'Worksheet'}
+ assert(worksheet.ole_methods.size > 0)
+ end
+ def test_helpfile
+ classes = WIN32OLE_TYPE.ole_classes(MS_EXCEL_TYPELIB)
+ worksheet = classes.find {|c| c.name == 'Worksheet'}
+ assert_match(/VBAXL.*\.(CHM|HLP)$/, worksheet.helpfile)
+ end
+ def test_helpcontext
+ classes = WIN32OLE_TYPE.ole_classes(MS_EXCEL_TYPELIB)
+ worksheet = classes.find {|c| c.name == 'Worksheet'}
+ assert_equal(131088, worksheet.helpcontext)
+ end
+ def test_to_s
+ type = WIN32OLE_TYPE.new(MS_EXCEL_TYPELIB, 'Application')
+ assert_equal("Application", "#{type}");
+ end
+end
diff --git a/ruby_1_8_6/ext/win32ole/tests/testOLEVARIABLE.rb b/ruby_1_8_6/ext/win32ole/tests/testOLEVARIABLE.rb
new file mode 100644
index 0000000000..b4bb0b57d9
--- /dev/null
+++ b/ruby_1_8_6/ext/win32ole/tests/testOLEVARIABLE.rb
@@ -0,0 +1,49 @@
+# You need RubyUnit and MS Excel and MSI to run this test script
+
+require 'rubyunit'
+
+require 'win32ole'
+require 'oleserver'
+
+class TestOLEVARIABLE < RUNIT::TestCase
+ include OLESERVER
+ def test_name
+ classes = WIN32OLE_TYPE.ole_classes(MS_EXCEL_TYPELIB)
+ chart = classes.find {|c| c.name == 'XlChartType'}
+ var_names = chart.variables.collect {|m| m.name}
+ assert(var_names.size > 0)
+ assert(var_names.include?('xl3DColumn'))
+ end
+ def test_to_s
+ classes = WIN32OLE_TYPE.ole_classes(MS_EXCEL_TYPELIB)
+ chart = classes.find {|c| c.name == 'XlChartType'}
+ var_names = chart.variables.collect {|m| "#{m}"}
+ assert(var_names.size > 0)
+ assert(var_names.include?('xl3DColumn'))
+ end
+ def test_ole_type
+ classes = WIN32OLE_TYPE.ole_classes(MS_EXCEL_TYPELIB)
+ chart = classes.find {|c| c.name == 'XlChartType'}
+ var = chart.variables.find {|m| m.name == 'xl3DColumn'}
+ assert_equal('INT', var.ole_type)
+ end
+ def test_ole_type_detail
+ classes = WIN32OLE_TYPE.ole_classes(MS_EXCEL_TYPELIB)
+ chart = classes.find {|c| c.name == 'XlChartType'}
+ var = chart.variables.find {|m| m.name == 'xl3DColumn'}
+ assert_equal(['INT'], var.ole_type_detail)
+ end
+
+ def test_value
+ classes = WIN32OLE_TYPE.ole_classes(MS_EXCEL_TYPELIB)
+ chart = classes.find {|c| c.name == 'XlChartType'}
+ var = chart.variables.find {|m| m.name == 'xl3DColumn'}
+ assert_equal(-4100, var.value)
+ end
+ def test_visible
+ classes = WIN32OLE_TYPE.ole_classes(MS_EXCEL_TYPELIB)
+ chart = classes.find {|c| c.name == 'XlChartType'}
+ var = chart.variables.find {|m| m.name == 'xl3DColumn'}
+ assert(var.visible?)
+ end
+end
diff --git a/ruby_1_8_6/ext/win32ole/tests/testVARIANT.rb b/ruby_1_8_6/ext/win32ole/tests/testVARIANT.rb
new file mode 100644
index 0000000000..f274778f27
--- /dev/null
+++ b/ruby_1_8_6/ext/win32ole/tests/testVARIANT.rb
@@ -0,0 +1,32 @@
+# You need RubyUnit and MS Excel and MSI to run this test script
+
+require 'rubyunit'
+
+require 'win32ole'
+
+class TestWin32OLE_VARIANT < RUNIT::TestCase
+ include WIN32OLE::VARIANT
+ def test_variant
+ assert_equal(2, VT_I2)
+ assert_equal(3, VT_I4)
+ assert_equal(4, VT_R4)
+ assert_equal(5, VT_R8)
+ assert_equal(6, VT_CY)
+ assert_equal(7, VT_DATE)
+ assert_equal(8, VT_BSTR)
+ assert_equal(9, VT_DISPATCH)
+ assert_equal(10, VT_ERROR)
+ assert_equal(11, VT_BOOL)
+ assert_equal(12, VT_VARIANT)
+ assert_equal(13, VT_UNKNOWN)
+ assert_equal(16, VT_I1)
+ assert_equal(17, VT_UI1)
+ assert_equal(18, VT_UI2)
+ assert_equal(19, VT_UI4)
+ assert_equal(22, VT_INT)
+ assert_equal(23, VT_UINT)
+ assert_equal(0x2000, VT_ARRAY)
+ assert_equal(0x4000, VT_BYREF)
+ end
+end
+
diff --git a/ruby_1_8_6/ext/win32ole/tests/testWIN32OLE.rb b/ruby_1_8_6/ext/win32ole/tests/testWIN32OLE.rb
new file mode 100644
index 0000000000..5c01507377
--- /dev/null
+++ b/ruby_1_8_6/ext/win32ole/tests/testWIN32OLE.rb
@@ -0,0 +1,372 @@
+# You need RubyUnit and MS Excel and MSI to run this test script
+
+require 'runit/testcase'
+require 'runit/cui/testrunner'
+
+require 'win32ole'
+require 'oleserver'
+
+module EXCEL_CONST
+end
+
+module CONST1
+end
+
+module CONST2
+end
+
+module CONST3
+end
+
+class TestWin32OLE < RUNIT::TestCase
+ include OLESERVER
+ def setup
+ @excel = WIN32OLE.new("Excel.Application")
+ @excel.visible = true
+ end
+ def test_s_new
+ assert_instance_of(WIN32OLE, @excel)
+ end
+ def test_s_new_DCOM
+ rexcel = WIN32OLE.new("Excel.Application", "localhost")
+ assert_instance_of(WIN32OLE, rexcel)
+ rexcel.visible = true
+ rexcel.quit
+ end
+ def test_s_new_from_clsid
+ excel = WIN32OLE.new("{00024500-0000-0000-C000-000000000046}")
+ assert_instance_of(WIN32OLE, excel)
+ excel.quit
+ exc = assert_exception(WIN32OLERuntimeError) {
+ WIN32OLE.new("{000}")
+ }
+ assert_match(/unknown OLE server: `\{000\}'/, exc.message)
+ end
+ def test_s_connect
+ excel2 = WIN32OLE.connect('Excel.Application')
+ assert_instance_of(WIN32OLE, excel2)
+ end
+
+ def test_s_const_load
+ assert(!defined?(EXCEL_CONST::XlTop))
+ WIN32OLE.const_load(@excel, EXCEL_CONST)
+ assert_equal(-4160, EXCEL_CONST::XlTop)
+
+ assert(!defined?(CONST1::XlTop))
+ WIN32OLE.const_load(MS_EXCEL_TYPELIB, CONST1)
+ assert_equal(-4160, CONST1::XlTop)
+ end
+
+ def test_s_codepage
+ assert_equal(WIN32OLE::CP_ACP, WIN32OLE.codepage)
+ end
+
+ def test_s_codepage_set
+ WIN32OLE.codepage = WIN32OLE::CP_UTF8
+ assert_equal(WIN32OLE::CP_UTF8, WIN32OLE.codepage)
+ WIN32OLE.codepage = WIN32OLE::CP_ACP
+ end
+
+ def test_const_CP_ACP
+ assert_equal(0, WIN32OLE::CP_ACP)
+ end
+
+ def test_const_CP_OEMCP
+ assert_equal(1, WIN32OLE::CP_OEMCP)
+ end
+
+ def test_const_CP_MACCP
+ assert_equal(2, WIN32OLE::CP_MACCP)
+ end
+
+ def test_const_CP_THREAD_ACP
+ assert_equal(3, WIN32OLE::CP_THREAD_ACP)
+ end
+
+ def test_const_CP_SYMBOL
+ assert_equal(42, WIN32OLE::CP_SYMBOL)
+ end
+
+ def test_const_CP_UTF7
+ assert_equal(65000, WIN32OLE::CP_UTF7)
+ end
+
+ def test_const_CP_UTF8
+ assert_equal(65001, WIN32OLE::CP_UTF8)
+ end
+
+ def test_s_codepage_changed
+ book = @excel.workbooks.add
+ sheet = book.worksheets(1)
+ begin
+ WIN32OLE.codepage = WIN32OLE::CP_UTF8
+ sheet.range("A1").value = [0x3042].pack("U*")
+ val = sheet.range("A1").value
+ assert_equal("\343\201\202", val)
+ WIN32OLE.codepage = WIN32OLE::CP_ACP
+ val = sheet.range("A1").value
+ assert_equal("\202\240", val)
+ ensure
+ book.saved = true
+ end
+ end
+
+ def test_get_win32ole_object
+ workbooks = @excel.Workbooks;
+ assert_instance_of(WIN32OLE, workbooks)
+ end
+ def test_each
+ workbooks = @excel.Workbooks
+ assert_no_exception {
+ i = 0;
+ workbooks.each do |workbook|
+ print i += 1
+ end
+ }
+ workbooks.add
+ workbooks.add
+ i = 0
+ workbooks.each do |workbook|
+ i+=1
+ end
+ assert_equal(2, i)
+ workbooks.each do |workbook|
+ workbook.saved = true
+ end
+ end
+ def test_setproperty_bracket
+ book = @excel.workbooks.add
+ sheet = book.worksheets(1)
+ begin
+ sheet.range("A1")['Value'] = 10
+ assert_equal(10, sheet.range("A1").value)
+ sheet['Cells', 1, 2] = 10
+ assert_equal(10, sheet.range("B1").value)
+ assert_equal(10, sheet['Cells', 1, 2].value)
+ ensure
+ book.saved = true
+ end
+ end
+ def test_convert_bignum
+ book = @excel.workbooks.add
+ sheet = book.worksheets(1)
+ begin
+ sheet.range("A1").value = 999999999
+ sheet.range("A2").value = 9999999999
+ sheet.range("A3").value = "=A1*10 + 9"
+ assert_equal(9999999999, sheet.range("A2").value)
+ assert_equal(9999999999, sheet.range("A3").value)
+
+ ensure
+ book.saved = true
+ end
+ end
+
+ def test_ole_invoke_with_named_arg
+ book = @excel.workbooks.add
+ sheets = book.worksheets
+ sheet = book.worksheets(1)
+ num = sheets.count
+ begin
+ sheets.add({'count' => 2, 'after'=>sheet})
+ assert_equal(2, sheets.count - num);
+ ensure
+ book.saved = true
+ end
+ end
+
+ def test_ole_invoke_with_named_arg_last
+ book = @excel.workbooks.add
+ sheets = book.worksheets
+ sheet = book.worksheets(1)
+ num = sheets.count
+ begin
+ sheets.add(sheet, {'count' => 2})
+ assert_equal(2, sheets.count - num);
+ ensure
+ book.saved = true
+ end
+ end
+
+ def test_setproperty
+ @excel.setproperty('Visible', false)
+ assert_equal(false, @excel.Visible)
+ @excel.setproperty('Visible', true)
+ assert_equal(true, @excel.Visible)
+ book = @excel.workbooks.add
+ sheet = book.worksheets(1)
+ begin
+ sheet.setproperty('Cells', 1, 2, 10)
+ assert_equal(10, sheet.range("B1").value)
+ ensure
+ book.saved = true
+ end
+ end
+ def test_no_exist_property
+ isok = false
+ begin
+ @excel.unknown_prop = 1
+ rescue WIN32OLERuntimeError
+ isok = true
+ end
+ assert(isok)
+
+ isok = false
+ begin
+ @excel['unknown_prop'] = 2
+ rescue WIN32OLERuntimeError
+ isok = true
+ end
+ assert(isok)
+ end
+
+ def test_setproperty_with_equal
+ book = @excel.workbooks.add
+ sheet = book.worksheets(1)
+ begin
+ sheet.range("B1").value = 10
+ assert_equal(10, sheet.range("B1").value)
+ sheet.range("C1:D1").value = [11, 12]
+ assert_equal(11, sheet.range("C1").value)
+ assert_equal(12, sheet.range("D1").value)
+ ensure
+ book.saved = true
+ end
+ end
+ def test_invoke
+ workbooks = @excel.invoke( 'workbooks' )
+ assert_instance_of(WIN32OLE, workbooks)
+ book = workbooks.invoke( 'add' )
+ assert_instance_of(WIN32OLE, book)
+ end
+ def test_ole_methods
+ methods = @excel.ole_methods
+ method_names = methods.collect{|m| m.name}
+ assert(method_names.include?("Quit"))
+ end
+ def test_ole_func_methods
+ methods = @excel.ole_func_methods
+ assert(methods.size > 0)
+ method_names = methods.collect{|m| m.name}
+ assert(method_names.include?("Quit"))
+ end
+ def test_ole_put_methods
+ methods = @excel.ole_put_methods
+ assert(methods.size > 0)
+ method_names = methods.collect{|m| m.name}
+ assert(method_names.include?("Visible"))
+ end
+ def test_ole_get_methods
+ methods = @excel.ole_get_methods
+ assert(methods.size > 0)
+ method_names = methods.collect{|m| m.name}
+ assert(method_names.include?("Visible"))
+ end
+ def test_ole_method_help
+ quit_info = @excel.ole_method_help("Quit")
+ assert_equal(0, quit_info.size_params)
+ assert_equal(0, quit_info.size_opt_params)
+
+ workbooks = @excel.Workbooks
+ add_info = workbooks.ole_method_help("Add")
+ assert_equal(1, add_info.size_params)
+ assert_equal(1, add_info.size_opt_params)
+ assert(add_info.params[0].input?)
+ assert(add_info.params[0].optional?)
+ assert_equal('VARIANT', add_info.params[0].ole_type)
+ end
+ def teardown
+ @excel.quit
+ @excel = nil
+ GC.start
+ end
+end
+
+class TestWin32OLE_WITH_MSI < RUNIT::TestCase
+ def setup
+ installer = WIN32OLE.new("WindowsInstaller.Installer")
+ @record = installer.CreateRecord(2)
+ end
+
+ # Sorry, this test fails.
+ # Win32OLE does not support this style to set property.
+ # Use Win32OLE#setproperty or Win32OLE#[]= .
+ # def test_invoke
+ # @record.invoke("StringData", 1, 'cccc')
+ # assert_equal('cccc', @record.StringData(1))
+ # end
+
+ def test_setproperty
+ @record.setproperty( "StringData", 1, 'dddd')
+ assert_equal('dddd', @record.StringData(1))
+ end
+ def test_bracket_equal_with_arg
+ @record[ "StringData", 1 ] = 'ffff'
+ assert_equal('ffff', @record.StringData(1))
+ end
+
+ def test__invoke
+ shell=WIN32OLE.new('Shell.Application')
+ assert_equal(shell.NameSpace(0).title, shell._invoke(0x60020002, [0], [WIN32OLE::VARIANT::VT_VARIANT]).title)
+ end
+end
+
+# ---------------------
+#
+# a subclass of Win32OLE
+# override new() and connect()
+class MyExcel<WIN32OLE
+ def MyExcel.new
+ super "Excel.Application"
+ end
+ def MyExcel.connect
+ super "Excel.Application"
+ end
+end
+
+class TestMyExcel < TestWin32OLE
+#
+# because we overrided new() and connect()
+# we need to change the test.
+# also, because the class will be different
+#
+ def setup
+ @excel = MyExcel.new
+ @excel.visible = true
+ end
+ def test_s_new
+ assert_instance_of(MyExcel, @excel)
+ end
+ def test_s_connect
+ excel2 = MyExcel.connect
+ assert_instance_of(MyExcel, excel2)
+ end
+#
+# const_load didn't like to be called twice,
+# and I don't know how to undefine something in Ruby yet
+# so, hide the test.
+#
+ private :test_s_const_load
+end
+
+if $0 == __FILE__
+ puts "Now Test Win32OLE version #{WIN32OLE::VERSION}"
+ if ARGV.size == 0
+ suite = RUNIT::TestSuite.new
+ suite.add_test(TestWin32OLE.suite)
+ suite.add_test(TestMyExcel.suite)
+ begin
+ installer = WIN32OLE.new("WindowsInstaller.Installer")
+ suite.add_test(TestWin32OLE_WITH_MSI.suite)
+ rescue
+ puts "Skip some test with MSI"
+ end
+ else
+ suite = RUNIT::TestSuite.new
+ ARGV.each do |testmethod|
+ suite.add_test(TestWin32OLE.new(testmethod))
+ end
+ end
+ RUNIT::CUI::TestRunner.quiet_mode = true
+ RUNIT::CUI::TestRunner.run(suite)
+end
diff --git a/ruby_1_8_6/ext/win32ole/tests/test_ole_methods.rb b/ruby_1_8_6/ext/win32ole/tests/test_ole_methods.rb
new file mode 100644
index 0000000000..ca1c03b010
--- /dev/null
+++ b/ruby_1_8_6/ext/win32ole/tests/test_ole_methods.rb
@@ -0,0 +1,36 @@
+#
+# This is test for [ruby-talk:196897]
+#
+begin
+ require 'win32ole'
+rescue LoadError
+end
+require "test/unit"
+
+if defined?(WIN32OLE)
+ class TestWIN32OLE_FOR_PROPERTYPUTREF < Test::Unit::TestCase
+
+ def setup
+ @obj = WIN32OLE.new('Scripting.Dictionary')
+ end
+
+ def test_ole_methods
+ x = @obj.ole_methods.select {|m|
+ m.invoke_kind == 'PROPERTYPUTREF'
+ }
+ assert(x.size > 0)
+ assert_equal(1, x.size)
+ assert_equal('Item', x[0].name)
+ end
+
+ def test_ole_put_methods
+ x = @obj.ole_put_methods.select {|m|
+ m.invoke_kind == 'PROPERTYPUTREF'
+ }
+ assert(x.size > 0)
+ assert_equal(1, x.size)
+ assert_equal('Item', x[0].name)
+ end
+
+ end
+end
diff --git a/ruby_1_8_6/ext/win32ole/tests/test_propertyputref.rb b/ruby_1_8_6/ext/win32ole/tests/test_propertyputref.rb
new file mode 100644
index 0000000000..befc35ca9c
--- /dev/null
+++ b/ruby_1_8_6/ext/win32ole/tests/test_propertyputref.rb
@@ -0,0 +1,19 @@
+require 'test/unit'
+require 'win32ole'
+
+class TestWIN32OLE_PROPERTYPUTREF < Test::Unit::TestCase
+ def setup
+ begin
+ @sapi = WIN32OLE.new('SAPI.SpVoice')
+ rescue WIN32OLERuntimeError
+ @sapi = nil
+ end
+ end
+ def test_sapi
+ if @sapi
+ new_id = @sapi.getvoices.item(2).Id
+ @sapi.voice = @sapi.getvoices.item(2)
+ assert_equal(new_id, @sapi.voice.Id)
+ end
+ end
+end
diff --git a/ruby_1_8_6/ext/win32ole/tests/test_word.rb b/ruby_1_8_6/ext/win32ole/tests/test_word.rb
new file mode 100644
index 0000000000..53a6c521ba
--- /dev/null
+++ b/ruby_1_8_6/ext/win32ole/tests/test_word.rb
@@ -0,0 +1,37 @@
+#
+# This is test for [ruby-Bugs#3237]
+#
+begin
+ require 'win32ole'
+rescue LoadError
+end
+require "test/unit"
+
+if defined?(WIN32OLE)
+ class TestWIN32OLE_WITH_WORD < Test::Unit::TestCase
+
+ def setup
+ begin
+ @obj = WIN32OLE.new('Word.Application')
+ rescue WIN32OLERuntimeError
+ @obj = nil
+ end
+ end
+
+ def test_ole_methods
+ if @obj
+ @obj.visible = true
+ @obj.wordbasic.disableAutoMacros(true)
+ assert(true)
+ end
+ end
+
+ def teardown
+ if @obj
+ @obj.quit
+ @obj = nil
+ end
+ end
+
+ end
+end
diff --git a/ruby_1_8_6/ext/win32ole/tests/testall.rb b/ruby_1_8_6/ext/win32ole/tests/testall.rb
new file mode 100644
index 0000000000..d45541f571
--- /dev/null
+++ b/ruby_1_8_6/ext/win32ole/tests/testall.rb
@@ -0,0 +1,15 @@
+require 'rubyunit'
+require 'win32ole'
+puts "Now Test Win32OLE version #{WIN32OLE::VERSION}"
+# RUNIT::CUI::TestRunner.quiet_mode = true
+require "testWIN32OLE"
+require "testOLETYPE"
+require "testOLEPARAM"
+require "testOLEMETHOD"
+require "testOLEVARIABLE"
+require "testVARIANT"
+require "testNIL2VTEMPTY"
+require "test_ole_methods.rb"
+require "test_propertyputref.rb"
+require "test_word.rb"
+# require "testOLEEVENT"