ext/win32ole/tests/testOLEMETHOD.rb


DEFINITIONS

This source file includes following functions.


   1  # You need RubyUnit and MS Excel and MSI to run this test script 
   2  
   3  require 'rubyunit'
   4  
   5  require 'win32ole'
   6  require 'oleserver'
   7  
   8  class TestOLEMETHOD < RUNIT::TestCase
   9    include OLESERVER
  10    def setup
  11      @excel_app = WIN32OLE_TYPE.new(MS_EXCEL_TYPELIB, 'Application')
  12    end
  13    def test_s_new
  14      m = WIN32OLE_METHOD.new(@excel_app, 'Quit')
  15      assert_instance_of(WIN32OLE_METHOD, m)
  16      m =  WIN32OLE_METHOD.new(@excel_app, 'WorkbookOpen')
  17      assert_instance_of(WIN32OLE_METHOD, m)
  18      m =  WIN32OLE_METHOD.new(@excel_app, 'workbookopen')
  19      assert_instance_of(WIN32OLE_METHOD, m)
  20    end
  21    def test_name
  22      m = WIN32OLE_METHOD.new(@excel_app, 'Quit')
  23      assert_equal('Quit', m.name)
  24    end
  25    def test_return_type
  26      m = WIN32OLE_METHOD.new(@excel_app, 'ActiveCell')
  27      assert_equal('Range', m.return_type)
  28      m = WIN32OLE_METHOD.new(@excel_app, 'ActivePrinter')
  29      assert_equal('BSTR', m.return_type)
  30    end
  31    def test_return_vtype
  32      m = WIN32OLE_METHOD.new(@excel_app, 'ActiveCell')
  33      assert_equal(WIN32OLE::VARIANT::VT_PTR, m.return_vtype)
  34      m = WIN32OLE_METHOD.new(@excel_app, 'ActivePrinter')
  35      assert_equal(WIN32OLE::VARIANT::VT_BSTR, m.return_vtype)
  36    end
  37    def test_return_type_detail
  38      m = WIN32OLE_METHOD.new(@excel_app, 'ActiveCell')
  39      assert_equal(['PTR', 'USERDEFINED', 'Range'], m.return_type_detail)
  40      m = WIN32OLE_METHOD.new(@excel_app, 'ActivePrinter')
  41      assert_equal(['BSTR'], m.return_type_detail)
  42    end
  43  
  44    def test_invoke_kind
  45      m = WIN32OLE_METHOD.new(@excel_app, 'ActiveCell')
  46      assert_equal('PROPERTYGET', m.invoke_kind)
  47    end
  48    def test_visible
  49      m = WIN32OLE_METHOD.new(@excel_app, 'ActiveCell')
  50      assert(m.visible?)
  51      m = WIN32OLE_METHOD.new(@excel_app, 'AddRef')
  52      assert(!m.visible?)
  53    end
  54    def test_event
  55      m =  WIN32OLE_METHOD.new(@excel_app, 'WorkbookOpen')
  56      assert(m.event?)
  57      m =  WIN32OLE_METHOD.new(@excel_app, 'ActiveCell')
  58      assert(!m.event?)
  59    end
  60    def test_event_interface
  61      m = WIN32OLE_METHOD.new(@excel_app, 'WorkbookOpen')
  62      assert_equal('AppEvents', m.event_interface)
  63      m = WIN32OLE_METHOD.new(@excel_app, 'ActiveCell')
  64      assert_nil(m.event_interface)
  65    end
  66    def test_helpstring
  67      domdoc = WIN32OLE_TYPE.new(MS_XML_TYPELIB, 'DOMDocument')
  68      m =  WIN32OLE_METHOD.new(domdoc, 'abort')
  69      assert_equal('abort an asynchronous download', m.helpstring)
  70    end
  71    def test_helpfile
  72      m = WIN32OLE_METHOD.new(@excel_app, 'ActiveCell')
  73      assert_match(/VBAXL.*\.(HLP|CHM)$/i, m.helpfile)
  74    end
  75    def test_helpcontext
  76      m = WIN32OLE_METHOD.new(@excel_app, 'ActiveCell')
  77      assert(m.helpcontext > 0)
  78    end
  79    def test_offset_vtbl
  80      m = WIN32OLE_METHOD.new(@excel_app, 'QueryInterface')
  81      assert_equal(0, m.offset_vtbl)
  82    end
  83  end