* 2022-01-18 [ci skip]
[ruby-80x24.org.git] / test / win32ole / test_win32ole_param.rb
blob09452d19270d166b8d5a41342fa2ee3959bbf68b
1 # frozen_string_literal: false
2 begin
3   require 'win32ole'
4 rescue LoadError
5 end
6 require "test/unit"
8 if defined?(WIN32OLE_PARAM)
9   class TestWIN32OLE_PARAM < Test::Unit::TestCase
11     def setup
12       ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "ShellLinkObject")
13       m_geticonlocation = WIN32OLE_METHOD.new(ole_type, "GetIconLocation")
14       @param_pbs = m_geticonlocation.params[0]
16       ole_type = WIN32OLE_TYPE.new("Microsoft HTML Object Library", "FontNames")
17       m_count = WIN32OLE_METHOD.new(ole_type, "Count")
18       @param_p = m_count.params[0]
20       ole_type = WIN32OLE_TYPE.new("Microsoft Scripting Runtime", "FileSystemObject")
21       m_copyfile = WIN32OLE_METHOD.new(ole_type, "CopyFile")
22       @param_source = m_copyfile.params[0]
23       @param_overwritefiles = m_copyfile.params[2]
25       ole_type = WIN32OLE_TYPE.new("Microsoft Scripting Runtime", "Dictionary")
26       m_add = WIN32OLE_METHOD.new(ole_type, "Add")
27       @param_key = m_add.params[0]
28     end
30     def test_s_new
31       assert_raise(ArgumentError) {
32         WIN32OLE_PARAM.new("hoge")
33       }
34       ole_type = WIN32OLE_TYPE.new("Microsoft Scripting Runtime", "FileSystemObject")
35       m_copyfile = WIN32OLE_METHOD.new(ole_type, "CopyFile")
36       assert_raise(IndexError) {
37         WIN32OLE_PARAM.new(m_copyfile, 4);
38       }
39       assert_raise(IndexError) {
40         WIN32OLE_PARAM.new(m_copyfile, 0);
41       }
42       param = WIN32OLE_PARAM.new(m_copyfile, 3)
43       assert_equal("OverWriteFiles", param.name)
44       assert_equal(WIN32OLE_PARAM, param.class)
45       assert_equal(true, param.default)
46       assert_equal("#<WIN32OLE_PARAM:OverWriteFiles=true>", param.inspect)
47     end
49     def test_name
50       assert_equal('Source', @param_source.name)
51       assert_equal('Key', @param_key.name)
52     end
54     def test_ole_type
55       assert_equal('BSTR', @param_source.ole_type)
56       assert_equal('VARIANT', @param_key.ole_type)
57     end
59     def test_ole_type_detail
60       assert_equal(['BSTR'], @param_source.ole_type_detail)
61       assert_equal(['PTR', 'VARIANT'], @param_key.ole_type_detail)
62     end
64     def test_input?
65       assert_equal(true, @param_source.input?)
66       assert_equal(false, @param_pbs.input?)
67     end
69     def test_output?
70       assert_equal(false, @param_source.output?)
71       assert_equal(true, @param_pbs.output?)
72     end
74     def test_optional?
75       assert_equal(false, @param_source.optional?)
76       assert_equal(true, @param_overwritefiles.optional?)
77     end
79     def test_retval?
80       assert_equal(false, @param_source.retval?)
81       assert_equal(true, @param_p.retval?)
82     end
84     def test_default
85       assert_equal(nil, @param_source.default)
86       assert_equal(true, @param_overwritefiles.default)
87     end
89     def test_to_s
90       assert_equal(@param_source.name, @param_source.to_s)
91     end
93     def test_inspect
94       assert_equal("#<WIN32OLE_PARAM:Source>", @param_source.inspect)
95       assert_equal("#<WIN32OLE_PARAM:OverWriteFiles=true>", @param_overwritefiles.inspect)
96     end
97   end
98 end