blob: 679169d68c012ac94fdc96203eef532816327312 (
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
# You need RubyUnit and MS Excel and MSI to run this test script
require 'test/unit'
require 'runit/testcase'
# require 'runit/cui/testrunner'
require 'win32ole'
require 'oleserver'
module EXCEL_CONST
end
module CONST1
end
module CONST2
end
module CONST3
end
class TestWin32OLE < RUNIT::TestCase
include OLESERVER
def setup
@excel = WIN32OLE.new("Excel.Application")
@excel.visible = true
end
def test_s_codepage_changed
book = @excel.workbooks.add
sheet = book.worksheets(1)
begin
WIN32OLE.codepage = WIN32OLE::CP_UTF8
sheet.range("A1").value = [0x3042].pack("U*")
val = sheet.range("A1").value
assert_equal("\343\201\202", val)
WIN32OLE.codepage = WIN32OLE::CP_ACP
val = sheet.range("A1").value
assert_equal("\202\240", val)
ensure
book.saved = true
end
end
def test_convert_bignum
book = @excel.workbooks.add
sheet = book.worksheets(1)
begin
sheet.range("A1").value = 999999999
sheet.range("A2").value = 9999999999
sheet.range("A3").value = "=A1*10 + 9"
assert_equal(9999999999, sheet.range("A2").value)
assert_equal(9999999999, sheet.range("A3").value)
ensure
book.saved = true
end
end
def teardown
@excel.quit
@excel = nil
GC.start
end
end
# ---------------------
#
# a subclass of Win32OLE
# override new() and connect()
class MyExcel<WIN32OLE
def MyExcel.new
super "Excel.Application"
end
def MyExcel.connect
super "Excel.Application"
end
end
class TestMyExcel < TestWin32OLE
#
# because we overrided new() and connect()
# we need to change the test.
# also, because the class will be different
#
def setup
@excel = MyExcel.new
@excel.visible = true
end
def test_s_new
assert_instance_of(MyExcel, @excel)
end
def test_s_connect
excel2 = MyExcel.connect
assert_instance_of(MyExcel, excel2)
end
end
|