writeexcel 0.1.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (143) hide show
  1. data/README +26 -31
  2. data/examples/a_simple.rb +42 -42
  3. data/examples/{autofilters.rb → autofilter.rb} +264 -266
  4. data/examples/bigfile.rb +29 -0
  5. data/examples/chart_area.rb +120 -0
  6. data/examples/chart_bar.rb +119 -0
  7. data/examples/chart_column.rb +119 -0
  8. data/examples/chart_line.rb +119 -0
  9. data/examples/chart_pie.rb +107 -0
  10. data/examples/chart_scatter.rb +120 -0
  11. data/examples/chart_stock.rb +147 -0
  12. data/examples/copyformat.rb +51 -51
  13. data/examples/data_validate.rb +278 -278
  14. data/examples/date_time.rb +86 -86
  15. data/examples/defined_name.rb +31 -0
  16. data/examples/demo.rb +120 -118
  17. data/examples/diag_border.rb +35 -35
  18. data/examples/formats.rb +489 -489
  19. data/examples/header.rb +136 -136
  20. data/examples/hidden.rb +28 -28
  21. data/examples/hyperlink.rb +42 -42
  22. data/examples/images.rb +52 -52
  23. data/examples/merge1.rb +39 -39
  24. data/examples/merge2.rb +44 -44
  25. data/examples/merge3.rb +65 -65
  26. data/examples/merge4.rb +82 -82
  27. data/examples/merge5.rb +79 -79
  28. data/examples/properties.rb +33 -0
  29. data/examples/properties_jp.rb +32 -0
  30. data/examples/protection.rb +46 -46
  31. data/examples/regions.rb +52 -52
  32. data/examples/repeat.rb +42 -42
  33. data/examples/stats.rb +75 -75
  34. data/examples/stocks.rb +80 -80
  35. data/examples/tab_colors.rb +30 -30
  36. data/examples/write_arrays.rb +82 -0
  37. data/lib/writeexcel.rb +1134 -18
  38. data/lib/writeexcel/biffwriter.rb +273 -260
  39. data/lib/writeexcel/chart.rb +2306 -217
  40. data/lib/writeexcel/charts/area.rb +152 -0
  41. data/lib/writeexcel/charts/bar.rb +177 -0
  42. data/lib/writeexcel/charts/column.rb +156 -0
  43. data/lib/writeexcel/charts/external.rb +61 -0
  44. data/lib/writeexcel/charts/line.rb +152 -0
  45. data/lib/writeexcel/charts/pie.rb +169 -0
  46. data/lib/writeexcel/charts/scatter.rb +192 -0
  47. data/lib/writeexcel/charts/stock.rb +211 -0
  48. data/lib/writeexcel/excelformulaparser.rb +208 -195
  49. data/lib/writeexcel/format.rb +1697 -1108
  50. data/lib/writeexcel/formula.rb +1050 -986
  51. data/lib/writeexcel/olewriter.rb +322 -322
  52. data/lib/writeexcel/properties.rb +251 -250
  53. data/lib/writeexcel/storage_lite.rb +968 -0
  54. data/lib/writeexcel/workbook.rb +3294 -2630
  55. data/lib/writeexcel/worksheet.rb +9012 -6377
  56. data/test/excelfile/Chart1.xls +0 -0
  57. data/test/excelfile/Chart2.xls +0 -0
  58. data/test/excelfile/Chart3.xls +0 -0
  59. data/test/excelfile/Chart4.xls +0 -0
  60. data/test/excelfile/Chart5.xls +0 -0
  61. data/test/perl_output/Chart1.xls.data +0 -0
  62. data/test/perl_output/Chart2.xls.data +0 -0
  63. data/test/perl_output/Chart3.xls.data +0 -0
  64. data/test/perl_output/Chart4.xls.data +0 -0
  65. data/test/perl_output/Chart5.xls.data +0 -0
  66. data/test/perl_output/a_simple.xls +0 -0
  67. data/test/perl_output/autofilter.xls +0 -0
  68. data/test/perl_output/chart_area.xls +0 -0
  69. data/test/perl_output/chart_bar.xls +0 -0
  70. data/test/perl_output/chart_column.xls +0 -0
  71. data/test/perl_output/chart_line.xls +0 -0
  72. data/test/perl_output/data_validate.xls +0 -0
  73. data/test/perl_output/date_time.xls +0 -0
  74. data/test/perl_output/demo.xls +0 -0
  75. data/test/perl_output/demo101.bin +0 -0
  76. data/test/perl_output/demo201.bin +0 -0
  77. data/test/perl_output/demo301.bin +0 -0
  78. data/test/perl_output/demo401.bin +0 -0
  79. data/test/perl_output/demo501.bin +0 -0
  80. data/test/perl_output/diag_border.xls +0 -0
  81. data/test/perl_output/headers.xls +0 -0
  82. data/test/perl_output/hyperlink.xls +0 -0
  83. data/test/perl_output/images.xls +0 -0
  84. data/test/perl_output/merge1.xls +0 -0
  85. data/test/perl_output/merge2.xls +0 -0
  86. data/test/perl_output/merge3.xls +0 -0
  87. data/test/perl_output/merge4.xls +0 -0
  88. data/test/perl_output/merge5.xls +0 -0
  89. data/test/perl_output/protection.xls +0 -0
  90. data/test/perl_output/regions.xls +0 -0
  91. data/test/perl_output/stats.xls +0 -0
  92. data/test/perl_output/stocks.xls +0 -0
  93. data/test/perl_output/tab_colors.xls +0 -0
  94. data/test/perl_output/unicode_cyrillic.xls +0 -0
  95. data/test/perl_output/workbook1.xls +0 -0
  96. data/test/perl_output/workbook2.xls +0 -0
  97. data/test/tc_all.rb +32 -31
  98. data/test/tc_biff.rb +104 -104
  99. data/test/tc_chart.rb +22 -22
  100. data/test/tc_example_match.rb +1944 -1280
  101. data/test/tc_format.rb +1254 -1267
  102. data/test/tc_formula.rb +63 -63
  103. data/test/tc_ole.rb +110 -110
  104. data/test/tc_storage_lite.rb +149 -0
  105. data/test/tc_workbook.rb +140 -115
  106. data/test/tc_worksheet.rb +115 -115
  107. data/test/test_00_IEEE_double.rb +14 -14
  108. data/test/test_01_add_worksheet.rb +12 -12
  109. data/test/test_02_merge_formats.rb +58 -58
  110. data/test/test_04_dimensions.rb +397 -397
  111. data/test/test_05_rows.rb +182 -182
  112. data/test/test_06_extsst.rb +80 -80
  113. data/test/test_11_date_time.rb +484 -484
  114. data/test/test_12_date_only.rb +506 -506
  115. data/test/test_13_date_seconds.rb +486 -486
  116. data/test/test_21_escher.rb +642 -629
  117. data/test/test_22_mso_drawing_group.rb +750 -739
  118. data/test/test_23_note.rb +78 -78
  119. data/test/test_24_txo.rb +80 -80
  120. data/test/test_25_position_object.rb +82 -0
  121. data/test/test_26_autofilter.rb +327 -327
  122. data/test/test_27_autofilter.rb +144 -144
  123. data/test/test_28_autofilter.rb +174 -174
  124. data/test/test_29_process_jpg.rb +681 -131
  125. data/test/test_30_validation_dval.rb +82 -82
  126. data/test/test_31_validation_dv_strings.rb +131 -131
  127. data/test/test_32_validation_dv_formula.rb +211 -211
  128. data/test/test_40_property_types.rb +191 -191
  129. data/test/test_41_properties.rb +238 -238
  130. data/test/test_42_set_properties.rb +442 -419
  131. data/test/test_50_name_stored.rb +305 -0
  132. data/test/test_51_name_print_area.rb +363 -0
  133. data/test/test_52_name_print_titles.rb +460 -0
  134. data/test/test_53_autofilter.rb +209 -0
  135. data/test/test_60_chart_generic.rb +576 -0
  136. data/test/test_61_chart_subclasses.rb +97 -0
  137. data/test/test_62_chart_formats.rb +270 -0
  138. data/test/test_63_chart_area_formats.rb +647 -0
  139. data/test/test_chartex.rb +35 -0
  140. data/test/ts_all.rb +46 -34
  141. data/writeexcel.gemspec +18 -0
  142. data/writeexcel.rdoc +583 -0
  143. metadata +162 -108
