summaryrefslogtreecommitdiff
path: root/jni/ruby/test/win32ole
diff options
context:
space:
mode:
authorJari Vetoniemi <jari.vetoniemi@indooratlas.com>2020-03-16 18:49:26 +0900
committerJari Vetoniemi <jari.vetoniemi@indooratlas.com>2020-03-30 00:39:06 +0900
commitfcbf63e62c627deae76c1b8cb8c0876c536ed811 (patch)
tree64cb17de3f41a2b6fef2368028fbd00349946994 /jni/ruby/test/win32ole
Fresh start
Diffstat (limited to 'jni/ruby/test/win32ole')
-rw-r--r--jni/ruby/test/win32ole/err_in_callback.rb9
-rw-r--r--jni/ruby/test/win32ole/orig_data.csv5
-rw-r--r--jni/ruby/test/win32ole/test_err_in_callback.rb55
-rw-r--r--jni/ruby/test/win32ole/test_folderitem2_invokeverb.rb65
-rw-r--r--jni/ruby/test/win32ole/test_nil2vtempty.rb36
-rw-r--r--jni/ruby/test/win32ole/test_ole_methods.rb36
-rw-r--r--jni/ruby/test/win32ole/test_propertyputref.rb30
-rw-r--r--jni/ruby/test/win32ole/test_thread.rb33
-rw-r--r--jni/ruby/test/win32ole/test_win32ole.rb564
-rw-r--r--jni/ruby/test/win32ole/test_win32ole_event.rb391
-rw-r--r--jni/ruby/test/win32ole/test_win32ole_method.rb146
-rw-r--r--jni/ruby/test/win32ole/test_win32ole_param.rb106
-rw-r--r--jni/ruby/test/win32ole/test_win32ole_record.rb313
-rw-r--r--jni/ruby/test/win32ole/test_win32ole_type.rb249
-rw-r--r--jni/ruby/test/win32ole/test_win32ole_typelib.rb116
-rw-r--r--jni/ruby/test/win32ole/test_win32ole_variable.rb61
-rw-r--r--jni/ruby/test/win32ole/test_win32ole_variant.rb725
-rw-r--r--jni/ruby/test/win32ole/test_win32ole_variant_m.rb35
-rw-r--r--jni/ruby/test/win32ole/test_win32ole_variant_outarg.rb68
-rw-r--r--jni/ruby/test/win32ole/test_word.rb71
20 files changed, 3114 insertions, 0 deletions
diff --git a/jni/ruby/test/win32ole/err_in_callback.rb b/jni/ruby/test/win32ole/err_in_callback.rb
new file mode 100644
index 0000000..fabb7be
--- /dev/null
+++ b/jni/ruby/test/win32ole/err_in_callback.rb
@@ -0,0 +1,9 @@
+require 'win32ole'
+db = WIN32OLE.new('ADODB.Connection')
+db.connectionString = "Driver={Microsoft Text Driver (*.txt; *.csv)};DefaultDir=.;"
+ev = WIN32OLE_EVENT.new(db)
+ev.on_event('WillConnect') {|*args|
+ foo
+}
+db.open
+WIN32OLE_EVENT.message_loop
diff --git a/jni/ruby/test/win32ole/orig_data.csv b/jni/ruby/test/win32ole/orig_data.csv
new file mode 100644
index 0000000..3931c6a
--- /dev/null
+++ b/jni/ruby/test/win32ole/orig_data.csv
@@ -0,0 +1,5 @@
+ID,VALUE
+1,"A"
+2,"B"
+3,"C"
+4,"B"
diff --git a/jni/ruby/test/win32ole/test_err_in_callback.rb b/jni/ruby/test/win32ole/test_err_in_callback.rb
new file mode 100644
index 0000000..cae6d49
--- /dev/null
+++ b/jni/ruby/test/win32ole/test_err_in_callback.rb
@@ -0,0 +1,55 @@
+#
+# test Win32OLE avoids cfp consistency error when the exception raised
+# in WIN32OLE_EVENT handler block. [ruby-dev:35450]
+#
+
+begin
+ require 'win32ole'
+rescue LoadError
+end
+if defined?(WIN32OLE)
+ require 'mkmf'
+ require 'pathname'
+ require 'test/unit'
+ require 'tmpdir'
+ class TestErrInCallBack < Test::Unit::TestCase
+ def setup
+ @ruby = nil
+ if File.exist?("./" + CONFIG["RUBY_INSTALL_NAME"] + CONFIG["EXEEXT"])
+ sep = File::ALT_SEPARATOR || "/"
+ @ruby = "." + sep + CONFIG["RUBY_INSTALL_NAME"]
+ cwd = Pathname.new(File.expand_path('.'))
+ @iopt = $:.map {|e|
+ " -I " + (Pathname.new(e).relative_path_from(cwd).to_s rescue e)
+ }.join("")
+ script = File.join(File.dirname(__FILE__), "err_in_callback.rb")
+ @script = Pathname.new(script).relative_path_from(cwd).to_s rescue script
+ end
+ end
+
+ def available_adodb?
+ begin
+ WIN32OLE.new('ADODB.Connection')
+ rescue WIN32OLERuntimeError
+ return false
+ end
+ return true
+ end
+
+ def test_err_in_callback
+ skip "'ADODB.Connection' is not available" unless available_adodb?
+ if @ruby
+ Dir.mktmpdir do |tmpdir|
+ logfile = File.join(tmpdir, "test_err_in_callback.log")
+ cmd = "#{@ruby} -v #{@iopt} #{@script} > #{logfile.gsub(%r(/), '\\')} 2>&1"
+ system(cmd)
+ str = ""
+ open(logfile) {|ifs|
+ str = ifs.read
+ }
+ assert_match(/NameError/, str)
+ end
+ end
+ end
+ end
+end
diff --git a/jni/ruby/test/win32ole/test_folderitem2_invokeverb.rb b/jni/ruby/test/win32ole/test_folderitem2_invokeverb.rb
new file mode 100644
index 0000000..c5ec88c
--- /dev/null
+++ b/jni/ruby/test/win32ole/test_folderitem2_invokeverb.rb
@@ -0,0 +1,65 @@
+#
+# This script check that Win32OLE can execute InvokeVerb method of FolderItem2.
+#
+
+begin
+ require 'win32ole'
+rescue LoadError
+end
+require 'test/unit'
+
+if defined?(WIN32OLE)
+ class TestInvokeVerb < Test::Unit::TestCase
+ def setup
+ # make dummy file for InvokeVerb test.
+ @fso = WIN32OLE.new('Scripting.FileSystemObject')
+ dummy_file = @fso.GetTempName
+ @cfolder = @fso.getFolder(".")
+ f = @cfolder.CreateTextFile(dummy_file)
+ f.close
+ @dummy_path = @cfolder.path + "\\" + dummy_file
+
+ shell=WIN32OLE.new('Shell.Application')
+ @nsp = shell.NameSpace(@cfolder.path)
+ @fi2 = @nsp.parseName(dummy_file)
+ end
+
+ def find_link(path)
+ arlink = []
+ @cfolder.files.each do |f|
+ if /\.lnk$/ =~ f.path
+ linkinfo = @nsp.parseName(f.name).getLink
+ arlink.push f if linkinfo.path == path
+ end
+ end
+ arlink
+ end
+
+ def test_invokeverb
+ # in Windows Vista (not tested), Windows 7
+ # The verb must be in English.
+ # Creating Shortcut is "Link"
+ links = find_link(@dummy_path)
+ assert_equal(0, links.size)
+
+ # Now create shortcut to @dummy_path
+ arg = WIN32OLE_VARIANT.new("Link")
+ @fi2.InvokeVerb(arg)
+
+ # Now search shortcut to @dummy_path
+ links = find_link(@dummy_path)
+ assert_equal(1, links.size)
+ @lpath = links[0].path
+ end
+
+ def teardown
+ if @lpath
+ @fso.deleteFile(@lpath)
+ end
+ if @dummy_path
+ @fso.deleteFile(@dummy_path)
+ end
+ end
+
+ end
+end
diff --git a/jni/ruby/test/win32ole/test_nil2vtempty.rb b/jni/ruby/test/win32ole/test_nil2vtempty.rb
new file mode 100644
index 0000000..8508ecd
--- /dev/null
+++ b/jni/ruby/test/win32ole/test_nil2vtempty.rb
@@ -0,0 +1,36 @@
+# This is test script to check that WIN32OLE should convert nil to VT_EMPTY in second try.
+# [ruby-talk:137054]
+begin
+ require 'win32ole'
+rescue LoadError
+end
+require 'test/unit'
+
+if defined?(WIN32OLE)
+ 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)
+ assert_equal("_Recordset", rs.ole_type.name)
+
+ rs = con.openSchema(4, [WIN32OLE_VARIANT::Empty, WIN32OLE_VARIANT::Empty, "DUMMY", "TABLE"])
+ assert(rs)
+ assert_equal("_Recordset", rs.ole_type.name)
+ end
+ end
+ end
+end
diff --git a/jni/ruby/test/win32ole/test_ole_methods.rb b/jni/ruby/test/win32ole/test_ole_methods.rb
new file mode 100644
index 0000000..869828d
--- /dev/null
+++ b/jni/ruby/test/win32ole/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/jni/ruby/test/win32ole/test_propertyputref.rb b/jni/ruby/test/win32ole/test_propertyputref.rb
new file mode 100644
index 0000000..24459af
--- /dev/null
+++ b/jni/ruby/test/win32ole/test_propertyputref.rb
@@ -0,0 +1,30 @@
+require 'test/unit'
+begin
+ require 'win32ole'
+rescue LoadError
+end
+
+if defined?(WIN32OLE)
+ class TestWIN32OLE_PROPERTYPUTREF < Test::Unit::TestCase
+ def setup
+ begin
+ @sapi = WIN32OLE.new('SAPI.SpVoice')
+ @sv = @sapi.voice
+ rescue WIN32OLERuntimeError
+ @sapi = nil
+ end
+ end
+ def test_sapi
+ if @sapi
+ new_id = @sapi.getvoices.item(0).Id
+ @sapi.voice = @sapi.getvoices.item(0)
+ assert_equal(new_id, @sapi.voice.Id)
+ end
+ end
+ def teardown
+ if @sapi
+ @sapi.voice = @sv
+ end
+ end
+ end
+end
diff --git a/jni/ruby/test/win32ole/test_thread.rb b/jni/ruby/test/win32ole/test_thread.rb
new file mode 100644
index 0000000..56a6357
--- /dev/null
+++ b/jni/ruby/test/win32ole/test_thread.rb
@@ -0,0 +1,33 @@
+begin
+ require 'win32ole'
+rescue LoadError
+end
+require 'test/unit'
+
+if defined?(WIN32OLE)
+ class TestThread < Test::Unit::TestCase
+ #
+ # test for Bug #2618(ruby-core:27634)
+ #
+ def assert_creating_win32ole_object_in_thread(meth)
+ t = Thread.__send__(meth) {
+ WIN32OLE.new('Scripting.Dictionary')
+ }
+ assert_nothing_raised(WIN32OLERuntimeError, "[Bug #2618] Thread.#{meth}") {
+ t.join
+ }
+ end
+
+ def test_creating_win32ole_object_in_thread_new
+ assert_creating_win32ole_object_in_thread(:new)
+ end
+
+ def test_creating_win32ole_object_in_thread_start
+ assert_creating_win32ole_object_in_thread(:start)
+ end
+
+ def test_creating_win32ole_object_in_thread_fork
+ assert_creating_win32ole_object_in_thread(:fork)
+ end
+ end
+end
diff --git a/jni/ruby/test/win32ole/test_win32ole.rb b/jni/ruby/test/win32ole/test_win32ole.rb
new file mode 100644
index 0000000..b41fd59
--- /dev/null
+++ b/jni/ruby/test/win32ole/test_win32ole.rb
@@ -0,0 +1,564 @@
+# coding: us-ascii
+
+begin
+ require 'win32ole'
+rescue LoadError
+end
+require 'test/unit'
+
+if defined?(WIN32OLE)
+ module CONST1
+ end
+ module CONST2
+ end
+
+ module TestCaseForDict
+ def test_convert_bignum
+ @dict1.add("a", 9999999999)
+ @dict1.add("b", 999999999)
+ @dict1.add("c", @dict1.item("b") * 10 + 9)
+ assert_equal(9999999999, @dict1.item("a"))
+ assert_equal(9999999999, @dict1.item("c"))
+ end
+ def test_add
+ @dict1.add("a", 1000)
+ assert_equal(1000, @dict1.item("a"))
+ end
+ def test_setproperty_equal_ended
+ @dict1.compareMode = 1
+ @dict1.add("one", 1)
+ assert_equal(1, @dict1.item("ONE"))
+ @dict2.add("one", 1)
+ assert_nil(@dict2.item("ONE"))
+ assert_equal(1, @dict2.item("one"))
+ end
+ def test_non_exist_property
+ assert_raise(WIN32OLERuntimeError) {
+ @dict1.unknown_property = 1
+ }
+ end
+
+ def test_raise_message
+ exc = assert_raise(WIN32OLERuntimeError) {
+ @dict1.add
+ }
+ assert_match(/^\(in OLE method `add': \)/, exc.message) #`
+
+ exc = assert_raise(WIN32OLERuntimeError) {
+ @dict1._invoke(1, [], [])
+ }
+ assert_match(/^\(in OLE method `<dispatch id:1>': \)/, exc.message) #`
+
+ exc = assert_raise(WIN32OLERuntimeError) {
+ @dict1.compareMode = -1
+ }
+ assert_match(/^\(in setting property `compareMode': \)/, exc.message) #`
+ end
+
+ def test_no_method_error
+ exc = assert_raise(NoMethodError) {
+ @dict1.non_exist_method
+ }
+ assert_match(/non_exist_method/, exc.message)
+ end
+
+ def test_ole_methods
+ methods = @dict1.ole_methods
+ mnames = methods.collect {|m|
+ m.name
+ }
+ assert(mnames.include?("Add"))
+ end
+
+ def test_ole_func_methods
+ methods = @dict1.ole_func_methods
+ mnames = methods.collect {|m|
+ m.name
+ }
+ assert(mnames.include?("Add"))
+ end
+
+ def test_ole_put_methods
+ methods = @dict1.ole_put_methods
+ mnames = methods.collect {|m|
+ m.name
+ }
+ assert(mnames.include?("CompareMode"))
+ end
+
+ def test_ole_get_methods
+ methods = @dict1.ole_get_methods
+ mnames = methods.collect {|m|
+ m.name
+ }
+ assert(mnames.include?("Count"))
+ end
+
+ def test_ole_mehtod_help
+ minfo = @dict1.ole_method_help("Add")
+ assert_equal(2, minfo.size_params)
+ end
+
+ def test_ole_typelib
+ tlib = @dict1.ole_typelib
+ assert_equal("Microsoft Scripting Runtime", tlib.name);
+ end
+
+ def test_each
+ @dict1.add("one", 1)
+ @dict1.add("two", 2)
+ i = 0
+ @dict1.keys.each do |item|
+ i += 1
+ end
+ assert_equal(2, i)
+ end
+
+ def test_bracket
+ @dict1.add("foo", "FOO")
+ assert_equal("FOO", @dict1.item("foo"))
+ assert_equal("FOO", @dict1["foo"])
+ end
+
+ def test_bracket_equal
+ @dict1.add("foo", "FOO")
+ @dict1["foo"] = "BAR"
+ assert_equal("BAR", @dict1["foo"])
+ end
+
+ def test_bracket_with_numkey
+ @dict1.add(1, "ONE")
+ @dict1.add(2, "two")
+ assert_equal("ONE", @dict1[1])
+ @dict1[2] = "TWO"
+ assert_equal("TWO", @dict1[2])
+ end
+
+ def test_invoke_with_array
+ @dict1.add("ary1", [1,2,3])
+ assert_equal([1,2,3], @dict1["ary1"])
+
+ @dict1.add("ary2", [[1,2,"a"], [3,4,"b"]])
+ assert_equal([[1,2,"a"], [3,4,"b"]], @dict1["ary2"])
+
+ @dict1.add("ary3", [[[1]]])
+ assert_equal([[[1]]], @dict1["ary3"])
+
+ @dict1.add("ary4", [[[1], [2], [3]], [[4], [5], [6]]])
+ assert_equal([[[1],[2], [3]], [[4], [5], [6]]], @dict1["ary4"])
+ end
+ end
+
+ class TestWin32OLE < Test::Unit::TestCase
+ include TestCaseForDict
+ def setup
+ @dict1 = WIN32OLE.new('Scripting.Dictionary')
+ @dict2 = WIN32OLE.new('Scripting.Dictionary')
+ end
+ def test_s_new
+ assert_instance_of(WIN32OLE, @dict1)
+ assert_instance_of(WIN32OLE, @dict2)
+ end
+
+ def test_s_new_exc
+ assert_raise(TypeError) {
+ WIN32OLE.new(1)
+ }
+ assert_raise(TypeError) {
+ WIN32OLE.new("Scripting.Dictionary", 1)
+ }
+ end
+
+ def test_s_new_exc_svr_tainted
+ th = Thread.start {
+ $SAFE = 1
+ svr = "Scripting.Dictionary"
+ svr.taint
+ WIN32OLE.new(svr)
+ }
+ exc = assert_raise(SecurityError) {
+ th.join
+ }
+ assert_match(/insecure object creation - `Scripting.Dictionary'/, exc.message)
+ end
+
+ def test_s_new_exc_host_tainted
+ th = Thread.start {
+ $SAFE = 1
+ svr = "Scripting.Dictionary"
+ host = "localhost"
+ host.taint
+ WIN32OLE.new(svr, host)
+ }
+ exc = assert_raise(SecurityError) {
+ th.join
+ }
+ assert_match(/insecure object creation - `localhost'/, exc.message)
+ end
+
+ 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
+
+ def test_s_connect
+ obj = WIN32OLE.connect("winmgmts:")
+ assert_instance_of(WIN32OLE, obj)
+ end
+
+ def test_s_connect_exc
+ assert_raise(TypeError) {
+ WIN32OLE.connect(1)
+ }
+ end
+
+ def test_s_coonect_exc_tainted
+ th = Thread.start {
+ $SAFE = 1
+ svr = "winmgmts:"
+ svr.taint
+ WIN32OLE.connect(svr)
+ }
+ exc = assert_raise(SecurityError) {
+ th.join
+ }
+ assert_match(/insecure connection - `winmgmts:'/, exc.message)
+ end
+
+ def test_invoke_accept_symbol_hash_key
+ fso = WIN32OLE.new('Scripting.FileSystemObject')
+ afolder = fso.getFolder(".")
+ bfolder = fso.getFolder({"FolderPath" => "."})
+ cfolder = fso.getFolder({:FolderPath => "."})
+ assert_equal(afolder.path, bfolder.path)
+ 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_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_invoke_hash_key_non_str_sym
+ fso = WIN32OLE.new('Scripting.FileSystemObject')
+ begin
+ fso.getFolder({1 => "."})
+ assert(false)
+ rescue TypeError
+ assert(true)
+ 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)
+ item = folder.items.item(0)
+ name = folder.getDetailsOf(item, 0)
+ assert_equal(item.name, name)
+ name = folder.getDetailsOf({:vItem => item, :iColumn => 0})
+ assert_equal(item.name, name)
+ name = folder.getDetailsOf({"vItem" => item, :iColumn => 0})
+ 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_ole_query_interface
+ shell=WIN32OLE.new('Shell.Application')
+ assert_raise(ArgumentError) {
+ shell.ole_query_interface
+ }
+ shell2 = shell.ole_query_interface('{A4C6892C-3BA9-11D2-9DEA-00C04FB16162}')
+ assert_instance_of(WIN32OLE, shell2)
+ end
+
+ def test_ole_respond_to
+ fso = WIN32OLE.new('Scripting.FileSystemObject')
+ assert(fso.ole_respond_to?('getFolder'))
+ assert(fso.ole_respond_to?('GETFOLDER'))
+ assert(fso.ole_respond_to?(:getFolder))
+ assert(!fso.ole_respond_to?('XXXXX'))
+ assert_raise(TypeError) {
+ assert_raise(fso.ole_respond_to?(1))
+ }
+ end
+
+ def test_invoke
+ fso = WIN32OLE.new('Scripting.FileSystemObject')
+ assert(fso.invoke(:getFolder, "."))
+ assert(fso.invoke('getFolder', "."))
+ 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_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
+
+ #
+ # WIN32OLE.codepage is initialized according to Encoding.default_external.
+ #
+ # def test_s_codepage
+ # assert_equal(WIN32OLE::CP_ACP, WIN32OLE.codepage)
+ # end
+
+ def test_s_codepage_set
+ cp = WIN32OLE.codepage
+ WIN32OLE.codepage = WIN32OLE::CP_UTF8
+ assert_equal(WIN32OLE::CP_UTF8, WIN32OLE.codepage)
+ WIN32OLE.codepage = cp
+ end
+
+ def test_s_codepage_changed
+ cp = WIN32OLE.codepage
+ fso = WIN32OLE.new("Scripting.FileSystemObject")
+ fname = fso.getTempName
+ begin
+ obj = WIN32OLE_VARIANT.new([0x3042].pack("U*").force_encoding("UTF-8"))
+ WIN32OLE.codepage = WIN32OLE::CP_UTF8
+ assert_equal("\xE3\x81\x82".force_encoding("CP65001"), obj.value)
+
+ begin
+ WIN32OLE.codepage = 932 # Windows-31J
+ rescue WIN32OLERuntimeError
+ end
+ if (WIN32OLE.codepage == 932)
+ assert_equal("\x82\xA0".force_encoding("CP932"), obj.value)
+ end
+
+ begin
+ WIN32OLE.codepage = 20932 # MS EUC-JP
+ rescue WIN32OLERuntimeError
+ end
+ if (WIN32OLE.codepage == 20932)
+ assert_equal("\xA4\xA2".force_encoding("CP20932"), obj.value)
+ end
+
+ WIN32OLE.codepage = cp
+ file = fso.opentextfile(fname, 2, true)
+ test_str = [0x3042].pack("U*").encode("UTF-16LE")
+ begin
+ file.write test_str.force_encoding("UTF-16")
+ ensure
+ file.close
+ end
+ str = ""
+ open(fname, "r:ascii-8bit") {|ifs|
+ str = ifs.read
+ }
+ assert_equal(test_str.force_encoding("ascii-8bit"), str)
+
+ # This test fail if codepage 20932 (euc) is not installed.
+ begin
+ WIN32OLE.codepage = 20932
+ rescue WIN32OLERuntimeError
+ end
+ if (WIN32OLE.codepage == 20932)
+ WIN32OLE.codepage = cp
+ file = fso.opentextfile(fname, 2, true)
+ begin
+ file.write [164, 162].pack("c*").force_encoding("UTF-16")
+ ensure
+ file.close
+ end
+ open(fname, "r:ascii-8bit") {|ifs|
+ str = ifs.read
+ }
+ assert_equal("\244\242", str)
+ end
+
+ ensure
+ WIN32OLE.codepage = cp
+ if (File.exist?(fname))
+ File.unlink(fname)
+ end
+ end
+ end
+
+ def test_cp51932
+ cp = WIN32OLE.codepage
+ begin
+ obj = WIN32OLE_VARIANT.new([0x3042].pack("U*").force_encoding("UTF-8"))
+ begin
+ WIN32OLE.codepage = 51932
+ rescue
+ end
+ if WIN32OLE.codepage == 51932
+ assert_equal("\xA4\xA2".force_encoding("CP51932"), obj.value)
+ end
+ ensure
+ WIN32OLE.codepage = cp
+ end
+ end
+
+ def test_s_locale
+ assert_equal(WIN32OLE::LOCALE_SYSTEM_DEFAULT, WIN32OLE.locale)
+ end
+
+ def test_s_locale_set
+ begin
+ begin
+ WIN32OLE.locale = 1041
+ rescue WIN32OLERuntimeError
+ STDERR.puts("\n#{__FILE__}:#{__LINE__}:#{self.class.name}.test_s_locale_set is skipped(Japanese locale is not installed)")
+ return
+ end
+ assert_equal(1041, WIN32OLE.locale)
+ WIN32OLE.locale = WIN32OLE::LOCALE_SYSTEM_DEFAULT
+ assert_raise(WIN32OLERuntimeError) {
+ WIN32OLE.locale = 111
+ }
+ assert_equal(WIN32OLE::LOCALE_SYSTEM_DEFAULT, WIN32OLE.locale)
+ ensure
+ WIN32OLE.locale = WIN32OLE::LOCALE_SYSTEM_DEFAULT
+ end
+ end
+
+ def test_s_locale_change
+ begin
+ begin
+ WIN32OLE.locale = 0x0411
+ rescue WIN32OLERuntimeError
+ end
+ if WIN32OLE.locale == 0x0411
+ obj = WIN32OLE_VARIANT.new("\\100,000", WIN32OLE::VARIANT::VT_CY)
+ assert_equal("100000", obj.value)
+ assert_raise(WIN32OLERuntimeError) {
+ obj = WIN32OLE_VARIANT.new("$100.000", WIN32OLE::VARIANT::VT_CY)
+ }
+ else
+ STDERR.puts("\n#{__FILE__}:#{__LINE__}:#{self.class.name}.test_s_locale_change is skipped(Japanese locale is not installed)")
+ end
+
+ begin
+ WIN32OLE.locale = 1033
+ rescue WIN32OLERuntimeError
+ end
+ if WIN32OLE.locale == 1033
+ obj = WIN32OLE_VARIANT.new("$100,000", WIN32OLE::VARIANT::VT_CY)
+ assert_equal("100000", obj.value)
+ else
+ STDERR.puts("\n#{__FILE__}:#{__LINE__}:#{self.class.name}.test_s_locale_change is skipped(US English locale is not installed)")
+ end
+ ensure
+ WIN32OLE.locale = WIN32OLE::LOCALE_SYSTEM_DEFAULT
+ end
+ 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_const_LOCALE_SYSTEM_DEFAULT
+ assert_equal(0x0800, WIN32OLE::LOCALE_SYSTEM_DEFAULT);
+ end
+
+ def test_const_LOCALE_USER_DEFAULT
+ assert_equal(0x0400, WIN32OLE::LOCALE_USER_DEFAULT);
+ end
+
+ def test_method_missing
+ assert_raise(ArgumentError) {@dict1.method_missing}
+ assert_raise(TypeError) {@dict1.method_missing(1)}
+ assert_raise(ArgumentError) {@dict1.method_missing("foo=")}
+ assert_raise(ArgumentError) {@dict1.method_missing("foo=", 1, 2)}
+ end
+ end
+
+ # test of subclass of WIN32OLE
+ class MyDict < WIN32OLE
+ def MyDict.new
+ super('Scripting.Dictionary')
+ end
+ end
+ class TestMyDict < Test::Unit::TestCase
+ include TestCaseForDict
+ def setup
+ @dict1 = MyDict.new
+ @dict2 = MyDict.new
+ end
+ def test_s_new
+ assert_instance_of(MyDict, @dict1)
+ assert_instance_of(MyDict, @dict2)
+ end
+ end
+end
diff --git a/jni/ruby/test/win32ole/test_win32ole_event.rb b/jni/ruby/test/win32ole/test_win32ole_event.rb
new file mode 100644
index 0000000..86004cd
--- /dev/null
+++ b/jni/ruby/test/win32ole/test_win32ole_event.rb
@@ -0,0 +1,391 @@
+begin
+ require 'win32ole'
+rescue LoadError
+end
+require 'test/unit'
+
+def ado_installed?
+ installed = false
+ if defined?(WIN32OLE)
+ db = nil
+ begin
+ db = WIN32OLE.new('ADODB.Connection')
+ db.connectionString = "Driver={Microsoft Text Driver (*.txt; *.csv)};DefaultDir=.;"
+ db.open
+ db.close
+ db = nil
+ installed = true
+ rescue
+ end
+ end
+ installed
+end
+
+def swbemsink_avairable?
+ available = false
+ if defined?(WIN32OLE)
+ wmi = nil
+ begin
+ wmi = WIN32OLE.new('WbemScripting.SWbemSink')
+ available = true
+ rescue
+ end
+ end
+ available
+end
+
+if defined?(WIN32OLE_EVENT)
+ class TestWIN32OLE_EVENT < Test::Unit::TestCase
+ def test_s_new_exception
+ assert_raise(TypeError) {
+ WIN32OLE_EVENT.new("A")
+ }
+ end
+ def test_s_new_non_exist_event
+ dict = WIN32OLE.new('Scripting.Dictionary')
+ assert_raise(RuntimeError) {
+ WIN32OLE_EVENT.new(dict)
+ }
+ end
+ end
+
+ class TestWIN32OLE_EVENT_SWbemSink < Test::Unit::TestCase
+ unless swbemsink_avairable?
+ def test_dummy_for_skip_message
+ skip "'WbemScripting.SWbemSink' is not available"
+ end
+ else
+ def setup
+ @wmi = WIN32OLE.connect('winmgmts://localhost/root/cimv2')
+ @sws = WIN32OLE.new('WbemScripting.SWbemSink')
+ @event = @event1 = @event2 = ""
+ @sql = "SELECT * FROM __InstanceModificationEvent WITHIN 1 WHERE TargetInstance ISA 'Win32_LocalTime'"
+ end
+
+ def message_loop
+ 2.times do
+ WIN32OLE_EVENT.message_loop
+ sleep 1
+ end
+ end
+
+ def default_handler(event, *args)
+ @event += event
+ end
+
+ def handler1
+ @event1 = "handler1"
+ end
+
+ def test_s_new_non_exist_event
+ assert_raise(RuntimeError) {
+ WIN32OLE_EVENT.new(@sws, 'XXXXX')
+ }
+ end
+
+ def test_s_new
+ obj = WIN32OLE_EVENT.new(@sws, 'ISWbemSinkEvents')
+ assert_instance_of(WIN32OLE_EVENT, obj)
+ obj = WIN32OLE_EVENT.new(@sws)
+ assert_instance_of(WIN32OLE_EVENT, obj)
+ end
+
+ def test_s_new_loop
+ @wmi.ExecNotificationQueryAsync(@sws, @sql)
+ ev = WIN32OLE_EVENT.new(@sws)
+ ev.on_event {|*args| default_handler(*args)}
+ message_loop
+ 10.times do |i|
+ WIN32OLE_EVENT.new(@sws)
+ message_loop
+ GC.start
+ end
+ assert_match(/OnObjectReady/, @event)
+ end
+
+ def test_on_event
+ @wmi.ExecNotificationQueryAsync(@sws, @sql)
+ ev = WIN32OLE_EVENT.new(@sws, 'ISWbemSinkEvents')
+ ev.on_event {|*args| default_handler(*args)}
+ message_loop
+ assert_match(/OnObjectReady/, @event)
+ end
+
+ def test_on_event_symbol
+ @wmi.ExecNotificationQueryAsync(@sws, @sql)
+ ev = WIN32OLE_EVENT.new(@sws)
+ ev.on_event(:OnObjectReady) {|*args|
+ handler1
+ }
+ message_loop
+ assert_equal("handler1", @event1)
+ end
+
+ end
+ end
+
+ class TestWIN32OLE_EVENT_ADO < Test::Unit::TestCase
+ unless ado_installed?
+ def test_dummy_for_skip_message
+ skip "ActiveX Data Object Library not found"
+ end
+ else
+ CONNSTR="Driver={Microsoft Text Driver (*.txt; *.csv)};DefaultDir=.;"
+ module ADO
+ end
+ def message_loop
+ WIN32OLE_EVENT.message_loop
+ end
+
+ def default_handler(event, *args)
+ @event += event
+ end
+
+ def setup
+ @db = WIN32OLE.new('ADODB.Connection')
+ if !defined?(ADO::AdStateOpen)
+ WIN32OLE.const_load(@db, ADO)
+ end
+ @db.connectionString = CONNSTR
+ @event = ""
+ @event2 = ""
+ @event3 = ""
+ end
+
+ def test_on_event2
+ ev = WIN32OLE_EVENT.new(@db, 'ConnectionEvents')
+ ev.on_event('WillConnect') {|*args| handler1}
+ ev.on_event('WillConnect') {|*args| handler2}
+ @db.open
+ message_loop
+ assert_equal("handler2", @event2)
+ end
+
+ def test_on_event4
+ ev = WIN32OLE_EVENT.new(@db, 'ConnectionEvents')
+ ev.on_event{|*args| handler1}
+ ev.on_event{|*args| handler2}
+ ev.on_event('WillConnect'){|*args| handler3(*args)}
+ @db.open
+ message_loop
+ assert_equal(CONNSTR, @event3)
+ assert("handler2", @event2)
+ end
+
+ def test_on_event5
+ ev = WIN32OLE_EVENT.new(@db, 'ConnectionEvents')
+ ev.on_event {|*args| default_handler(*args)}
+ ev.on_event('WillConnect'){|*args| handler3(*args)}
+ @db.open
+ message_loop
+ assert_match(/ConnectComplete/, @event)
+ assert(/WillConnect/ !~ @event)
+ assert_equal(CONNSTR, @event3)
+ end
+
+ def test_unadvise
+ ev = WIN32OLE_EVENT.new(@db, 'ConnectionEvents')
+ ev.on_event {|*args| default_handler(*args)}
+ @db.open
+ message_loop
+ assert_match(/WillConnect/, @event)
+ ev.unadvise
+ @event = ""
+ @db.close
+ @db.open
+ message_loop
+ assert_equal("", @event);
+ assert_raise(WIN32OLERuntimeError) {
+ ev.on_event {|*args| default_handler(*args)}
+ }
+ end
+
+
+ def test_on_event_with_outargs
+ ev = WIN32OLE_EVENT.new(@db)
+ @db.connectionString = 'XXX' # set illegal connection string
+ assert_raise(WIN32OLERuntimeError) {
+ @db.open
+ }
+ ev.on_event_with_outargs('WillConnect'){|*args|
+ args.last[0] = CONNSTR # ConnectionString = CONNSTR
+ }
+ @db.open
+ message_loop
+ assert(true)
+ end
+
+ def test_on_event_hash_return
+ ev = WIN32OLE_EVENT.new(@db)
+ ev.on_event('WillConnect'){|*args|
+ {:return => 1, :ConnectionString => CONNSTR}
+ }
+ @db.connectionString = 'XXX'
+ @db.open
+ assert(true)
+ end
+
+ def test_on_event_hash_return2
+ ev = WIN32OLE_EVENT.new(@db)
+ ev.on_event('WillConnect'){|*args|
+ {:ConnectionString => CONNSTR}
+ }
+ @db.connectionString = 'XXX'
+ @db.open
+ assert(true)
+ end
+
+ def test_on_event_hash_return3
+ ev = WIN32OLE_EVENT.new(@db)
+ ev.on_event('WillConnect'){|*args|
+ {'ConnectionString' => CONNSTR}
+ }
+ @db.connectionString = 'XXX'
+ @db.open
+ assert(true)
+ end
+
+ def test_on_event_hash_return4
+ ev = WIN32OLE_EVENT.new(@db)
+ ev.on_event('WillConnect'){|*args|
+ {'return' => 1, 'ConnectionString' => CONNSTR}
+ }
+ @db.connectionString = 'XXX'
+ @db.open
+ assert(true)
+ end
+
+ def test_on_event_hash_return5
+ ev = WIN32OLE_EVENT.new(@db)
+ ev.on_event('WillConnect'){|*args|
+ {0 => CONNSTR}
+ }
+ @db.connectionString = 'XXX'
+ @db.open
+ assert(true)
+ end
+
+ def test_off_event
+ ev = WIN32OLE_EVENT.new(@db)
+ ev.on_event{handler1}
+ ev.off_event
+ @db.open
+ message_loop
+ assert_equal("", @event2)
+ end
+
+ def test_off_event_arg
+ ev = WIN32OLE_EVENT.new(@db)
+ ev.on_event('WillConnect'){handler1}
+ ev.off_event('WillConnect')
+ @db.open
+ message_loop
+ assert_equal("", @event2)
+ end
+
+ def test_off_event_arg2
+ ev = WIN32OLE_EVENT.new(@db)
+ ev.on_event('WillConnect'){handler1}
+ ev.on_event('ConnectComplete'){handler1}
+ ev.off_event('WillConnect')
+ @db.open
+ message_loop
+ assert_equal("handler1", @event2)
+ end
+
+ def test_off_event_sym_arg
+ ev = WIN32OLE_EVENT.new(@db)
+ ev.on_event('WillConnect'){handler1}
+ ev.off_event(:WillConnect)
+ @db.open
+ message_loop
+ assert_equal("", @event2)
+ end
+
+ def handler1
+ @event2 = "handler1"
+ end
+
+ def handler2
+ @event2 = "handler2"
+ end
+
+ def handler3(*arg)
+ @event3 += arg[0]
+ end
+
+ def teardown
+ if @db && @db.state == ADO::AdStateOpen
+ @db.close
+ end
+ message_loop
+ @db = nil
+ end
+
+ class Handler1
+ attr_reader :val1, :val2, :val3, :val4
+ def initialize
+ @val1 = nil
+ @val2 = nil
+ @val3 = nil
+ @val4 = nil
+ end
+ def onWillConnect(conn, uid, pwd, opts, stat, pconn)
+ @val1 = conn
+ end
+ def onConnectComplete(err, stat, pconn)
+ @val2 = err
+ @val3 = stat
+ end
+ def onInfoMessage(err, stat, pconn)
+ @val4 = stat
+ end
+ end
+
+ class Handler2
+ attr_reader :ev
+ def initialize
+ @ev = ""
+ end
+ def method_missing(ev, *arg)
+ @ev += ev
+ end
+ end
+
+ def test_handler1
+ ev = WIN32OLE_EVENT.new(@db)
+ h1 = Handler1.new
+ ev.handler = h1
+ @db.open
+ message_loop
+ assert_equal(CONNSTR, h1.val1)
+ assert_equal(h1.val1, ev.handler.val1)
+ assert_equal(nil, h1.val2)
+ assert_equal(ADO::AdStateOpen, h1.val3)
+ assert_equal(ADO::AdStateOpen, h1.val4)
+ end
+
+ def test_handler2
+ ev = WIN32OLE_EVENT.new(@db)
+ h2 = Handler2.new
+ ev.handler = h2
+ @db.open
+ message_loop
+ assert(h2.ev != "")
+ end
+
+ def test_s_new_exc_tainted
+ th = Thread.new {
+ $SAFE=1
+ str = 'ConnectionEvents'
+ str.taint
+ ev = WIN32OLE_EVENT.new(@db, str)
+ }
+ exc = assert_raise(SecurityError) {
+ th.join
+ }
+ assert_match(/insecure event creation - `ConnectionEvents'/, exc.message)
+ end
+ end
+ end
+end
diff --git a/jni/ruby/test/win32ole/test_win32ole_method.rb b/jni/ruby/test/win32ole/test_win32ole_method.rb
new file mode 100644
index 0000000..2a4e3d0
--- /dev/null
+++ b/jni/ruby/test/win32ole/test_win32ole_method.rb
@@ -0,0 +1,146 @@
+begin
+ require 'win32ole'
+rescue LoadError
+end
+require "test/unit"
+
+if defined?(WIN32OLE_METHOD)
+ class TestWIN32OLE_METHOD < Test::Unit::TestCase
+
+ def setup
+ ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell")
+ @m_open = WIN32OLE_METHOD.new(ole_type, "open")
+ @m_namespace = WIN32OLE_METHOD.new(ole_type, "namespace")
+ @m_parent = WIN32OLE_METHOD.new(ole_type, "parent")
+ @m_invoke = WIN32OLE_METHOD.new(ole_type, "invoke")
+ @m_browse_for_folder = WIN32OLE_METHOD.new(ole_type, "BrowseForFolder")
+
+ ole_type = WIN32OLE_TYPE.new("Microsoft Scripting Runtime", "File")
+ @m_file_name = WIN32OLE_METHOD.new(ole_type, "name")
+
+ ole_type = WIN32OLE_TYPE.new("Microsoft Internet Controls", "WebBrowser")
+ @m_navigate_complete = WIN32OLE_METHOD.new(ole_type, "NavigateComplete")
+ end
+
+ def test_initialize
+ ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell")
+ assert_raise(TypeError) {
+ WIN32OLE_METHOD.new(1, 2)
+ }
+ assert_raise(ArgumentError) {
+ WIN32OLE_METHOD.new("foo")
+ }
+ assert_raise(ArgumentError) {
+ WIN32OLE_METHOD.new(ole_type)
+ }
+ assert_raise(WIN32OLERuntimeError) {
+ WIN32OLE_METHOD.new(ole_type, "NonExistMethod")
+ }
+ assert_raise(TypeError) {
+ WIN32OLE_METHOD.new(ole_type, 1)
+ }
+ method = WIN32OLE_METHOD.new(ole_type, "Open")
+ assert_instance_of(WIN32OLE_METHOD, method)
+ method = WIN32OLE_METHOD.new(ole_type, "open")
+ assert_instance_of(WIN32OLE_METHOD, method)
+ end
+
+ def test_name
+ assert_equal("Open", @m_open.name)
+ end
+
+ def test_return_type
+ assert_equal("VOID", @m_open.return_type)
+ assert_equal("Folder", @m_namespace.return_type)
+ end
+
+ def test_return_vtype
+ assert_equal(24, @m_open.return_vtype)
+ assert_equal(26, @m_namespace.return_vtype)
+ end
+
+ def test_return_type_detail
+ assert_equal(['VOID'], @m_open.return_type_detail)
+ assert_equal(['PTR', 'USERDEFINED', 'Folder'], @m_namespace.return_type_detail)
+ end
+
+ def test_invoke_kind
+ assert_equal('FUNC', @m_open.invoke_kind)
+ assert_equal('FUNC', @m_namespace.invoke_kind)
+ assert_equal('PROPERTYGET', @m_parent.invoke_kind)
+ end
+
+ def test_invkind
+ assert_equal(1, @m_namespace.invkind)
+ assert_equal(2, @m_parent.invkind)
+ end
+
+ def test_visible?
+ assert(@m_namespace.visible?)
+ assert(!@m_invoke.visible?)
+ end
+
+ def test_event?
+ assert(@m_navigate_complete.event?)
+ assert(!@m_namespace.event?)
+ end
+
+ def test_event_interface
+ assert_equal("DWebBrowserEvents", @m_navigate_complete.event_interface)
+ assert_equal(nil, @m_namespace.event_interface)
+ end
+
+ def test_helpstring
+ assert_equal("Get special folder from ShellSpecialFolderConstants", @m_namespace.helpstring)
+ end
+
+ def test_helpfile
+ assert_equal("", @m_namespace.helpfile)
+ assert_match(/VBENLR.*\.CHM$/i, @m_file_name.helpfile)
+ end
+
+ def test_helpcontext
+ assert_equal(0, @m_namespace.helpcontext)
+ assert_equal(2181996, @m_file_name.helpcontext)
+ end
+
+ def test_dispid
+ assert_equal(1610743810, @m_namespace.dispid)
+ end
+
+ def is_ruby64?
+ /mswin64|x64-mingw/ =~ RUBY_PLATFORM
+ end
+
+ def test_offset_vtbl
+ exp = is_ruby64? ? 48 : 24
+ assert_equal(exp, @m_invoke.offset_vtbl)
+ end
+
+ def test_size_params
+ assert_equal(1, @m_open.size_params)
+ assert_equal(4, @m_browse_for_folder.size_params)
+ end
+
+ def test_size_opt_params
+ assert_equal(0, @m_open.size_opt_params)
+ assert_equal(1, @m_browse_for_folder.size_opt_params)
+ end
+
+ def test_params
+ params = @m_browse_for_folder.params
+ assert_instance_of(Array, params)
+ assert_equal(4, params.size)
+ assert_instance_of(WIN32OLE_PARAM, params[0])
+ end
+
+ def test_to_s
+ assert_equal(@m_namespace.name, @m_namespace.to_s)
+ end
+
+ def test_inspect
+ assert_equal("#<WIN32OLE_METHOD:NameSpace>", @m_namespace.inspect)
+ end
+
+ end
+end
diff --git a/jni/ruby/test/win32ole/test_win32ole_param.rb b/jni/ruby/test/win32ole/test_win32ole_param.rb
new file mode 100644
index 0000000..1a4eeff
--- /dev/null
+++ b/jni/ruby/test/win32ole/test_win32ole_param.rb
@@ -0,0 +1,106 @@
+begin
+ require 'win32ole'
+rescue LoadError
+end
+require "test/unit"
+
+if defined?(WIN32OLE_PARAM)
+ class TestWIN32OLE_PARAM < Test::Unit::TestCase
+
+ def setup
+ ole_type = WIN32OLE_TYPE.new("Microsoft Internet Controls", "WebBrowser")
+ m_navigate = WIN32OLE_METHOD.new(ole_type, "Navigate")
+ m_before_navigate = WIN32OLE_METHOD.new(ole_type, "BeforeNavigate")
+ params = m_navigate.params
+ @param_url = params[0]
+ @param_flags = params[1]
+ @param_cancel = m_before_navigate.params[5]
+
+ ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "ShellLinkObject")
+ m_geticonlocation = WIN32OLE_METHOD.new(ole_type, "GetIconLocation")
+ @param_pbs = m_geticonlocation.params[0]
+
+ ole_type = WIN32OLE_TYPE.new("Microsoft HTML Object Library", "FontNames")
+ m_count = WIN32OLE_METHOD.new(ole_type, "Count")
+ @param_p = m_count.params[0]
+
+ ole_type = WIN32OLE_TYPE.new("Microsoft Scripting Runtime", "FileSystemObject")
+ m_copyfile = WIN32OLE_METHOD.new(ole_type, "CopyFile")
+ @param_overwritefiles = m_copyfile.params[2]
+ end
+
+ def test_s_new
+ assert_raise(ArgumentError) {
+ WIN32OLE_PARAM.new("hoge")
+ }
+ ole_type = WIN32OLE_TYPE.new("Microsoft Scripting Runtime", "FileSystemObject")
+ m_copyfile = WIN32OLE_METHOD.new(ole_type, "CopyFile")
+ assert_raise(IndexError) {
+ WIN32OLE_PARAM.new(m_copyfile, 4);
+ }
+ assert_raise(IndexError) {
+ WIN32OLE_PARAM.new(m_copyfile, 0);
+ }
+ assert_raise(IndexError) {
+ WIN32OLE_PARAM.new(m_copyfile, 0);
+ }
+ param = WIN32OLE_PARAM.new(m_copyfile, 3)
+ assert_equal("OverWriteFiles", param.name)
+ assert_equal(WIN32OLE_PARAM, param.class)
+ assert_equal(true, param.default)
+ assert_equal("#<WIN32OLE_PARAM:OverWriteFiles=true>", param.inspect)
+ end
+
+ def test_name
+ assert_equal('URL', @param_url.name)
+ assert_equal('Flags', @param_flags.name)
+ assert_equal('Cancel', @param_cancel.name)
+ end
+
+ def test_ole_type
+ assert_equal('BSTR', @param_url.ole_type)
+ assert_equal('VARIANT', @param_flags.ole_type)
+ end
+
+ def test_ole_type_detail
+ assert_equal(['BSTR'], @param_url.ole_type_detail)
+ assert_equal(['PTR', 'VARIANT'], @param_flags.ole_type_detail)
+ end
+
+ def test_input?
+ assert(@param_url.input?)
+ assert(@param_cancel.input?)
+ assert(!@param_pbs.input?)
+ end
+
+ def test_output?
+ assert(!@param_url.output?)
+ assert(@param_cancel.output?)
+ assert(@param_pbs.output?)
+ end
+
+ def test_optional?
+ assert(!@param_url.optional?)
+ assert(@param_flags.optional?)
+ end
+
+ def test_retval?
+ assert(!@param_url.retval?)
+ assert(@param_p.retval?)
+ end
+
+ def test_default
+ assert_equal(nil, @param_url.default)
+ assert_equal(true, @param_overwritefiles.default)
+ end
+
+ def test_to_s
+ assert_equal(@param_url.name, @param_url.to_s)
+ end
+
+ def test_inspect
+ assert_equal("#<WIN32OLE_PARAM:URL>", @param_url.inspect)
+ assert_equal("#<WIN32OLE_PARAM:OverWriteFiles=true>", @param_overwritefiles.inspect)
+ end
+ end
+end
diff --git a/jni/ruby/test/win32ole/test_win32ole_record.rb b/jni/ruby/test/win32ole/test_win32ole_record.rb
new file mode 100644
index 0000000..265feb8
--- /dev/null
+++ b/jni/ruby/test/win32ole/test_win32ole_record.rb
@@ -0,0 +1,313 @@
+# coding: us-ascii
+
+begin
+ require 'win32ole'
+rescue LoadError
+end
+require 'test/unit'
+
+PROGID_CLR='System.Runtime.Serialization.FormatterConverter'
+PROGID_RBCOMTEST='RbComTest.ComSrvTest'
+
+=begin
+RbComTest.ComSrvTest is following VB.NET COM server(RbComTest solution).
+
+Imports System.Runtime.InteropServices
+Public Class ComSrvTest
+ <StructLayout(LayoutKind.Sequential)> _
+ Public Structure Book
+ <MarshalAs(UnmanagedType.BStr)> _
+ Public title As String
+ Public cost As Integer
+ End Structure
+
+ Public Function getBook() As Book
+ Dim book As New Book
+ book.title = "The Ruby Book"
+ book.cost = 20
+ Return book
+ End Function
+
+ Public Function getBooks() As Book()
+ Dim book() As Book = {New Book, New Book}
+ book(0).title = "The CRuby Book"
+ book(0).cost = 30
+ book(1).title = "The JRuby Book"
+ book(1).cost = 40
+ Return book
+ End Function
+
+ Public Sub getBookByRefObject(ByRef obj As Object)
+ Dim book As New Book
+ book.title = "The Ruby Reference Book"
+ book.cost = 50
+ obj = book
+ End Sub
+
+ Public Function getVer2BookByValBook(<MarshalAs(UnmanagedType.Struct)> ByVal book As Book) As Book
+ Dim ret As New Book
+ ret.title = book.title + " ver2"
+ ret.cost = book.cost * 1.1
+ Return ret
+ End Function
+
+ Public Sub getBookByRefBook(<MarshalAs(UnmanagedType.LPStruct)> ByRef book As Book)
+ book.title = "The Ruby Reference Book2"
+ book.cost = 44
+ End Sub
+
+ Public Sub getVer3BookByRefBook(<MarshalAs(UnmanagedType.LPStruct)> ByRef book As Book)
+ book.title += " ver3"
+ book.cost *= 1.2
+ End Sub
+End Class
+=end
+
+
+if defined?(WIN32OLE_RECORD)
+ def rbcomtest_exist?
+ exist = false
+ begin
+ obj = WIN32OLE.new(PROGID_RBCOMTEST)
+ exist = true
+ rescue WIN32OLERuntimeError
+ exist = false
+ end
+ exist
+ end
+
+ class TestWIN32OLE_RECORD_BY_RBCOMTEST < Test::Unit::TestCase
+ unless rbcomtest_exist?
+ def test_dummy_for_skip_message
+ skip "#{PROGID_RBCOMTEST} for WIN32OLE_RECORD test is not installed"
+ end
+ else
+ def setup
+ @obj = WIN32OLE.new(PROGID_RBCOMTEST)
+ end
+
+ def test_s_new_from_win32ole
+ rec = WIN32OLE_RECORD.new('Book', @obj)
+ assert(rec)
+ assert_instance_of(WIN32OLE_RECORD, rec)
+ end
+
+ def test_s_new_from_win32ole_typelib
+ tlib = @obj.ole_typelib
+ rec = WIN32OLE_RECORD.new('Book', tlib)
+ assert(rec)
+ assert_instance_of(WIN32OLE_RECORD, rec)
+ end
+
+ def test_s_new_raise
+ assert_raise(WIN32OLERuntimeError) {
+ rec = WIN32OLE_RECORD.new('NonExistRecordName', @obj)
+ }
+ assert_raise(ArgumentError) {
+ rec = WIN32OLE_RECORD.new
+ }
+ assert_raise(ArgumentError) {
+ rec = WIN32OLE_RECORD.new('NonExistRecordName')
+ }
+ end
+
+ def test_to_h
+ rec = WIN32OLE_RECORD.new('Book', @obj)
+ assert_equal({'title'=>nil, 'cost'=>nil}, rec.to_h)
+ end
+
+ def test_typename
+ rec = WIN32OLE_RECORD.new('Book', @obj)
+ assert_equal('Book', rec.typename)
+ end
+
+ def test_method_missing_getter
+ rec = WIN32OLE_RECORD.new('Book', @obj)
+ assert_equal(nil, rec.title)
+ assert_raise(KeyError) {
+ rec.non_exist_name
+ }
+ end
+
+ def test_method_missing_setter
+ rec = WIN32OLE_RECORD.new('Book', @obj)
+ rec.title = "Ruby Book"
+ assert_equal("Ruby Book", rec.title)
+ end
+
+ def test_get_record_from_comserver
+ rec = @obj.getBook
+ assert_instance_of(WIN32OLE_RECORD, rec)
+ assert_equal("The Ruby Book", rec.title)
+ assert_equal(20, rec.cost)
+ end
+
+ def test_get_record_array_from_comserver
+ rec = @obj.getBooks
+ assert_instance_of(Array, rec)
+ assert_equal(2, rec.size)
+ assert_instance_of(WIN32OLE_RECORD, rec[0])
+ assert_equal("The CRuby Book", rec[0].title)
+ assert_equal(30, rec[0].cost)
+ assert_instance_of(WIN32OLE_RECORD, rec[1])
+ assert_equal("The JRuby Book", rec[1].title)
+ assert_equal(40, rec[1].cost)
+ end
+
+ def test_pass_record_parameter
+ rec = WIN32OLE_RECORD.new('Book', @obj)
+ rec.title = "Ruby Book"
+ rec.cost = 60
+ book = @obj.getVer2BookByValBook(rec)
+ assert_equal("Ruby Book ver2", book.title)
+ assert_equal(66, book.cost)
+ end
+
+ def test_pass_variant_parameter_byref
+ obj = WIN32OLE_VARIANT.new(nil, WIN32OLE::VARIANT::VT_VARIANT|WIN32OLE::VARIANT::VT_BYREF)
+ @obj.getBookByRefBook(obj)
+ assert_instance_of(WIN32OLE_RECORD, obj.value)
+ book = obj.value
+ assert_equal("The Ruby Reference Book2", book.title)
+ assert_equal(44, book.cost)
+ end
+
+ def test_pass_record_parameter_byref
+ book = WIN32OLE_RECORD.new('Book', @obj)
+ @obj.getBookByRefBook(book)
+ assert_equal("The Ruby Reference Book2", book.title)
+ assert_equal(44, book.cost)
+ end
+
+ def test_pass_and_get_record_parameter_byref
+ book = WIN32OLE_RECORD.new('Book', @obj)
+ book.title = "Ruby Book"
+ book.cost = 60
+ @obj.getVer3BookByRefBook(book)
+ assert_equal("Ruby Book ver3", book.title)
+ assert_equal(72, book.cost)
+ end
+
+ def test_ole_instance_variable_get
+ obj = WIN32OLE_RECORD.new('ComObject', @obj)
+ assert_equal(nil, obj.ole_instance_variable_get(:object_id))
+ assert_equal(nil, obj.ole_instance_variable_get('object_id'))
+ end
+
+ def test_ole_instance_variable_set
+ book = WIN32OLE_RECORD.new('Book', @obj)
+ book.ole_instance_variable_set(:title, "Ruby Book")
+ assert_equal("Ruby Book", book.title)
+ book.ole_instance_variable_set('title', "Ruby Book2")
+ assert_equal("Ruby Book2", book.title)
+ end
+
+ def test_inspect
+ book = WIN32OLE_RECORD.new('Book', @obj)
+ assert_equal(%q[#<WIN32OLE_RECORD(Book) {"title"=>nil, "cost"=>nil}>], book.inspect)
+ end
+ end
+ end
+
+ def clr_exist?
+ exist = false
+ begin
+ obj = WIN32OLE.new(PROGID_CLR)
+ exist = true
+ rescue WIN32OLERuntimeError
+ exist = false
+ end
+ exist
+ end
+
+ class TestWIN32OLE_CLR < Test::Unit::TestCase
+ unless clr_exist?
+ def test_dummy_for_skip_message
+ skip "#{PROGID_CLR}(.Net Framework 3.5) not found."
+ end
+ else
+ def setup
+ @obj = WIN32OLE.new(PROGID_CLR)
+ end
+
+ def test_s_new_from_win32ole
+ rec = WIN32OLE_RECORD.new('Decimal', @obj)
+ assert(rec)
+ assert_instance_of(WIN32OLE_RECORD, rec)
+ end
+
+ def test_s_new_from_win32ole_typelib
+ tlib = @obj.ole_typelib
+ rec = WIN32OLE_RECORD.new('Decimal', tlib)
+ assert(rec)
+ assert_instance_of(WIN32OLE_RECORD, rec)
+ end
+
+ def test_s_new_raise
+ assert_raise(WIN32OLERuntimeError) {
+ rec = WIN32OLE_RECORD.new('NonExistRecordName', @obj)
+ }
+ assert_raise(ArgumentError) {
+ rec = WIN32OLE_RECORD.new
+ }
+ assert_raise(ArgumentError) {
+ rec = WIN32OLE_RECORD.new('NonExistRecordName')
+ }
+ end
+
+ def test_to_h
+ rec = WIN32OLE_RECORD.new('Decimal', @obj)
+ assert_equal({'lo'=>nil, 'mid'=>nil, 'hi'=>nil, 'flags'=>nil}, rec.to_h)
+ end
+
+ def test_typename
+ rec = WIN32OLE_RECORD.new('Decimal', @obj)
+ assert_equal('Decimal', rec.typename)
+ end
+
+ def test_method_missing_getter
+ rec = WIN32OLE_RECORD.new('Decimal', @obj)
+ assert_equal(nil, rec.lo)
+ assert_raise(KeyError) {
+ rec.non_exist_name
+ }
+ end
+
+ def test_method_missing_setter
+ rec = WIN32OLE_RECORD.new('Decimal', @obj)
+ rec.lo = 1
+ assert_equal(1, rec.lo)
+ end
+
+ def test_pass_record_parameter
+ rec = WIN32OLE_RECORD.new('Decimal', @obj)
+ rec.lo = 0
+ rec.mid = 1
+ rec.hi = 0
+ rec.flags = false
+ assert_equal(2**32, @obj.ToInt64(rec))
+ end
+
+ def test_ole_instance_variable_get
+ obj = WIN32OLE_RECORD.new('Decimal', @obj)
+ assert_equal(nil, obj.ole_instance_variable_get(:lo))
+ assert_equal(nil, obj.ole_instance_variable_get('lo'))
+ end
+
+ def test_ole_instance_variable_set
+ rec = WIN32OLE_RECORD.new('Decimal', @obj)
+ rec.ole_instance_variable_set(:lo, 1)
+ assert_equal(1, rec.lo)
+ rec.ole_instance_variable_set('lo', 2)
+ assert_equal(2, rec.lo)
+ end
+
+ def test_inspect
+ rec = WIN32OLE_RECORD.new('Decimal', @obj)
+ assert_equal(%q[#<WIN32OLE_RECORD(Decimal) {"flags"=>nil, "hi"=>nil, "lo"=>nil, "mid"=>nil}>], rec.inspect)
+ end
+
+ end
+ end
+
+end
diff --git a/jni/ruby/test/win32ole/test_win32ole_type.rb b/jni/ruby/test/win32ole/test_win32ole_type.rb
new file mode 100644
index 0000000..5422352
--- /dev/null
+++ b/jni/ruby/test/win32ole/test_win32ole_type.rb
@@ -0,0 +1,249 @@
+begin
+ require 'win32ole'
+rescue LoadError
+end
+require "test/unit"
+
+if defined?(WIN32OLE_TYPE)
+ class TestWIN32OLE_TYPE < Test::Unit::TestCase
+
+ def test_s_progids
+ progids = WIN32OLE_TYPE.progids
+ assert_instance_of(Array, progids)
+ assert(progids.size > 0)
+ assert_instance_of(String, progids[0])
+ assert(progids.include?("Shell.Application.1"))
+ end
+
+ def test_initialize
+ assert_raise(ArgumentError) {
+ WIN32OLE_TYPE.new
+ }
+ assert_raise(ArgumentError) {
+ WIN32OLE_TYPE.new("foo")
+ }
+ assert_raise(TypeError) {
+ WIN32OLE_TYPE.new(1, 2)
+ }
+ assert_raise(TypeError) {
+ WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", 1)
+ }
+ assert_raise(WIN32OLERuntimeError) {
+ WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "foo")
+ }
+ assert_raise(WIN32OLERuntimeError) {
+ WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Application")
+ }
+ ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell")
+ assert_instance_of(WIN32OLE_TYPE, ole_type)
+ assert_equal("Shell", ole_type.name)
+ assert_equal("Class", ole_type.ole_type)
+ assert_equal("{13709620-C279-11CE-A49E-444553540000}", ole_type.guid)
+ assert_equal("Shell.Application.1", ole_type.progid)
+ assert_equal(true, ole_type.visible?)
+ assert_equal("Shell", ole_type.to_s)
+ assert_equal(0, ole_type.major_version)
+ assert_equal(0, ole_type.minor_version)
+ assert_equal(5, ole_type.typekind)
+ assert_equal("Shell Object Type Information", ole_type.helpstring)
+ assert_equal(nil, ole_type.src_type)
+ assert_equal("", ole_type.helpfile)
+ assert_equal(0, ole_type.helpcontext)
+ assert_equal([], ole_type.variables)
+ assert(ole_type.ole_methods.select{|m|/NameSpace/i =~ m.name}.size > 0)
+
+ ole_type2 = WIN32OLE_TYPE.new("{13709620-C279-11CE-A49E-444553540000}", "Shell")
+ assert_instance_of(WIN32OLE_TYPE, ole_type)
+ assert_equal(ole_type.name, ole_type2.name)
+ assert_equal(ole_type.ole_type, ole_type2.ole_type)
+ assert_equal(ole_type.guid, ole_type2.guid)
+ assert_equal(ole_type.progid, ole_type2.progid)
+ assert_equal(ole_type.visible?, ole_type2.visible?)
+ assert_equal(ole_type.to_s, ole_type2.to_s)
+ assert_equal(ole_type.major_version, ole_type2.major_version)
+ assert_equal(ole_type.minor_version, ole_type2.minor_version)
+ assert_equal(ole_type.typekind, ole_type2.typekind)
+ assert_equal(ole_type.helpstring, ole_type2.helpstring)
+ assert_equal(ole_type.src_type, ole_type2.src_type)
+ assert_equal(ole_type.helpfile, ole_type2.helpfile)
+ assert_equal(ole_type.helpcontext, ole_type2.helpcontext)
+ assert_equal(ole_type.variables.size, ole_type2.variables.size)
+ assert_equal(ole_type.ole_methods[0].name, ole_type2.ole_methods[0].name)
+ assert_equal(ole_type.ole_typelib.name, ole_type2.ole_typelib.name)
+ assert_equal(ole_type.implemented_ole_types.size, ole_type2.implemented_ole_types.size)
+ assert_equal(ole_type.inspect, ole_type2.inspect)
+ end
+
+ def setup
+ @ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell")
+ end
+
+ def test_name
+ assert_equal("Shell", @ole_type.name)
+ end
+
+ def test_ole_type
+ assert_equal("Class", @ole_type.ole_type)
+ end
+
+ def test_guid
+ assert_equal("{13709620-C279-11CE-A49E-444553540000}", @ole_type.guid)
+ end
+
+ def test_progid
+ assert_equal("Shell.Application.1", @ole_type.progid)
+ end
+
+ def test_visible?
+ assert(@ole_type.visible?)
+ ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "IShellDispatch")
+ assert(!ole_type.visible?)
+ end
+
+ def test_to_s
+ assert_equal(@ole_type.to_s, @ole_type.name)
+ end
+
+ def test_major_version
+ assert_equal(0, @ole_type.major_version)
+ # ole_type = WIN32OLE_TYPE.new("Microsoft Word 11.0 Object Library", "Documents")
+ # assert_equal(8, ole_type.major_version)
+ end
+
+ def test_minor_version
+ assert_equal(0, @ole_type.minor_version)
+ # ole_type = WIN32OLE_TYPE.new("Microsoft Word 11.0 Object Library", "Documents")
+ # assert_equal(3, ole_type.minor_version)
+ end
+
+ def test_typekind
+ assert_equal(5, @ole_type.typekind)
+ end
+
+ def test_helpstring
+ assert_equal("Shell Object Type Information", @ole_type.helpstring)
+ end
+
+ def test_src_type
+ ole_type = WIN32OLE_TYPE.new("Microsoft Scripting Runtime", "DriveTypeConst")
+ assert_match(/__MIDL___MIDL_itf_scrrun_/, ole_type.src_type)
+ assert_equal(nil, @ole_type.src_type)
+ end
+
+ def test_helpfile
+ assert_equal("", @ole_type.helpfile)
+ ole_type = WIN32OLE_TYPE.new("Microsoft Scripting Runtime", "Folders")
+ assert_match(/VBENLR98\.CHM$/i, ole_type.helpfile)
+ end
+
+ def test_helpcontext
+ assert_equal(0, @ole_type.helpcontext)
+ ole_type = WIN32OLE_TYPE.new("Microsoft Scripting Runtime", "Folders")
+ assert_equal(2181929, ole_type.helpcontext)
+ end
+
+ def test_variables
+ variables = @ole_type.variables
+ assert_instance_of(Array, variables)
+ assert(variables.size == 0)
+
+ ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "ShellSpecialFolderConstants")
+ variables = ole_type.variables
+ assert_instance_of(Array, variables)
+ assert(variables.size > 0)
+
+ assert_instance_of(WIN32OLE_VARIABLE, variables[0])
+ end
+
+ def test_ole_methods
+ methods = @ole_type.ole_methods
+ assert_instance_of(Array, methods)
+ assert(methods.size > 0)
+ assert_instance_of(WIN32OLE_METHOD, methods[0]);
+ assert(methods.collect{|m| m.name}.include?("Application"))
+ end
+
+ def test_ole_typelib
+ tlib = @ole_type.ole_typelib
+ assert_instance_of(WIN32OLE_TYPELIB, tlib)
+ assert_equal("Microsoft Shell Controls And Automation", tlib.name)
+ end
+
+ def test_implemented_ole_types
+ ole_types = @ole_type.implemented_ole_types
+ assert_instance_of(Array, ole_types)
+ assert_equal(1, ole_types.size)
+ assert_match(/^IShellDispatch\d{0,1}$/, ole_types[0].name)
+
+ ie_otype = WIN32OLE_TYPE.new("Microsoft Internet Controls", "InternetExplorer")
+ ole_types = ie_otype.implemented_ole_types
+ assert_equal(4, ole_types.size)
+ otype = ole_types.select{|t| t.name == "IWebBrowser2"}
+ assert_equal(1, otype.size)
+ otype = ole_types.select{|t| t.name == "IWebBrowserApp"}
+ assert_equal(1, otype.size)
+ otype = ole_types.select{|t| t.name == "DWebBrowserEvents2"}
+ assert_equal(1, otype.size)
+ otype = ole_types.select{|t| t.name == "DWebBrowserEvents"}
+ assert_equal(1, otype.size)
+ end
+
+ def test_default_ole_types
+ ie_otype = WIN32OLE_TYPE.new("Microsoft Internet Controls", "InternetExplorer")
+ ole_types = ie_otype.default_ole_types
+ otype = ole_types.select{|t| t.name == "IWebBrowser2"}
+ assert_equal(1, otype.size)
+ otype = ole_types.select{|t| t.name == "IWebBrowserApp"}
+ assert_equal(0, otype.size)
+ otype = ole_types.select{|t| t.name == "DWebBrowserEvents2"}
+ assert_equal(1, otype.size)
+ otype = ole_types.select{|t| t.name == "DWebBrowserEvents"}
+ assert_equal(0, otype.size)
+ end
+
+ def test_source_ole_types
+ ie_otype = WIN32OLE_TYPE.new("Microsoft Internet Controls", "InternetExplorer")
+ ole_types = ie_otype.source_ole_types
+ otype = ole_types.select{|t| t.name == "IWebBrowser2"}
+ assert_equal(0, otype.size)
+ otype = ole_types.select{|t| t.name == "IWebBrowserApp"}
+ assert_equal(0, otype.size)
+ otype = ole_types.select{|t| t.name == "DWebBrowserEvents2"}
+ assert_equal(1, otype.size)
+ otype = ole_types.select{|t| t.name == "DWebBrowserEvents"}
+ assert_equal(1, otype.size)
+ end
+
+ def test_default_event_sources
+ ie_otype = WIN32OLE_TYPE.new("Microsoft Internet Controls", "InternetExplorer")
+ ole_types = ie_otype.default_event_sources
+ otype = ole_types.select{|t| t.name == "IWebBrowser2"}
+ assert_equal(0, otype.size)
+ otype = ole_types.select{|t| t.name == "IWebBrowserApp"}
+ assert_equal(0, otype.size)
+ otype = ole_types.select{|t| t.name == "DWebBrowserEvents2"}
+ assert_equal(1, otype.size)
+ otype = ole_types.select{|t| t.name == "DWebBrowserEvents"}
+ assert_equal(0, otype.size)
+ end
+
+ def test_inspect
+ assert_equal("#<WIN32OLE_TYPE:Shell>", @ole_type.inspect)
+ end
+ # WIN32OLE_TYPE.typelibs will be obsoleted.
+ def test_s_typelibs
+ tlibs = WIN32OLE_TYPE.typelibs.sort
+ tlibs2 = WIN32OLE_TYPELIB.typelibs.collect{|t|t.name}.sort
+ assert_equal(tlibs2, tlibs)
+ end
+
+ # WIN32OLE_TYPE.ole_classes will be obsoleted.
+ def test_s_ole_classes
+ ots1 = WIN32OLE_TYPE.ole_classes("Microsoft Shell Controls And Automation")
+ ots2 = WIN32OLE_TYPELIB.new("Microsoft Shell Controls And Automation").ole_types
+ otns1 = ots1.collect{|t| t.name}.sort
+ otns2 = ots2.collect{|t| t.name}.sort
+ assert_equal(otns2, otns1)
+ end
+ end
+end
diff --git a/jni/ruby/test/win32ole/test_win32ole_typelib.rb b/jni/ruby/test/win32ole/test_win32ole_typelib.rb
new file mode 100644
index 0000000..a548bc1
--- /dev/null
+++ b/jni/ruby/test/win32ole/test_win32ole_typelib.rb
@@ -0,0 +1,116 @@
+begin
+ require 'win32ole'
+rescue LoadError
+end
+require "test/unit"
+
+if defined?(WIN32OLE_TYPELIB)
+ class TestWIN32OLE_TYPELIB < Test::Unit::TestCase
+ def test_s_typelibs
+ tlibs = WIN32OLE_TYPELIB.typelibs
+ assert_instance_of(Array, tlibs)
+ assert(tlibs.size > 0)
+ tlib = tlibs.find {|t| t.name == "Microsoft Shell Controls And Automation"}
+ assert(tlib)
+ end
+
+ def test_initialize
+ assert_raise(ArgumentError) {
+ WIN32OLE_TYPELIB.new(1,2,3,4)
+ }
+
+ assert_raise(TypeError) {
+ WIN32OLE_TYPELIB.new(100)
+ }
+
+ tlib = WIN32OLE_TYPELIB.new("Microsoft Shell Controls And Automation")
+ assert_instance_of(WIN32OLE_TYPELIB, tlib)
+
+ tlib = WIN32OLE_TYPELIB.new("Microsoft Shell Controls And Automation", 1.0)
+ assert_instance_of(WIN32OLE_TYPELIB, tlib)
+
+ tlib = WIN32OLE_TYPELIB.new("Microsoft Shell Controls And Automation", 1, 0)
+ assert_instance_of(WIN32OLE_TYPELIB, tlib)
+ guid = tlib.guid
+
+ tlib_by_guid = WIN32OLE_TYPELIB.new(guid, 1, 0)
+ assert_instance_of(WIN32OLE_TYPELIB, tlib_by_guid)
+ assert_equal("Microsoft Shell Controls And Automation" , tlib_by_guid.name)
+
+ path = tlib.path
+ tlib_by_path = WIN32OLE_TYPELIB.new(path)
+ assert_equal("Microsoft Shell Controls And Automation" , tlib_by_path.name)
+
+ assert_raise(WIN32OLERuntimeError) {
+ WIN32OLE_TYPELIB.new("Non Exist Type Library")
+ }
+ end
+
+ # #Bug:3907 [ruby-dev:42338]
+ def test_initialize_with_REG_EXPAND_SZ
+ tlib = WIN32OLE_TYPELIB.new("Disk Management Snap-In Object Library")
+ assert_instance_of(WIN32OLE_TYPELIB, tlib)
+ end
+
+ def test_guid
+ tlib = WIN32OLE_TYPELIB.new("Microsoft Shell Controls And Automation")
+ assert_equal("{50A7E9B0-70EF-11D1-B75A-00A0C90564FE}", tlib.guid)
+ end
+
+ def test_name
+ tlib = WIN32OLE_TYPELIB.new("Microsoft Shell Controls And Automation")
+ assert_equal("Microsoft Shell Controls And Automation", tlib.name)
+ tlib = WIN32OLE_TYPELIB.new("{50A7E9B0-70EF-11D1-B75A-00A0C90564FE}")
+ assert_equal("Microsoft Shell Controls And Automation", tlib.name)
+ end
+
+ def test_version
+ tlib = WIN32OLE_TYPELIB.new("Microsoft Shell Controls And Automation")
+ assert_equal("1.0", tlib.version)
+ end
+
+ def test_major_version
+ tlib = WIN32OLE_TYPELIB.new("Microsoft Shell Controls And Automation")
+ assert_equal(1, tlib.major_version)
+ end
+
+ def test_minor_version
+ tlib = WIN32OLE_TYPELIB.new("Microsoft Shell Controls And Automation")
+ assert_equal(0, tlib.minor_version)
+ end
+
+ def test_path
+ tlib = WIN32OLE_TYPELIB.new("Microsoft Shell Controls And Automation")
+ assert_match(/shell32\.dll$/i, tlib.path)
+ end
+
+ def test_visible?
+ tlib = WIN32OLE_TYPELIB.new("Microsoft Shell Controls And Automation")
+ assert(tlib.visible?)
+ end
+
+ def test_library_name
+ tlib = WIN32OLE_TYPELIB.new("Microsoft Shell Controls And Automation")
+ assert_equal("Shell32", tlib.library_name)
+ end
+
+ def test_to_s
+ tlib = WIN32OLE_TYPELIB.new("Microsoft Shell Controls And Automation")
+ assert_equal("Microsoft Shell Controls And Automation", tlib.to_s)
+ end
+
+ def test_ole_types
+ tlib = WIN32OLE_TYPELIB.new("Microsoft Shell Controls And Automation")
+ ole_types = tlib.ole_types
+ assert_instance_of(Array, ole_types)
+ assert(ole_types.size > 0)
+ assert_instance_of(WIN32OLE_TYPE, ole_types[0])
+ end
+
+ def test_inspect
+ tlib = WIN32OLE_TYPELIB.new("Microsoft Shell Controls And Automation")
+ assert_equal("#<WIN32OLE_TYPELIB:Microsoft Shell Controls And Automation>", tlib.inspect)
+ end
+
+ end
+end
diff --git a/jni/ruby/test/win32ole/test_win32ole_variable.rb b/jni/ruby/test/win32ole/test_win32ole_variable.rb
new file mode 100644
index 0000000..5fdcb07
--- /dev/null
+++ b/jni/ruby/test/win32ole/test_win32ole_variable.rb
@@ -0,0 +1,61 @@
+begin
+ require 'win32ole'
+rescue LoadError
+end
+require "test/unit"
+
+if defined?(WIN32OLE_VARIABLE)
+ class TestWIN32OLE_VARIABLE < Test::Unit::TestCase
+
+ def setup
+ ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "ShellSpecialFolderConstants")
+ @var1 = ole_type.variables.find {|v| v.name == 'ssfDESKTOP'}
+
+ variables = WIN32OLE_TYPE.new("Microsoft Windows Installer Object Library", "Installer").variables
+ @var2 = variables.find {|v| v.name == 'UILevel'}
+ end
+
+ def test_name
+ assert_equal('ssfDESKTOP', @var1.name)
+ end
+
+ def test_ole_type
+ assert_equal('INT', @var1.ole_type)
+ assert_equal('MsiUILevel', @var2.ole_type)
+ end
+
+ def test_ole_type_detail
+ assert_equal(['INT'], @var1.ole_type_detail)
+ assert_equal(['USERDEFINED', 'MsiUILevel'], @var2.ole_type_detail)
+ end
+
+ def test_ole_type_value
+ assert_equal(0, @var1.value)
+ assert_equal(nil, @var2.value)
+ end
+
+ def test_ole_type_visible?
+ assert(@var1.visible?)
+ end
+
+ def test_ole_type_variable_kind
+ assert_equal("CONSTANT", @var1.variable_kind)
+ assert_equal("DISPATCH", @var2.variable_kind)
+ end
+
+ def test_ole_type_varkind
+ assert_equal(2, @var1.varkind)
+ assert_equal(3, @var2.varkind)
+ end
+
+ def test_to_s
+ assert_equal(@var1.name, @var1.to_s)
+ end
+
+ def test_inspect
+ assert_equal("#<WIN32OLE_VARIABLE:ssfDESKTOP=0>", @var1.inspect)
+ assert_equal("#<WIN32OLE_VARIABLE:UILevel=nil>", @var2.inspect)
+ end
+
+ end
+end
diff --git a/jni/ruby/test/win32ole/test_win32ole_variant.rb b/jni/ruby/test/win32ole/test_win32ole_variant.rb
new file mode 100644
index 0000000..9583a01
--- /dev/null
+++ b/jni/ruby/test/win32ole/test_win32ole_variant.rb
@@ -0,0 +1,725 @@
+begin
+ require 'win32ole'
+rescue LoadError
+end
+require "test/unit"
+
+if defined?(WIN32OLE_VARIANT)
+
+ class TestWIN32OLE_VARIANT < Test::Unit::TestCase
+ def setup
+ @orglocale = WIN32OLE.locale
+ WIN32OLE.locale = 0x0409 # set locale US-Eng
+ end
+
+ def teardown
+ WIN32OLE.locale = @orglocale
+ end
+
+ def test_s_new
+ obj = WIN32OLE_VARIANT.new('foo')
+ assert_instance_of(WIN32OLE_VARIANT, obj)
+ end
+
+ def test_s_new_exc
+ assert_raise(TypeError) {
+ WIN32OLE_VARIANT.new(/foo/)
+ }
+ end
+
+ def test_s_new_ary
+ obj = WIN32OLE_VARIANT.new([1])
+ assert_instance_of(WIN32OLE_VARIANT, obj)
+ assert_raise(TypeError) {
+ WIN32OLE_VARIANT.new([/foo/])
+ }
+ end
+
+ def test_s_new_no_argument
+ ex = nil
+ begin
+ WIN32OLE_VARIANT.new
+ rescue ArgumentError
+ ex = $!
+ end
+ assert_instance_of(ArgumentError, ex)
+ assert_equal("wrong number of arguments (0 for 1..3)", ex.message);
+ end
+
+ def test_s_new_one_argument
+ ex = nil
+ begin
+ WIN32OLE_VARIANT.new('foo')
+ rescue
+ ex = $!
+ end
+ assert_equal(nil, ex);
+ end
+
+ def test_s_new_with_nil
+ obj = WIN32OLE_VARIANT.new(nil, WIN32OLE::VARIANT::VT_I2)
+ assert_equal(0, obj.value)
+ assert_equal(WIN32OLE::VARIANT::VT_I2, obj.vartype)
+
+ obj = WIN32OLE_VARIANT.new(nil, WIN32OLE::VARIANT::VT_I4)
+ assert_equal(0, obj.value)
+ assert_equal(WIN32OLE::VARIANT::VT_I4, obj.vartype)
+
+ obj = WIN32OLE_VARIANT.new(nil, WIN32OLE::VARIANT::VT_R4)
+ assert_equal(0, obj.value)
+ assert_equal(WIN32OLE::VARIANT::VT_R4, obj.vartype)
+
+ obj = WIN32OLE_VARIANT.new(nil, WIN32OLE::VARIANT::VT_R8)
+ assert_equal(0, obj.value)
+ assert_equal(WIN32OLE::VARIANT::VT_R8, obj.vartype)
+
+ obj = WIN32OLE_VARIANT.new(nil, WIN32OLE::VARIANT::VT_CY)
+ assert_equal("0", obj.value)
+ assert_equal(WIN32OLE::VARIANT::VT_CY, obj.vartype)
+
+ obj = WIN32OLE_VARIANT.new(nil, WIN32OLE::VARIANT::VT_DATE)
+ assert_equal(Time.new(1899,12,30), obj.value)
+ assert_equal(WIN32OLE::VARIANT::VT_DATE, obj.vartype)
+
+ obj = WIN32OLE_VARIANT.new(nil, WIN32OLE::VARIANT::VT_BSTR)
+ assert_equal("", obj.value)
+ assert_equal(WIN32OLE::VARIANT::VT_BSTR, obj.vartype)
+
+ obj = WIN32OLE_VARIANT.new(nil, WIN32OLE::VARIANT::VT_DISPATCH)
+ assert_nil(obj.value)
+ assert_equal(WIN32OLE::VARIANT::VT_DISPATCH, obj.vartype)
+
+ obj = WIN32OLE_VARIANT.new(nil, WIN32OLE::VARIANT::VT_BOOL)
+ assert_equal(false, obj.value)
+ assert_equal(WIN32OLE::VARIANT::VT_BOOL, obj.vartype)
+
+ obj = WIN32OLE_VARIANT.new(nil, WIN32OLE::VARIANT::VT_VARIANT)
+ assert_nil(obj.value)
+ assert_equal(WIN32OLE::VARIANT::VT_VARIANT, obj.vartype)
+
+ obj = WIN32OLE_VARIANT.new(nil, WIN32OLE::VARIANT::VT_I1)
+ assert_equal(0, obj.value)
+ assert_equal(WIN32OLE::VARIANT::VT_I1, obj.vartype)
+
+ obj = WIN32OLE_VARIANT.new(nil, WIN32OLE::VARIANT::VT_UI1)
+ assert_equal(0, obj.value)
+ assert_equal(WIN32OLE::VARIANT::VT_UI1, obj.vartype)
+
+ obj = WIN32OLE_VARIANT.new(nil, WIN32OLE::VARIANT::VT_UI2)
+ assert_equal(0, obj.value)
+ assert_equal(WIN32OLE::VARIANT::VT_UI2, obj.vartype)
+
+ obj = WIN32OLE_VARIANT.new(nil, WIN32OLE::VARIANT::VT_UI4)
+ assert_equal(0, obj.value)
+ assert_equal(WIN32OLE::VARIANT::VT_UI4, obj.vartype)
+
+
+ if defined?(WIN32OLE::VARIANT::VT_I8)
+ obj = WIN32OLE_VARIANT.new(nil, WIN32OLE::VARIANT::VT_I8)
+ assert_equal(0, obj.value)
+ assert_equal(WIN32OLE::VARIANT::VT_I8, obj.vartype)
+ end
+
+ if defined?(WIN32OLE::VARIANT::VT_UI8)
+ obj = WIN32OLE_VARIANT.new(nil, WIN32OLE::VARIANT::VT_UI8)
+ assert_equal(0, obj.value)
+ assert_equal(WIN32OLE::VARIANT::VT_UI8, obj.vartype)
+ end
+
+ obj = WIN32OLE_VARIANT.new(nil, WIN32OLE::VARIANT::VT_INT)
+ assert_equal(0, obj.value)
+ assert_equal(WIN32OLE::VARIANT::VT_INT, obj.vartype)
+
+ obj = WIN32OLE_VARIANT.new(nil, WIN32OLE::VARIANT::VT_UINT)
+ assert_equal(0, obj.value)
+ assert_equal(WIN32OLE::VARIANT::VT_UINT, obj.vartype)
+ end
+
+ def test_s_new_with_non_nil
+ obj = WIN32OLE_VARIANT.new(2, WIN32OLE::VARIANT::VT_I2)
+ assert_equal(2, obj.value)
+ assert_equal(WIN32OLE::VARIANT::VT_I2, obj.vartype)
+
+ obj = WIN32OLE_VARIANT.new(3, WIN32OLE::VARIANT::VT_I4)
+ assert_equal(3, obj.value)
+ assert_equal(WIN32OLE::VARIANT::VT_I4, obj.vartype)
+
+ obj = WIN32OLE_VARIANT.new(4.5, WIN32OLE::VARIANT::VT_R4)
+ assert_equal(4.5, obj.value)
+ assert_equal(WIN32OLE::VARIANT::VT_R4, obj.vartype)
+
+ obj = WIN32OLE_VARIANT.new(5.5, WIN32OLE::VARIANT::VT_R8)
+ assert_equal(5.5, obj.value)
+ assert_equal(WIN32OLE::VARIANT::VT_R8, obj.vartype)
+
+ obj = WIN32OLE_VARIANT.new(600, WIN32OLE::VARIANT::VT_CY)
+ assert_equal("600", obj.value)
+ assert_equal(WIN32OLE::VARIANT::VT_CY, obj.vartype)
+
+ obj = WIN32OLE_VARIANT.new("2001-06-15 12:17:34", WIN32OLE::VARIANT::VT_DATE)
+ assert_equal(Time.new(2001,06,15,12,17,34), obj.value)
+ assert_equal(WIN32OLE::VARIANT::VT_DATE, obj.vartype)
+
+ obj = WIN32OLE_VARIANT.new("foo", WIN32OLE::VARIANT::VT_BSTR)
+ assert_equal("foo", obj.value)
+ assert_equal(WIN32OLE::VARIANT::VT_BSTR, obj.vartype)
+
+ obj = WIN32OLE_VARIANT.new(true, WIN32OLE::VARIANT::VT_BOOL)
+ assert_equal(true, obj.value)
+ assert_equal(WIN32OLE::VARIANT::VT_BOOL, obj.vartype)
+
+ obj = WIN32OLE_VARIANT.new(2, WIN32OLE::VARIANT::VT_I1)
+ assert_equal(2, obj.value)
+ assert_equal(WIN32OLE::VARIANT::VT_I1, obj.vartype)
+
+ obj = WIN32OLE_VARIANT.new(3, WIN32OLE::VARIANT::VT_UI1)
+ assert_equal(3, obj.value)
+ assert_equal(WIN32OLE::VARIANT::VT_UI1, obj.vartype)
+
+ obj = WIN32OLE_VARIANT.new(4, WIN32OLE::VARIANT::VT_UI2)
+ assert_equal(4, obj.value)
+ assert_equal(WIN32OLE::VARIANT::VT_UI2, obj.vartype)
+
+ obj = WIN32OLE_VARIANT.new(5, WIN32OLE::VARIANT::VT_UI4)
+ assert_equal(5, obj.value)
+ assert_equal(WIN32OLE::VARIANT::VT_UI4, obj.vartype)
+
+ if defined?(WIN32OLE::VARIANT::VT_I8)
+ obj = WIN32OLE_VARIANT.new(-123456789012345, WIN32OLE::VARIANT::VT_I8)
+ assert_equal(-123456789012345, obj.value)
+ assert_equal(WIN32OLE::VARIANT::VT_I8, obj.vartype)
+ end
+
+ if defined?(WIN32OLE::VARIANT::VT_UI8)
+ obj = WIN32OLE_VARIANT.new(123456789012345, WIN32OLE::VARIANT::VT_UI8)
+ assert_equal(123456789012345, obj.value)
+ assert_equal(WIN32OLE::VARIANT::VT_UI8, obj.vartype)
+ end
+
+ obj = WIN32OLE_VARIANT.new(4, WIN32OLE::VARIANT::VT_INT)
+ assert_equal(4, obj.value)
+ assert_equal(WIN32OLE::VARIANT::VT_INT, obj.vartype)
+
+ obj = WIN32OLE_VARIANT.new(5, WIN32OLE::VARIANT::VT_UINT)
+ assert_equal(5, obj.value)
+ assert_equal(WIN32OLE::VARIANT::VT_UINT, obj.vartype)
+ end
+
+ def test_s_new_with_non_nil_byref
+ obj = WIN32OLE_VARIANT.new(2, WIN32OLE::VARIANT::VT_I2|WIN32OLE::VARIANT::VT_BYREF)
+ assert_equal(2, obj.value)
+ assert_equal(WIN32OLE::VARIANT::VT_I2|WIN32OLE::VARIANT::VT_BYREF, obj.vartype)
+
+ obj = WIN32OLE_VARIANT.new(3, WIN32OLE::VARIANT::VT_I4|WIN32OLE::VARIANT::VT_BYREF)
+ assert_equal(3, obj.value)
+ assert_equal(WIN32OLE::VARIANT::VT_I4|WIN32OLE::VARIANT::VT_BYREF, obj.vartype)
+
+ obj = WIN32OLE_VARIANT.new(4.5, WIN32OLE::VARIANT::VT_R4|WIN32OLE::VARIANT::VT_BYREF)
+ assert_equal(4.5, obj.value)
+ assert_equal(WIN32OLE::VARIANT::VT_R4|WIN32OLE::VARIANT::VT_BYREF, obj.vartype)
+
+ obj = WIN32OLE_VARIANT.new(5.5, WIN32OLE::VARIANT::VT_R8|WIN32OLE::VARIANT::VT_BYREF)
+ assert_equal(5.5, obj.value)
+ assert_equal(WIN32OLE::VARIANT::VT_R8|WIN32OLE::VARIANT::VT_BYREF, obj.vartype)
+
+ obj = WIN32OLE_VARIANT.new(600, WIN32OLE::VARIANT::VT_CY|WIN32OLE::VARIANT::VT_BYREF)
+ assert_equal("600", obj.value)
+ assert_equal(WIN32OLE::VARIANT::VT_CY|WIN32OLE::VARIANT::VT_BYREF, obj.vartype)
+
+ obj = WIN32OLE_VARIANT.new("2001-06-15 12:17:34", WIN32OLE::VARIANT::VT_DATE|WIN32OLE::VARIANT::VT_BYREF)
+ assert_equal(Time.new(2001,06,15,12,17,34), obj.value)
+ assert_equal(WIN32OLE::VARIANT::VT_DATE|WIN32OLE::VARIANT::VT_BYREF, obj.vartype)
+
+ obj = WIN32OLE_VARIANT.new("foo", WIN32OLE::VARIANT::VT_BSTR|WIN32OLE::VARIANT::VT_BYREF)
+ assert_equal("foo", obj.value)
+ assert_equal(WIN32OLE::VARIANT::VT_BSTR|WIN32OLE::VARIANT::VT_BYREF, obj.vartype)
+
+ obj = WIN32OLE_VARIANT.new(true, WIN32OLE::VARIANT::VT_BOOL|WIN32OLE::VARIANT::VT_BYREF)
+ assert_equal(true, obj.value)
+ assert_equal(WIN32OLE::VARIANT::VT_BOOL|WIN32OLE::VARIANT::VT_BYREF, obj.vartype)
+
+ obj = WIN32OLE_VARIANT.new(2, WIN32OLE::VARIANT::VT_I1|WIN32OLE::VARIANT::VT_BYREF)
+ assert_equal(2, obj.value)
+ assert_equal(WIN32OLE::VARIANT::VT_I1|WIN32OLE::VARIANT::VT_BYREF, obj.vartype)
+
+ obj = WIN32OLE_VARIANT.new(3, WIN32OLE::VARIANT::VT_UI1|WIN32OLE::VARIANT::VT_BYREF)
+ assert_equal(3, obj.value)
+ assert_equal(WIN32OLE::VARIANT::VT_UI1|WIN32OLE::VARIANT::VT_BYREF, obj.vartype)
+
+ obj = WIN32OLE_VARIANT.new(4, WIN32OLE::VARIANT::VT_UI2|WIN32OLE::VARIANT::VT_BYREF)
+ assert_equal(4, obj.value)
+ assert_equal(WIN32OLE::VARIANT::VT_UI2|WIN32OLE::VARIANT::VT_BYREF, obj.vartype)
+
+ obj = WIN32OLE_VARIANT.new(5, WIN32OLE::VARIANT::VT_UI4|WIN32OLE::VARIANT::VT_BYREF)
+ assert_equal(5, obj.value)
+ assert_equal(WIN32OLE::VARIANT::VT_UI4|WIN32OLE::VARIANT::VT_BYREF, obj.vartype)
+
+ obj = WIN32OLE_VARIANT.new(4, WIN32OLE::VARIANT::VT_INT|WIN32OLE::VARIANT::VT_BYREF)
+ assert_equal(4, obj.value)
+ assert_equal(WIN32OLE::VARIANT::VT_INT|WIN32OLE::VARIANT::VT_BYREF, obj.vartype)
+
+ obj = WIN32OLE_VARIANT.new(5, WIN32OLE::VARIANT::VT_UINT|WIN32OLE::VARIANT::VT_BYREF)
+ assert_equal(5, obj.value)
+ assert_equal(WIN32OLE::VARIANT::VT_UINT|WIN32OLE::VARIANT::VT_BYREF, obj.vartype)
+ end
+
+ def test_s_new_with_i8_byref
+ obj = WIN32OLE_VARIANT.new(-123456789012345, WIN32OLE::VARIANT::VT_I8|WIN32OLE::VARIANT::VT_BYREF)
+ assert_equal(-123456789012345, obj.value)
+ assert_equal(WIN32OLE::VARIANT::VT_I8|WIN32OLE::VARIANT::VT_BYREF, obj.vartype)
+ end
+
+ def test_s_new_with_ui8_byref
+ obj = WIN32OLE_VARIANT.new(123456789012345, WIN32OLE::VARIANT::VT_UI8|WIN32OLE::VARIANT::VT_BYREF)
+ assert_equal(123456789012345, obj.value)
+ assert_equal(WIN32OLE::VARIANT::VT_UI8|WIN32OLE::VARIANT::VT_BYREF, obj.vartype)
+ end
+
+ def test_value
+ obj = WIN32OLE_VARIANT.new('foo')
+ assert_equal('foo', obj.value)
+ end
+
+ def test_s_new_2_argument
+ obj = WIN32OLE_VARIANT.new('foo', WIN32OLE::VARIANT::VT_BSTR|WIN32OLE::VARIANT::VT_BYREF)
+ assert_equal('foo', obj.value);
+ end
+
+ def test_s_new_2_argument2
+ obj = WIN32OLE_VARIANT.new('foo', WIN32OLE::VARIANT::VT_BSTR)
+ assert_equal('foo', obj.value);
+ end
+
+ def test_s_new_dispatch_array
+ vt = WIN32OLE::VARIANT::VT_ARRAY|WIN32OLE::VARIANT::VT_DISPATCH
+ obj = WIN32OLE_VARIANT.new(nil, vt)
+ assert_equal(vt, obj.vartype)
+ assert_nil(obj.value)
+
+ vt = WIN32OLE::VARIANT::VT_ARRAY|WIN32OLE::VARIANT::VT_DISPATCH|WIN32OLE::VARIANT::VT_BYREF
+ obj = WIN32OLE_VARIANT.new(nil, vt)
+ assert_equal(vt, obj.vartype)
+ assert_nil(obj.value)
+ end
+
+ def test_s_new_array
+ # should not occur stack over flow
+ ar = (1..500000).to_a.map{|i| [i]}
+ ar2 = WIN32OLE_VARIANT.new(ar)
+ assert_equal(ar, ar2.value)
+ end
+
+ def test_s_new_vt_record_exc
+ # VT_RECORD (= 36) should not be allowed in WIN32OLE_VARIANT#new
+ assert_raise(ArgumentError) {
+ WIN32OLE_VARIANT.new(nil, 36)
+ }
+ end
+
+ def test_s_array
+ obj = WIN32OLE_VARIANT.array([2,3], WIN32OLE::VARIANT::VT_I4)
+ assert_instance_of(WIN32OLE_VARIANT, obj)
+ assert_equal(WIN32OLE::VARIANT::VT_I4|WIN32OLE::VARIANT::VT_ARRAY, obj.vartype)
+ assert_equal([[0, 0, 0],[0, 0, 0]], obj.value)
+
+ obj = WIN32OLE_VARIANT.array([2,3], WIN32OLE::VARIANT::VT_I4|WIN32OLE::VARIANT::VT_BYREF)
+ assert_equal(WIN32OLE::VARIANT::VT_I4|WIN32OLE::VARIANT::VT_BYREF|WIN32OLE::VARIANT::VT_ARRAY, obj.vartype)
+ assert_equal([[0, 0, 0],[0, 0, 0]], obj.value)
+
+ obj = WIN32OLE_VARIANT.array([2,3], WIN32OLE::VARIANT::VT_I4|WIN32OLE::VARIANT::VT_ARRAY)
+ assert_instance_of(WIN32OLE_VARIANT, obj)
+ assert_equal(WIN32OLE::VARIANT::VT_I4|WIN32OLE::VARIANT::VT_ARRAY, obj.vartype)
+ assert_equal([[0, 0, 0],[0, 0, 0]], obj.value)
+
+ assert_equal(0, obj[0,0])
+ obj[0,0] = 10
+ assert_equal([[10, 0, 0],[0, 0, 0]], obj.value)
+ obj[0,1] = "13.2"
+ assert_equal([[10, 13, 0],[0, 0, 0]], obj.value)
+
+ obj = WIN32OLE_VARIANT.array([3, 2], WIN32OLE::VARIANT::VT_VARIANT)
+ obj[0,0] = 10
+ obj[0,1] = "string"
+ obj[1,0] = 12.735
+ assert_equal([[10, "string"],[12.735, nil],[nil,nil]], obj.value)
+
+ obj = WIN32OLE_VARIANT.array([2,3], WIN32OLE::VARIANT::VT_DISPATCH)
+ assert_equal([[nil, nil, nil],[nil,nil,nil]], obj.value)
+
+ end
+
+ def test_s_array_exc
+ assert_raise(TypeError) {
+ WIN32OLE_VARIANT.array(2, WIN32OLE::VARIANT::VT_I4)
+ }
+ end
+
+ def test_conversion_num2str
+ obj = WIN32OLE_VARIANT.new(124, WIN32OLE::VARIANT::VT_BSTR)
+ assert_equal("124", obj.value);
+ end
+
+ def test_conversion_float2int
+ obj = WIN32OLE_VARIANT.new(12.345, WIN32OLE::VARIANT::VT_I4)
+ assert_equal(12, obj.value)
+ obj = WIN32OLE_VARIANT.new(12.345, WIN32OLE::VARIANT::VT_I4|WIN32OLE::VARIANT::VT_BYREF)
+ assert_equal(12, obj.value)
+ end
+
+ def test_conversion_str2num
+ obj = WIN32OLE_VARIANT.new("12.345", WIN32OLE::VARIANT::VT_R8)
+ assert_equal(12.345, obj.value)
+ end
+
+ def test_conversion_ole_variant2ole_variant
+ obj = WIN32OLE_VARIANT.new("12.345", WIN32OLE::VARIANT::VT_R4)
+ obj = WIN32OLE_VARIANT.new(obj, WIN32OLE::VARIANT::VT_I4)
+ assert_equal(12, obj.value)
+ end
+
+ def test_conversion_str2date
+ obj = WIN32OLE_VARIANT.new("2004-12-24 12:24:45", WIN32OLE::VARIANT::VT_DATE)
+ assert_equal(Time.new(2004,12,24,12,24,45), obj.value)
+ end
+
+ def test_conversion_time2date
+ dt = Time.mktime(2004, 12, 24, 12, 24, 45)
+ obj = WIN32OLE_VARIANT.new(dt, WIN32OLE::VARIANT::VT_DATE)
+ assert_equal(dt, obj.value)
+ end
+
+ def test_conversion_dbl2date_with_msec
+ # Date is "2014/8/27 12:34:56.789"
+ obj = WIN32OLE_VARIANT.new(41878.524268391200167, WIN32OLE::VARIANT::VT_DATE)
+ t = obj.value
+ assert_equal("2014-08-27 12:34:56", t.strftime('%Y-%m-%d %H:%M:%S'))
+ assert_in_delta(0.789, t.nsec / 1000000000.0, 0.001)
+ end
+
+ def test_conversion_time2date_with_msec
+ t0 = Time.new(2014, 8, 27, 12, 34, 56)
+ t0 += 0.789
+ t1 = WIN32OLE_VARIANT.new(t0).value
+
+ # The t0.nsec is 789000000 and t1.nsec is 789000465
+ # because of error range by conversion Time between VT_DATE Variant.
+ # So check t1 and t0 are in error by less than one millisecond.
+ msg = "Expected:#{t0.strftime('%Y-%m-%dT%H:%M:%S.%N')} but was:#{t1.strftime('%Y-%m-%dT%H:%M:%S.%N')}"
+ assert_in_delta(t0, t1, 0.001, msg)
+
+ t0 = Time.new(2014, 8, 27, 12, 34, 56)
+ t0 += 0.999999999
+ t1 = WIN32OLE_VARIANT.new(t0).value
+ msg = "Expected:#{t0.strftime('%Y-%m-%dT%H:%M:%S.%N')} but was:#{t1.strftime('%Y-%m-%dT%H:%M:%S.%N')}"
+
+ # The t0 is "2014/08/27 12:34.56.999999999" and
+ # the t1 is "2014/08/27 12:34:57.000000628"
+ assert_in_delta(t0, t1, 0.001, msg)
+
+ t0 = Time.now
+ t1 = WIN32OLE_VARIANT.new(t0).value
+ msg = "Expected:#{t0.strftime('%Y-%m-%dT%H:%M:%S.%N')} but was:#{t1.strftime('%Y-%m-%dT%H:%M:%S.%N')}"
+ assert_in_delta(t0, t1, 0.001, msg)
+ end
+
+ # this test failed because of VariantTimeToSystemTime
+ # and SystemTimeToVariantTime API ignores wMilliseconds
+ # member of SYSTEMTIME struct.
+ #
+ # def test_conversion_time_nsec2date
+ # dt = Time.new(2004, 12,24, 12, 24, 45)
+ # dt += 0.1
+ # obj = WIN32OLE_VARIANT.new(dt, WIN32OLE::VARIANT::VT_DATE)
+ # assert_equal(dt, obj.value)
+ # end
+
+ def test_conversion_str2cy
+ begin
+ WIN32OLE.locale = 0x0411 # set locale Japanese
+ rescue WIN32OLERuntimeError
+ skip("Japanese locale is not installed")
+ end
+ if WIN32OLE.locale == 0x0411
+ obj = WIN32OLE_VARIANT.new("\\10,000", WIN32OLE::VARIANT::VT_CY)
+ assert_equal("10000", obj.value)
+ end
+ end
+
+ def test_create_vt_array
+ obj = WIN32OLE_VARIANT.new([1.2, 2.3], WIN32OLE::VARIANT::VT_ARRAY|WIN32OLE::VARIANT::VT_R8)
+ assert_equal([1.2, 2.3], obj.value)
+ assert_equal(WIN32OLE::VARIANT::VT_ARRAY|WIN32OLE::VARIANT::VT_R8, obj.vartype)
+
+ obj = WIN32OLE_VARIANT.new([1.2, 2.3], WIN32OLE::VARIANT::VT_ARRAY|WIN32OLE::VARIANT::VT_R8|WIN32OLE::VARIANT::VT_BYREF)
+ assert_equal([1.2, 2.3], obj.value)
+ assert_equal(WIN32OLE::VARIANT::VT_ARRAY|WIN32OLE::VARIANT::VT_R8|WIN32OLE::VARIANT::VT_BYREF, obj.vartype)
+ end
+
+ def test_create_vt_array2
+ obj = WIN32OLE_VARIANT.new([1.2, "a"], WIN32OLE::VARIANT::VT_ARRAY)
+ assert_equal([1.2, "a"], obj.value)
+ assert_equal(WIN32OLE::VARIANT::VT_ARRAY|WIN32OLE::VARIANT::VT_VARIANT, obj.vartype)
+
+ obj = WIN32OLE_VARIANT.new([1.2, "a"])
+ assert_equal([1.2, "a"], obj.value)
+ assert_equal(WIN32OLE::VARIANT::VT_ARRAY|WIN32OLE::VARIANT::VT_VARIANT, obj.vartype)
+ end
+
+
+ def test_create_vt_nested_array
+ obj = WIN32OLE_VARIANT.new([[1.2, "a", "b"], [3.4, "C", "D"]], WIN32OLE::VARIANT::VT_ARRAY)
+ assert_equal([[1.2, "a", "b"], [3.4, "C", "D"]], obj.value)
+
+ obj = WIN32OLE_VARIANT.new([[1.2, "a", "b"], [3.4, "C", "D"]])
+ assert_equal([[1.2, "a", "b"], [3.4, "C", "D"]], obj.value)
+
+ obj = WIN32OLE_VARIANT.new([[1.2, "a", "b"], [3.4, "C", "D"], [5.6, "E", "F"]])
+ assert_equal([[1.2, "a", "b"], [3.4, "C", "D"], [5.6, "E", "F"]], obj.value)
+
+ obj = WIN32OLE_VARIANT.new([[[1.2], [3.4]], [[5.6], [7.8]], [[9.1],[9.2]]])
+ assert_equal([[[1.2], [3.4]], [[5.6], [7.8]], [[9.1],[9.2]]], obj.value)
+ end
+
+ def test_create_vt_array3
+ obj = WIN32OLE_VARIANT.new([])
+ assert_equal([], obj.value)
+
+ obj = WIN32OLE_VARIANT.new([[]])
+ assert_equal([[]], obj.value)
+
+ obj = WIN32OLE_VARIANT.new([[],[]])
+ assert_equal([[],[]], obj.value)
+
+ obj = WIN32OLE_VARIANT.new([], WIN32OLE::VARIANT::VT_ARRAY|WIN32OLE::VARIANT::VT_BYREF)
+ assert_equal([], obj.value)
+
+ obj = WIN32OLE_VARIANT.new([[]], WIN32OLE::VARIANT::VT_ARRAY|WIN32OLE::VARIANT::VT_BYREF)
+ assert_equal([[]], obj.value)
+
+ obj = WIN32OLE_VARIANT.new([[],[]], WIN32OLE::VARIANT::VT_ARRAY|WIN32OLE::VARIANT::VT_BYREF)
+ assert_equal([[],[]], obj.value)
+ end
+
+ def test_create_vt_array_nil
+ vartype = WIN32OLE::VARIANT::VT_ARRAY|WIN32OLE::VARIANT::VT_DISPATCH|WIN32OLE::VARIANT::VT_BYREF
+ obj = WIN32OLE_VARIANT.new(nil, vartype)
+ assert_nil(obj.value)
+ assert_equal(vartype, obj.vartype)
+
+ vartype = WIN32OLE::VARIANT::VT_ARRAY|WIN32OLE::VARIANT::VT_DISPATCH
+ obj = WIN32OLE_VARIANT.new(nil, vartype)
+ assert_nil(obj.value)
+ assert_equal(vartype, obj.vartype)
+ end
+
+ def test_create_vt_array_str
+ vartype = WIN32OLE::VARIANT::VT_ARRAY|WIN32OLE::VARIANT::VT_BSTR
+ obj = WIN32OLE_VARIANT.new(["abc", "123"], vartype)
+ assert_equal(vartype, obj.vartype)
+ assert_equal(["abc", "123"], obj.value)
+
+ vartype = WIN32OLE::VARIANT::VT_ARRAY|WIN32OLE::VARIANT::VT_BYREF|WIN32OLE::VARIANT::VT_BSTR
+ obj = WIN32OLE_VARIANT.new(["abc", "123"], vartype)
+ assert_equal(vartype, obj.vartype)
+ assert_equal(["abc", "123"], obj.value)
+ end
+
+ def test_create_vt_array_exc
+ exc = assert_raise(TypeError) {
+ WIN32OLE_VARIANT.new(1, WIN32OLE::VARIANT::VT_ARRAY);
+ }
+ assert_match(/wrong argument type Fixnum \(expected Array\)/, exc.message)
+ end
+
+ def test_create_vt_array_str2ui1array
+ obj = WIN32OLE_VARIANT.new("ABC", WIN32OLE::VARIANT::VT_ARRAY|WIN32OLE::VARIANT::VT_UI1)
+ assert_equal("ABC", obj.value)
+
+ obj.value = "DEF"
+ assert_equal("DEF", obj.value)
+ obj[0] = 71
+ assert_equal("GEF", obj.value)
+
+ obj = WIN32OLE_VARIANT.new([65, 0].pack("C*"), WIN32OLE::VARIANT::VT_ARRAY|WIN32OLE::VARIANT::VT_UI1)
+ assert_equal([65, 0].pack("C*"), obj.value)
+
+ obj = WIN32OLE_VARIANT.new("abc", WIN32OLE::VARIANT::VT_ARRAY|WIN32OLE::VARIANT::VT_UI1|WIN32OLE::VARIANT::VT_BYREF)
+ assert_equal("abc", obj.value)
+ obj.value = "DEF"
+ assert_equal("DEF", obj.value)
+ assert_equal(WIN32OLE::VARIANT::VT_ARRAY|WIN32OLE::VARIANT::VT_UI1|WIN32OLE::VARIANT::VT_BYREF, obj.vartype)
+ obj[1] = 71
+ assert_equal("DGF", obj.value)
+
+ end
+
+ def test_create_vt_array_int
+ obj = WIN32OLE_VARIANT.new([65, 0], WIN32OLE::VARIANT::VT_ARRAY|WIN32OLE::VARIANT::VT_UI1)
+ assert_equal([65, 0].pack("C*"), obj.value)
+
+ obj = WIN32OLE_VARIANT.new([65, 0])
+ assert_equal([65, 0], obj.value)
+
+ obj = WIN32OLE_VARIANT.new([65, 0], WIN32OLE::VARIANT::VT_I2|WIN32OLE::VARIANT::VT_ARRAY)
+ assert_equal([65, 0], obj.value)
+
+ end
+
+ def test_vt_array_bracket
+ obj = WIN32OLE_VARIANT.new([[1,2,3],[4,5,6]])
+ assert_equal(1, obj[0,0])
+ assert_equal(2, obj[0,1])
+ assert_equal(3, obj[0,2])
+ assert_equal(4, obj[1,0])
+ assert_equal(5, obj[1,1])
+ assert_equal(6, obj[1,2])
+
+ assert_raise(WIN32OLERuntimeError) {
+ obj[0,4]
+ }
+ assert_raise(WIN32OLERuntimeError) {
+ obj[0,-1]
+ }
+ assert_raise(ArgumentError) {
+ obj[0]
+ }
+
+ obj[0,0] = 7
+ obj[1,2] = 8
+ assert_equal([[7,2,3], [4,5,8]], obj.value)
+
+ assert_raise(WIN32OLERuntimeError) {
+ obj[0,4] = 9
+ }
+ assert_raise(WIN32OLERuntimeError) {
+ obj[0,-1] = 10
+ }
+ assert_raise(ArgumentError) {
+ obj[0] = 11
+ }
+ end
+
+ def test_conversion_vt_date
+ obj = WIN32OLE_VARIANT.new(-657434, WIN32OLE::VARIANT::VT_DATE)
+ assert_equal(Time.new(100,1,1), obj.value)
+
+ obj = WIN32OLE_VARIANT.new("1500/12/29 23:59:59", WIN32OLE::VARIANT::VT_DATE)
+ assert_equal(Time.new(1500,12,29,23,59,59), obj.value)
+
+ obj = WIN32OLE_VARIANT.new("1500/12/30 00:00:00", WIN32OLE::VARIANT::VT_DATE)
+ assert_equal(Time.new(1500,12,30), obj.value)
+
+ obj = WIN32OLE_VARIANT.new("1500/12/30 00:00:01", WIN32OLE::VARIANT::VT_DATE)
+ assert_equal(Time.new(1500,12,30,0,0,1), obj.value)
+
+ obj = WIN32OLE_VARIANT.new("1899/12/29 23:59:59", WIN32OLE::VARIANT::VT_DATE)
+ assert_equal(Time.new(1899,12,29,23,59,59), obj.value)
+
+ obj = WIN32OLE_VARIANT.new("1899/12/30 00:00:00", WIN32OLE::VARIANT::VT_DATE)
+ assert_equal(Time.new(1899,12,30), obj.value)
+
+ obj = WIN32OLE_VARIANT.new("1899/12/30 00:00:01", WIN32OLE::VARIANT::VT_DATE)
+ assert_equal(Time.new(1899,12,30,0,0,1), obj.value)
+
+ obj = WIN32OLE_VARIANT.new(0, WIN32OLE::VARIANT::VT_DATE)
+ assert_equal(Time.new(1899,12,30), obj.value)
+
+ obj = WIN32OLE_VARIANT.new("2008/12/29 23:59:59", WIN32OLE::VARIANT::VT_DATE)
+ assert_equal(Time.new(2008,12,29,23,59,59), obj.value)
+
+ obj = WIN32OLE_VARIANT.new("2008/12/30 00:00:00", WIN32OLE::VARIANT::VT_DATE)
+ assert_equal(Time.new(2008,12,30,0,0,0), obj.value)
+
+ obj = WIN32OLE_VARIANT.new("2008/12/30 00:00:01", WIN32OLE::VARIANT::VT_DATE)
+ assert_equal(Time.new(2008,12,30,0,0,1), obj.value)
+
+ obj = WIN32OLE_VARIANT.new("9999/12/31 23:59:59", WIN32OLE::VARIANT::VT_DATE)
+ assert_equal(Time.new(9999,12,31,23,59,59), obj.value)
+ end
+
+ def test_create_nil_dispatch
+ var = WIN32OLE_VARIANT.new(nil, WIN32OLE::VARIANT::VT_DISPATCH)
+ assert_nil(var.value)
+ end
+
+ def test_create_variant_byref
+ obj = WIN32OLE_VARIANT.new("Str", WIN32OLE::VARIANT::VT_VARIANT|WIN32OLE::VARIANT::VT_BYREF);
+ assert_equal("Str", obj.value);
+ end
+
+ def test_vartype
+ obj = WIN32OLE_VARIANT.new("Str")
+ assert_equal(WIN32OLE::VARIANT::VT_BSTR, obj.vartype)
+ end
+
+ def test_set_value
+ obj = WIN32OLE_VARIANT.new(10)
+ obj.value = 12
+ assert_equal(12, obj.value)
+ assert_equal(WIN32OLE::VARIANT::VT_I4, obj.vartype)
+ obj.value = "14"
+ assert_equal(14, obj.value)
+ assert_equal(WIN32OLE::VARIANT::VT_I4, obj.vartype)
+ obj.value = 11.2
+ assert_equal(11, obj.value)
+ assert_equal(WIN32OLE::VARIANT::VT_I4, obj.vartype)
+
+ obj = WIN32OLE_VARIANT.new([1,2])
+ assert_raise(WIN32OLERuntimeError) {
+ obj.value = [3,4]
+ }
+
+ obj = WIN32OLE_VARIANT.new("2007/01/01", WIN32OLE::VARIANT::VT_DATE)
+ assert_raise(WIN32OLERuntimeError) {
+ obj.value = "hogehoge"
+ }
+ assert_equal(Time.new(2007,1,1), obj.value)
+
+ obj2 = WIN32OLE_VARIANT.new("2006/01/01", WIN32OLE::VARIANT::VT_DATE)
+ obj.value = obj2
+ assert_equal(Time.new(2006,01,01), obj.value)
+ end
+
+ def test_c_nothing
+ assert_nil(WIN32OLE_VARIANT::Nothing.value)
+ end
+
+ def test_c_empty
+ assert_nil(WIN32OLE_VARIANT::Empty.value)
+ end
+
+ def test_c_null
+ assert_nil(WIN32OLE_VARIANT::Null.value)
+ end
+
+ def test_c_noparam
+ # DISP_E_PARAMNOTFOUND
+ assert_equal(-2147352572, WIN32OLE_VARIANT::NoParam.value)
+ end
+
+ def test_vt_error_noparam
+ v = WIN32OLE_VARIANT.new(-1, WIN32OLE::VARIANT::VT_ERROR)
+ assert_equal(-1, v.value)
+ fso = WIN32OLE.new("Scripting.FileSystemObject")
+ exc = assert_raise(WIN32OLERuntimeError) {
+ fso.openTextFile("NonExistingFile", v, false)
+ }
+ assert_match(/Type mismatch/i, exc.message)
+ exc = assert_raise(WIN32OLERuntimeError) {
+ fso.openTextFile("NonExistingFile", WIN32OLE_VARIANT::NoParam, false)
+ }
+ # 800A0035 is 'file not found' error.
+ assert_match(/800A0035/, exc.message)
+
+ # -2147352572 is DISP_E_PARAMNOTFOUND
+ v = WIN32OLE_VARIANT.new(-2147352572, WIN32OLE::VARIANT::VT_ERROR)
+ exc = assert_raise(WIN32OLERuntimeError) {
+ fso.openTextFile("NonExistingFile", WIN32OLE_VARIANT::NoParam, false)
+ }
+ # 800A0035 is 'file not found' error code.
+ assert_match(/800A0035/, exc.message)
+ end
+
+ end
+end
+
diff --git a/jni/ruby/test/win32ole/test_win32ole_variant_m.rb b/jni/ruby/test/win32ole/test_win32ole_variant_m.rb
new file mode 100644
index 0000000..b3e48c2
--- /dev/null
+++ b/jni/ruby/test/win32ole/test_win32ole_variant_m.rb
@@ -0,0 +1,35 @@
+begin
+ require 'win32ole'
+rescue LoadError
+end
+require "test/unit"
+
+if defined?(WIN32OLE::VARIANT)
+ class TestWin32OLE_VARIANT_MODULE < Test::Unit::TestCase
+ include WIN32OLE::VARIANT
+ def test_variant
+ assert_equal(0, VT_EMPTY)
+ assert_equal(1, VT_NULL)
+ 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
+end
diff --git a/jni/ruby/test/win32ole/test_win32ole_variant_outarg.rb b/jni/ruby/test/win32ole/test_win32ole_variant_outarg.rb
new file mode 100644
index 0000000..ffc8e06
--- /dev/null
+++ b/jni/ruby/test/win32ole/test_win32ole_variant_outarg.rb
@@ -0,0 +1,68 @@
+begin
+ require 'win32ole'
+rescue LoadError
+end
+require 'test/unit'
+require 'fileutils'
+
+def ado_csv_installed?
+ installed = false
+ if defined?(WIN32OLE)
+ db = nil
+ begin
+ db = WIN32OLE.new('ADODB.Connection')
+ db.connectionString = "Driver={Microsoft Text Driver (*.txt; *.csv)};DefaultDir=.;"
+ db.open
+ db.close
+ db = nil
+ installed = true
+ rescue
+ end
+ end
+ installed
+end
+
+if defined?(WIN32OLE_VARIANT)
+ class TestWIN32OLE_VARIANT_OUTARG < Test::Unit::TestCase
+ module ADO
+ end
+ CONNSTR="Driver={Microsoft Text Driver (*.txt; *.csv)};DefaultDir=.;"
+ def setup
+ return if !ado_csv_installed?
+
+ FileUtils.cp(File.dirname(__FILE__) + '/orig_data.csv', './data.csv')
+ @db = WIN32OLE.new('ADODB.Connection')
+ if !defined?(ADO::AdStateOpen)
+ WIN32OLE.const_load(@db, ADO)
+ end
+ @db.connectionString = CONNSTR
+ @db.open
+ end
+
+ def test_variant_ref_and_argv
+ if !ado_csv_installed?
+ skip("ActiveX Data Object Library not found")
+ end
+ sql = "INSERT INTO data.csv VALUES (5, 'E')"
+ @db.execute(sql, -1)
+ c = WIN32OLE::ARGV[1]
+ assert_equal(1, c)
+ obj = WIN32OLE_VARIANT.new(nil, WIN32OLE::VARIANT::VT_VARIANT|WIN32OLE::VARIANT::VT_BYREF)
+ assert_equal(nil, obj.value)
+ @db.execute(sql , obj)
+ assert_equal(1, obj.value)
+ obj = WIN32OLE_VARIANT.new(-100, WIN32OLE::VARIANT::VT_VARIANT|WIN32OLE::VARIANT::VT_BYREF)
+ assert_equal(-100, obj.value)
+ @db.execute(sql, obj)
+ assert_equal(1, obj.value)
+ end
+
+ def teardown
+ return if !ado_csv_installed?
+ if @db && @db.state == ADO::AdStateOpen
+ @db.close
+ end
+ File.unlink("data.csv")
+ end
+ end
+end
diff --git a/jni/ruby/test/win32ole/test_word.rb b/jni/ruby/test/win32ole/test_word.rb
new file mode 100644
index 0000000..acfa214
--- /dev/null
+++ b/jni/ruby/test/win32ole/test_word.rb
@@ -0,0 +1,71 @@
+#
+# This is test for [ruby-Bugs#3237]
+#
+begin
+ require 'win32ole'
+rescue LoadError
+end
+require "test/unit"
+
+def word_installed?
+ installed = false
+ w = nil
+ if defined?(WIN32OLE)
+ begin
+ w = WIN32OLE.new('Word.Application')
+ installed = true
+ rescue
+ ensure
+ if w
+ w.quit
+ w = nil
+ end
+ end
+ end
+ return installed
+end
+
+if defined?(WIN32OLE)
+ dotest = word_installed?
+ if !dotest
+ STDERR.puts("\n#{__FILE__} skipped(Microsoft Word not found.)")
+ end
+ if dotest
+ class TestWIN32OLE_WITH_WORD < Test::Unit::TestCase
+ def setup
+ begin
+ @obj = WIN32OLE.new('Word.Application')
+ rescue WIN32OLERuntimeError
+ @obj = nil
+ if !$skipped
+ $skipped = true
+ end
+ end
+ end
+
+ def test_ole_methods
+ if @obj
+ @obj.visible = true
+ @obj.wordbasic.disableAutoMacros(true)
+ assert(true)
+ else
+ 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
+ @obj = nil
+ end
+ end
+ end
+ end
+end