[rubygems/rubygems] Use a constant empty tar header to avoid extra allocations
[ruby.git] / test / win32ole / test_win32ole_typelib.rb
blob31d6122756be5313dbb7718025d93070bbb90429
1 # frozen_string_literal: false
2 begin
3   require 'win32ole'
4 rescue LoadError
5 end
6 require "test/unit"
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)
12     end
14     def test_s_typelibs
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"}
19       assert(tlib)
20     end
22     def test_initialize
23       assert_raise(ArgumentError) {
24         WIN32OLE::TypeLib.new(1,2,3,4)
25       }
27       assert_raise(TypeError) {
28         WIN32OLE::TypeLib.new(100)
29       }
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)
39       guid = tlib.guid
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)
45       path = tlib.path
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")
51       }
52     end
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)
58     end
60     def test_guid
61       tlib = WIN32OLE::TypeLib.new("Microsoft Shell Controls And Automation")
62       assert_equal("{50A7E9B0-70EF-11D1-B75A-00A0C90564FE}", tlib.guid)
63     end
65     def test_name
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)
70     end
72     def test_version
73       tlib = WIN32OLE::TypeLib.new("Microsoft Shell Controls And Automation")
74       assert_equal("1.0", tlib.version)
75     end
77     def test_major_version
78       tlib = WIN32OLE::TypeLib.new("Microsoft Shell Controls And Automation")
79       assert_equal(1, tlib.major_version)
80     end
82     def test_minor_version
83       tlib = WIN32OLE::TypeLib.new("Microsoft Shell Controls And Automation")
84       assert_equal(0, tlib.minor_version)
85     end
87     def test_path
88       tlib = WIN32OLE::TypeLib.new("Microsoft Shell Controls And Automation")
89       assert_match(/shell32\.dll$/i, tlib.path)
90     end
92     def test_visible?
93       tlib = WIN32OLE::TypeLib.new("Microsoft Shell Controls And Automation")
94       assert(tlib.visible?)
95     end
97     def test_library_name
98       tlib = WIN32OLE::TypeLib.new("Microsoft Shell Controls And Automation")
99       assert_equal("Shell32", tlib.library_name)
100     end
102     def test_to_s
103       tlib = WIN32OLE::TypeLib.new("Microsoft Shell Controls And Automation")
104       assert_equal("Microsoft Shell Controls And Automation", tlib.to_s)
105     end
107     def test_ole_types
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])
113     end
115     def test_inspect
116       tlib = WIN32OLE::TypeLib.new("Microsoft Shell Controls And Automation")
117       assert_equal("#<WIN32OLE::TypeLib:Microsoft Shell Controls And Automation>", tlib.inspect)
118     end
120   end