ricardoo27-writeexcel 0.6.12.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (245) hide show
  1. data/.document +5 -0
  2. data/.gitattributes +1 -0
  3. data/README.rdoc +136 -0
  4. data/Rakefile +52 -0
  5. data/VERSION +1 -0
  6. data/charts/chartex.rb +316 -0
  7. data/charts/demo1.rb +46 -0
  8. data/charts/demo101.bin +0 -0
  9. data/charts/demo2.rb +65 -0
  10. data/charts/demo201.bin +0 -0
  11. data/charts/demo3.rb +117 -0
  12. data/charts/demo301.bin +0 -0
  13. data/charts/demo4.rb +119 -0
  14. data/charts/demo401.bin +0 -0
  15. data/charts/demo5.rb +48 -0
  16. data/charts/demo501.bin +0 -0
  17. data/examples/a_simple.rb +43 -0
  18. data/examples/autofilter.rb +265 -0
  19. data/examples/bigfile.rb +30 -0
  20. data/examples/chart_area.rb +121 -0
  21. data/examples/chart_bar.rb +120 -0
  22. data/examples/chart_column.rb +120 -0
  23. data/examples/chart_line.rb +120 -0
  24. data/examples/chart_pie.rb +108 -0
  25. data/examples/chart_scatter.rb +121 -0
  26. data/examples/chart_stock.rb +148 -0
  27. data/examples/chess.rb +142 -0
  28. data/examples/colors.rb +129 -0
  29. data/examples/comments1.rb +27 -0
  30. data/examples/comments2.rb +352 -0
  31. data/examples/copyformat.rb +52 -0
  32. data/examples/data_validate.rb +279 -0
  33. data/examples/date_time.rb +87 -0
  34. data/examples/defined_name.rb +32 -0
  35. data/examples/demo.rb +124 -0
  36. data/examples/diag_border.rb +36 -0
  37. data/examples/formats.rb +490 -0
  38. data/examples/formula_result.rb +30 -0
  39. data/examples/header.rb +137 -0
  40. data/examples/hide_sheet.rb +29 -0
  41. data/examples/hyperlink.rb +43 -0
  42. data/examples/images.rb +63 -0
  43. data/examples/indent.rb +31 -0
  44. data/examples/merge1.rb +40 -0
  45. data/examples/merge2.rb +45 -0
  46. data/examples/merge3.rb +66 -0
  47. data/examples/merge4.rb +83 -0
  48. data/examples/merge5.rb +80 -0
  49. data/examples/merge6.rb +67 -0
  50. data/examples/outline.rb +255 -0
  51. data/examples/outline_collapsed.rb +209 -0
  52. data/examples/panes.rb +113 -0
  53. data/examples/password_protection.rb +33 -0
  54. data/examples/properties.rb +34 -0
  55. data/examples/properties_jp.rb +33 -0
  56. data/examples/protection.rb +47 -0
  57. data/examples/regions.rb +53 -0
  58. data/examples/repeat.rb +43 -0
  59. data/examples/republic.png +0 -0
  60. data/examples/right_to_left.rb +27 -0
  61. data/examples/row_wrap.rb +53 -0
  62. data/examples/set_first_sheet.rb +14 -0
  63. data/examples/stats.rb +74 -0
  64. data/examples/stocks.rb +81 -0
  65. data/examples/store_formula.rb +15 -0
  66. data/examples/tab_colors.rb +31 -0
  67. data/examples/utf8.rb +15 -0
  68. data/examples/write_arrays.rb +83 -0
  69. data/html/en/doc_en.html +5946 -0
  70. data/html/images/a_simple.jpg +0 -0
  71. data/html/images/area1.jpg +0 -0
  72. data/html/images/bar1.jpg +0 -0
  73. data/html/images/chart_area.xls +0 -0
  74. data/html/images/column1.jpg +0 -0
  75. data/html/images/data_validation.jpg +0 -0
  76. data/html/images/line1.jpg +0 -0
  77. data/html/images/pie1.jpg +0 -0
  78. data/html/images/regions.jpg +0 -0
  79. data/html/images/scatter1.jpg +0 -0
  80. data/html/images/stats.jpg +0 -0
  81. data/html/images/stock1.jpg +0 -0
  82. data/html/images/stocks.jpg +0 -0
  83. data/html/index.html +16 -0
  84. data/html/style.css +433 -0
  85. data/lib/writeexcel.rb +1159 -0
  86. data/lib/writeexcel/biffwriter.rb +223 -0
  87. data/lib/writeexcel/caller_info.rb +12 -0
  88. data/lib/writeexcel/cell_range.rb +332 -0
  89. data/lib/writeexcel/chart.rb +1968 -0
  90. data/lib/writeexcel/charts/area.rb +154 -0
  91. data/lib/writeexcel/charts/bar.rb +177 -0
  92. data/lib/writeexcel/charts/column.rb +156 -0
  93. data/lib/writeexcel/charts/external.rb +66 -0
  94. data/lib/writeexcel/charts/line.rb +154 -0
  95. data/lib/writeexcel/charts/pie.rb +169 -0
  96. data/lib/writeexcel/charts/scatter.rb +192 -0
  97. data/lib/writeexcel/charts/stock.rb +213 -0
  98. data/lib/writeexcel/col_info.rb +87 -0
  99. data/lib/writeexcel/colors.rb +68 -0
  100. data/lib/writeexcel/comments.rb +460 -0
  101. data/lib/writeexcel/compatibility.rb +65 -0
  102. data/lib/writeexcel/convert_date_time.rb +117 -0
  103. data/lib/writeexcel/data_validations.rb +370 -0
  104. data/lib/writeexcel/debug_info.rb +41 -0
  105. data/lib/writeexcel/embedded_chart.rb +35 -0
  106. data/lib/writeexcel/excelformula.y +139 -0
  107. data/lib/writeexcel/excelformulaparser.rb +587 -0
  108. data/lib/writeexcel/format.rb +1575 -0
  109. data/lib/writeexcel/formula.rb +987 -0
  110. data/lib/writeexcel/helper.rb +78 -0
  111. data/lib/writeexcel/image.rb +218 -0
  112. data/lib/writeexcel/olewriter.rb +305 -0
  113. data/lib/writeexcel/outline.rb +24 -0
  114. data/lib/writeexcel/properties.rb +242 -0
  115. data/lib/writeexcel/shared_string_table.rb +153 -0
  116. data/lib/writeexcel/storage_lite.rb +984 -0
  117. data/lib/writeexcel/workbook.rb +2478 -0
  118. data/lib/writeexcel/worksheet.rb +6925 -0
  119. data/lib/writeexcel/worksheets.rb +25 -0
  120. data/lib/writeexcel/write_file.rb +63 -0
  121. data/test/excelfile/Chart1.xls +0 -0
  122. data/test/excelfile/Chart2.xls +0 -0
  123. data/test/excelfile/Chart3.xls +0 -0
  124. data/test/excelfile/Chart4.xls +0 -0
  125. data/test/excelfile/Chart5.xls +0 -0
  126. data/test/helper.rb +31 -0
  127. data/test/perl_output/Chart1.xls.data +0 -0
  128. data/test/perl_output/Chart2.xls.data +0 -0
  129. data/test/perl_output/Chart3.xls.data +0 -0
  130. data/test/perl_output/Chart4.xls.data +0 -0
  131. data/test/perl_output/Chart5.xls.data +0 -0
  132. data/test/perl_output/README +31 -0
  133. data/test/perl_output/a_simple.xls +0 -0
  134. data/test/perl_output/autofilter.xls +0 -0
  135. data/test/perl_output/biff_add_continue_testdata +0 -0
  136. data/test/perl_output/chart_area.xls +0 -0
  137. data/test/perl_output/chart_bar.xls +0 -0
  138. data/test/perl_output/chart_column.xls +0 -0
  139. data/test/perl_output/chart_line.xls +0 -0
  140. data/test/perl_output/chess.xls +0 -0
  141. data/test/perl_output/colors.xls +0 -0
  142. data/test/perl_output/comments0.xls +0 -0
  143. data/test/perl_output/comments1.xls +0 -0
  144. data/test/perl_output/comments2.xls +0 -0
  145. data/test/perl_output/data_validate.xls +0 -0
  146. data/test/perl_output/date_time.xls +0 -0
  147. data/test/perl_output/defined_name.xls +0 -0
  148. data/test/perl_output/demo.xls +0 -0
  149. data/test/perl_output/demo101.bin +0 -0
  150. data/test/perl_output/demo201.bin +0 -0
  151. data/test/perl_output/demo301.bin +0 -0
  152. data/test/perl_output/demo401.bin +0 -0
  153. data/test/perl_output/demo501.bin +0 -0
  154. data/test/perl_output/diag_border.xls +0 -0
  155. data/test/perl_output/f_font_biff +0 -0
  156. data/test/perl_output/f_font_key +1 -0
  157. data/test/perl_output/f_xf_biff +0 -0
  158. data/test/perl_output/file_font_biff +0 -0
  159. data/test/perl_output/file_font_key +1 -0
  160. data/test/perl_output/file_xf_biff +0 -0
  161. data/test/perl_output/formula_result.xls +0 -0
  162. data/test/perl_output/headers.xls +0 -0
  163. data/test/perl_output/hidden.xls +0 -0
  164. data/test/perl_output/hide_zero.xls +0 -0
  165. data/test/perl_output/hyperlink.xls +0 -0
  166. data/test/perl_output/images.xls +0 -0
  167. data/test/perl_output/indent.xls +0 -0
  168. data/test/perl_output/merge1.xls +0 -0
  169. data/test/perl_output/merge2.xls +0 -0
  170. data/test/perl_output/merge3.xls +0 -0
  171. data/test/perl_output/merge4.xls +0 -0
  172. data/test/perl_output/merge5.xls +0 -0
  173. data/test/perl_output/merge6.xls +0 -0
  174. data/test/perl_output/ole_write_header +0 -0
  175. data/test/perl_output/outline.xls +0 -0
  176. data/test/perl_output/outline_collapsed.xls +0 -0
  177. data/test/perl_output/panes.xls +0 -0
  178. data/test/perl_output/password_protection.xls +0 -0
  179. data/test/perl_output/protection.xls +0 -0
  180. data/test/perl_output/regions.xls +0 -0
  181. data/test/perl_output/right_to_left.xls +0 -0
  182. data/test/perl_output/set_first_sheet.xls +0 -0
  183. data/test/perl_output/stats.xls +0 -0
  184. data/test/perl_output/stocks.xls +0 -0
  185. data/test/perl_output/store_formula.xls +0 -0
  186. data/test/perl_output/tab_colors.xls +0 -0
  187. data/test/perl_output/unicode_cyrillic.xls +0 -0
  188. data/test/perl_output/utf8.xls +0 -0
  189. data/test/perl_output/workbook1.xls +0 -0
  190. data/test/perl_output/workbook2.xls +0 -0
  191. data/test/perl_output/ws_colinfo +1 -0
  192. data/test/perl_output/ws_store_colinfo +0 -0
  193. data/test/perl_output/ws_store_dimensions +0 -0
  194. data/test/perl_output/ws_store_filtermode +0 -0
  195. data/test/perl_output/ws_store_filtermode_off +0 -0
  196. data/test/perl_output/ws_store_filtermode_on +0 -0
  197. data/test/perl_output/ws_store_selection +0 -0
  198. data/test/perl_output/ws_store_window2 +1 -0
  199. data/test/republic.png +0 -0
  200. data/test/test_00_IEEE_double.rb +13 -0
  201. data/test/test_01_add_worksheet.rb +10 -0
  202. data/test/test_02_merge_formats.rb +49 -0
  203. data/test/test_04_dimensions.rb +388 -0
  204. data/test/test_05_rows.rb +175 -0
  205. data/test/test_06_extsst.rb +74 -0
  206. data/test/test_11_date_time.rb +475 -0
  207. data/test/test_12_date_only.rb +525 -0
  208. data/test/test_13_date_seconds.rb +477 -0
  209. data/test/test_21_escher.rb +624 -0
  210. data/test/test_22_mso_drawing_group.rb +741 -0
  211. data/test/test_23_note.rb +57 -0
  212. data/test/test_24_txo.rb +74 -0
  213. data/test/test_25_position_object.rb +80 -0
  214. data/test/test_26_autofilter.rb +309 -0
  215. data/test/test_27_autofilter.rb +126 -0
  216. data/test/test_28_autofilter.rb +156 -0
  217. data/test/test_29_process_jpg.rb +670 -0
  218. data/test/test_30_validation_dval.rb +74 -0
  219. data/test/test_31_validation_dv_strings.rb +123 -0
  220. data/test/test_32_validation_dv_formula.rb +203 -0
  221. data/test/test_40_property_types.rb +188 -0
  222. data/test/test_41_properties.rb +235 -0
  223. data/test/test_42_set_properties.rb +434 -0
  224. data/test/test_50_name_stored.rb +295 -0
  225. data/test/test_51_name_print_area.rb +353 -0
  226. data/test/test_52_name_print_titles.rb +450 -0
  227. data/test/test_53_autofilter.rb +199 -0
  228. data/test/test_60_chart_generic.rb +574 -0
  229. data/test/test_61_chart_subclasses.rb +84 -0
  230. data/test/test_62_chart_formats.rb +268 -0
  231. data/test/test_63_chart_area_formats.rb +645 -0
  232. data/test/test_biff.rb +71 -0
  233. data/test/test_big_workbook.rb +17 -0
  234. data/test/test_compatibility.rb +12 -0
  235. data/test/test_example_match.rb +3246 -0
  236. data/test/test_format.rb +1189 -0
  237. data/test/test_formula.rb +61 -0
  238. data/test/test_ole.rb +102 -0
  239. data/test/test_storage_lite.rb +116 -0
  240. data/test/test_workbook.rb +146 -0
  241. data/test/test_worksheet.rb +106 -0
  242. data/utils/add_magic_comment.rb +80 -0
  243. data/writeexcel.gemspec +278 -0
  244. data/writeexcel.rdoc +1425 -0
  245. metadata +292 -0
