summaryrefslogtreecommitdiff
path: root/jni/ruby/test/win32ole/test_win32ole_param.rb
blob: 1a4eeff301075ec14da5e398d00542dfa88a0f01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
begin
  require 'win32ole'
rescue LoadError
end
require "test/unit"

if defined?(WIN32OLE_PARAM)
  class TestWIN32OLE_PARAM < Test::Unit::TestCase

    def setup
      ole_type = WIN32OLE_TYPE.new("Microsoft Internet Controls", "WebBrowser")
      m_navigate = WIN32OLE_METHOD.new(ole_type, "Navigate")
      m_before_navigate = WIN32OLE_METHOD.new(ole_type, "BeforeNavigate")
      params = m_navigate.params
      @param_url = params[0]
      @param_flags = params[1]
      @param_cancel = m_before_navigate.params[5]

      ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "ShellLinkObject")
      m_geticonlocation = WIN32OLE_METHOD.new(ole_type, "GetIconLocation")
      @param_pbs = m_geticonlocation.params[0]

      ole_type = WIN32OLE_TYPE.new("Microsoft HTML Object Library", "FontNames")
      m_count = WIN32OLE_METHOD.new(ole_type, "Count")
      @param_p = m_count.params[0]

      ole_type = WIN32OLE_TYPE.new("Microsoft Scripting Runtime", "FileSystemObject")
      m_copyfile = WIN32OLE_METHOD.new(ole_type, "CopyFile")
      @param_overwritefiles = m_copyfile.params[2]
    end

    def test_s_new
      assert_raise(ArgumentError) {
        WIN32OLE_PARAM.new("hoge")
      }
      ole_type = WIN32OLE_TYPE.new("Microsoft Scripting Runtime", "FileSystemObject")
      m_copyfile = WIN32OLE_METHOD.new(ole_type, "CopyFile")
      assert_raise(IndexError) {
        WIN32OLE_PARAM.new(m_copyfile, 4);
      }
      assert_raise(IndexError) {
        WIN32OLE_PARAM.new(m_copyfile, 0);
      }
      assert_raise(IndexError) {
        WIN32OLE_PARAM.new(m_copyfile, 0);
      }
      param = WIN32OLE_PARAM.new(m_copyfile, 3)
      assert_equal("OverWriteFiles", param.name)
      assert_equal(WIN32OLE_PARAM, param.class)
      assert_equal(true, param.default)
      assert_equal("#<WIN32OLE_PARAM:OverWriteFiles=true>", param.inspect)
    end

    def test_name
      assert_equal('URL', @param_url.name)
      assert_equal('Flags', @param_flags.name)
      assert_equal('Cancel', @param_cancel.name)
    end

    def test_ole_type
      assert_equal('BSTR', @param_url.ole_type)
      assert_equal('VARIANT', @param_flags.ole_type)
    end

    def test_ole_type_detail
      assert_equal(['BSTR'], @param_url.ole_type_detail)
      assert_equal(['PTR', 'VARIANT'], @param_flags.ole_type_detail)
    end

    def test_input?
      assert(@param_url.input?)
      assert(@param_cancel.input?)
      assert(!@param_pbs.input?)
    end

    def test_output?
      assert(!@param_url.output?)
      assert(@param_cancel.output?)
      assert(@param_pbs.output?)
    end

    def test_optional?
      assert(!@param_url.optional?)
      assert(@param_flags.optional?)
    end

    def test_retval?
      assert(!@param_url.retval?)
      assert(@param_p.retval?)
    end

    def test_default
      assert_equal(nil, @param_url.default)
      assert_equal(true, @param_overwritefiles.default)
    end

    def test_to_s
      assert_equal(@param_url.name, @param_url.to_s)
    end

    def test_inspect
      assert_equal("#<WIN32OLE_PARAM:URL>", @param_url.inspect)
      assert_equal("#<WIN32OLE_PARAM:OverWriteFiles=true>", @param_overwritefiles.inspect)
    end
  end
end