diff options
Diffstat (limited to 'ext/win32ole/tests')
-rw-r--r-- | ext/win32ole/tests/testOLETYPELIB.rb | 134 | ||||
-rw-r--r-- | ext/win32ole/tests/testOLEVARIABLE.rb | 4 | ||||
-rw-r--r-- | ext/win32ole/tests/testWIN32OLE.rb | 36 | ||||
-rw-r--r-- | ext/win32ole/tests/testall.rb | 4 |
4 files changed, 150 insertions, 28 deletions
diff --git a/ext/win32ole/tests/testOLETYPELIB.rb b/ext/win32ole/tests/testOLETYPELIB.rb new file mode 100644 index 0000000000..9248ecfefb --- /dev/null +++ b/ext/win32ole/tests/testOLETYPELIB.rb @@ -0,0 +1,134 @@ +require 'test/unit' +require 'win32ole' +require 'oleserver' + +class TestOLETYPELIB < Test::Unit::TestCase + include OLESERVER + def test_exists_typelib + assert(Module.constants.include?("WIN32OLE_TYPELIB")) + end + + def test_s_new + tlib = WIN32OLE_TYPELIB.new(MS_EXCEL_TYPELIB) + end + + def test_s_new_non_exist_tlib + exception_occured = false + msg = "" + begin + tlib = WIN32OLE_TYPELIB.new('NON EXIST TYPELIB') + rescue WIN32OLERuntimeError + msg = $!.to_s + exception_occured = true + end + assert_equal("Not found type library `NON EXIST TYPELIB`", msg) + assert(exception_occured) + end + + def test_guid + tlib = WIN32OLE_TYPELIB.new(MS_EXCEL_TYPELIB) + assert_not_equal("", tlib.guid) + end + + def test_s_new_from_guid + tlib = WIN32OLE_TYPELIB.new(MS_EXCEL_TYPELIB); + guid = tlib.guid + tlib2 = WIN32OLE_TYPELIB.new(guid); + assert_equal(tlib.name, tlib2.name); + end + + def test_version + tlib = WIN32OLE_TYPELIB.new(MS_EXCEL_TYPELIB); + assert(tlib.version > 0) + end + + def test_major_version + tlib = WIN32OLE_TYPELIB.new(MS_EXCEL_TYPELIB) + assert(tlib.major_version > 0) + end + + def test_minor_version + tlib = WIN32OLE_TYPELIB.new(MS_EXCEL_TYPELIB) + assert(tlib.minor_version >= 0) + end + + def test_create_tlib_obj + ex = nil + begin + tlib1 = WIN32OLE_TYPELIB.new(MS_EXCEL_TYPELIB) + ex = WIN32OLE.new('Excel.Application') + tlib2 = ex.ole_typelib + assert_equal(tlib1.name, tlib2.name) + assert_equal(tlib1.major_version, tlib2.major_version) + assert_equal(tlib1.minor_version, tlib2.minor_version) + ensure + if ex + ex.quit + end + end + end + + def test_create_tlib_obj2 + ex = nil + begin + tlib1 = WIN32OLE_TYPELIB.new(MS_EXCEL_TYPELIB) + tlib2 = WIN32OLE_TYPELIB.new(tlib1.guid, tlib1.major_version, tlib1.minor_version) + assert_equal(tlib1.name, tlib2.name) + assert_equal(tlib1.major_version, tlib2.major_version) + assert_equal(tlib1.minor_version, tlib2.minor_version) + ensure + if ex + ex.quit + end + end + end + + def test_create_tlib_obj3 + ex = nil + begin + tlib1 = WIN32OLE_TYPELIB.new(MS_EXCEL_TYPELIB) + tlib2 = WIN32OLE_TYPELIB.new(tlib1.guid, tlib1.version) + assert_equal(tlib1.name, tlib2.name) + assert_equal(tlib1.guid, tlib2.guid) + assert_equal(tlib1.major_version, tlib2.major_version) + assert_equal(tlib1.minor_version, tlib2.minor_version) + ensure + if ex + ex.quit + end + end + end + + def test_name + tlib = WIN32OLE_TYPELIB.new(MS_EXCEL_TYPELIB) + assert_equal(MS_EXCEL_TYPELIB, tlib.name) + end + + def test_to_s + tlib = WIN32OLE_TYPELIB.new(MS_EXCEL_TYPELIB) + assert_equal(tlib.name, tlib.to_s) + end + + def test_path + tlib = WIN32OLE_TYPELIB.new(MS_EXCEL_TYPELIB) + assert(/EXCEL/ =~ tlib.path) + end + + def test_ole_classes + tlib = WIN32OLE_TYPELIB.new(MS_EXCEL_TYPELIB) + classes = tlib.ole_classes + assert(classes.instance_of?(Array)) + assert(classes.size > 0) + assert('WIN32OLE_TYPE', classes[0].class) + assert(classes.collect{|i| i.name}.include?('Workbooks')) + end + + def test_s_typelibs + tlibs = WIN32OLE_TYPELIB.typelibs + assert(tlibs.instance_of?(Array)) + assert(tlibs.size > 0) + assert('WIN32OLE_TYPELIB', tlibs[0].class) + tlibnames = tlibs.collect{|i| i.name} + tlibnames.include?('Microsoft Internet Controlls') + end +end diff --git a/ext/win32ole/tests/testOLEVARIABLE.rb b/ext/win32ole/tests/testOLEVARIABLE.rb index b4bb0b57d9..935bd24cbb 100644 --- a/ext/win32ole/tests/testOLEVARIABLE.rb +++ b/ext/win32ole/tests/testOLEVARIABLE.rb @@ -22,7 +22,9 @@ class TestOLEVARIABLE < RUNIT::TestCase assert(var_names.include?('xl3DColumn')) end def test_ole_type - classes = WIN32OLE_TYPE.ole_classes(MS_EXCEL_TYPELIB) + tlib = WIN32OLE_TYPELIB.new(MS_EXCEL_TYPELIB) + classes = tlib.ole_classes + # 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) diff --git a/ext/win32ole/tests/testWIN32OLE.rb b/ext/win32ole/tests/testWIN32OLE.rb index c8df97f6f7..7611da84ac 100644 --- a/ext/win32ole/tests/testWIN32OLE.rb +++ b/ext/win32ole/tests/testWIN32OLE.rb @@ -1,7 +1,8 @@ # You need RubyUnit and MS Excel and MSI to run this test script +require 'test/unit' require 'runit/testcase' -require 'runit/cui/testrunner' +# require 'runit/cui/testrunner' require 'win32ole' require 'oleserver' @@ -40,7 +41,7 @@ class TestWin32OLE < RUNIT::TestCase exc = assert_exception(WIN32OLERuntimeError) { WIN32OLE.new("{000}") } - assert_match(/Unknown OLE server : `\{000\}'/, exc.message) + assert_match(/Unknown OLE server `\{000\}'/, exc.message) end def test_s_connect excel2 = WIN32OLE.connect('Excel.Application') @@ -220,6 +221,12 @@ class TestWin32OLE < RUNIT::TestCase 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 teardown @excel.quit @excel = nil @@ -227,7 +234,8 @@ class TestWin32OLE < RUNIT::TestCase end end -class TestWin32OLE_WITH_MSI < RUNIT::TestCase +# class TestWin32OLE_WITH_MSI < RUNIT::TestCase +class TestWin32OLE_WITH_MSI < Test::Unit::TestCase def setup installer = WIN32OLE.new("WindowsInstaller.Installer") @record = installer.CreateRecord(2) @@ -288,25 +296,3 @@ class TestMyExcel < TestWin32OLE # 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/ext/win32ole/tests/testall.rb b/ext/win32ole/tests/testall.rb index 17bae2c810..a943ae09b9 100644 --- a/ext/win32ole/tests/testall.rb +++ b/ext/win32ole/tests/testall.rb @@ -1,11 +1,11 @@ -require 'rubyunit' +require 'test/unit' 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 "testOLETYPELIB" # require "testOLEEVENT" |