summaryrefslogtreecommitdiff
path: root/test/win32ole
diff options
context:
space:
mode:
authorsuke <suke@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-03-02 12:35:02 +0000
committersuke <suke@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-03-02 12:35:02 +0000
commite8783d008c8944bb66ed7620d45f39286b5f948f (patch)
tree18df7f631ccf3846057307564b37604e4d684625 /test/win32ole
parent582f1ecdfbad7147e7c0668fc072441503cb7ba1 (diff)
* ext/win32ole/win32ole.c (get_ptr_of_variant, ole_set_safe_array,
ole_val2ptr_variant, ole_val2olevariantdata, ole_variant2val, ): fix some bugs of WIN32OLE_VARIANT.new when variant type is VT_ARRAY|VT_BSTR or VT_BYREF. * ext/win32ole/win32ole.c (folevariant_s_array, folevariant_initialize): WIN32OLE_VARIANT#[], WIN32OLE_VARIANT#[]=, WIN32OLE_VARIANT#value= is defined as instance method of WIN32OLE_VARIANT. * test/win32ole/test_win32ole_variant.rb: add some test for VT_ARRAY, VT_BYREF variant type. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11959 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/win32ole')
-rw-r--r--test/win32ole/test_win32ole_variant.rb284
1 files changed, 278 insertions, 6 deletions
diff --git a/test/win32ole/test_win32ole_variant.rb b/test/win32ole/test_win32ole_variant.rb
index e6c2912..67ed783 100644
--- a/test/win32ole/test_win32ole_variant.rb
+++ b/test/win32ole/test_win32ole_variant.rb
@@ -4,16 +4,21 @@ rescue LoadError
end
require "test/unit"
+$MSGS = []
+def add_skip_message(msg)
+ $MSGS.push msg
+end
+
if defined?(WIN32OLE_VARIANT)
class TestWIN32OLE_VARIANT < Test::Unit::TestCase
- def test_new
+ def test_s_new
obj = WIN32OLE_VARIANT.new('foo')
assert_instance_of(WIN32OLE_VARIANT, obj)
end
- def test_new_no_argument
+ def test_s_new_no_argument
ex = nil
begin
obj = WIN32OLE_VARIANT.new
@@ -24,7 +29,7 @@ if defined?(WIN32OLE_VARIANT)
assert_equal("wrong number of arguments (0 for 1..3)", ex.message);
end
- def test_new_one_argument
+ def test_s_new_one_argument
ex = nil
begin
obj = WIN32OLE_VARIANT.new('foo')
@@ -34,21 +39,264 @@ if defined?(WIN32OLE_VARIANT)
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("1899/12/30 00:00:00", 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("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("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
+
+ # This test is failed in cygwin.
+ # The tagVARIANT definition has no union member pllVal in cygwin.
+ def test_s_new_with_i8_byref
+ if defined?(WIN32OLE::VARIANT::VT_I8) && /mswin/ =~ RUBY_PLATFORM
+ 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)
+ else
+ STDERR.puts("\n#{__FILE__}:#{__LINE__}:#{self.class.name}.test_s_new_with_i8_byref is skipped")
+ end
+ end
+
+ # This test is failed in cygwin.
+ # The tagVARIANT definition has no union member pullVal in cygwin.
+ def test_s_new_with_ui8_byref
+ if defined?(WIN32OLE::VARIANT::VT_UI8) && /mswin/ =~ RUBY_PLATFORM
+ 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)
+ else
+ STDERR.puts("\n#{__FILE__}:#{__LINE__}:#{self.class.name}.test_s_new_with_ui8_byref is skipped.")
+ end
+ end
+
def test_value
obj = WIN32OLE_VARIANT.new('foo')
assert_equal('foo', obj.value)
end
- def test_new_2_argument
+ 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_new_2_argument2
+ 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_array
obj = WIN32OLE_VARIANT.array([2,3], WIN32OLE::VARIANT::VT_I4)
assert_instance_of(WIN32OLE_VARIANT, obj)
@@ -75,6 +323,9 @@ if defined?(WIN32OLE_VARIANT)
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
@@ -194,6 +445,18 @@ if defined?(WIN32OLE_VARIANT)
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) {
obj = WIN32OLE_VARIANT.new(1, WIN32OLE::VARIANT::VT_ARRAY);
@@ -213,6 +476,14 @@ if defined?(WIN32OLE_VARIANT)
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
@@ -289,7 +560,7 @@ if defined?(WIN32OLE_VARIANT)
assert_equal(WIN32OLE::VARIANT::VT_I4, obj.vartype)
obj = WIN32OLE_VARIANT.new([1,2])
- assert_raise(NoMethodError) {
+ assert_raise(WIN32OLERuntimeError) {
obj.value = [3,4]
}
@@ -318,3 +589,4 @@ if defined?(WIN32OLE_VARIANT)
end
end
+