writeexcel 0.3.5 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. data/.gitattributes +1 -0
  2. data/README.rdoc +12 -6
  3. data/VERSION +1 -1
  4. data/charts/chartex.rb +316 -315
  5. data/charts/demo1.rb +1 -0
  6. data/charts/demo2.rb +1 -0
  7. data/charts/demo3.rb +117 -116
  8. data/charts/demo4.rb +119 -118
  9. data/charts/demo5.rb +48 -47
  10. data/examples/a_simple.rb +1 -0
  11. data/examples/autofilter.rb +1 -0
  12. data/examples/bigfile.rb +30 -29
  13. data/examples/chart_area.rb +121 -120
  14. data/examples/chart_bar.rb +120 -119
  15. data/examples/chart_column.rb +120 -119
  16. data/examples/chart_line.rb +120 -119
  17. data/examples/chart_pie.rb +108 -107
  18. data/examples/chart_scatter.rb +121 -120
  19. data/examples/chart_stock.rb +148 -147
  20. data/examples/chess.rb +1 -0
  21. data/examples/colors.rb +1 -0
  22. data/examples/comments1.rb +1 -0
  23. data/examples/comments2.rb +3 -2
  24. data/examples/copyformat.rb +1 -0
  25. data/examples/data_validate.rb +1 -0
  26. data/examples/date_time.rb +1 -0
  27. data/examples/defined_name.rb +1 -0
  28. data/examples/demo.rb +1 -0
  29. data/examples/diag_border.rb +1 -0
  30. data/examples/formats.rb +1 -0
  31. data/examples/formula_result.rb +1 -0
  32. data/examples/header.rb +1 -0
  33. data/examples/hide_sheet.rb +1 -0
  34. data/examples/hyperlink.rb +1 -0
  35. data/examples/images.rb +1 -0
  36. data/examples/indent.rb +1 -0
  37. data/examples/merge1.rb +1 -0
  38. data/examples/merge2.rb +1 -0
  39. data/examples/merge3.rb +1 -0
  40. data/examples/merge4.rb +1 -0
  41. data/examples/merge5.rb +1 -0
  42. data/examples/merge6.rb +67 -66
  43. data/examples/outline.rb +1 -0
  44. data/examples/outline_collapsed.rb +1 -0
  45. data/examples/panes.rb +1 -0
  46. data/examples/properties.rb +1 -0
  47. data/examples/properties_jp.rb +1 -0
  48. data/examples/protection.rb +1 -0
  49. data/examples/regions.rb +1 -0
  50. data/examples/repeat.rb +1 -0
  51. data/examples/right_to_left.rb +1 -0
  52. data/examples/row_wrap.rb +1 -0
  53. data/examples/stats.rb +1 -0
  54. data/examples/stocks.rb +1 -0
  55. data/examples/tab_colors.rb +1 -0
  56. data/examples/write_arrays.rb +1 -0
  57. data/lib/writeexcel.rb +6 -1
  58. data/lib/writeexcel/biffwriter.rb +21 -20
  59. data/lib/writeexcel/chart.rb +25 -12
  60. data/lib/writeexcel/charts/area.rb +153 -152
  61. data/lib/writeexcel/charts/bar.rb +178 -177
  62. data/lib/writeexcel/charts/column.rb +157 -156
  63. data/lib/writeexcel/charts/external.rb +62 -61
  64. data/lib/writeexcel/charts/line.rb +153 -152
  65. data/lib/writeexcel/charts/pie.rb +170 -169
  66. data/lib/writeexcel/charts/scatter.rb +4 -3
  67. data/lib/writeexcel/charts/stock.rb +212 -211
  68. data/lib/writeexcel/compatibility.rb +320 -0
  69. data/lib/writeexcel/excelformulaparser.rb +587 -586
  70. data/lib/writeexcel/format.rb +12 -13
  71. data/lib/writeexcel/formula.rb +30 -28
  72. data/lib/writeexcel/helper.rb +23 -0
  73. data/lib/writeexcel/olewriter.rb +5 -16
  74. data/lib/writeexcel/properties.rb +43 -54
  75. data/lib/writeexcel/storage_lite.rb +981 -968
  76. data/lib/writeexcel/workbook.rb +94 -73
  77. data/lib/writeexcel/worksheet.rb +230 -210
  78. data/test/helper.rb +19 -0
  79. data/test/test_00_IEEE_double.rb +1 -0
  80. data/test/test_01_add_worksheet.rb +1 -0
  81. data/test/test_02_merge_formats.rb +3 -5
  82. data/test/test_04_dimensions.rb +3 -5
  83. data/test/test_05_rows.rb +6 -6
  84. data/test/test_06_extsst.rb +8 -8
  85. data/test/test_11_date_time.rb +3 -5
  86. data/test/test_12_date_only.rb +3 -5
  87. data/test/test_13_date_seconds.rb +4 -6
  88. data/test/test_21_escher.rb +3 -5
  89. data/test/test_22_mso_drawing_group.rb +20 -22
  90. data/test/test_23_note.rb +5 -7
  91. data/test/test_24_txo.rb +3 -5
  92. data/test/test_25_position_object.rb +84 -79
  93. data/test/test_26_autofilter.rb +3 -13
  94. data/test/test_27_autofilter.rb +3 -13
  95. data/test/test_28_autofilter.rb +3 -13
  96. data/test/test_29_process_jpg.rb +5 -0
  97. data/test/test_30_validation_dval.rb +3 -5
  98. data/test/test_31_validation_dv_strings.rb +3 -5
  99. data/test/test_32_validation_dv_formula.rb +3 -5
  100. data/test/test_40_property_types.rb +10 -9
  101. data/test/test_41_properties.rb +1 -0
  102. data/test/test_42_set_properties.rb +14 -15
  103. data/test/test_50_name_stored.rb +299 -302
  104. data/test/test_51_name_print_area.rb +357 -360
  105. data/test/test_52_name_print_titles.rb +454 -457
  106. data/test/test_53_autofilter.rb +203 -206
  107. data/test/test_60_chart_generic.rb +5 -0
  108. data/test/test_61_chart_subclasses.rb +95 -94
  109. data/test/test_62_chart_formats.rb +272 -267
  110. data/test/test_63_chart_area_formats.rb +649 -644
  111. data/test/test_biff.rb +12 -38
  112. data/test/test_compatibility.rb +627 -0
  113. data/test/test_example_match.rb +3 -18
  114. data/test/test_format.rb +46 -105
  115. data/test/test_formula.rb +1 -0
  116. data/test/test_ole.rb +3 -4
  117. data/test/test_storage_lite.rb +125 -146
  118. data/test/test_workbook.rb +2 -23
  119. data/test/test_worksheet.rb +4 -5
  120. data/utils/add_magic_comment.rb +80 -0
  121. data/writeexcel.gemspec +8 -2
  122. metadata +10 -4