@@ -0,0 +1,460 @@
1
+ ##########################################################################
2
+ # test_52_name_print_titles.rb
3
+ #
4
+ # Tests for the Excel EXTERNSHEET and NAME records created by print_are()..
5
+ #
6
+ # reverse('ゥ'), September 2008, John McNamara, jmcnamara@cpan.org
7
+ #
8
+ # original written in Perl by John McNamara
9
+ # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
10
+ #
11
+ #########################################################################
12
+ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
13
+ require 'test/unit'
14
+ require 'rubygems'
15
+ require 'writeexcel'
16
+ require 'stringio'
17
+
18
+ class TC_Name_Print_Titles < Test::Unit::TestCase
19
+ def setup
20
+ @test_file = StringIO.new
21
+ @workbook = WriteExcel.new(@test_file)
22
+ @workbook.not_using_tmpfile
23
+ end
24
+
25
+ def test_repeat_rows_for_top_row_only
26
+ worksheet1 = @workbook.add_worksheet
27
+
28
+ worksheet1.repeat_rows(0)
29
+
30
+ # Test the EXTERNSHEET record.
31
+ @workbook.calculate_extern_sizes
32
+ @workbook.store_externsheet
33
+
34
+ target = [%w(
35
+ 17 00 08 00 01 00 00 00 00 00 00 00
36
+ ).join('')].pack('H*')
37
+
38
+ caption = " \tExternsheet"
39
+ result = _unpack_externsheet(@workbook.data)
40
+ target = _unpack_externsheet(target)
41
+ assert_equal(target, result)
42
+
43
+ # Test the NAME record.
44
+ @workbook.clear_data_for_test
45
+ @workbook.store_names
46
+
47
+ target = [%w(
48
+ 18 00 1B 00 20 00 00 01 0B 00 00 00 01 00 00 00
49
+ 00 00 00 07 3B 00 00 00 00 00 00 00 00 FF 00
50
+ ).join('')].pack('H*')
51
+
52
+ caption = " \t+ Name repeats ( Sheet1!1:1 )";
53
+ result = _unpack_name(@workbook.data)
54
+ target = _unpack_name(target)
55
+ assert_equal(target, result)
56
+ end
57
+
58
+ def test_repeat_rows_for_top_10_rows
59
+ worksheet1 = @workbook.add_worksheet
60
+
61
+ worksheet1.repeat_rows(0, 9)
62
+
63
+ # Test the EXTERNSHEET record.
64
+ @workbook.calculate_extern_sizes
65
+ @workbook.store_externsheet
66
+
67
+ target = [%w(
68
+ 17 00 08 00 01 00 00 00 00 00 00 00
69
+ ).join('')].pack('H*')
70
+
71
+ caption = " \tExternsheet"
72
+ result = _unpack_externsheet(@workbook.data)
73
+ target = _unpack_externsheet(target)
74
+ assert_equal(target, result)
75
+
76
+ # Test the NAME record.
77
+ @workbook.clear_data_for_test
78
+ @workbook.store_names
79
+
80
+ target = [%w(
81
+ 18 00 1B 00 20 00 00 01 0B 00 00 00 01 00 00 00
82
+ 00 00 00 07 3B 00 00 00 00 09 00 00 00 FF 00
83
+ ).join('')].pack('H*')
84
+
85
+ caption = " \t+ Name repeats ( Sheet1!1:10 )";
86
+ result = _unpack_name(@workbook.data)
87
+ target = _unpack_name(target)
88
+ assert_equal(target, result)
89
+ end
90
+
91
+ def test_repeat_columns_for_a_single_column
92
+ worksheet1 = @workbook.add_worksheet
93
+
94
+ worksheet1.repeat_columns(0)
95
+
96
+ # Test the EXTERNSHEET record.
97
+ @workbook.calculate_extern_sizes
98
+ @workbook.store_externsheet
99
+
100
+ target = [%w(
101
+ 17 00 08 00 01 00 00 00 00 00 00 00
102
+ ).join('')].pack('H*')
103
+
104
+ caption = " \tExternsheet"
105
+ result = _unpack_externsheet(@workbook.data)
106
+ target = _unpack_externsheet(target)
107
+ assert_equal(target, result)
108
+
109
+ # Test the NAME record.
110
+ @workbook.clear_data_for_test
111
+ @workbook.store_names
112
+
113
+ target = [%w(
114
+ 18 00 1B 00 20 00 00 01 0B 00 00 00 01 00 00 00
115
+ 00 00 00 07 3B 00 00 00 00 FF FF 00 00 00 00
116
+ ).join('')].pack('H*')
117
+
118
+ caption = " \t+ Name repeats ( Sheet1!A:A )";
119
+ result = _unpack_name(@workbook.data)
120
+ target = _unpack_name(target)
121
+ assert_equal(target, result)
122
+ end
123
+
124
+ def test_repeat_columns_for_a_single_column_A1_notation
125
+ worksheet1 = @workbook.add_worksheet
126
+
127
+ worksheet1.repeat_columns('A:A')
128
+
129
+ # Test the EXTERNSHEET record.
130
+ @workbook.calculate_extern_sizes
131
+ @workbook.store_externsheet
132
+
133
+ target = [%w(
134
+ 17 00 08 00 01 00 00 00 00 00 00 00
135
+ ).join('')].pack('H*')
136
+
137
+ caption = " \tExternsheet"
138
+ result = _unpack_externsheet(@workbook.data)
139
+ target = _unpack_externsheet(target)
140
+ assert_equal(target, result)
141
+
142
+ # Test the NAME record.
143
+ @workbook.clear_data_for_test
144
+ @workbook.store_names
145
+
146
+ target = [%w(
147
+ 18 00 1B 00 20 00 00 01 0B 00 00 00 01 00 00 00
148
+ 00 00 00 07 3B 00 00 00 00 FF FF 00 00 00 00
149
+ ).join('')].pack('H*')
150
+
151
+ caption = " \t+ Name repeats ( Sheet1!A:A )";
152
+ result = _unpack_name(@workbook.data)
153
+ target = _unpack_name(target)
154
+ assert_equal(target, result)
155
+ end
156
+
157
+ def test_repeat_columns_for_a_10_columns
158
+ worksheet1 = @workbook.add_worksheet
159
+
160
+ worksheet1.repeat_columns(0, 9)
161
+
162
+ # Test the EXTERNSHEET record.
163
+ @workbook.calculate_extern_sizes
164
+ @workbook.store_externsheet
165
+
166
+ target = [%w(
167
+ 17 00 08 00 01 00 00 00 00 00 00 00
168
+ ).join('')].pack('H*')
169
+
170
+ caption = " \tExternsheet"
171
+ result = _unpack_externsheet(@workbook.data)
172
+ target = _unpack_externsheet(target)
173
+ assert_equal(target, result)
174
+
175
+ # Test the NAME record.
176
+ @workbook.clear_data_for_test
177
+ @workbook.store_names
178
+
179
+ target = [%w(
180
+ 18 00 1B 00 20 00 00 01 0B 00 00 00 01 00 00 00
181
+ 00 00 00 07 3B 00 00 00 00 FF FF 00 00 09 00
182
+ ).join('')].pack('H*')
183
+
184
+ caption = " \t+ Name repeats ( Sheet1!A:J )";
185
+ result = _unpack_name(@workbook.data)
186
+ target = _unpack_name(target)
187
+ assert_equal(target, result)
188
+ end
189
+
190
+ def test_repeat_columns_for_a_10_columns_A1_notation
191
+ worksheet1 = @workbook.add_worksheet
192
+
193
+ worksheet1.repeat_columns('A:J')
194
+
195
+ # Test the EXTERNSHEET record.
196
+ @workbook.calculate_extern_sizes
197
+ @workbook.store_externsheet
198
+
199
+ target = [%w(
200
+ 17 00 08 00 01 00 00 00 00 00 00 00
201
+ ).join('')].pack('H*')
202
+
203
+ caption = " \tExternsheet"
204
+ result = _unpack_externsheet(@workbook.data)
205
+ target = _unpack_externsheet(target)
206
+ assert_equal(target, result)
207
+
208
+ # Test the NAME record.
209
+ @workbook.clear_data_for_test
210
+ @workbook.store_names
211
+
212
+ target = [%w(
213
+ 18 00 1B 00 20 00 00 01 0B 00 00 00 01 00 00 00
214
+ 00 00 00 07 3B 00 00 00 00 FF FF 00 00 09 00
215
+ ).join('')].pack('H*')
216
+
217
+ caption = " \t+ Name repeats ( Sheet1!A:J )";
218
+ result = _unpack_name(@workbook.data)
219
+ target = _unpack_name(target)
220
+ assert_equal(target, result)
221
+ end
222
+
223
+ def test_repeat_rows_on_multiple_sheets
224
+ worksheet1 = @workbook.add_worksheet
225
+ worksheet2 = @workbook.add_worksheet
226
+ worksheet3 = @workbook.add_worksheet
227
+
228
+ worksheet1.repeat_rows(0, 1)
229
+ worksheet2.repeat_rows(3, 4)
230
+ worksheet3.repeat_rows(6, 7)
231
+
232
+ # Test the EXTERNSHEET record.
233
+ @workbook.calculate_extern_sizes
234
+ @workbook.store_externsheet
235
+
236
+ target = [%w(
237
+ 17 00 14 00 03 00 00 00 00 00 00 00 00 00 01 00
238
+ 01 00 00 00 02 00 02 00
239
+ ).join('')].pack('H*')
240
+
241
+ caption = " \tExternsheet"
242
+ result = _unpack_externsheet(@workbook.data)
243
+ target = _unpack_externsheet(target)
244
+ assert_equal(target, result)
245
+
246
+ # Test the NAME record.
247
+ @workbook.clear_data_for_test
248
+ @workbook.store_names
249
+
250
+ target = [%w(
251
+ 18 00 1B 00 20 00 00 01 0B 00 00 00 01 00 00 00
252
+ 00 00 00 07 3B 00 00 00 00 01 00 00 00 FF 00
253
+
254
+ 18 00 1B 00 20 00 00 01 0B 00 00 00 02 00 00 00
255
+ 00 00 00 07 3B 01 00 03 00 04 00 00 00 FF 00
256
+
257
+ 18 00 1B 00 20 00 00 01 0B 00 00 00 03 00 00 00
258
+ 00 00 00 07 3B 02 00 06 00 07 00 00 00 FF 00
259
+ ).join('')].pack('H*')
260
+
261
+ caption = " \t+ Name repeats ( Sheet1!1:2, Sheet2!4:5, Sheet3!7:8 )";
262
+ result = _unpack_name(@workbook.data)
263
+ target = _unpack_name(target)
264
+ assert_equal(target, result)
265
+ end
266
+
267
+ def test_repeat_rows_on_multiple_sheets_with_sheets_spaced_out
268
+ worksheet1 = @workbook.add_worksheet
269
+ worksheet2 = @workbook.add_worksheet
270
+ worksheet3 = @workbook.add_worksheet
271
+ worksheet4 = @workbook.add_worksheet
272
+ worksheet5 = @workbook.add_worksheet
273
+
274
+ worksheet1.repeat_rows(0, 1)
275
+ worksheet3.repeat_rows(3, 4)
276
+ worksheet5.repeat_rows(6, 7)
277
+
278
+ # Test the EXTERNSHEET record.
279
+ @workbook.calculate_extern_sizes
280
+ @workbook.store_externsheet
281
+
282
+ target = [%w(
283
+ 17 00 14 00 03 00 00 00 00 00 00 00 00 00 02 00
284
+ 02 00 00 00 04 00 04 00
285
+ ).join('')].pack('H*')
286
+
287
+ caption = " \tExternsheet"
288
+ result = _unpack_externsheet(@workbook.data)
289
+ target = _unpack_externsheet(target)
290
+ assert_equal(target, result)
291
+
292
+ # Test the NAME record.
293
+ @workbook.clear_data_for_test
294
+ @workbook.store_names
295
+
296
+ target = [%w(
297
+ 18 00 1B 00 20 00 00 01 0B 00 00 00 01 00 00 00
298
+ 00 00 00 07 3B 00 00 00 00 01 00 00 00 FF 00
299
+
300
+ 18 00 1B 00 20 00 00 01 0B 00 00 00 03 00 00 00
301
+ 00 00 00 07 3B 01 00 03 00 04 00 00 00 FF 00
302
+
303
+ 18 00 1B 00 20 00 00 01 0B 00 00 00 05 00 00 00
304
+ 00 00 00 07 3B 02 00 06 00 07 00 00 00 FF 00
305
+ ).join('')].pack('H*')
306
+
307
+ caption = " \t+ Name repeats ( Sheet1!1:2, Sheet3!4:5, Sheet5!7:8 )";
308
+ result = _unpack_name(@workbook.data)
309
+ target = _unpack_name(target)
310
+ assert_equal(target, result)
311
+ end
312
+
313
+ def test_repeat_rows_and_repeat_columns_together
314
+ worksheet1 = @workbook.add_worksheet
315
+
316
+ worksheet1.repeat_rows(1, 2)
317
+ worksheet1.repeat_columns(3, 4)
318
+
319
+ # Test the EXTERNSHEET record.
320
+ @workbook.calculate_extern_sizes
321
+ @workbook.store_externsheet
322
+
323
+ target = [%w(
324
+ 17 00 08 00 01 00 00 00 00 00 00 00
325
+ ).join('')].pack('H*')
326
+
327
+ caption = " \tExternsheet"
328
+ result = _unpack_externsheet(@workbook.data)
329
+ target = _unpack_externsheet(target)
330
+ assert_equal(target, result)
331
+
332
+ # Test the NAME record.
333
+ @workbook.clear_data_for_test
334
+ @workbook.store_names
335
+
336
+ target = [%w(
337
+ 18 00 2A 00 20 00 00 01 1A 00 00 00 01 00 00 00
338
+ 00 00 00 07 29 17 00 3B 00 00 00 00 FF FF 03 00
339
+ 04 00 3B 00 00 01 00 02 00 00 00 FF 00 10
340
+ ).join('')].pack('H*')
341
+
342
+ caption = " \t+ Name repeats ( Sheet1!2:3, Sheet1!D:E )";
343
+ result = _unpack_name(@workbook.data)
344
+ target = _unpack_name(target)
345
+ assert_equal(target, result)
346
+ end
347
+
348
+ ###############################################################################
349
+ #
350
+ # Unpack the binary data into a format suitable for printing in tests.
351
+ #
352
+ def unpack_record(data)
353
+ data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
354
+ end
355
+
356
+ ###############################################################################
357
+ #
358
+ # _unpack_externsheet()
359
+ #
360
+ # Unpack the EXTERNSHEET recordfor easier comparison.
361
+ #
362
+ def _unpack_externsheet(data)
363
+ externsheet = Hash.new
364
+
365
+ externsheet['record'] = data[0, 2].unpack('v')[0]
366
+ data[0, 2] = ''
367
+ externsheet['length'] = data[0, 2].unpack('v')[0]
368
+ data[0, 2] = ''
369
+ externsheet['count'] = data[0, 2].unpack('v')[0]
370
+ data[0, 2] = ''
371
+ externsheet['array'] = [];
372
+
373
+ externsheet['count'].times do
374
+ externsheet['array'] << data[0, 6].unpack('vvv')
375
+ data[0, 6] = ''
376
+ end
377
+ externsheet
378
+ end
379
+
380
+ ###############################################################################
381
+ #
382
+ # _unpack_name()
383
+ #
384
+ # Unpack 1 or more NAME structures into a AoH for easier comparison.
385
+ #
386
+ def _unpack_name(data)
387
+ names = Array.new
388
+ while data.length > 0
389
+ name = Hash.new
390
+
391
+ name['record'] = data[0, 2].unpack('v')[0]
392
+ data[0, 2] = ''
393
+ name['length'] = data[0, 2].unpack('v')[0]
394
+ data[0, 2] = ''
395
+ name['flags'] = data[0, 2].unpack('v')[0]
396
+ data[0, 2] = ''
397
+ name['shortcut'] = data[0, 1].unpack('C')[0]
398
+ data[0, 1] = ''
399
+ name['str_len'] = data[0, 1].unpack('C')[0]
400
+ data[0, 1] = ''
401
+ name['formula_len'] = data[0, 2].unpack('v')[0]
402
+ data[0, 2] = ''
403
+ name['itals'] = data[0, 2].unpack('v')[0]
404
+ data[0, 2] = ''
405
+ name['sheet_index'] = data[0, 2].unpack('v')[0]
406
+ data[0, 2] = ''
407
+ name['menu_len'] = data[0, 1].unpack('C')[0]
408
+ data[0, 1] = ''
409
+ name['desc_len'] = data[0, 1].unpack('C')[0]
410
+ data[0, 1] = ''
411
+ name['help_len'] = data[0, 1].unpack('C')[0]
412
+ data[0, 1] = ''
413
+ name['status_len'] = data[0, 1].unpack('C')[0]
414
+ data[0, 1] = ''
415
+ name['encoding'] = data[0, 1].unpack('C')[0]
416
+ data[0, 1] = ''
417
+
418
+ # Decode the individual flag fields.
419
+ flag = Hash.new
420
+ flag['hidden'] = name['flags'] & 0x0001
421
+ flag['function'] = name['flags'] & 0x0002
422
+ flag['vb'] = name['flags'] & 0x0004
423
+ flag['macro'] = name['flags'] & 0x0008
424
+ flag['complex'] = name['flags'] & 0x0010
425
+ flag['builtin'] = name['flags'] & 0x0020
426
+ flag['group'] = name['flags'] & 0x0FC0
427
+ flag['binary'] = name['flags'] & 0x1000
428
+ name['flags'] = flag
429
+
430
+ # Decode the string part of the NAME structure.
431
+ if name['encoding'] == 1
432
+ # UTF-16 name. Leave in hex.
433
+ name['string'] = data[0, 2 * name['str_len']].unpack('H*')[0].upcase
434
+ data[0, 2 * name['str_len']] = ''
435
+ elsif flag['builtin'] != 0
436
+ # 1 digit builtin name. Leave in hex.
437
+ name['string'] = data[0, name['str_len']].unpack('H*')[0].upcase
438
+ data[0, name['str_len']] = ''
439
+ else
440
+ # ASCII name.
441
+ name['string'] = data[0, name['str_len']].unpack('C*').pack('C*')
442
+ data[0, name['str_len']] = ''
443
+ end
444
+
445
+ # Keep the formula as a hex string.
446
+ name['formula'] = data[0, name['formula_len']].unpack('H*')[0].upcase
447
+ data[0, name['formula_len']] = ''
448
+
449
+ names << name
450
+ end
451
+ names
452
+ end
453
+
454
+ def assert_hash_equal?(result, target)
455
+ assert_equal(result.keys.sort, target.keys.sort)
456
+ result.each_key do |key|
457
+ assert_equal(result[key], target[key])
458
+ end
459
+ end
460
+ end