mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
990ae267cd
ole_val_ary2variant_ary): fix WIN32OLE_VARIANT.new bug when 1st argument is empty array, and when 2nd argument is VT_ARRAY|VT_BYREF. * test/win32ole/test_win32ole_variant.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11670 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
204 lines
6.3 KiB
Ruby
204 lines
6.3 KiB
Ruby
begin
|
|
require 'win32ole'
|
|
rescue LoadError
|
|
end
|
|
require "test/unit"
|
|
|
|
if defined?(WIN32OLE_VARIANT)
|
|
|
|
class TestWIN32OLE_VARIANT < Test::Unit::TestCase
|
|
|
|
def test_new
|
|
obj = WIN32OLE_VARIANT.new('foo')
|
|
assert_instance_of(WIN32OLE_VARIANT, obj)
|
|
end
|
|
|
|
def test_new_no_argument
|
|
ex = nil
|
|
begin
|
|
obj = 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_new_one_argument
|
|
ex = nil
|
|
begin
|
|
obj = WIN32OLE_VARIANT.new('foo')
|
|
rescue
|
|
ex = $!
|
|
end
|
|
assert_equal(nil, ex);
|
|
end
|
|
|
|
def test_value
|
|
obj = WIN32OLE_VARIANT.new('foo')
|
|
assert_equal('foo', obj.value)
|
|
end
|
|
|
|
def test_new_2_argument
|
|
obj = WIN32OLE_VARIANT.new('foo', WIN32OLE::VARIANT::VT_BSTR|WIN32OLE::VARIANT::VT_BYREF)
|
|
assert_equal('foo', obj.value);
|
|
end
|
|
|
|
def test_new_2_argument2
|
|
obj = WIN32OLE_VARIANT.new('foo', WIN32OLE::VARIANT::VT_BSTR)
|
|
assert_equal('foo', obj.value);
|
|
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)
|
|
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("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("2004/12/24 12:24:45", obj.value)
|
|
end
|
|
|
|
def test_conversion_str2cy
|
|
begin
|
|
WIN32OLE.locale = 0x0411 # set locale Japanese
|
|
obj = WIN32OLE_VARIANT.new("\\10,000", WIN32OLE::VARIANT::VT_CY)
|
|
assert_equal("10000", obj.value)
|
|
ensure
|
|
WIN32OLE.locale = WIN32OLE::LOCALE_SYSTEM_DEFAULT
|
|
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_exc
|
|
exc = assert_raise(TypeError) {
|
|
obj = 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 = WIN32OLE_VARIANT.new([65, 0].pack("C*"), WIN32OLE::VARIANT::VT_ARRAY|WIN32OLE::VARIANT::VT_UI1)
|
|
assert_equal([65, 0].pack("C*"), 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_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_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
|
|
|
|
end
|
|
end
|