@@ -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 in perl 5.8.
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 in perl 5.8.
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
@@ -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
- t = Time.now.strftime("%Y%m%d")
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
- @fh = File.new(@ruby_file,"w+")
984
- @fh.print(@format.get_xf)
985
- @fh.close
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
- @fh = File.new(@ruby_file,"w+")
1006
- @fh.print(@format.get_font)
1007
- @fh.close
1000
+ @ruby_file.print(@format.get_font)
1008
1001
  contents = IO.readlines(perl_file)
1009
- rcontents = IO.readlines(@ruby_file)
1010
- assert_equal(contents,rcontents,"Contents not the same")
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
- @fh = File.new(@ruby_file,"w+")
1016
- @fh.print(@format.get_font)
1017
- @fh.close
1018
- contents = IO.readlines(perl_file)
1019
- rcontents = IO.readlines(@ruby_file)
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
- @fh = File.new(@ruby_file,"w+")
1026
- @fh.print(@format.get_font_key)
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
- @fh = File.new(@ruby_file,"w+")
1034
- @fh.print(@format.get_font_key)
1035
- @fh.close
1036
- contents = IO.readlines(perl_file)
1037
- rcontents = IO.readlines(@ruby_file)
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(:bold => true, :size => 10, :color => 'black',
1044
- :fg_color => 43, :align => 'top', :text_wrap => true,
1045
- :border => 1)
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
- @fh = File.new(@ruby_file,"w+")
1055
- @fh.print(@format.get_xf)
1056
- @fh.close
1057
- rsize = File.size(@ruby_file)
1058
- assert_equal(size,rsize,"File sizes not the same")
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
- @fh = File.new(@ruby_file,"w+")
1083
- @fh.print(@format.get_font)
1084
- @fh.close
1085
- rsize = File.size(@ruby_file)
1086
- assert_equal(size,rsize,"File sizes not the same")
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
- @fh = File.new(@ruby_file,"w+")
1111
- @fh.print(@format.get_font_key)
1112
- @fh.close
1113
- rsize = File.size(@ruby_file)
1114
- assert_equal(size,rsize,"File sizes not the same")
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
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  require 'helper'
2
3
 