@@ -0,0 +1,84 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'helper'
3
+ require 'stringio'
4
+
5
+ ###############################################################################
6
+ #
7
+ # A test for Chart.
8
+ #
9
+ # Tests for the Excel chart.rb methods.
10
+ #
11
+ # reverse(''), December 2009, John McNamara, jmcnamara@cpan.org
12
+ #
13
+ # original written in Perl by John McNamara
14
+ # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
15
+ #
16
+ class TC_chart_subclasses < Test::Unit::TestCase
17
+ def setup
18
+ io = StringIO.new
19
+ @workbook = WriteExcel.new(io)
20
+ end
21
+
22
+ def test_store_chart_type_of_column
23
+ chart = Writeexcel::Chart.factory('Chart::Column', @workbook, nil, nil)
24
+ expected = %w(
25
+ 17 10 06 00 00 00 96 00 00 00
26
+ ).join(' ')
27
+ got = unpack_record(chart.store_chart_type)
28
+ assert_equal(expected, got)
29
+ end
30
+
31
+ def test_store_chart_type_of_bar
32
+ chart = Writeexcel::Chart.factory('Chart::Bar', @workbook, nil, nil)
33
+ expected = %w(
34
+ 17 10 06 00 00 00 96 00 01 00
35
+ ).join(' ')
36
+ got = unpack_record(chart.store_chart_type)
37
+ assert_equal(expected, got)
38
+ end
39
+
40
+ def test_store_chart_type_of_line
41
+ chart = Writeexcel::Chart.factory('Chart::Line', @workbook, nil, nil)
42
+ expected = %w(
43
+ 18 10 02 00 00 00
44
+ ).join(' ')
45
+ got = unpack_record(chart.store_chart_type)
46
+ assert_equal(expected, got)
47
+ end
48
+
49
+ def test_store_chart_type_of_area
50
+ chart = Writeexcel::Chart.factory('Chart::Area', @workbook, nil, nil)
51
+ expected = %w(
52
+ 1A 10 02 00 01 00
53
+ ).join(' ')
54
+ got = unpack_record(chart.store_chart_type)
55
+ assert_equal(expected, got)
56
+ end
57
+
58
+ def test_store_chart_type_of_pie
59
+ chart = Writeexcel::Chart.factory('Chart::Pie', @workbook, nil, nil)
60
+ expected = %w(
61
+ 19 10 06 00 00 00 00 00 02 00
62
+ ).join(' ')
63
+ got = unpack_record(chart.store_chart_type)
64
+ assert_equal(expected, got)
65
+ end
66
+
67
+ def test_store_chart_type_of_scatter
68
+ chart = Writeexcel::Chart.factory('Chart::Scatter', @workbook, nil, nil)
69
+ expected = %w(
70
+ 1B 10 06 00 64 00 01 00 00 00
71
+ ).join(' ')
72
+ got = unpack_record(chart.store_chart_type)
73
+ assert_equal(expected, got)
74
+ end
75
+
76
+ def test_store_chart_type_of_stock
77
+ chart = Writeexcel::Chart.factory('Chart::Stock', @workbook, nil, nil)
78
+ expected = %w(
79
+ 18 10 02 00 00 00
80
+ ).join(' ')
81
+ got = unpack_record(chart.store_chart_type)
82
+ assert_equal(expected, got)
83
+ end
84
+ end
@@ -0,0 +1,268 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'helper'
3
+ require 'stringio'
4
+
5
+ ###############################################################################
6
+ #
7
+ # A test for Spreadsheet::Writeexcel::Chart.
8
+ #
9
+ # Tests for the Excel Chart.pm format conversion methods.
10
+ #
11
+ # reverse('ゥ'), January 2010, John McNamara, jmcnamara@cpan.org
12
+ #
13
+ # original written in Perl by John McNamara
14
+ # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
15
+ #
16
+ class TC_ChartFormats < Test::Unit::TestCase
17
+ def setup
18
+ @io = StringIO.new
19
+ @workbook = WriteExcel.new(@io)
20
+ @chart = @workbook.add_chart(:type => 'Chart::Column')
21
+ end
22
+
23
+ ###############################################################################
24
+ #
25
+ # Test. User defined colour as string.
26
+ #
27
+ def test_user_defined_color_as_string
28
+ color = 'red'
29
+ caption1 = " \tChart: index = get_color_indices(#{color})"
30
+ caption2 = " \tChart: rgb = get_color_indices(#{color})"
31
+
32
+ expected_index = 0x0A
33
+ expected_rgb = 0x000000FF
34
+
35
+ got_index, got_rgb = @chart.__send__("get_color_indices", color)
36
+
37
+ assert_equal(expected_index, got_index, caption1)
38
+ assert_equal(expected_rgb, got_rgb, caption2)
39
+
40
+ color = 'black'
41
+ caption1 = " \tChart: index = get_color_indices(#{color})"
42
+ caption2 = " \tChart: rgb = get_color_indices(#{color})"
43
+
44
+ expected_index = 0x08
45
+ expected_rgb = 0x00000000
46
+
47
+ got_index, got_rgb = @chart.__send__("get_color_indices", color)
48
+
49
+ assert_equal(expected_index, got_index, caption1)
50
+ assert_equal(expected_rgb, got_rgb, caption2)
51
+
52
+ color = 'white'
53
+ caption1 = " \tChart: index = get_color_indices(#{color})"
54
+ caption2 = " \tChart: rgb = get_color_indices(#{color})"
55
+
56
+ expected_index = 0x09
57
+ expected_rgb = 0x00FFFFFF
58
+
59
+ got_index, got_rgb = @chart.__send__("get_color_indices", color)
60
+
61
+ assert_equal(expected_index, got_index, caption1)
62
+ assert_equal(expected_rgb, got_rgb, caption2)
63
+ end
64
+
65
+ ###############################################################################
66
+ #
67
+ # Test. User defined colour as an index.
68
+ #
69
+ def test_user_defined_color_as_an_index
70
+ color = 0x0A
71
+ caption1 = " \tChart: index = get_color_indices(#{color})"
72
+ caption2 = " \tChart: rgb = get_color_indices(#{color})"
73
+
74
+ expected_index = 0x0A
75
+ expected_rgb = 0x000000FF
76
+
77
+
78
+ got_index, got_rgb = @chart.__send__("get_color_indices", color)
79
+
80
+ assert_equal(expected_index, got_index, caption1)
81
+ assert_equal(expected_rgb, got_rgb, caption2)
82
+ end
83
+
84
+ ###############################################################################
85
+ #
86
+ # Test. User defined colour as an out of range index.
87
+ #
88
+ def test_user_defined_color_as_an_out_of_range_index
89
+ color = 7
90
+ caption1 = " \tChart: index = get_color_indices(#{color})"
91
+ caption2 = " \tChart: rgb = get_color_indices(#{color})"
92
+
93
+ expected_index = nil
94
+ expected_rgb = nil
95
+
96
+ got_index, got_rgb = @chart.__send__("get_color_indices", color)
97
+
98
+ assert_equal(expected_index, got_index, caption1)
99
+ assert_equal(expected_rgb, got_rgb, caption2)
100
+
101
+ color = 64
102
+ caption1 = " \tChart: index = get_color_indices(#{color})"
103
+ caption2 = " \tChart: rgb = get_color_indices(#{color})"
104
+
105
+ expected_index = nil
106
+ expected_rgb = nil
107
+
108
+ got_index, got_rgb = @chart.__send__("get_color_indices", color)
109
+
110
+ assert_equal(expected_index, got_index, caption1)
111
+ assert_equal(expected_rgb, got_rgb, caption2)
112
+ end
113
+
114
+ ###############################################################################
115
+ #
116
+ # Test. User defined colour as an invalid string.
117
+ #
118
+ def test_user_defined_color_as_an_invalid_string
119
+ color = 'plaid'
120
+ caption1 = " \tChart: index = get_color_indices(#{color})"
121
+ caption2 = " \tChart: rgb = get_color_indices(#{color})"
122
+
123
+ expected_index = nil
124
+ expected_rgb = nil
125
+
126
+ got_index, got_rgb = @chart.__send__("get_color_indices", color)
127
+
128
+ assert_equal(expected_index, got_index, caption1)
129
+ assert_equal(expected_rgb, got_rgb, caption2)
130
+ end
131
+
132
+ ###############################################################################
133
+ #
134
+ # Test. User defined colour as an undef property.
135
+ #
136
+ def test_user_defined_color_as_an_nil_property
137
+ color = nil
138
+ caption1 = " \tChart: index = get_color_indices(#{color})"
139
+ caption2 = " \tChart: rgb = get_color_indices(#{color})"
140
+
141
+ expected_index = nil
142
+ expected_rgb = nil
143
+
144
+ got_index, got_rgb = @chart.__send__("get_color_indices", color)
145
+
146
+ assert_equal(expected_index, got_index, caption1)
147
+ assert_equal(expected_rgb, got_rgb, caption2)
148
+ end
149
+
150
+ ###############################################################################
151
+ #
152
+ # Test. Line patterns with indices.
153
+ #
154
+ def test_line_patterns_with_indices
155
+ caption = " \tChart: pattern = _get_line_pattern()"
156
+
157
+ values = {
158
+ 0 => 5,
159
+ 1 => 0,
160
+ 2 => 1,
161
+ 3 => 2,
162
+ 4 => 3,
163
+ 5 => 4,
164
+ 6 => 7,
165
+ 7 => 6,
166
+ 8 => 8,
167
+ 9 => 0,
168
+ nil => 0
169
+ }
170
+
171
+ expected = []
172
+ got = []
173
+
174
+ values.each do |user, excel|
175
+ got.push(@chart.__send__("get_line_pattern", user))
176
+ expected.push(excel)
177
+ end
178
+
179
+ assert_equal(expected, got, caption)
180
+ end
181
+
182
+ ###############################################################################
183
+ #
184
+ # Test. Line patterns with names.
185
+ #
186
+ def test_line_patterns_with_names
187
+ caption = " \tChart: pattern = _get_line_pattern()"
188
+
189
+ values = {
190
+ 'solid' => 0,
191
+ 'dash' => 1,
192
+ 'dot' => 2,
193
+ 'dash-dot' => 3,
194
+ 'dash-dot-dot' => 4,
195
+ 'none' => 5,
196
+ 'dark-gray' => 6,
197
+ 'medium-gray' => 7,
198
+ 'light-gray' => 8,
199
+ 'DASH' => 1,
200
+ 'fictional' => 0
201
+ }
202
+
203
+ expected = []
204
+ got = []
205
+
206
+ values.each do |user, excel|
207
+ got.push(@chart.__send__("get_line_pattern", user))
208
+ expected.push(excel)
209
+ end
210
+
211
+ assert_equal(expected, got, caption)
212
+ end
213
+
214
+ ###############################################################################
215
+ #
216
+ # Test. Line weights with indices.
217
+ #
218
+ def test_line_weights_with_indices
219
+ caption = " \tChart: weight = _get_line_weight()"
220
+
221
+ values = {
222
+ 1 => -1,
223
+ 2 => 0,
224
+ 3 => 1,
225
+ 4 => 2,
226
+ 5 => 0,
227
+ 0 => 0,
228
+ nil => 0
229
+ }
230
+
231
+ expected = []
232
+ got = []
233
+
234
+ values.each do |user, excel|
235
+ got.push(@chart.__send__("get_line_weight", user))
236
+ expected.push(excel)
237
+ end
238
+
239
+ assert_equal(expected, got, caption)
240
+ end
241
+
242
+ ###############################################################################
243
+ #
244
+ # Test. Line weights with names.
245
+ #
246
+ def test_line_weights_with_names
247
+ caption = " \tChart: weight = _get_line_weight()"
248
+
249
+ values = {
250
+ 'hairline' => -1,
251
+ 'narrow' => 0,
252
+ 'medium' => 1,
253
+ 'wide' => 2,
254
+ 'WIDE' => 2,
255
+ 'Fictional' => 0,
256
+ }
257
+
258
+ expected = []
259
+ got = []
260
+
261
+ values.each do |user, excel|
262
+ got.push(@chart.__send__("get_line_weight", user))
263
+ expected.push(excel)
264
+ end
265
+
266
+ assert_equal(expected, got, caption)
267
+ end
268
+ end
@@ -0,0 +1,645 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'helper'
3
+ require 'stringio'
4
+
5
+ ###############################################################################
6
+ #
7
+ # A test for Spreadsheet::Writeexcel::Chart.
8
+ #
9
+ # Tests for the Excel Chart.pm format conversion methods.
10
+ #
11
+ # reverse('ゥ'), January 2010, John McNamara, jmcnamara@cpan.org
12
+ #
13
+ # original written in Perl by John McNamara
14
+ # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
15
+ #
16
+ class TC_ChartAreaFormats < Test::Unit::TestCase
17
+ def setup
18
+ @io = StringIO.new
19
+ @workbook = WriteExcel.new(@io)
20
+ @chart = @workbook.add_chart(:type => 'Chart::Column')
21
+ @chart.using_tmpfile = false
22
+ @caption1 = " \tChart: chartarea format - line";
23
+ @caption2 = " \tChart: chartarea format - area";
24
+ @embed_caption1 = " \tChart: embedded chartarea format - line";
25
+ @embed_caption2 = " \tChart: embedded chartarea format - area";
26
+ @plotarea_caption1 = " \tChart: plotarea format - line";
27
+ @plotarea_caption2 = " \tChart: plotarea format - area";
28
+ end
29
+
30
+ ###############################################################################
31
+ #
32
+ # 1. Test the chartarea format methods. See the set_*area() properties below.
33
+ #
34
+ def test_the_chartarea_format_methods
35
+ reset_chart(@chart)
36
+
37
+ @chart.set_chartarea(
38
+ :color => 'red',
39
+ :line_color => 'black',
40
+ :line_pattern => 2,
41
+ :line_weight => 3
42
+ )
43
+
44
+ expected_line = %w(
45
+ 07 10 0C 00 00 00 00 00 01 00 01 00 00 00 08 00
46
+ ).join(' ')
47
+
48
+ expected_area = %w(
49
+ 0A 10 10 00 FF 00 00 00 00 00 00 00 01 00 00 00
50
+ 0A 00 08 00
51
+ ).join(' ')
52
+
53
+ got_line, got_area = get_chartarea_formats(@chart)
54
+
55
+ assert_equal(expected_line, got_line, @caption1)
56
+ assert_equal(expected_area, got_area, @caption2)
57
+
58
+
59
+ reset_chart(@chart)
60
+
61
+ @chart.set_chartarea(
62
+ :color => 'red'
63
+ )
64
+
65
+ expected_line = %w(
66
+ 07 10 0C 00 00 00 00 00 05 00 FF FF 08 00 4D 00
67
+ ).join(' ')
68
+
69
+ expected_area = %w(
70
+ 0A 10 10 00 FF 00 00 00 00 00 00 00 01 00 00 00
71
+ 0A 00 08 00
72
+ ).join(' ')
73
+
74
+ got_line, got_area = get_chartarea_formats(@chart)
75
+
76
+ assert_equal(expected_line, got_line, @caption1)
77
+ assert_equal(expected_area, got_area, @caption2)
78
+
79
+
80
+ reset_chart(@chart)
81
+
82
+ @chart.set_chartarea(
83
+ :line_color => 'red'
84
+ )
85
+
86
+ expected_line = %w(
87
+ 07 10 0C 00 FF 00 00 00 00 00 FF FF 00 00 0A 00
88
+ ).join(' ')
89
+
90
+ expected_area = %w(
91
+ 0A 10 10 00 FF FF FF 00 00 00 00 00 00 00 00 00
92
+ 4E 00 4D 00
93
+ ).join(' ')
94
+
95
+ got_line, got_area = get_chartarea_formats(@chart)
96
+
97
+ assert_equal(expected_line, got_line, @caption1)
98
+ assert_equal(expected_area, got_area, @caption2)
99
+
100
+
101
+ reset_chart(@chart)
102
+
103
+ @chart.set_chartarea(
104
+ :line_pattern => 2
105
+ )
106
+
107
+ expected_line = %w(
108
+ 07 10 0C 00 00 00 00 00 01 00 FF FF 00 00 4F 00
109
+ ).join(' ')
110
+
111
+ expected_area = %w(
112
+ 0A 10 10 00 FF FF FF 00 00 00 00 00 00 00 00 00
113
+ 4E 00 4D 00
114
+ ).join(' ')
115
+
116
+ got_line, got_area = get_chartarea_formats(@chart)
117
+
118
+ assert_equal(expected_line, got_line, @caption1)
119
+ assert_equal(expected_area, got_area, @caption2)
120
+
121
+
122
+ reset_chart(@chart)
123
+
124
+ @chart.set_chartarea(
125
+ :line_weight => 3
126
+ )
127
+
128
+ expected_line = %w(
129
+ 07 10 0C 00 00 00 00 00 00 00 01 00 00 00 4F 00
130
+ ).join(' ')
131
+
132
+ expected_area = %w(
133
+ 0A 10 10 00 FF FF FF 00 00 00 00 00 00 00 00 00
134
+ 4E 00 4D 00
135
+ ).join(' ')
136
+
137
+ got_line, got_area = get_chartarea_formats(@chart)
138
+
139
+ assert_equal(expected_line, got_line, @caption1)
140
+ assert_equal(expected_area, got_area, @caption2)
141
+
142
+
143
+ reset_chart(@chart)
144
+
145
+ @chart.set_chartarea(
146
+ :color => 'red',
147
+ :line_color => 'black'
148
+ )
149
+
150
+ expected_line = %w(
151
+ 07 10 0C 00 00 00 00 00 00 00 FF FF 00 00 08 00
152
+ ).join(' ')
153
+
154
+ expected_area = %w(
155
+ 0A 10 10 00 FF 00 00 00 00 00 00 00 01 00 00 00
156
+ 0A 00 08 00
157
+ ).join(' ')
158
+
159
+ got_line, got_area = get_chartarea_formats(@chart)
160
+
161
+ assert_equal(expected_line, got_line, @caption1)
162
+ assert_equal(expected_area, got_area, @caption2)
163
+
164
+
165
+ reset_chart(@chart)
166
+
167
+ @chart.set_chartarea(
168
+ :color => 'red',
169
+ :line_pattern => 2
170
+ )
171
+
172
+ expected_line = %w(
173
+ 07 10 0C 00 00 00 00 00 01 00 FF FF 00 00 4F 00
174
+ ).join(' ')
175
+
176
+ expected_area = %w(
177
+ 0A 10 10 00 FF 00 00 00 00 00 00 00 01 00 00 00
178
+ 0A 00 08 00
179
+ ).join(' ')
180
+
181
+ got_line, got_area = get_chartarea_formats(@chart)
182
+
183
+ assert_equal(expected_line, got_line, @caption1)
184
+ assert_equal(expected_area, got_area, @caption2)
185
+
186
+
187
+ reset_chart(@chart)
188
+
189
+ @chart.set_chartarea(
190
+ :color => 'red',
191
+ :line_weight => 3
192
+ )
193
+
194
+ expected_line = %w(
195
+ 07 10 0C 00 00 00 00 00 00 00 01 00 00 00 4F 00
196
+ ).join(' ')
197
+
198
+ expected_area = %w(
199
+ 0A 10 10 00 FF 00 00 00 00 00 00 00 01 00 00 00
200
+ 0A 00 08 00
201
+ ).join(' ')
202
+
203
+ got_line, got_area = get_chartarea_formats(@chart)
204
+
205
+ assert_equal(expected_line, got_line, @caption1)
206
+ assert_equal(expected_area, got_area, @caption2)
207
+
208
+
209
+ @chart.embedded = true
210
+
211
+ reset_chart(@chart, true)
212
+
213
+ @chart.set_chartarea(
214
+ )
215
+
216
+ expected_line = %w(
217
+ 07 10 0C 00 00 00 00 00 00 00 00 00 09 00 4D 00
218
+ ).join(' ')
219
+
220
+ expected_area = %w(
221
+ 0A 10 10 00 FF FF FF 00 00 00 00 00 01 00 01 00
222
+ 4E 00 4D 00
223
+ ).join(' ')
224
+
225
+ got_line, got_area = get_chartarea_formats(@chart)
226
+
227
+ assert_equal(expected_line, got_line, @embed_caption1)
228
+ assert_equal(expected_area, got_area, @embed_caption2)
229
+
230
+
231
+ reset_chart(@chart, true)
232
+
233
+ @chart.set_chartarea(
234
+ :color => 'red',
235
+ :line_color => 'black',
236
+ :line_pattern => 2,
237
+ :line_weight => 3
238
+ )
239
+
240
+ expected_line = %w(
241
+ 07 10 0C 00 00 00 00 00 01 00 01 00 00 00 08 00
242
+ ).join(' ')
243
+
244
+ expected_area = %w(
245
+ 0A 10 10 00 FF 00 00 00 00 00 00 00 01 00 00 00
246
+ 0A 00 08 00
247
+ ).join(' ')
248
+
249
+ got_line, got_area = get_chartarea_formats(@chart)
250
+
251
+ assert_equal(expected_line, got_line, @embed_caption1)
252
+ assert_equal(expected_area, got_area, @embed_caption2)
253
+
254
+
255
+ reset_chart(@chart, true)
256
+
257
+ @chart.set_chartarea(
258
+ :color => 'red'
259
+ )
260
+
261
+ expected_line = %w(
262
+ 07 10 0C 00 00 00 00 00 00 00 FF FF 09 00 4D 00
263
+ ).join(' ')
264
+
265
+ expected_area = %w(
266
+ 0A 10 10 00 FF 00 00 00 00 00 00 00 01 00 00 00
267
+ 0A 00 08 00
268
+ ).join(' ')
269
+
270
+ got_line, got_area = get_chartarea_formats(@chart)
271
+
272
+ assert_equal(expected_line, got_line, @embed_caption1)
273
+ assert_equal(expected_area, got_area, @embed_caption2)
274
+
275
+
276
+ reset_chart(@chart, true)
277
+
278
+ @chart.set_chartarea(
279
+ :line_color => 'red'
280
+ )
281
+
282
+ expected_line = %w(
283
+ 07 10 0C 00 FF 00 00 00 00 00 FF FF 00 00 0A 00
284
+ ).join(' ')
285
+
286
+ expected_area = %w(
287
+ 0A 10 10 00 FF FF FF 00 00 00 00 00 01 00 01 00
288
+ 4E 00 4D 00
289
+ ).join(' ')
290
+
291
+ got_line, got_area = get_chartarea_formats(@chart)
292
+
293
+ assert_equal(expected_line, got_line, @embed_caption1)
294
+ assert_equal(expected_area, got_area, @embed_caption2)
295
+
296
+
297
+ reset_chart(@chart, true)
298
+
299
+ @chart.set_chartarea(
300
+ :line_pattern => 2
301
+ )
302
+
303
+ expected_line = %w(
304
+ 07 10 0C 00 00 00 00 00 01 00 FF FF 00 00 4F 00
305
+ ).join(' ')
306
+
307
+ expected_area = %w(
308
+ 0A 10 10 00 FF FF FF 00 00 00 00 00 01 00 01 00
309
+ 4E 00 4D 00
310
+ ).join(' ')
311
+
312
+ got_line, got_area = get_chartarea_formats(@chart)
313
+
314
+ assert_equal(expected_line, got_line, @embed_caption1)
315
+ assert_equal(expected_area, got_area, @embed_caption2)
316
+
317
+
318
+ reset_chart(@chart, true)
319
+
320
+ @chart.set_chartarea(
321
+ :line_weight => 3
322
+ )
323
+
324
+ expected_line = %w(
325
+ 07 10 0C 00 00 00 00 00 00 00 01 00 00 00 4F 00
326
+ ).join(' ')
327
+
328
+ expected_area = %w(
329
+ 0A 10 10 00 FF FF FF 00 00 00 00 00 01 00 01 00
330
+ 4E 00 4D 00
331
+ ).join(' ')
332
+
333
+ got_line, got_area = get_chartarea_formats(@chart)
334
+
335
+ assert_equal(expected_line, got_line, @embed_caption1)
336
+ assert_equal(expected_area, got_area, @embed_caption2)
337
+
338
+
339
+ reset_chart(@chart, true)
340
+
341
+ @chart.set_chartarea(
342
+ :color => 'red',
343
+ :line_color => 'black'
344
+ )
345
+
346
+ expected_line = %w(
347
+ 07 10 0C 00 00 00 00 00 00 00 FF FF 00 00 08 00
348
+ ).join(' ')
349
+
350
+ expected_area = %w(
351
+ 0A 10 10 00 FF 00 00 00 00 00 00 00 01 00 00 00
352
+ 0A 00 08 00
353
+ ).join(' ')
354
+
355
+ got_line, got_area = get_chartarea_formats(@chart)
356
+
357
+ assert_equal(expected_line, got_line, @embed_caption1)
358
+ assert_equal(expected_area, got_area, @embed_caption2)
359
+
360
+
361
+ reset_chart(@chart, true)
362
+
363
+ @chart.set_chartarea(
364
+ :color => 'red',
365
+ :line_pattern => 2
366
+ )
367
+
368
+ expected_line = %w(
369
+ 07 10 0C 00 00 00 00 00 01 00 FF FF 00 00 4F 00
370
+ ).join(' ')
371
+
372
+ expected_area = %w(
373
+ 0A 10 10 00 FF 00 00 00 00 00 00 00 01 00 00 00
374
+ 0A 00 08 00
375
+ ).join(' ')
376
+
377
+ got_line, got_area = get_chartarea_formats(@chart)
378
+
379
+ assert_equal(expected_line, got_line, @embed_caption1)
380
+ assert_equal(expected_area, got_area, @embed_caption2)
381
+
382
+
383
+ reset_chart(@chart, true)
384
+
385
+ @chart.set_chartarea(
386
+ :color => 'red',
387
+ :line_weight => 3
388
+ )
389
+
390
+ expected_line = %w(
391
+ 07 10 0C 00 00 00 00 00 00 00 01 00 00 00 4F 00
392
+ ).join(' ')
393
+
394
+ expected_area = %w(
395
+ 0A 10 10 00 FF 00 00 00 00 00 00 00 01 00 00 00
396
+ 0A 00 08 00
397
+ ).join(' ')
398
+
399
+ got_line, got_area = get_chartarea_formats(@chart)
400
+
401
+ assert_equal(expected_line, got_line, @embed_caption1)
402
+ assert_equal(expected_area, got_area, @embed_caption2)
403
+
404
+
405
+ @chart.embedded = false
406
+
407
+ reset_chart(@chart)
408
+
409
+ @chart.set_plotarea(
410
+ )
411
+
412
+ expected_line = %w(
413
+ 07 10 0C 00 80 80 80 00 00 00 00 00 00 00 17 00
414
+ ).join(' ')
415
+
416
+ expected_area = %w(
417
+ 0A 10 10 00 C0 C0 C0 00 00 00 00 00 01 00 00 00
418
+ 16 00 4F 00
419
+ ).join(' ')
420
+
421
+ got_line, got_area = get_plotarea_formats(@chart)
422
+
423
+ assert_equal(expected_line, got_line, @plotarea_caption1)
424
+ assert_equal(expected_area, got_area, @plotarea_caption2)
425
+
426
+
427
+ reset_chart(@chart)
428
+
429
+ @chart.set_plotarea(
430
+ :color => 'red',
431
+ :line_color => 'black',
432
+ :line_pattern => 2,
433
+ :line_weight => 3
434
+ )
435
+
436
+ expected_line = %w(
437
+ 07 10 0C 00 00 00 00 00 01 00 01 00 00 00 08 00
438
+ ).join(' ')
439
+
440
+ expected_area = %w(
441
+ 0A 10 10 00 FF 00 00 00 00 00 00 00 01 00 00 00
442
+ 0A 00 08 00
443
+ ).join(' ')
444
+
445
+ got_line, got_area = get_plotarea_formats(@chart)
446
+
447
+ assert_equal(expected_line, got_line, @plotarea_caption1)
448
+ assert_equal(expected_area, got_area, @plotarea_caption2)
449
+
450
+
451
+ reset_chart(@chart)
452
+
453
+ @chart.set_plotarea(
454
+ :color => 'red'
455
+ )
456
+
457
+ expected_line = %w(
458
+ 07 10 0C 00 80 80 80 00 00 00 00 00 00 00 17 00
459
+ ).join(' ')
460
+
461
+ expected_area = %w(
462
+ 0A 10 10 00 FF 00 00 00 00 00 00 00 01 00 00 00
463
+ 0A 00 08 00
464
+ ).join(' ')
465
+
466
+ got_line, got_area = get_plotarea_formats(@chart)
467
+
468
+ assert_equal(expected_line, got_line, @plotarea_caption1)
469
+ assert_equal(expected_area, got_area, @plotarea_caption2)
470
+
471
+
472
+ reset_chart(@chart)
473
+
474
+ @chart.set_plotarea(
475
+ :line_color => 'red'
476
+ )
477
+
478
+ expected_line = %w(
479
+ 07 10 0C 00 FF 00 00 00 00 00 00 00 00 00 0A 00
480
+ ).join(' ')
481
+
482
+ expected_area = %w(
483
+ 0A 10 10 00 C0 C0 C0 00 00 00 00 00 01 00 00 00
484
+ 16 00 08 00
485
+ ).join(' ')
486
+
487
+ got_line, got_area = get_plotarea_formats(@chart)
488
+
489
+ assert_equal(expected_line, got_line, @plotarea_caption1)
490
+ assert_equal(expected_area, got_area, @plotarea_caption2)
491
+
492
+
493
+ reset_chart(@chart)
494
+
495
+ @chart.set_plotarea(
496
+ :line_pattern => 2
497
+ )
498
+
499
+ expected_line = %w(
500
+ 07 10 0C 00 80 80 80 00 01 00 00 00 00 00 17 00
501
+ ).join(' ')
502
+
503
+ expected_area = %w(
504
+ 0A 10 10 00 C0 C0 C0 00 00 00 00 00 01 00 00 00
505
+ 16 00 08 00
506
+ ).join(' ')
507
+
508
+ got_line, got_area = get_plotarea_formats(@chart)
509
+
510
+ assert_equal(expected_line, got_line, @plotarea_caption1)
511
+ assert_equal(expected_area, got_area, @plotarea_caption2)
512
+
513
+
514
+ reset_chart(@chart)
515
+
516
+ @chart.set_plotarea(
517
+ :line_weight => 3
518
+ )
519
+
520
+ expected_line = %w(
521
+ 07 10 0C 00 80 80 80 00 00 00 01 00 00 00 17 00
522
+ ).join(' ')
523
+
524
+ expected_area = %w(
525
+ 0A 10 10 00 C0 C0 C0 00 00 00 00 00 01 00 00 00
526
+ 16 00 08 00
527
+ ).join(' ')
528
+
529
+ got_line, got_area = get_plotarea_formats(@chart)
530
+
531
+ assert_equal(expected_line, got_line, @plotarea_caption1)
532
+ assert_equal(expected_area, got_area, @plotarea_caption2)
533
+
534
+
535
+ reset_chart(@chart)
536
+
537
+ @chart.set_plotarea(
538
+ :color => 'red',
539
+ :line_color => 'black'
540
+ )
541
+
542
+ expected_line = %w(
543
+ 07 10 0C 00 00 00 00 00 00 00 00 00 00 00 08 00
544
+ ).join(' ')
545
+
546
+ expected_area = %w(
547
+ 0A 10 10 00 FF 00 00 00 00 00 00 00 01 00 00 00
548
+ 0A 00 08 00
549
+ ).join(' ')
550
+
551
+ got_line, got_area = get_plotarea_formats(@chart)
552
+
553
+ assert_equal(expected_line, got_line, @plotarea_caption1)
554
+ assert_equal(expected_area, got_area, @plotarea_caption2)
555
+
556
+
557
+ reset_chart(@chart)
558
+
559
+ @chart.set_plotarea(
560
+ :color => 'red',
561
+ :line_pattern => 2
562
+ )
563
+
564
+ expected_line = %w(
565
+ 07 10 0C 00 80 80 80 00 01 00 00 00 00 00 17 00
566
+ ).join(' ')
567
+
568
+ expected_area = %w(
569
+ 0A 10 10 00 FF 00 00 00 00 00 00 00 01 00 00 00
570
+ 0A 00 08 00
571
+ ).join(' ')
572
+
573
+ got_line, got_area = get_plotarea_formats(@chart)
574
+
575
+ assert_equal(expected_line, got_line, @plotarea_caption1)
576
+ assert_equal(expected_area, got_area, @plotarea_caption2)
577
+
578
+
579
+ reset_chart(@chart)
580
+
581
+ @chart.set_plotarea(
582
+ :color => 'red',
583
+ :line_weight => 3
584
+ )
585
+
586
+ expected_line = %w(
587
+ 07 10 0C 00 80 80 80 00 00 00 01 00 00 00 17 00
588
+ ).join(' ')
589
+
590
+ expected_area = %w(
591
+ 0A 10 10 00 FF 00 00 00 00 00 00 00 01 00 00 00
592
+ 0A 00 08 00
593
+ ).join(' ')
594
+
595
+ got_line, got_area = get_plotarea_formats(@chart)
596
+
597
+ assert_equal(expected_line, got_line, @plotarea_caption1)
598
+ assert_equal(expected_area, got_area, @plotarea_caption2)
599
+ end
600
+
601
+
602
+ ###############################################################################
603
+ #
604
+ # Reset the chart data for testing.
605
+ #
606
+ def reset_chart(chart, embedded = nil)
607
+ # Reset the chart data.
608
+ chart.data = ''
609
+ chart.__send__("set_default_properties")
610
+
611
+ if embedded
612
+ chart.set_embedded_config_data
613
+ end
614
+ end
615
+
616
+ ###############################################################################
617
+ #
618
+ # Extract Line and Area format records from the Chartarea Frame stream.
619
+ #
620
+ def get_chartarea_formats(chart)
621
+ chart.__send__("store_chartarea_frame_stream")
622
+
623
+ line = unpack_record(chart.data[12, 16])
624
+ area = unpack_record(chart.data[28, 20])
625
+
626
+ [line, area]
627
+ end
628
+
629
+ ###############################################################################
630
+ #
631
+ # Extract Line and Area format records from the Chartarea Frame stream.
632
+ #
633
+ def get_plotarea_formats(chart)
634
+ chart.__send__("store_plotarea_frame_stream")
635
+
636
+ line = unpack_record(chart.data[12, 16])
637
+ area = unpack_record(chart.data[28, 20])
638
+
639
+ [line, area]
640
+ end
641
+
642
+ def unpack_record(data)
643
+ data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
644
+ end
645
+ end