15
module TestCaseForDict
16
def test_convert_bignum
17
@dict1.add("a", 9999999999)
18
@dict1.add("b", 999999999)
19
@dict1.add("c", @dict1.item("b") * 10 + 9)
20
assert_equal(9999999999, @dict1.item("a"))
21
assert_equal(9999999999, @dict1.item("c"))
25
assert_equal(1000, @dict1.item("a"))
27
def test_setproperty_equal_ended
28
@dict1.compareMode = 1
30
assert_equal(1, @dict1.item("ONE"))
32
assert_nil(@dict2.item("ONE"))
33
assert_equal(1, @dict2.item("one"))
35
def test_non_exist_property
36
assert_raise(WIN32OLERuntimeError) {
37
@dict1.unknown_property = 1
41
def test_raise_message
42
exc = assert_raise(WIN32OLERuntimeError) {
45
assert_match(/^\(in OLE method `add': \)/, exc.message)
47
exc = assert_raise(WIN32OLERuntimeError) {
48
@dict1._invoke(1, [], [])
50
assert_match(/^\(in OLE method `<dispatch id:1>': \)/, exc.message)
52
exc = assert_raise(WIN32OLERuntimeError) {
53
@dict1.compareMode = 100
55
assert_match(/^\(in setting property `compareMode': \)/, exc.message)
59
methods = @dict1.ole_methods
60
mnames = methods.collect {|m|
63
assert(mnames.include?("Add"))
66
def test_ole_func_methods
67
methods = @dict1.ole_func_methods
68
mnames = methods.collect {|m|
71
assert(mnames.include?("Add"))
74
def test_ole_put_methods
75
methods = @dict1.ole_put_methods
76
mnames = methods.collect {|m|
79
assert(mnames.include?("CompareMode"))
82
def test_ole_get_methods
83
methods = @dict1.ole_get_methods
84
mnames = methods.collect {|m|
87
assert(mnames.include?("Count"))
90
def test_ole_mehtod_help
91
minfo = @dict1.ole_method_help("Add")
92
assert_equal(2, minfo.size_params)
96
tlib = @dict1.ole_typelib
97
assert_equal("Microsoft Scripting Runtime", tlib.name);
104
@dict1.keys.each do |item|
111
@dict1.add("foo", "FOO")
112
assert_equal("FOO", @dict1.item("foo"))
113
assert_equal("FOO", @dict1["foo"])
116
def test_bracket_equal
117
@dict1.add("foo", "FOO")
118
@dict1["foo"] = "BAR"
119
assert_equal("BAR", @dict1["foo"])
122
def test_invoke_with_array
123
@dict1.add("ary1", [1,2,3])
124
assert_equal([1,2,3], @dict1["ary1"])
126
@dict1.add("ary2", [[1,2,"a"], [3,4,"b"]])
127
assert_equal([[1,2,"a"], [3,4,"b"]], @dict1["ary2"])
129
@dict1.add("ary3", [[[1]]])
130
assert_equal([[[1]]], @dict1["ary3"])
132
@dict1.add("ary4", [[[1], [2], [3]], [[4], [5], [6]]])
133
assert_equal([[[1],[2], [3]], [[4], [5], [6]]], @dict1["ary4"])
137
class TestWin32OLE < Test::Unit::TestCase
138
include TestCaseForDict
140
@dict1 = WIN32OLE.new('Scripting.Dictionary')
141
@dict2 = WIN32OLE.new('Scripting.Dictionary')
144
assert_instance_of(WIN32OLE, @dict1)
145
assert_instance_of(WIN32OLE, @dict2)
149
rshell = WIN32OLE.new("Shell.Application")
150
assert_instance_of(WIN32OLE, rshell)
153
def test_s_new_from_clsid
154
shell = WIN32OLE.new("{13709620-C279-11CE-A49E-444553540000}")
155
assert_instance_of(WIN32OLE, shell)
156
exc = assert_raise(WIN32OLERuntimeError) {
157
WIN32OLE.new("{000}")
159
assert_match(/unknown OLE server: `\{000\}'/, exc.message)
163
obj = WIN32OLE.connect("winmgmts:")
164
assert_instance_of(WIN32OLE, obj)
167
def test_invoke_accept_symbol_hash_key
168
fso = WIN32OLE.new('Scripting.FileSystemObject')
169
afolder = fso.getFolder(".")
170
bfolder = fso.getFolder({"FolderPath" => "."})
171
cfolder = fso.getFolder({:FolderPath => "."})
172
assert_equal(afolder.path, bfolder.path)
173
assert_equal(afolder.path, cfolder.path)
178
installer = WIN32OLE.new("WindowsInstaller.Installer")
179
record = installer.CreateRecord(2)
180
# this is the way to set property with argument in Win32OLE.
181
record.setproperty( "StringData", 1, 'dddd')
182
assert_equal('dddd', record.StringData(1))
186
fso = WIN32OLE.new('Scripting.FileSystemObject')
188
assert_match(/^IFileSystem/, tobj.name)
191
def test_ole_obj_help
192
fso = WIN32OLE.new('Scripting.FileSystemObject')
193
tobj = fso.ole_obj_help
194
assert_match(/^IFileSystem/, tobj.name)
198
def test_invoke_hash_key_non_str_sym
199
fso = WIN32OLE.new('Scripting.FileSystemObject')
201
bfolder = fso.getFolder({1 => "."})
209
def test_get_win32ole_object
210
shell = WIN32OLE.new('Shell.Application')
211
folder = shell.nameSpace(0)
212
assert_instance_of(WIN32OLE, folder)
215
def test_invoke_accept_multi_hash_key
216
shell = WIN32OLE.new('Shell.Application')
217
folder = shell.nameSpace(0)
218
item = folder.items.item(0)
219
name = folder.getDetailsOf(item, 0)
220
assert_equal(item.name, name)
221
name = folder.getDetailsOf({:vItem => item, :iColumn => 0})
222
assert_equal(item.name, name)
223
name = folder.getDetailsOf({"vItem" => item, :iColumn => 0})
224
assert_equal(item.name, name)
227
def test_ole_invoke_with_named_arg_last
228
shell = WIN32OLE.new('Shell.Application')
229
folder = shell.nameSpace(0)
230
item = folder.items.item(0)
231
name = folder.getDetailsOf(item, {:iColumn => 0})
232
assert_equal(item.name, name)
236
shell=WIN32OLE.new('Shell.Application')
237
assert_equal(shell.NameSpace(0).title, shell._invoke(0x60020002, [0], [WIN32OLE::VARIANT::VT_VARIANT]).title)
240
def test_ole_query_interface
241
shell=WIN32OLE.new('Shell.Application')
242
assert_raise(ArgumentError) {
243
shell2 = shell.ole_query_interface
245
shell2 = shell.ole_query_interface('{A4C6892C-3BA9-11D2-9DEA-00C04FB16162}')
246
assert_instance_of(WIN32OLE, shell2)
249
def test_s_const_load
250
assert(!defined?(CONST1::SsfWINDOWS))
251
shell=WIN32OLE.new('Shell.Application')
252
WIN32OLE.const_load(shell, CONST1)
253
assert_equal(36, CONST1::SsfWINDOWS)
255
assert(!defined?(CONST2::SsfWINDOWS))
256
WIN32OLE.const_load("Microsoft Shell Controls And Automation", CONST2)
257
assert_equal(36, CONST2::SsfWINDOWS)
260
def test_s_create_guid
261
guid = WIN32OLE.create_guid
262
assert_match(/^\{[A-Z0-9]{8}\-[A-Z0-9]{4}\-[A-Z0-9]{4}\-[A-Z0-9]{4}\-[A-Z0-9]{12}/,
267
assert_equal(WIN32OLE::CP_ACP, WIN32OLE.codepage)
270
def test_s_codepage_set
271
WIN32OLE.codepage = WIN32OLE::CP_UTF8
272
assert_equal(WIN32OLE::CP_UTF8, WIN32OLE.codepage)
273
WIN32OLE.codepage = WIN32OLE::CP_ACP
276
def test_s_codepage_changed
277
fso = WIN32OLE.new("Scripting.FileSystemObject")
278
fname = fso.getTempName
280
WIN32OLE.codepage = WIN32OLE::CP_UTF8
281
file = fso.opentextfile(fname, 2, true)
282
file.write [0x3042].pack("U*")
288
assert_equal("\202\240", str)
290
WIN32OLE.codepage = WIN32OLE::CP_ACP
291
file = fso.opentextfile(fname, 2, true)
292
file.write [0x3042].pack("U*")
297
assert_equal("\343\201", str)
299
# This test fail if codepage 20932 (euc) is not installed.
301
WIN32OLE.codepage = 20932
302
rescue WIN32OLERuntimeError
304
if (WIN32OLE.codepage == 20932)
305
file = fso.opentextfile(fname, 2, true)
306
file.write [164, 162].pack("c*")
311
assert_equal("\202\240", str)
315
WIN32OLE.codepage = WIN32OLE::CP_ACP
316
if (File.exist?(fname))
323
assert_equal(WIN32OLE::LOCALE_SYSTEM_DEFAULT, WIN32OLE.locale)
326
def test_s_locale_set
328
WIN32OLE.locale = 1041
329
assert_equal(1041, WIN32OLE.locale)
330
WIN32OLE.locale = WIN32OLE::LOCALE_SYSTEM_DEFAULT
331
assert_raise(WIN32OLERuntimeError) {
332
WIN32OLE.locale = 111
334
assert_equal(WIN32OLE::LOCALE_SYSTEM_DEFAULT, WIN32OLE.locale)
336
WIN32OLE.locale = WIN32OLE::LOCALE_SYSTEM_DEFAULT
340
def test_s_locale_change
342
WIN32OLE.locale = 0x0411
343
obj = WIN32OLE_VARIANT.new("\\100,000", WIN32OLE::VARIANT::VT_CY)
344
assert_equal("100000", obj.value)
346
WIN32OLE.locale = 1033
347
obj = WIN32OLE_VARIANT.new("$100,000", WIN32OLE::VARIANT::VT_CY)
348
assert_equal("100000", obj.value)
350
WIN32OLE.locale = WIN32OLE::LOCALE_SYSTEM_DEFAULT
354
def test_const_CP_ACP
355
assert_equal(0, WIN32OLE::CP_ACP)
358
def test_const_CP_OEMCP
359
assert_equal(1, WIN32OLE::CP_OEMCP)
362
def test_const_CP_MACCP
363
assert_equal(2, WIN32OLE::CP_MACCP)
366
def test_const_CP_THREAD_ACP
367
assert_equal(3, WIN32OLE::CP_THREAD_ACP)
370
def test_const_CP_SYMBOL
371
assert_equal(42, WIN32OLE::CP_SYMBOL)
374
def test_const_CP_UTF7
375
assert_equal(65000, WIN32OLE::CP_UTF7)
378
def test_const_CP_UTF8
379
assert_equal(65001, WIN32OLE::CP_UTF8)
382
def test_const_LOCALE_SYSTEM_DEFAULT
383
assert_equal(0x0800, WIN32OLE::LOCALE_SYSTEM_DEFAULT);
386
def test_const_LOCALE_USER_DEFAULT
387
assert_equal(0x0400, WIN32OLE::LOCALE_USER_DEFAULT);
391
# test of subclass of WIN32OLE
392
class MyDict < WIN32OLE
394
super('Scripting.Dictionary')
397
class TestMyDict < Test::Unit::TestCase
398
include TestCaseForDict
404
assert_instance_of(MyDict, @dict1)
405
assert_instance_of(MyDict, @dict2)