3
4
  class TC_Formula < Test::Unit::TestCase
@@ -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
- t = Time.now.strftime("%Y%m%d")
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
@@ -1,146 +1,125 @@
1
- require 'helper'
2
- require 'stringio'
3
-
4
- =begin
5
- def compare_file(expected, target)
6
- fh_e = File.open(expected, "r")
7
- fh_t = File.open(target, "r")
8
- while true do
9
- e1 = fh_e.read(1)
10
- t1 = fh_t.read(1)
11
- if e1.nil?
12
- assert( t1.nil?, "#{expexted} is EOF but #{target} is NOT EOF.")
13
- break
14
- elsif t1.nil?
15
- assert( e1.nil?, '#{target} is EOF but #{expected} is NOT EOF.')
16
- break
17
- end
18
- assert_equal(e1, t1, sprintf(" #{expected} = '%s' but #{target} = '%s'", e1, t1))
19
- break
20
- end
21
- fh_e.close
22
- fh_t.close
23
- end
24
- =end
25
-
26
- class TC_OLEStorageLite < Test::Unit::TestCase
27
- TEST_DIR = File.expand_path(File.dirname(__FILE__))
28
- PERL_OUTDIR = File.join(TEST_DIR, 'perl_output')
29
- EXCEL_OUTDIR = File.join(TEST_DIR, 'excelfile')
30
-
31
- def setup
32
- @ole = OLEStorageLite.new
33
- end
34
-
35
- def teardown
36
- end
37
-
38
- def test_olestoragelite_new
39
- ole = OLEStorageLite.new
40
- assert_nil(ole.file)
41
-
42
- io = StringIO.new
43
- ole = OLEStorageLite.new(io)
44
- assert_equal(io, ole.file)
45
-
46
- file = 'test.ole'
47
- ole = OLEStorageLite.new(file)
48
- assert_equal(file, ole.file)
49
-
50
- end
51
-
52
- def test_asc2ucs
53
- result = @ole.asc2ucs('Root Entry')
54
- target = %w(
55
- 52 00 6F 00 6F 00 74 00 20 00 45 00 6E 00 74 00 72 00 79 00
56
- ).join(" ")
57
- assert_equal(target, unpack_record(result))
58
- end
59
-
60
- def test_ucs2asc
61
- strings = [
62
- 'Root Entry',
63
- ''
64
- ]
65
- strings.each do |str|
66
- result = @ole.ucs2asc(@ole.asc2ucs(str))
67
- assert_equal(str, result)
68
- end
69
- end
70
-
71
- def unpack_record(data)
72
- data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
73
- end
74
-
75
- end
76
-
77
- class TC_OLEStorageLitePPSFile < Test::Unit::TestCase
78
- def setup
79
- end
80
-
81
- def teardown
82
- end
83
-
84
- def test_constructor
85
- data = [
86
- { :name => 'name', :data => 'data' },
87
- { :name => '', :data => 'data' },
88
- { :name => 'name', :data => '' },
89
- { :name => '', :data => '' },
90
- ]
91
- data.each do |d|
92
- olefile = OLEStorageLitePPSFile.new(d[:name])
93
- assert_equal(d[:name], olefile.name)
94
- end
95
- data.each do |d|
96
- olefile = OLEStorageLitePPSFile.new(d[:name], d[:data])
97
- assert_equal(d[:name], olefile.name)
98
- assert_equal(d[:data], olefile.data)
99
- end
100
- end
101
-
102
- def test_append_no_file
103
- olefile = OLEStorageLitePPSFile.new('name')
104
- assert_equal('', olefile.data)
105
-
106
- data = [ "data", "\r\n", "\r", "\n" ]
107
- data.each do |d|
108
- olefile = OLEStorageLitePPSFile.new('name')
109
- olefile.append(d)
110
- assert_equal(d, olefile.data)
111
- end
112
- end
113
-
114
- def test_append_tempfile
115
- data = [ "data", "\r\n", "\r", "\n" ]
116
- data.each do |d|
117
- olefile = OLEStorageLitePPSFile.new('name')
118
- olefile.set_file
119
- pps_file = olefile.pps_file
120
-
121
- olefile.append(d)
122
- pps_file.open
123
- pps_file.binmode
124
- assert_equal(d, pps_file.read)
125
- end
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