aboutsummaryrefslogtreecommitdiffstats
path: root/test/win32ole/test_win32ole_type_event.rb
blob: e1b5806b4297effb638d034ed966cc6e27d99c4a (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
# frozen_string_literal: false
begin
  require 'win32ole'
rescue LoadError
end
require "test/unit"

if defined?(WIN32OLE_TYPE)
  def ado_installed?
    installed = false
    if defined?(WIN32OLE)
      begin
        WIN32OLE.new('ADODB.Connection')
        installed = true
      rescue
      end
    end
    installed
  end

  class TestWIN32OLE_TYPE_EVENT < Test::Unit::TestCase
    unless ado_installed?
      def test_dummy_for_skip_message
        skip 'ActiveX Data Object Library not found'
      end
    else

      def setup
        typelib = WIN32OLE.new('ADODB.Connection').ole_typelib
        @ole_type = WIN32OLE_TYPE.new(typelib.name, 'Connection')
      end

      def test_implemented_ole_types
        ole_types = @ole_type.implemented_ole_types.map(&:name).sort
        assert_equal(['ConnectionEvents', '_Connection'], ole_types)
      end

      def test_default_ole_types
        ole_types = @ole_type.default_ole_types.map(&:name).sort
        assert_equal(['ConnectionEvents', '_Connection'], ole_types)
      end

      def test_source_ole_types
        ole_types = @ole_type.source_ole_types.map(&:name)
        assert_equal(['ConnectionEvents'], ole_types)
      end

      def test_default_event_sources
        event_sources = @ole_type.default_event_sources.map(&:name)
        assert_equal(['ConnectionEvents'], event_sources)
      end
    end
  end
end