1 # frozen_string_literal: false
8 if defined?(WIN32OLE::TypeLib)
9 class TestWIN32OLE_TYPELIB < Test::Unit::TestCase
10 def test_toplevel_constants_backward_compatibility
11 assert_equal(WIN32OLE::TypeLib, ::WIN32OLE_TYPELIB)
15 tlibs = WIN32OLE::TypeLib.typelibs
16 assert_instance_of(Array, tlibs)
17 assert(tlibs.size > 0)
18 tlib = tlibs.find {|t| t.name == "Microsoft Shell Controls And Automation"}
23 assert_raise(ArgumentError) {
24 WIN32OLE::TypeLib.new(1,2,3,4)
27 assert_raise(TypeError) {
28 WIN32OLE::TypeLib.new(100)
31 tlib = WIN32OLE::TypeLib.new("Microsoft Shell Controls And Automation")
32 assert_instance_of(WIN32OLE::TypeLib, tlib)
34 tlib = WIN32OLE::TypeLib.new("Microsoft Shell Controls And Automation", 1.0)
35 assert_instance_of(WIN32OLE::TypeLib, tlib)
37 tlib = WIN32OLE::TypeLib.new("Microsoft Shell Controls And Automation", 1, 0)
38 assert_instance_of(WIN32OLE::TypeLib, tlib)
41 tlib_by_guid = WIN32OLE::TypeLib.new(guid, 1, 0)
42 assert_instance_of(WIN32OLE::TypeLib, tlib_by_guid)
43 assert_equal("Microsoft Shell Controls And Automation" , tlib_by_guid.name)
46 tlib_by_path = WIN32OLE::TypeLib.new(path)
47 assert_equal("Microsoft Shell Controls And Automation" , tlib_by_path.name)
49 assert_raise(WIN32OLE::RuntimeError) {
50 WIN32OLE::TypeLib.new("Non Exist Type Library")
54 # #Bug:3907 [ruby-dev:42338]
55 def test_initialize_with_REG_EXPAND_SZ
56 tlib = WIN32OLE::TypeLib.new("Disk Management Snap-In Object Library")
57 assert_instance_of(WIN32OLE::TypeLib, tlib)
61 tlib = WIN32OLE::TypeLib.new("Microsoft Shell Controls And Automation")
62 assert_equal("{50A7E9B0-70EF-11D1-B75A-00A0C90564FE}", tlib.guid)
66 tlib = WIN32OLE::TypeLib.new("Microsoft Shell Controls And Automation")
67 assert_equal("Microsoft Shell Controls And Automation", tlib.name)
68 tlib = WIN32OLE::TypeLib.new("{50A7E9B0-70EF-11D1-B75A-00A0C90564FE}")
69 assert_equal("Microsoft Shell Controls And Automation", tlib.name)
73 tlib = WIN32OLE::TypeLib.new("Microsoft Shell Controls And Automation")
74 assert_equal("1.0", tlib.version)
77 def test_major_version
78 tlib = WIN32OLE::TypeLib.new("Microsoft Shell Controls And Automation")
79 assert_equal(1, tlib.major_version)
82 def test_minor_version
83 tlib = WIN32OLE::TypeLib.new("Microsoft Shell Controls And Automation")
84 assert_equal(0, tlib.minor_version)
88 tlib = WIN32OLE::TypeLib.new("Microsoft Shell Controls And Automation")
89 assert_match(/shell32\.dll$/i, tlib.path)
93 tlib = WIN32OLE::TypeLib.new("Microsoft Shell Controls And Automation")
98 tlib = WIN32OLE::TypeLib.new("Microsoft Shell Controls And Automation")
99 assert_equal("Shell32", tlib.library_name)
103 tlib = WIN32OLE::TypeLib.new("Microsoft Shell Controls And Automation")
104 assert_equal("Microsoft Shell Controls And Automation", tlib.to_s)
108 tlib = WIN32OLE::TypeLib.new("Microsoft Shell Controls And Automation")
109 ole_types = tlib.ole_types
110 assert_instance_of(Array, ole_types)
111 assert(ole_types.size > 0)
112 assert_instance_of(WIN32OLE::Type, ole_types[0])
116 tlib = WIN32OLE::TypeLib.new("Microsoft Shell Controls And Automation")
117 assert_equal("#<WIN32OLE::TypeLib:Microsoft Shell Controls And Automation>", tlib.inspect)