1 # frozen_string_literal: false
8 if defined?(WIN32OLE::Method)
9 class TestWIN32OLE_METHOD < Test::Unit::TestCase
12 ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "Shell")
13 @m_open = WIN32OLE::Method.new(ole_type, "open")
14 @m_namespace = WIN32OLE::Method.new(ole_type, "namespace")
15 @m_parent = WIN32OLE::Method.new(ole_type, "parent")
16 @m_invoke = WIN32OLE::Method.new(ole_type, "invoke")
17 @m_browse_for_folder = WIN32OLE::Method.new(ole_type, "BrowseForFolder")
19 ole_type = WIN32OLE::Type.new("Microsoft Scripting Runtime", "File")
20 @m_file_name = WIN32OLE::Method.new(ole_type, "name")
23 def test_toplevel_constants_backward_compatibility
24 assert_equal(WIN32OLE::Method, ::WIN32OLE_METHOD)
28 ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "Shell")
29 assert_raise(TypeError) {
30 WIN32OLE::Method.new(1, 2)
32 assert_raise(ArgumentError) {
33 WIN32OLE::Method.new("foo")
35 assert_raise(ArgumentError) {
36 WIN32OLE::Method.new(ole_type)
38 assert_raise(WIN32OLE::RuntimeError) {
39 WIN32OLE::Method.new(ole_type, "NonExistMethod")
41 assert_raise(TypeError) {
42 WIN32OLE::Method.new(ole_type, 1)
44 method = WIN32OLE::Method.new(ole_type, "Open")
45 assert_instance_of(WIN32OLE::Method, method)
46 method = WIN32OLE::Method.new(ole_type, "open")
47 assert_instance_of(WIN32OLE::Method, method)
51 assert_equal("Open", @m_open.name)
55 assert_equal("VOID", @m_open.return_type)
56 assert_equal("Folder", @m_namespace.return_type)
60 assert_equal(24, @m_open.return_vtype)
61 assert_equal(26, @m_namespace.return_vtype)
64 def test_return_type_detail
65 assert_equal(['VOID'], @m_open.return_type_detail)
66 assert_equal(['PTR', 'USERDEFINED', 'Folder'], @m_namespace.return_type_detail)
70 assert_equal('FUNC', @m_open.invoke_kind)
71 assert_equal('FUNC', @m_namespace.invoke_kind)
72 assert_equal('PROPERTYGET', @m_parent.invoke_kind)
76 assert_equal(1, @m_namespace.invkind)
77 assert_equal(2, @m_parent.invkind)
81 assert(@m_namespace.visible?)
82 assert(!@m_invoke.visible?)
86 assert_equal("Get special folder from ShellSpecialFolderConstants", @m_namespace.helpstring)
90 assert_equal("", @m_namespace.helpfile)
91 assert_match(/VBENLR.*\.CHM$/i, @m_file_name.helpfile)
95 assert_equal(0, @m_namespace.helpcontext)
96 assert_equal(2181996, @m_file_name.helpcontext)
100 assert_equal(1610743810, @m_namespace.dispid)
104 /mswin64|x64-mingw/ =~ RUBY_PLATFORM
108 exp = is_ruby64? ? 48 : 24
109 assert_equal(exp, @m_invoke.offset_vtbl)
113 assert_equal(1, @m_open.size_params)
114 assert_equal(4, @m_browse_for_folder.size_params)
117 def test_size_opt_params
118 assert_equal(0, @m_open.size_opt_params)
119 assert_equal(1, @m_browse_for_folder.size_opt_params)
123 params = @m_browse_for_folder.params
124 assert_instance_of(Array, params)
125 assert_equal(4, params.size)
126 assert_instance_of(WIN32OLE::Param, params[0])
130 assert_equal(@m_namespace.name, @m_namespace.to_s)
134 assert_equal("#<WIN32OLE::Method:NameSpace>", @m_namespace.inspect)