2006-04-30 19:37:54 -04:00
|
|
|
begin
|
|
|
|
require 'win32ole'
|
|
|
|
rescue LoadError
|
|
|
|
end
|
|
|
|
require "test/unit"
|
2005-08-13 08:13:20 -04:00
|
|
|
|
2006-04-30 19:37:54 -04:00
|
|
|
if defined?(WIN32OLE_VARIANT)
|
2005-08-13 08:13:20 -04:00
|
|
|
|
2006-04-30 19:37:54 -04:00
|
|
|
class TestWIN32OLE_VARIANT < Test::Unit::TestCase
|
2012-08-06 06:21:12 -04:00
|
|
|
def setup
|
|
|
|
@orglocale = WIN32OLE.locale
|
|
|
|
WIN32OLE.locale = 0x0409 # set locale US-Eng
|
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
|
|
|
WIN32OLE.locale = @orglocale
|
|
|
|
end
|
2007-02-08 08:48:16 -05:00
|
|
|
|
2007-03-02 07:35:02 -05:00
|
|
|
def test_s_new
|
2006-04-30 19:37:54 -04:00
|
|
|
obj = WIN32OLE_VARIANT.new('foo')
|
|
|
|
assert_instance_of(WIN32OLE_VARIANT, obj)
|
2005-08-13 08:13:20 -04:00
|
|
|
end
|
|
|
|
|
2008-11-06 07:38:49 -05:00
|
|
|
def test_s_new_exc
|
|
|
|
assert_raise(TypeError) {
|
|
|
|
WIN32OLE_VARIANT.new(/foo/)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2013-09-08 01:06:20 -04:00
|
|
|
def test_s_new_ary
|
|
|
|
obj = WIN32OLE_VARIANT.new([1])
|
|
|
|
assert_instance_of(WIN32OLE_VARIANT, obj)
|
|
|
|
assert_raise(TypeError) {
|
|
|
|
WIN32OLE_VARIANT.new([/foo/])
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2007-03-02 07:35:02 -05:00
|
|
|
def test_s_new_no_argument
|
2006-04-30 19:37:54 -04:00
|
|
|
ex = nil
|
|
|
|
begin
|
2014-03-02 14:21:57 -05:00
|
|
|
WIN32OLE_VARIANT.new
|
2006-04-30 19:37:54 -04:00
|
|
|
rescue ArgumentError
|
|
|
|
ex = $!
|
|
|
|
end
|
|
|
|
assert_instance_of(ArgumentError, ex)
|
|
|
|
assert_equal("wrong number of arguments (0 for 1..3)", ex.message);
|
|
|
|
end
|
|
|
|
|
2007-03-02 07:35:02 -05:00
|
|
|
def test_s_new_one_argument
|
2006-04-30 19:37:54 -04:00
|
|
|
ex = nil
|
|
|
|
begin
|
2014-03-02 14:21:57 -05:00
|
|
|
WIN32OLE_VARIANT.new('foo')
|
2006-04-30 19:37:54 -04:00
|
|
|
rescue
|
|
|
|
ex = $!
|
|
|
|
end
|
|
|
|
assert_equal(nil, ex);
|
|
|
|
end
|
|
|
|
|
2007-03-02 07:35:02 -05:00
|
|
|
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)
|
2009-07-21 03:27:08 -04:00
|
|
|
assert_equal(Time.new(1899,12,30), obj.value)
|
2007-03-02 07:35:02 -05:00
|
|
|
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)
|
|
|
|
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2007-03-02 07:35:02 -05:00
|
|
|
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
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2007-03-02 07:35:02 -05:00
|
|
|
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)
|
2009-07-21 03:27:08 -04:00
|
|
|
assert_equal(Time.new(2001,06,15,12,17,34), obj.value)
|
2007-03-02 07:35:02 -05:00
|
|
|
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)
|
2009-07-21 03:27:08 -04:00
|
|
|
assert_equal(Time.new(2001,06,15,12,17,34), obj.value)
|
2007-03-02 07:35:02 -05:00
|
|
|
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
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2007-03-02 07:35:02 -05:00
|
|
|
def test_s_new_with_i8_byref
|
2013-01-11 17:59:51 -05:00
|
|
|
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)
|
2007-03-02 07:35:02 -05:00
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2007-03-02 07:35:02 -05:00
|
|
|
def test_s_new_with_ui8_byref
|
2013-01-11 17:59:51 -05:00
|
|
|
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)
|
2007-03-02 07:35:02 -05:00
|
|
|
end
|
|
|
|
|
2006-04-30 19:37:54 -04:00
|
|
|
def test_value
|
2005-08-13 08:13:20 -04:00
|
|
|
obj = WIN32OLE_VARIANT.new('foo')
|
2006-04-30 19:37:54 -04:00
|
|
|
assert_equal('foo', obj.value)
|
2005-08-13 08:13:20 -04:00
|
|
|
end
|
|
|
|
|
2007-03-02 07:35:02 -05:00
|
|
|
def test_s_new_2_argument
|
2007-01-27 04:46:34 -05:00
|
|
|
obj = WIN32OLE_VARIANT.new('foo', WIN32OLE::VARIANT::VT_BSTR|WIN32OLE::VARIANT::VT_BYREF)
|
2006-04-30 19:37:54 -04:00
|
|
|
assert_equal('foo', obj.value);
|
|
|
|
end
|
2005-08-13 08:13:20 -04:00
|
|
|
|
2007-03-02 07:35:02 -05:00
|
|
|
def test_s_new_2_argument2
|
2007-01-27 04:46:34 -05:00
|
|
|
obj = WIN32OLE_VARIANT.new('foo', WIN32OLE::VARIANT::VT_BSTR)
|
2006-04-30 19:37:54 -04:00
|
|
|
assert_equal('foo', obj.value);
|
2005-08-13 08:13:20 -04:00
|
|
|
end
|
|
|
|
|
2007-03-02 07:35:02 -05:00
|
|
|
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
|
|
|
|
|
2008-01-18 19:29:31 -05:00
|
|
|
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
|
|
|
|
|
2014-07-18 09:40:41 -04:00
|
|
|
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
|
|
|
|
|
2007-02-23 17:39:25 -05:00
|
|
|
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)
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2007-02-23 17:39:25 -05:00
|
|
|
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)
|
2007-03-02 07:35:02 -05:00
|
|
|
|
|
|
|
obj = WIN32OLE_VARIANT.array([2,3], WIN32OLE::VARIANT::VT_DISPATCH)
|
|
|
|
assert_equal([[nil, nil, nil],[nil,nil,nil]], obj.value)
|
2008-01-18 19:29:31 -05:00
|
|
|
|
2007-02-23 17:39:25 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_s_array_exc
|
|
|
|
assert_raise(TypeError) {
|
2014-03-02 14:21:57 -05:00
|
|
|
WIN32OLE_VARIANT.array(2, WIN32OLE::VARIANT::VT_I4)
|
2007-02-23 17:39:25 -05:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2006-04-30 19:37:54 -04:00
|
|
|
def test_conversion_num2str
|
|
|
|
obj = WIN32OLE_VARIANT.new(124, WIN32OLE::VARIANT::VT_BSTR)
|
|
|
|
assert_equal("124", obj.value);
|
2005-08-13 08:13:20 -04:00
|
|
|
end
|
|
|
|
|
2007-01-27 04:46:34 -05:00
|
|
|
def test_conversion_float2int
|
|
|
|
obj = WIN32OLE_VARIANT.new(12.345, WIN32OLE::VARIANT::VT_I4)
|
|
|
|
assert_equal(12, obj.value)
|
2007-02-23 17:39:25 -05:00
|
|
|
obj = WIN32OLE_VARIANT.new(12.345, WIN32OLE::VARIANT::VT_I4|WIN32OLE::VARIANT::VT_BYREF)
|
|
|
|
assert_equal(12, obj.value)
|
2007-01-27 04:46:34 -05:00
|
|
|
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
|
|
|
|
|
2006-04-30 19:37:54 -04:00
|
|
|
def test_conversion_str2date
|
|
|
|
obj = WIN32OLE_VARIANT.new("2004-12-24 12:24:45", WIN32OLE::VARIANT::VT_DATE)
|
2009-07-21 03:27:08 -04:00
|
|
|
assert_equal(Time.new(2004,12,24,12,24,45), obj.value)
|
2006-04-30 19:37:54 -04:00
|
|
|
end
|
2005-08-13 08:13:20 -04:00
|
|
|
|
2006-04-30 19:37:54 -04:00
|
|
|
def test_conversion_time2date
|
|
|
|
dt = Time.mktime(2004, 12, 24, 12, 24, 45)
|
|
|
|
obj = WIN32OLE_VARIANT.new(dt, WIN32OLE::VARIANT::VT_DATE)
|
2009-07-21 03:27:08 -04:00
|
|
|
assert_equal(dt, obj.value)
|
2006-04-30 19:37:54 -04:00
|
|
|
end
|
2005-08-13 08:13:20 -04:00
|
|
|
|
2014-08-27 06:57:28 -04:00
|
|
|
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'))
|
2014-09-20 22:18:37 -04:00
|
|
|
assert_in_delta(0.789, t.nsec / 1000000000.0, 0.001)
|
2014-08-27 06:57:28 -04:00
|
|
|
end
|
|
|
|
|
2014-09-01 07:16:57 -04:00
|
|
|
def test_conversion_time2date_with_msec
|
|
|
|
t0 = Time.new(2014, 8, 27, 12, 34, 56)
|
|
|
|
t0 += 0.789
|
|
|
|
t1 = WIN32OLE_VARIANT.new(t0).value
|
2014-09-22 07:01:22 -04:00
|
|
|
|
|
|
|
# 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)
|
2014-09-01 07:16:57 -04:00
|
|
|
|
|
|
|
t0 = Time.now
|
|
|
|
t1 = WIN32OLE_VARIANT.new(t0).value
|
2014-09-22 07:01:22 -04:00
|
|
|
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)
|
2014-09-01 07:16:57 -04:00
|
|
|
end
|
|
|
|
|
2009-07-21 03:27:08 -04:00
|
|
|
# this test failed because of VariantTimeToSystemTime
|
2011-05-15 07:55:52 -04:00
|
|
|
# and SystemTimeToVariantTime API ignores wMilliseconds
|
2009-07-21 03:27:08 -04:00
|
|
|
# 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
|
|
|
|
|
2006-04-30 19:37:54 -04:00
|
|
|
def test_conversion_str2cy
|
2009-03-05 22:56:38 -05:00
|
|
|
begin
|
2012-08-06 06:21:12 -04:00
|
|
|
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)
|
2007-01-29 07:41:50 -05:00
|
|
|
end
|
2006-04-30 19:37:54 -04:00
|
|
|
end
|
2006-04-30 09:11:12 -04:00
|
|
|
|
2006-04-30 19:37:54 -04:00
|
|
|
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)
|
2007-02-03 00:41:03 -05:00
|
|
|
assert_equal(WIN32OLE::VARIANT::VT_ARRAY|WIN32OLE::VARIANT::VT_R8, obj.vartype)
|
2007-02-08 08:48:16 -05:00
|
|
|
|
|
|
|
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)
|
2007-02-03 00:41:03 -05:00
|
|
|
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
|
|
|
|
|
2007-02-08 08:48:16 -05:00
|
|
|
|
2007-02-03 00:41:03 -05:00
|
|
|
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)
|
2007-02-08 08:48:16 -05:00
|
|
|
|
|
|
|
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)
|
2006-04-30 19:37:54 -04:00
|
|
|
end
|
2005-08-13 08:13:20 -04:00
|
|
|
|
2007-02-11 04:53:10 -05:00
|
|
|
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
|
|
|
|
|
2007-03-02 07:35:02 -05:00
|
|
|
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)
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2007-03-02 07:35:02 -05:00
|
|
|
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
|
|
|
|
|
2007-01-27 04:46:34 -05:00
|
|
|
def test_create_vt_array_exc
|
|
|
|
exc = assert_raise(TypeError) {
|
2014-03-02 14:21:57 -05:00
|
|
|
WIN32OLE_VARIANT.new(1, WIN32OLE::VARIANT::VT_ARRAY);
|
2007-01-27 04:46:34 -05:00
|
|
|
}
|
|
|
|
assert_match(/wrong argument type Fixnum \(expected Array\)/, exc.message)
|
|
|
|
end
|
|
|
|
|
2006-04-30 19:37:54 -04:00
|
|
|
def test_create_vt_array_str2ui1array
|
|
|
|
obj = WIN32OLE_VARIANT.new("ABC", WIN32OLE::VARIANT::VT_ARRAY|WIN32OLE::VARIANT::VT_UI1)
|
|
|
|
assert_equal("ABC", obj.value)
|
2006-03-12 03:09:48 -05:00
|
|
|
|
2007-02-23 17:39:25 -05:00
|
|
|
obj.value = "DEF"
|
|
|
|
assert_equal("DEF", obj.value)
|
|
|
|
obj[0] = 71
|
|
|
|
assert_equal("GEF", obj.value)
|
|
|
|
|
2006-04-30 19:37:54 -04:00
|
|
|
obj = WIN32OLE_VARIANT.new([65, 0].pack("C*"), WIN32OLE::VARIANT::VT_ARRAY|WIN32OLE::VARIANT::VT_UI1)
|
|
|
|
assert_equal([65, 0].pack("C*"), obj.value)
|
2006-03-18 19:56:59 -05:00
|
|
|
|
2007-03-02 07:35:02 -05:00
|
|
|
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)
|
|
|
|
|
2006-04-30 19:37:54 -04:00
|
|
|
end
|
2007-01-29 07:41:50 -05:00
|
|
|
|
2006-04-30 19:37:54 -04:00
|
|
|
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)
|
2006-03-18 19:56:59 -05:00
|
|
|
|
2006-04-30 19:37:54 -04:00
|
|
|
obj = WIN32OLE_VARIANT.new([65, 0])
|
|
|
|
assert_equal([65, 0], obj.value)
|
2006-03-18 19:56:59 -05:00
|
|
|
|
2006-04-30 19:37:54 -04:00
|
|
|
obj = WIN32OLE_VARIANT.new([65, 0], WIN32OLE::VARIANT::VT_I2|WIN32OLE::VARIANT::VT_ARRAY)
|
|
|
|
assert_equal([65, 0], obj.value)
|
2007-02-23 17:39:25 -05:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
2006-04-30 19:37:54 -04:00
|
|
|
end
|
2006-03-18 19:56:59 -05:00
|
|
|
|
2008-07-04 10:19:01 -04:00
|
|
|
def test_conversion_vt_date
|
|
|
|
obj = WIN32OLE_VARIANT.new(-657434, WIN32OLE::VARIANT::VT_DATE)
|
2009-07-21 03:27:08 -04:00
|
|
|
assert_equal(Time.new(100,1,1), obj.value)
|
2008-07-04 10:19:01 -04:00
|
|
|
|
|
|
|
obj = WIN32OLE_VARIANT.new("1500/12/29 23:59:59", WIN32OLE::VARIANT::VT_DATE)
|
2009-07-21 03:27:08 -04:00
|
|
|
assert_equal(Time.new(1500,12,29,23,59,59), obj.value)
|
2008-07-04 10:19:01 -04:00
|
|
|
|
|
|
|
obj = WIN32OLE_VARIANT.new("1500/12/30 00:00:00", WIN32OLE::VARIANT::VT_DATE)
|
2009-07-21 03:27:08 -04:00
|
|
|
assert_equal(Time.new(1500,12,30), obj.value)
|
2008-07-04 10:19:01 -04:00
|
|
|
|
|
|
|
obj = WIN32OLE_VARIANT.new("1500/12/30 00:00:01", WIN32OLE::VARIANT::VT_DATE)
|
2009-07-21 03:27:08 -04:00
|
|
|
assert_equal(Time.new(1500,12,30,0,0,1), obj.value)
|
2008-07-04 10:19:01 -04:00
|
|
|
|
|
|
|
obj = WIN32OLE_VARIANT.new("1899/12/29 23:59:59", WIN32OLE::VARIANT::VT_DATE)
|
2009-07-21 03:27:08 -04:00
|
|
|
assert_equal(Time.new(1899,12,29,23,59,59), obj.value)
|
2008-07-04 10:19:01 -04:00
|
|
|
|
|
|
|
obj = WIN32OLE_VARIANT.new("1899/12/30 00:00:00", WIN32OLE::VARIANT::VT_DATE)
|
2009-07-21 03:27:08 -04:00
|
|
|
assert_equal(Time.new(1899,12,30), obj.value)
|
2008-07-04 10:19:01 -04:00
|
|
|
|
|
|
|
obj = WIN32OLE_VARIANT.new("1899/12/30 00:00:01", WIN32OLE::VARIANT::VT_DATE)
|
2009-07-21 03:27:08 -04:00
|
|
|
assert_equal(Time.new(1899,12,30,0,0,1), obj.value)
|
2008-07-04 10:19:01 -04:00
|
|
|
|
|
|
|
obj = WIN32OLE_VARIANT.new(0, WIN32OLE::VARIANT::VT_DATE)
|
2009-07-21 03:27:08 -04:00
|
|
|
assert_equal(Time.new(1899,12,30), obj.value)
|
2008-07-04 10:19:01 -04:00
|
|
|
|
|
|
|
obj = WIN32OLE_VARIANT.new("2008/12/29 23:59:59", WIN32OLE::VARIANT::VT_DATE)
|
2009-07-21 03:27:08 -04:00
|
|
|
assert_equal(Time.new(2008,12,29,23,59,59), obj.value)
|
2008-07-04 10:19:01 -04:00
|
|
|
|
|
|
|
obj = WIN32OLE_VARIANT.new("2008/12/30 00:00:00", WIN32OLE::VARIANT::VT_DATE)
|
2009-07-21 03:27:08 -04:00
|
|
|
assert_equal(Time.new(2008,12,30,0,0,0), obj.value)
|
2008-07-04 10:19:01 -04:00
|
|
|
|
|
|
|
obj = WIN32OLE_VARIANT.new("2008/12/30 00:00:01", WIN32OLE::VARIANT::VT_DATE)
|
2009-07-21 03:27:08 -04:00
|
|
|
assert_equal(Time.new(2008,12,30,0,0,1), obj.value)
|
2008-07-04 10:19:01 -04:00
|
|
|
|
|
|
|
obj = WIN32OLE_VARIANT.new("9999/12/31 23:59:59", WIN32OLE::VARIANT::VT_DATE)
|
2009-07-21 03:27:08 -04:00
|
|
|
assert_equal(Time.new(9999,12,31,23,59,59), obj.value)
|
2008-07-04 10:19:01 -04:00
|
|
|
end
|
|
|
|
|
2007-01-18 17:08:29 -05:00
|
|
|
def test_create_nil_dispatch
|
|
|
|
var = WIN32OLE_VARIANT.new(nil, WIN32OLE::VARIANT::VT_DISPATCH)
|
|
|
|
assert_nil(var.value)
|
|
|
|
end
|
|
|
|
|
2007-01-27 04:46:34 -05:00
|
|
|
def test_create_variant_byref
|
|
|
|
obj = WIN32OLE_VARIANT.new("Str", WIN32OLE::VARIANT::VT_VARIANT|WIN32OLE::VARIANT::VT_BYREF);
|
|
|
|
assert_equal("Str", obj.value);
|
|
|
|
end
|
|
|
|
|
2007-01-29 07:41:50 -05:00
|
|
|
def test_vartype
|
|
|
|
obj = WIN32OLE_VARIANT.new("Str")
|
|
|
|
assert_equal(WIN32OLE::VARIANT::VT_BSTR, obj.vartype)
|
|
|
|
end
|
|
|
|
|
2007-02-23 17:39:25 -05:00
|
|
|
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])
|
2007-03-02 07:35:02 -05:00
|
|
|
assert_raise(WIN32OLERuntimeError) {
|
2007-02-23 17:39:25 -05:00
|
|
|
obj.value = [3,4]
|
|
|
|
}
|
|
|
|
|
|
|
|
obj = WIN32OLE_VARIANT.new("2007/01/01", WIN32OLE::VARIANT::VT_DATE)
|
|
|
|
assert_raise(WIN32OLERuntimeError) {
|
|
|
|
obj.value = "hogehoge"
|
|
|
|
}
|
2009-07-21 03:27:08 -04:00
|
|
|
assert_equal(Time.new(2007,1,1), obj.value)
|
2007-02-23 17:39:25 -05:00
|
|
|
|
|
|
|
obj2 = WIN32OLE_VARIANT.new("2006/01/01", WIN32OLE::VARIANT::VT_DATE)
|
|
|
|
obj.value = obj2
|
2009-07-21 03:27:08 -04:00
|
|
|
assert_equal(Time.new(2006,01,01), obj.value)
|
2007-02-23 17:39:25 -05:00
|
|
|
end
|
|
|
|
|
2007-01-19 03:22:45 -05:00
|
|
|
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
|
|
|
|
|
2014-09-06 03:52:04 -04:00
|
|
|
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
|
|
|
|
|
2006-03-18 19:56:59 -05:00
|
|
|
end
|
2005-08-13 08:13:20 -04:00
|
|
|
end
|
2007-03-02 07:35:02 -05:00
|
|
|
|