aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ext/win32ole/tests/testWIN32OLE.rb275
-rw-r--r--test/win32ole/test_win32ole.rb195
-rw-r--r--test/win32ole/test_word.rb8
3 files changed, 204 insertions, 274 deletions
diff --git a/ext/win32ole/tests/testWIN32OLE.rb b/ext/win32ole/tests/testWIN32OLE.rb
index a7cc96ca72..679169d68c 100644
--- a/ext/win32ole/tests/testWIN32OLE.rb
+++ b/ext/win32ole/tests/testWIN32OLE.rb
@@ -25,76 +25,7 @@ class TestWin32OLE < RUNIT::TestCase
@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
@@ -112,41 +43,6 @@ class TestWin32OLE < RUNIT::TestCase
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)
- ensure
- book.saved = true
- end
- end
def test_convert_bignum
book = @excel.workbooks.add
sheet = book.worksheets(1)
@@ -162,138 +58,6 @@ class TestWin32OLE < RUNIT::TestCase
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_type
- tobj = @excel.ole_type
- assert_equal('_Application', tobj.name)
- end
- def test_ole_obj_help
- tobj = @excel.ole_type
- assert_equal('_Application', tobj.name)
- 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 test_ole_typelib
- tlib = @excel.ole_typelib
- assert_equal(tlib.name, MS_EXCEL_TYPELIB);
- end
-
- def test_s_create_guid
- guid = WIN32OLE.create_guid
- assert_match(/^\{[A-Z0-9]{8}\-[A-Z0-9]{4}\-[A-Z0-9]{4}\-[A-Z0-9]{4}\-[A-Z0-9]{12}/,
- guid)
- end
def teardown
@excel.quit
@@ -302,37 +66,6 @@ class TestWin32OLE < RUNIT::TestCase
end
end
-# class TestWin32OLE_WITH_MSI < RUNIT::TestCase
-class TestWin32OLE_WITH_MSI < Test::Unit::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
-
- # Win32OLE does not support this style to set property.
- # 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
# ---------------------
#
@@ -364,10 +97,4 @@ class TestMyExcel < TestWin32OLE
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
diff --git a/test/win32ole/test_win32ole.rb b/test/win32ole/test_win32ole.rb
index df7a9abfd7..17afd2a197 100644
--- a/test/win32ole/test_win32ole.rb
+++ b/test/win32ole/test_win32ole.rb
@@ -9,7 +9,29 @@ end
require 'test/unit'
if defined?(WIN32OLE)
+ module CONST1
+ end
+ module CONST2
+ end
class TestWin32OLE < Test::Unit::TestCase
+ def test_s_new_DCOM
+ rshell = WIN32OLE.new("Shell.Application")
+ assert_instance_of(WIN32OLE, rshell)
+ end
+
+ def test_s_new_from_clsid
+ shell = WIN32OLE.new("{13709620-C279-11CE-A49E-444553540000}")
+ assert_instance_of(WIN32OLE, shell)
+ exc = assert_raise(WIN32OLERuntimeError) {
+ WIN32OLE.new("{000}")
+ }
+ assert_match(/unknown OLE server: `\{000\}'/, exc.message)
+ end
+
+ # test_s_connect was moved to test_word.rb
+ # def test_s_connect
+ # end
+
def test_invoke_accept_symbol_hash_key
fso = WIN32OLE.new('Scripting.FileSystemObject')
afolder = fso.getFolder(".")
@@ -19,6 +41,94 @@ if defined?(WIN32OLE)
assert_equal(afolder.path, cfolder.path)
fso = nil
end
+
+ def test_setproperty
+ installer = WIN32OLE.new("WindowsInstaller.Installer")
+ record = installer.CreateRecord(2)
+ # this is the way to set property with argument in Win32OLE.
+ record.setproperty( "StringData", 1, 'dddd')
+ assert_equal('dddd', record.StringData(1))
+ end
+
+ def test_setproperty_equal_ended
+ dict1 = WIN32OLE.new('Scripting.Dictionary')
+ dict1.compareMode = 1
+ dict1.add("one", 1)
+ assert_equal(1, dict1.item("ONE"))
+
+ dict2 = WIN32OLE.new('Scripting.Dictionary')
+ dict2.add("one", 1)
+ assert_nil(dict2.item("ONE"))
+ assert_equal(1, dict2.item("one"))
+ end
+
+ def test_non_exist_property
+ dict = WIN32OLE.new('Scripting.Dictionary')
+ assert_raise(WIN32OLERuntimeError) {
+ dict.unknown_property = 1
+ }
+ end
+
+ def test_ole_type
+ fso = WIN32OLE.new('Scripting.FileSystemObject')
+ tobj = fso.ole_type
+ assert_match(/^IFileSystem/, tobj.name)
+ end
+
+ def test_ole_obj_help
+ fso = WIN32OLE.new('Scripting.FileSystemObject')
+ tobj = fso.ole_obj_help
+ assert_match(/^IFileSystem/, tobj.name)
+ end
+
+ def test_ole_methods
+ dict = WIN32OLE.new('Scripting.Dictionary')
+ methods = dict.ole_methods
+ mnames = methods.collect {|m|
+ m.name
+ }
+ assert(mnames.include?("Add"))
+ end
+
+ def test_ole_func_methods
+ dict = WIN32OLE.new('Scripting.Dictionary')
+ methods = dict.ole_func_methods
+ mnames = methods.collect {|m|
+ m.name
+ }
+ assert(mnames.include?("Add"))
+ end
+
+ def test_ole_put_methods
+ dict = WIN32OLE.new('Scripting.Dictionary')
+ methods = dict.ole_put_methods
+ mnames = methods.collect {|m|
+ m.name
+ }
+ assert(mnames.include?("CompareMode"))
+ end
+
+ def test_ole_get_methods
+ dict = WIN32OLE.new('Scripting.Dictionary')
+ methods = dict.ole_get_methods
+ mnames = methods.collect {|m|
+ m.name
+ }
+ assert(mnames.include?("Count"))
+ end
+
+ def test_ole_mehtod_help
+ dict = WIN32OLE.new('Scripting.Dictionary')
+ minfo = dict.ole_method_help("Add")
+ assert_equal(2, minfo.size_params)
+ end
+
+ def test_ole_typelib
+ dict = WIN32OLE.new('Scripting.Dictionary')
+ tlib = dict.ole_typelib
+ assert_equal("Microsoft Scripting Runtime", tlib.name);
+ end
+
def test_invoke_hash_key_non_str_sym
fso = WIN32OLE.new('Scripting.FileSystemObject')
begin
@@ -29,6 +139,13 @@ if defined?(WIN32OLE)
end
fso = nil
end
+
+ def test_get_win32ole_object
+ shell = WIN32OLE.new('Shell.Application')
+ folder = shell.nameSpace(0)
+ assert_instance_of(WIN32OLE, folder)
+ end
+
def test_invoke_accept_multi_hash_key
shell = WIN32OLE.new('Shell.Application')
folder = shell.nameSpace(0)
@@ -41,6 +158,41 @@ if defined?(WIN32OLE)
assert_equal(item.name, name)
end
+ def test_ole_invoke_with_named_arg_last
+ shell = WIN32OLE.new('Shell.Application')
+ folder = shell.nameSpace(0)
+ item = folder.items.item(0)
+ name = folder.getDetailsOf(item, {:iColumn => 0})
+ assert_equal(item.name, name)
+ 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
+
+ def test_s_const_load
+ assert(!defined?(CONST1::SsfWINDOWS))
+ shell=WIN32OLE.new('Shell.Application')
+ WIN32OLE.const_load(shell, CONST1)
+ assert_equal(36, CONST1::SsfWINDOWS)
+
+ assert(!defined?(CONST2::SsfWINDOWS))
+ WIN32OLE.const_load("Microsoft Shell Controls And Automation", CONST2)
+ assert_equal(36, CONST2::SsfWINDOWS)
+ end
+
+ def test_each
+ dict = WIN32OLE.new('Scripting.Dictionary')
+ dict.add("one", 1)
+ dict.add("two", 2)
+ i = 0
+ dict.keys.each do |item|
+ i += 1
+ end
+ assert_equal(2, i)
+ end
+
def test_bracket
dict = WIN32OLE.new('Scripting.Dictionary')
dict.add("foo", "FOO")
@@ -54,5 +206,48 @@ if defined?(WIN32OLE)
dict["foo"] = "BAR"
assert_equal("BAR", dict["foo"])
end
+
+ def test_s_create_guid
+ guid = WIN32OLE.create_guid
+ assert_match(/^\{[A-Z0-9]{8}\-[A-Z0-9]{4}\-[A-Z0-9]{4}\-[A-Z0-9]{4}\-[A-Z0-9]{12}/,
+ guid)
+ 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
+
end
end
diff --git a/test/win32ole/test_word.rb b/test/win32ole/test_word.rb
index 53a6c521ba..2b455c6167 100644
--- a/test/win32ole/test_word.rb
+++ b/test/win32ole/test_word.rb
@@ -26,6 +26,14 @@ if defined?(WIN32OLE)
end
end
+ def test_s_connect
+ if @obj
+ obj2 = WIN32OLE.connect("Word.Application")
+ assert_instance_of(WIN32OLE, obj2)
+ obj2.visible = true
+ end
+ end
+
def teardown
if @obj
@obj.quit