summaryrefslogtreecommitdiff
path: root/ext/win32ole/tests/testOLEMETHOD.rb
blob: 4f65ec96b4c254ce119df61e72925a7b9ebf7246 (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
# You need RubyUnit and MS Excel and MSI to run this test script 

require 'rubyunit'

require 'win32ole'
require 'oleserver'

class TestOLEMETHOD < RUNIT::TestCase
  include OLESERVER
  def setup
    @excel_app = WIN32OLE_TYPE.new(MS_EXCEL_TYPELIB, 'Application')
  end
  def test_s_new
    m = WIN32OLE_METHOD.new(@excel_app, 'Quit')
    assert_instance_of(WIN32OLE_METHOD, m)
    m =  WIN32OLE_METHOD.new(@excel_app, 'WorkbookOpen')
    assert_instance_of(WIN32OLE_METHOD, m)
    m =  WIN32OLE_METHOD.new(@excel_app, 'workbookopen')
    assert_instance_of(WIN32OLE_METHOD, m)
  end
  def test_name
    m = WIN32OLE_METHOD.new(@excel_app, 'Quit')
    assert_equal('Quit', m.name)
  end
  def test_return_type
    m = WIN32OLE_METHOD.new(@excel_app, 'ActiveCell')
    assert_equal('Range', m.return_type)
    m = WIN32OLE_METHOD.new(@excel_app, 'ActivePrinter')
    assert_equal('BSTR', m.return_type)
  end
  def test_return_vtype
    m = WIN32OLE_METHOD.new(@excel_app, 'ActiveCell')
    assert_equal(WIN32OLE::VARIANT::VT_PTR, m.return_vtype)
    m = WIN32OLE_METHOD.new(@excel_app, 'ActivePrinter')
    assert_equal(WIN32OLE::VARIANT::VT_BSTR, m.return_vtype)
  end
  def test_return_type_detail
    m = WIN32OLE_METHOD.new(@excel_app, 'ActiveCell')
    assert_equal(['PTR', 'USERDEFINED', 'Range'], m.return_type_detail)
    m = WIN32OLE_METHOD.new(@excel_app, 'ActivePrinter')
    assert_equal(['BSTR'], m.return_type_detail)
  end

  def test_invoke_kind
    m = WIN32OLE_METHOD.new(@excel_app, 'ActiveCell')
    assert_equal('PROPERTYGET', m.invoke_kind)
  end
  def test_visible
    m = WIN32OLE_METHOD.new(@excel_app, 'ActiveCell')
    assert(m.visible?)
    m = WIN32OLE_METHOD.new(@excel_app, 'AddRef')
    assert(!m.visible?)
  end
  def test_event
    m =  WIN32OLE_METHOD.new(@excel_app, 'WorkbookOpen')
    assert(m.event?)
    m =  WIN32OLE_METHOD.new(@excel_app, 'ActiveCell')
    assert(!m.event?)
  end
  def test_event_interface
    m = WIN32OLE_METHOD.new(@excel_app, 'WorkbookOpen')
    assert_equal('AppEvents', m.event_interface)
    m = WIN32OLE_METHOD.new(@excel_app, 'ActiveCell')
    assert_nil(m.event_interface)
  end
  def test_helpstring
    domdoc = WIN32OLE_TYPE.new(MS_XML_TYPELIB, 'DOMDocument')
    m =  WIN32OLE_METHOD.new(domdoc, 'abort')
    assert_equal('abort an asynchronous download', m.helpstring)
  end
  def test_helpfile
    m = WIN32OLE_METHOD.new(@excel_app, 'ActiveCell')
    assert_match(/VBAXL.*\.(HLP|CHM)$/i, m.helpfile)
  end
  def test_helpcontext
    m = WIN32OLE_METHOD.new(@excel_app, 'ActiveCell')
    assert(m.helpcontext > 0)
  end
  def test_offset_vtbl
    m = WIN32OLE_METHOD.new(@excel_app, 'QueryInterface')
    assert_equal(0, m.offset_vtbl)
  end
end