1begin 2 require 'win32ole' 3rescue LoadError 4end 5require "test/unit" 6 7if defined?(WIN32OLE_PARAM) 8 class TestWIN32OLE_PARAM < Test::Unit::TestCase 9 10 def setup 11 ole_type = WIN32OLE_TYPE.new("Microsoft Internet Controls", "WebBrowser") 12 m_navigate = WIN32OLE_METHOD.new(ole_type, "Navigate") 13 m_before_navigate = WIN32OLE_METHOD.new(ole_type, "BeforeNavigate") 14 params = m_navigate.params 15 @param_url = params[0] 16 @param_flags = params[1] 17 @param_cancel = m_before_navigate.params[5] 18 19 ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "ShellLinkObject") 20 m_geticonlocation = WIN32OLE_METHOD.new(ole_type, "GetIconLocation") 21 @param_pbs = m_geticonlocation.params[0] 22 23 ole_type = WIN32OLE_TYPE.new("Microsoft HTML Object Library", "FontNames") 24 m_count = WIN32OLE_METHOD.new(ole_type, "Count") 25 @param_p = m_count.params[0] 26 27 ole_type = WIN32OLE_TYPE.new("Microsoft Scripting Runtime", "FileSystemObject") 28 m_copyfile = WIN32OLE_METHOD.new(ole_type, "CopyFile") 29 @param_overwritefiles = m_copyfile.params[2] 30 end 31 32 def test_s_new 33 assert_raise(ArgumentError) { 34 WIN32OLE_PARAM.new("hoge") 35 } 36 ole_type = WIN32OLE_TYPE.new("Microsoft Scripting Runtime", "FileSystemObject") 37 m_copyfile = WIN32OLE_METHOD.new(ole_type, "CopyFile") 38 assert_raise(IndexError) { 39 WIN32OLE_PARAM.new(m_copyfile, 4); 40 } 41 assert_raise(IndexError) { 42 WIN32OLE_PARAM.new(m_copyfile, 0); 43 } 44 assert_raise(IndexError) { 45 WIN32OLE_PARAM.new(m_copyfile, 0); 46 } 47 param = WIN32OLE_PARAM.new(m_copyfile, 3) 48 assert_equal("OverWriteFiles", param.name) 49 assert_equal(WIN32OLE_PARAM, param.class) 50 assert_equal(true, param.default) 51 assert_equal("#<WIN32OLE_PARAM:OverWriteFiles=true>", param.inspect) 52 end 53 54 def test_name 55 assert_equal('URL', @param_url.name) 56 assert_equal('Flags', @param_flags.name) 57 assert_equal('Cancel', @param_cancel.name) 58 end 59 60 def test_ole_type 61 assert_equal('BSTR', @param_url.ole_type) 62 assert_equal('VARIANT', @param_flags.ole_type) 63 end 64 65 def test_ole_type_detail 66 assert_equal(['BSTR'], @param_url.ole_type_detail) 67 assert_equal(['PTR', 'VARIANT'], @param_flags.ole_type_detail) 68 end 69 70 def test_input? 71 assert(@param_url.input?) 72 assert(@param_cancel.input?) 73 assert(!@param_pbs.input?) 74 end 75 76 def test_output? 77 assert(!@param_url.output?) 78 assert(@param_cancel.output?) 79 assert(@param_pbs.output?) 80 end 81 82 def test_optional? 83 assert(!@param_url.optional?) 84 assert(@param_flags.optional?) 85 end 86 87 def test_retval? 88 assert(!@param_url.retval?) 89 assert(@param_p.retval?) 90 end 91 92 def test_default 93 assert_equal(nil, @param_url.default) 94 assert_equal(true, @param_overwritefiles.default) 95 end 96 97 def test_to_s 98 assert_equal(@param_url.name, @param_url.to_s) 99 end 100 101 def test_inspect 102 assert_equal("#<WIN32OLE_PARAM:URL>", @param_url.inspect) 103 assert_equal("#<WIN32OLE_PARAM:OverWriteFiles=true>", @param_overwritefiles.inspect) 104 end 105 end 106end 107