writeexcel 0.3.5 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitattributes +1 -0
- data/README.rdoc +12 -6
- data/VERSION +1 -1
- data/charts/chartex.rb +316 -315
- data/charts/demo1.rb +1 -0
- data/charts/demo2.rb +1 -0
- data/charts/demo3.rb +117 -116
- data/charts/demo4.rb +119 -118
- data/charts/demo5.rb +48 -47
- data/examples/a_simple.rb +1 -0
- data/examples/autofilter.rb +1 -0
- data/examples/bigfile.rb +30 -29
- data/examples/chart_area.rb +121 -120
- data/examples/chart_bar.rb +120 -119
- data/examples/chart_column.rb +120 -119
- data/examples/chart_line.rb +120 -119
- data/examples/chart_pie.rb +108 -107
- data/examples/chart_scatter.rb +121 -120
- data/examples/chart_stock.rb +148 -147
- data/examples/chess.rb +1 -0
- data/examples/colors.rb +1 -0
- data/examples/comments1.rb +1 -0
- data/examples/comments2.rb +3 -2
- data/examples/copyformat.rb +1 -0
- data/examples/data_validate.rb +1 -0
- data/examples/date_time.rb +1 -0
- data/examples/defined_name.rb +1 -0
- data/examples/demo.rb +1 -0
- data/examples/diag_border.rb +1 -0
- data/examples/formats.rb +1 -0
- data/examples/formula_result.rb +1 -0
- data/examples/header.rb +1 -0
- data/examples/hide_sheet.rb +1 -0
- data/examples/hyperlink.rb +1 -0
- data/examples/images.rb +1 -0
- data/examples/indent.rb +1 -0
- data/examples/merge1.rb +1 -0
- data/examples/merge2.rb +1 -0
- data/examples/merge3.rb +1 -0
- data/examples/merge4.rb +1 -0
- data/examples/merge5.rb +1 -0
- data/examples/merge6.rb +67 -66
- data/examples/outline.rb +1 -0
- data/examples/outline_collapsed.rb +1 -0
- data/examples/panes.rb +1 -0
- data/examples/properties.rb +1 -0
- data/examples/properties_jp.rb +1 -0
- data/examples/protection.rb +1 -0
- data/examples/regions.rb +1 -0
- data/examples/repeat.rb +1 -0
- data/examples/right_to_left.rb +1 -0
- data/examples/row_wrap.rb +1 -0
- data/examples/stats.rb +1 -0
- data/examples/stocks.rb +1 -0
- data/examples/tab_colors.rb +1 -0
- data/examples/write_arrays.rb +1 -0
- data/lib/writeexcel.rb +6 -1
- data/lib/writeexcel/biffwriter.rb +21 -20
- data/lib/writeexcel/chart.rb +25 -12
- data/lib/writeexcel/charts/area.rb +153 -152
- data/lib/writeexcel/charts/bar.rb +178 -177
- data/lib/writeexcel/charts/column.rb +157 -156
- data/lib/writeexcel/charts/external.rb +62 -61
- data/lib/writeexcel/charts/line.rb +153 -152
- data/lib/writeexcel/charts/pie.rb +170 -169
- data/lib/writeexcel/charts/scatter.rb +4 -3
- data/lib/writeexcel/charts/stock.rb +212 -211
- data/lib/writeexcel/compatibility.rb +320 -0
- data/lib/writeexcel/excelformulaparser.rb +587 -586
- data/lib/writeexcel/format.rb +12 -13
- data/lib/writeexcel/formula.rb +30 -28
- data/lib/writeexcel/helper.rb +23 -0
- data/lib/writeexcel/olewriter.rb +5 -16
- data/lib/writeexcel/properties.rb +43 -54
- data/lib/writeexcel/storage_lite.rb +981 -968
- data/lib/writeexcel/workbook.rb +94 -73
- data/lib/writeexcel/worksheet.rb +230 -210
- data/test/helper.rb +19 -0
- data/test/test_00_IEEE_double.rb +1 -0
- data/test/test_01_add_worksheet.rb +1 -0
- data/test/test_02_merge_formats.rb +3 -5
- data/test/test_04_dimensions.rb +3 -5
- data/test/test_05_rows.rb +6 -6
- data/test/test_06_extsst.rb +8 -8
- data/test/test_11_date_time.rb +3 -5
- data/test/test_12_date_only.rb +3 -5
- data/test/test_13_date_seconds.rb +4 -6
- data/test/test_21_escher.rb +3 -5
- data/test/test_22_mso_drawing_group.rb +20 -22
- data/test/test_23_note.rb +5 -7
- data/test/test_24_txo.rb +3 -5
- data/test/test_25_position_object.rb +84 -79
- data/test/test_26_autofilter.rb +3 -13
- data/test/test_27_autofilter.rb +3 -13
- data/test/test_28_autofilter.rb +3 -13
- data/test/test_29_process_jpg.rb +5 -0
- data/test/test_30_validation_dval.rb +3 -5
- data/test/test_31_validation_dv_strings.rb +3 -5
- data/test/test_32_validation_dv_formula.rb +3 -5
- data/test/test_40_property_types.rb +10 -9
- data/test/test_41_properties.rb +1 -0
- data/test/test_42_set_properties.rb +14 -15
- data/test/test_50_name_stored.rb +299 -302
- data/test/test_51_name_print_area.rb +357 -360
- data/test/test_52_name_print_titles.rb +454 -457
- data/test/test_53_autofilter.rb +203 -206
- data/test/test_60_chart_generic.rb +5 -0
- data/test/test_61_chart_subclasses.rb +95 -94
- data/test/test_62_chart_formats.rb +272 -267
- data/test/test_63_chart_area_formats.rb +649 -644
- data/test/test_biff.rb +12 -38
- data/test/test_compatibility.rb +627 -0
- data/test/test_example_match.rb +3 -18
- data/test/test_format.rb +46 -105
- data/test/test_formula.rb +1 -0
- data/test/test_ole.rb +3 -4
- data/test/test_storage_lite.rb +125 -146
- data/test/test_workbook.rb +2 -23
- data/test/test_worksheet.rb +4 -5
- data/utils/add_magic_comment.rb +80 -0
- data/writeexcel.gemspec +8 -2
- metadata +10 -4
data/test/test_example_match.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
1
2
|
require 'helper'
|
2
3
|
require 'stringio'
|
3
4
|
|
@@ -8,13 +9,6 @@ class TC_example_match < Test::Unit::TestCase
|
|
8
9
|
|
9
10
|
def setup
|
10
11
|
@file = StringIO.new
|
11
|
-
=begin
|
12
|
-
t = Time.now.strftime("%Y%m%d")
|
13
|
-
path = "temp#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
|
14
|
-
@test_file = File.join(Dir.tmpdir, path)
|
15
|
-
@filename = @test_file
|
16
|
-
@filename2 = @test_file + "2"
|
17
|
-
=end
|
18
12
|
end
|
19
13
|
|
20
14
|
def test_a_simple
|
@@ -2297,7 +2291,7 @@ def test_comments2
|
|
2297
2291
|
worksheet1.write('C6', cell_text, text_wrap)
|
2298
2292
|
worksheet1.write_comment('C6', comment, :encoding => 1)
|
2299
2293
|
|
2300
|
-
# UTF-8 string
|
2294
|
+
# UTF-8 string.
|
2301
2295
|
worksheet1.set_row(8, 50)
|
2302
2296
|
cell_text = 'This is a UTF-8 string.'
|
2303
2297
|
comment = '☺' # chr 0x263a in perl.
|
@@ -2544,7 +2538,7 @@ def test_comments2
|
|
2544
2538
|
worksheet7.write_comment(cell, comment, :author => author,
|
2545
2539
|
:author_encoding => 1)
|
2546
2540
|
|
2547
|
-
# UTF-8 string
|
2541
|
+
# UTF-8 string.
|
2548
2542
|
author = '☺' # smiley
|
2549
2543
|
cell = 'C12'
|
2550
2544
|
cell_text = "Move the mouse over this cell and you will see 'Cell commented " +
|
@@ -3133,13 +3127,4 @@ def test_right_to_left
|
|
3133
3127
|
# do assertion
|
3134
3128
|
compare_file("#{PERL_OUTDIR}/right_to_left.xls", @file)
|
3135
3129
|
end
|
3136
|
-
|
3137
|
-
def compare_file(expected, target)
|
3138
|
-
# target is StringIO object.
|
3139
|
-
assert_equal(
|
3140
|
-
open(expected, 'rb') { |f| f.read },
|
3141
|
-
target.string,
|
3142
|
-
"#{File.basename(expected)} doesn't match."
|
3143
|
-
)
|
3144
|
-
end
|
3145
3130
|
end
|
data/test/test_format.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
1
2
|
require 'helper'
|
3
|
+
require 'stringio'
|
2
4
|
|
3
5
|
class TC_Format < Test::Unit::TestCase
|
4
6
|
|
@@ -6,15 +8,11 @@ class TC_Format < Test::Unit::TestCase
|
|
6
8
|
PERL_OUTDIR = File.join(TEST_DIR, 'perl_output')
|
7
9
|
|
8
10
|
def setup
|
9
|
-
|
10
|
-
path = "temp#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
|
11
|
-
@ruby_file = File.join(Dir.tmpdir, path)
|
11
|
+
@ruby_file = StringIO.new
|
12
12
|
@format = Format.new
|
13
13
|
end
|
14
14
|
|
15
15
|
def teardown
|
16
|
-
File.delete(@ruby_file) if File.exist?(@ruby_file)
|
17
|
-
@format = nil
|
18
16
|
end
|
19
17
|
|
20
18
|
def test_set_format_properties
|
@@ -980,12 +978,9 @@ def test_set_border_color
|
|
980
978
|
def test_xf_biff_size
|
981
979
|
perl_file = "#{PERL_OUTDIR}/file_xf_biff"
|
982
980
|
size = File.size(perl_file)
|
983
|
-
@
|
984
|
-
@
|
985
|
-
|
986
|
-
rsize = File.size(@ruby_file)
|
987
|
-
assert_equal(size,rsize,"File sizes not the same")
|
988
|
-
|
981
|
+
@ruby_file.print(@format.get_xf)
|
982
|
+
rsize = @ruby_file.size
|
983
|
+
assert_equal(size, rsize, "File sizes not the same")
|
989
984
|
end
|
990
985
|
|
991
986
|
# Because of the modifications to bg_color and fg_color, I know this
|
@@ -1002,47 +997,48 @@ def test_xf_biff_size
|
|
1002
997
|
|
1003
998
|
def test_font_biff_size
|
1004
999
|
perl_file = "#{PERL_OUTDIR}/file_font_biff"
|
1005
|
-
@
|
1006
|
-
@fh.print(@format.get_font)
|
1007
|
-
@fh.close
|
1000
|
+
@ruby_file.print(@format.get_font)
|
1008
1001
|
contents = IO.readlines(perl_file)
|
1009
|
-
|
1010
|
-
|
1002
|
+
@ruby_file.rewind
|
1003
|
+
rcontents = @ruby_file.readlines
|
1004
|
+
assert_equal(contents, rcontents, "Contents not the same")
|
1011
1005
|
end
|
1012
1006
|
|
1013
1007
|
def test_font_biff_contents
|
1014
1008
|
perl_file = "#{PERL_OUTDIR}/file_font_biff"
|
1015
|
-
@
|
1016
|
-
|
1017
|
-
@
|
1018
|
-
|
1019
|
-
rcontents
|
1020
|
-
assert_equal(contents,rcontents,"Contents not the same")
|
1009
|
+
@ruby_file.print(@format.get_font)
|
1010
|
+
contents = IO.readlines(perl_file)
|
1011
|
+
@ruby_file.rewind
|
1012
|
+
rcontents = @ruby_file.readlines
|
1013
|
+
assert_equal(contents, rcontents, "Contents not the same")
|
1021
1014
|
end
|
1022
1015
|
|
1023
1016
|
def test_get_font_key_size
|
1024
1017
|
perl_file = "#{PERL_OUTDIR}/file_font_key"
|
1025
|
-
@
|
1026
|
-
|
1027
|
-
@fh.close
|
1028
|
-
assert_equal(File.size(perl_file),File.size(@ruby_file),"Bad file size")
|
1018
|
+
@ruby_file.print(@format.get_font_key)
|
1019
|
+
assert_equal(File.size(perl_file), @ruby_file.size, "Bad file size")
|
1029
1020
|
end
|
1030
1021
|
|
1031
1022
|
def test_get_font_key_contents
|
1032
1023
|
perl_file = "#{PERL_OUTDIR}/file_font_key"
|
1033
|
-
@
|
1034
|
-
|
1035
|
-
@
|
1036
|
-
|
1037
|
-
rcontents
|
1038
|
-
assert_equal(contents,rcontents,"Contents not the same")
|
1024
|
+
@ruby_file.print(@format.get_font_key)
|
1025
|
+
contents = IO.readlines(perl_file)
|
1026
|
+
@ruby_file.rewind
|
1027
|
+
rcontents = @ruby_file.readlines
|
1028
|
+
assert_equal(contents, rcontents, "Contents not the same")
|
1039
1029
|
end
|
1040
1030
|
|
1041
1031
|
def test_initialize
|
1042
1032
|
assert_nothing_raised {
|
1043
|
-
Format.new(
|
1044
|
-
|
1045
|
-
|
1033
|
+
Format.new(
|
1034
|
+
:bold => true,
|
1035
|
+
:size => 10,
|
1036
|
+
:color => 'black',
|
1037
|
+
:fg_color => 43,
|
1038
|
+
:align => 'top',
|
1039
|
+
:text_wrap => true,
|
1040
|
+
:border => 1
|
1041
|
+
)
|
1046
1042
|
}
|
1047
1043
|
end
|
1048
1044
|
|
@@ -1051,85 +1047,31 @@ def test_initialize
|
|
1051
1047
|
def test_get_xf
|
1052
1048
|
perl_file = "#{PERL_OUTDIR}/file_xf_biff"
|
1053
1049
|
size = File.size(perl_file)
|
1054
|
-
@
|
1055
|
-
@
|
1056
|
-
|
1057
|
-
|
1058
|
-
|
1059
|
-
|
1060
|
-
fh_p = File.open(perl_file, "r")
|
1061
|
-
fh_r = File.open(@ruby_file, "r")
|
1062
|
-
while true do
|
1063
|
-
p1 = fh_p.read(1)
|
1064
|
-
r1 = fh_r.read(1)
|
1065
|
-
if p1.nil?
|
1066
|
-
assert( r1.nil?, 'p1 is EOF but r1 is NOT EOF.')
|
1067
|
-
break
|
1068
|
-
elsif r1.nil?
|
1069
|
-
assert( p1.nil?, 'r1 is EOF but p1 is NOT EOF.')
|
1070
|
-
break
|
1071
|
-
end
|
1072
|
-
assert_equal(p1, r1, sprintf(" p1 = %s but r1 = %s", p1, r1))
|
1073
|
-
break
|
1074
|
-
end
|
1075
|
-
fh_p.close
|
1076
|
-
fh_r.close
|
1050
|
+
@ruby_file.print(@format.get_xf)
|
1051
|
+
rsize = @ruby_file.size
|
1052
|
+
assert_equal(size, rsize, "File sizes not the same")
|
1053
|
+
|
1054
|
+
compare_file(perl_file, @ruby_file)
|
1077
1055
|
end
|
1078
1056
|
|
1079
1057
|
def test_get_font
|
1080
1058
|
perl_file = "#{PERL_OUTDIR}/file_font_biff"
|
1081
1059
|
size = File.size(perl_file)
|
1082
|
-
@
|
1083
|
-
@
|
1084
|
-
|
1085
|
-
|
1086
|
-
|
1087
|
-
|
1088
|
-
fh_p = File.open(perl_file, "r")
|
1089
|
-
fh_r = File.open(@ruby_file, "r")
|
1090
|
-
while true do
|
1091
|
-
p1 = fh_p.read(1)
|
1092
|
-
r1 = fh_r.read(1)
|
1093
|
-
if p1.nil?
|
1094
|
-
assert( r1.nil?, 'p1 is EOF but r1 is NOT EOF.')
|
1095
|
-
break
|
1096
|
-
elsif r1.nil?
|
1097
|
-
assert( p1.nil?, 'r1 is EOF but p1 is NOT EOF.')
|
1098
|
-
break
|
1099
|
-
end
|
1100
|
-
assert_equal(p1, r1, sprintf(" p1 = %s but r1 = %s", p1, r1))
|
1101
|
-
break
|
1102
|
-
end
|
1103
|
-
fh_p.close
|
1104
|
-
fh_r.close
|
1060
|
+
@ruby_file.print(@format.get_font)
|
1061
|
+
rsize = @ruby_file.size
|
1062
|
+
assert_equal(size, rsize, "File sizes not the same")
|
1063
|
+
|
1064
|
+
compare_file(perl_file, @ruby_file)
|
1105
1065
|
end
|
1106
1066
|
|
1107
1067
|
def test_get_font_key
|
1108
1068
|
perl_file = "#{PERL_OUTDIR}/file_font_key"
|
1109
1069
|
size = File.size(perl_file)
|
1110
|
-
@
|
1111
|
-
@
|
1112
|
-
|
1113
|
-
|
1114
|
-
|
1115
|
-
|
1116
|
-
fh_p = File.open(perl_file, "r")
|
1117
|
-
fh_r = File.open(@ruby_file, "r")
|
1118
|
-
while true do
|
1119
|
-
p1 = fh_p.read(1)
|
1120
|
-
r1 = fh_r.read(1)
|
1121
|
-
if p1.nil?
|
1122
|
-
assert( r1.nil?, 'p1 is EOF but r1 is NOT EOF.')
|
1123
|
-
break
|
1124
|
-
elsif r1.nil?
|
1125
|
-
assert( p1.nil?, 'r1 is EOF but p1 is NOT EOF.')
|
1126
|
-
break
|
1127
|
-
end
|
1128
|
-
assert_equal(p1, r1, sprintf(" p1 = %s but r1 = %s", p1, r1))
|
1129
|
-
break
|
1130
|
-
end
|
1131
|
-
fh_p.close
|
1132
|
-
fh_r.close
|
1070
|
+
@ruby_file.print(@format.get_font_key)
|
1071
|
+
rsize = @ruby_file.size
|
1072
|
+
assert_equal(size, rsize, "File sizes not the same")
|
1073
|
+
|
1074
|
+
compare_file(perl_file, @ruby_file)
|
1133
1075
|
end
|
1134
1076
|
|
1135
1077
|
def test_copy
|
@@ -1247,5 +1189,4 @@ def get_format_property(format)
|
|
1247
1189
|
:right_color => format.right_color
|
1248
1190
|
}
|
1249
1191
|
end
|
1250
|
-
|
1251
1192
|
end
|
data/test/test_formula.rb
CHANGED
data/test/test_ole.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
1
2
|
require 'helper'
|
3
|
+
require 'stringio'
|
2
4
|
|
3
5
|
class TC_OLE < Test::Unit::TestCase
|
4
6
|
|
5
7
|
def setup
|
6
|
-
|
7
|
-
path = "temp#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
|
8
|
-
@file = File.join(Dir.tmpdir, path)
|
8
|
+
@file = StringIO.new
|
9
9
|
@ole = OLEWriter.new(@file)
|
10
10
|
end
|
11
11
|
|
@@ -102,6 +102,5 @@ def test_write_property_storage_size
|
|
102
102
|
|
103
103
|
def teardown
|
104
104
|
@ole.close rescue nil
|
105
|
-
File.unlink(@file) if File.exists?(@file)
|
106
105
|
end
|
107
106
|
end
|
data/test/test_storage_lite.rb
CHANGED
@@ -1,146 +1,125 @@
|
|
1
|
-
|
2
|
-
require '
|
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
|
-
def
|
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
|
-
end
|
59
|
-
|
60
|
-
def
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
end
|
80
|
-
|
81
|
-
def
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
data = [
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
data.each do |d|
|
96
|
-
olefile = OLEStorageLitePPSFile.new(
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
end
|
127
|
-
|
128
|
-
def test_append_stringio
|
129
|
-
data = [ "data", "\r\n", "\r", "\n" ]
|
130
|
-
data.each do |d|
|
131
|
-
sio = StringIO.new
|
132
|
-
olefile = OLEStorageLitePPSFile.new('name')
|
133
|
-
olefile.set_file(sio)
|
134
|
-
pps_file = olefile.pps_file
|
135
|
-
|
136
|
-
olefile.append(d)
|
137
|
-
pps_file.rewind
|
138
|
-
assert_equal(d, pps_file.read)
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
def unpack_record(data)
|
143
|
-
data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
|
144
|
-
end
|
145
|
-
|
146
|
-
end
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'helper'
|
3
|
+
require 'stringio'
|
4
|
+
|
5
|
+
class TC_OLEStorageLite < Test::Unit::TestCase
|
6
|
+
TEST_DIR = File.expand_path(File.dirname(__FILE__))
|
7
|
+
PERL_OUTDIR = File.join(TEST_DIR, 'perl_output')
|
8
|
+
EXCEL_OUTDIR = File.join(TEST_DIR, 'excelfile')
|
9
|
+
|
10
|
+
def setup
|
11
|
+
@ole = OLEStorageLite.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def teardown
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_olestoragelite_new
|
18
|
+
ole = OLEStorageLite.new
|
19
|
+
assert_nil(ole.file)
|
20
|
+
|
21
|
+
io = StringIO.new
|
22
|
+
ole = OLEStorageLite.new(io)
|
23
|
+
assert_equal(io, ole.file)
|
24
|
+
|
25
|
+
file = 'test.ole'
|
26
|
+
ole = OLEStorageLite.new(file)
|
27
|
+
assert_equal(file, ole.file)
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_asc2ucs
|
32
|
+
result = @ole.asc2ucs('Root Entry')
|
33
|
+
target = %w(
|
34
|
+
52 00 6F 00 6F 00 74 00 20 00 45 00 6E 00 74 00 72 00 79 00
|
35
|
+
).join(" ")
|
36
|
+
assert_equal(target, unpack_record(result))
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_ucs2asc
|
40
|
+
strings = [
|
41
|
+
'Root Entry',
|
42
|
+
''
|
43
|
+
]
|
44
|
+
strings.each do |str|
|
45
|
+
result = @ole.ucs2asc(@ole.asc2ucs(str))
|
46
|
+
assert_equal(str, result)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def unpack_record(data)
|
51
|
+
data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
class TC_OLEStorageLitePPSFile < Test::Unit::TestCase
|
57
|
+
def setup
|
58
|
+
end
|
59
|
+
|
60
|
+
def teardown
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_constructor
|
64
|
+
data = [
|
65
|
+
{ :name => 'name', :data => 'data' },
|
66
|
+
{ :name => '', :data => 'data' },
|
67
|
+
{ :name => 'name', :data => '' },
|
68
|
+
{ :name => '', :data => '' },
|
69
|
+
]
|
70
|
+
data.each do |d|
|
71
|
+
olefile = OLEStorageLitePPSFile.new(d[:name])
|
72
|
+
assert_equal(d[:name], olefile.name)
|
73
|
+
end
|
74
|
+
data.each do |d|
|
75
|
+
olefile = OLEStorageLitePPSFile.new(d[:name], d[:data])
|
76
|
+
assert_equal(d[:name], olefile.name)
|
77
|
+
assert_equal(d[:data], olefile.data)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_append_no_file
|
82
|
+
olefile = OLEStorageLitePPSFile.new('name')
|
83
|
+
assert_equal('', olefile.data)
|
84
|
+
|
85
|
+
data = [ "data", "\r\n", "\r", "\n" ]
|
86
|
+
data.each do |d|
|
87
|
+
olefile = OLEStorageLitePPSFile.new('name')
|
88
|
+
olefile.append(d)
|
89
|
+
assert_equal(d, olefile.data)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_append_tempfile
|
94
|
+
data = [ "data", "\r\n", "\r", "\n" ]
|
95
|
+
data.each do |d|
|
96
|
+
olefile = OLEStorageLitePPSFile.new('name')
|
97
|
+
olefile.set_file
|
98
|
+
pps_file = olefile.pps_file
|
99
|
+
|
100
|
+
olefile.append(d)
|
101
|
+
pps_file.open
|
102
|
+
pps_file.binmode
|
103
|
+
assert_equal(d, pps_file.read)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_append_stringio
|
108
|
+
data = [ "data", "\r\n", "\r", "\n" ]
|
109
|
+
data.each do |d|
|
110
|
+
sio = StringIO.new
|
111
|
+
olefile = OLEStorageLitePPSFile.new('name')
|
112
|
+
olefile.set_file(sio)
|
113
|
+
pps_file = olefile.pps_file
|
114
|
+
|
115
|
+
olefile.append(d)
|
116
|
+
pps_file.rewind
|
117
|
+
assert_equal(d, pps_file.read)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def unpack_record(data)
|
122
|
+
data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|