writeexcel 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. data/README +103 -0
  2. data/examples/a_simple.rb +42 -0
  3. data/examples/autofilters.rb +266 -0
  4. data/examples/copyformat.rb +51 -0
  5. data/examples/data_validate.rb +278 -0
  6. data/examples/date_time.rb +86 -0
  7. data/examples/demo.rb +118 -0
  8. data/examples/diag_border.rb +35 -0
  9. data/examples/formats.rb +489 -0
  10. data/examples/header.rb +136 -0
  11. data/examples/hidden.rb +28 -0
  12. data/examples/hyperlink.rb +42 -0
  13. data/examples/images.rb +52 -0
  14. data/examples/merge1.rb +39 -0
  15. data/examples/merge2.rb +44 -0
  16. data/examples/merge3.rb +65 -0
  17. data/examples/merge4.rb +82 -0
  18. data/examples/merge5.rb +79 -0
  19. data/examples/protection.rb +46 -0
  20. data/examples/regions.rb +52 -0
  21. data/examples/repeat.rb +42 -0
  22. data/examples/republic.png +0 -0
  23. data/examples/stats.rb +75 -0
  24. data/examples/stocks.rb +80 -0
  25. data/examples/tab_colors.rb +30 -0
  26. data/lib/writeexcel/biffwriter.rb +260 -0
  27. data/lib/writeexcel/chart.rb +217 -0
  28. data/lib/writeexcel/excelformulaparser.rb +573 -0
  29. data/lib/writeexcel/format.rb +1108 -0
  30. data/lib/writeexcel/formula.rb +986 -0
  31. data/lib/writeexcel/olewriter.rb +322 -0
  32. data/lib/writeexcel/properties.rb +250 -0
  33. data/lib/writeexcel/workbook.rb +2630 -0
  34. data/lib/writeexcel/worksheet.rb +6377 -0
  35. data/lib/writeexcel.rb +18 -0
  36. data/test/perl_output/README +31 -0
  37. data/test/perl_output/a_simple.xls +0 -0
  38. data/test/perl_output/biff_add_continue_testdata +0 -0
  39. data/test/perl_output/data_validate.xls +0 -0
  40. data/test/perl_output/date_time.xls +0 -0
  41. data/test/perl_output/demo.xls +0 -0
  42. data/test/perl_output/diag_border.xls +0 -0
  43. data/test/perl_output/f_font_biff +0 -0
  44. data/test/perl_output/f_font_key +1 -0
  45. data/test/perl_output/f_xf_biff +0 -0
  46. data/test/perl_output/file_font_biff +0 -0
  47. data/test/perl_output/file_font_key +1 -0
  48. data/test/perl_output/file_xf_biff +0 -0
  49. data/test/perl_output/headers.xls +0 -0
  50. data/test/perl_output/hidden.xls +0 -0
  51. data/test/perl_output/hyperlink.xls +0 -0
  52. data/test/perl_output/images.xls +0 -0
  53. data/test/perl_output/merge1.xls +0 -0
  54. data/test/perl_output/merge2.xls +0 -0
  55. data/test/perl_output/merge3.xls +0 -0
  56. data/test/perl_output/merge4.xls +0 -0
  57. data/test/perl_output/merge5.xls +0 -0
  58. data/test/perl_output/ole_write_header +0 -0
  59. data/test/perl_output/protection.xls +0 -0
  60. data/test/perl_output/regions.xls +0 -0
  61. data/test/perl_output/stats.xls +0 -0
  62. data/test/perl_output/stocks.xls +0 -0
  63. data/test/perl_output/tab_colors.xls +0 -0
  64. data/test/perl_output/unicode_cyrillic.xls +0 -0
  65. data/test/perl_output/workbook1.xls +0 -0
  66. data/test/perl_output/workbook2.xls +0 -0
  67. data/test/perl_output/ws_colinfo +1 -0
  68. data/test/perl_output/ws_store_colinfo +0 -0
  69. data/test/perl_output/ws_store_dimensions +0 -0
  70. data/test/perl_output/ws_store_filtermode +0 -0
  71. data/test/perl_output/ws_store_filtermode_off +0 -0
  72. data/test/perl_output/ws_store_filtermode_on +0 -0
  73. data/test/perl_output/ws_store_selection +0 -0
  74. data/test/perl_output/ws_store_window2 +1 -0
  75. data/test/republic.png +0 -0
  76. data/test/tc_all.rb +31 -0
  77. data/test/tc_biff.rb +104 -0
  78. data/test/tc_chart.rb +22 -0
  79. data/test/tc_example_match.rb +1280 -0
  80. data/test/tc_format.rb +1267 -0
  81. data/test/tc_formula.rb +63 -0
  82. data/test/tc_ole.rb +110 -0
  83. data/test/tc_workbook.rb +115 -0
  84. data/test/tc_worksheet.rb +115 -0
  85. data/test/test_00_IEEE_double.rb +14 -0
  86. data/test/test_01_add_worksheet.rb +12 -0
  87. data/test/test_02_merge_formats.rb +58 -0
  88. data/test/test_04_dimensions.rb +397 -0
  89. data/test/test_05_rows.rb +182 -0
  90. data/test/test_06_extsst.rb +80 -0
  91. data/test/test_11_date_time.rb +484 -0
  92. data/test/test_12_date_only.rb +506 -0
  93. data/test/test_13_date_seconds.rb +486 -0
  94. data/test/test_21_escher.rb +629 -0
  95. data/test/test_22_mso_drawing_group.rb +739 -0
  96. data/test/test_23_note.rb +78 -0
  97. data/test/test_24_txo.rb +80 -0
  98. data/test/test_26_autofilter.rb +327 -0
  99. data/test/test_27_autofilter.rb +144 -0
  100. data/test/test_28_autofilter.rb +174 -0
  101. data/test/test_29_process_jpg.rb +131 -0
  102. data/test/test_30_validation_dval.rb +82 -0
  103. data/test/test_31_validation_dv_strings.rb +131 -0
  104. data/test/test_32_validation_dv_formula.rb +211 -0
  105. data/test/test_40_property_types.rb +191 -0
  106. data/test/test_41_properties.rb +238 -0
  107. data/test/test_42_set_properties.rb +419 -0
  108. data/test/ts_all.rb +34 -0
  109. metadata +170 -0
@@ -0,0 +1,174 @@
1
+ ##########################################################################
2
+ # test_28_autofilter.rb
3
+ #
4
+ # Tests for the token parsing methods used to parse autofilter expressions.
5
+ #
6
+ # reverse('©'), September 2005, 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
+
14
+ require "test/unit"
15
+ require 'writeexcel'
16
+
17
+ class TC_28_autofilter < Test::Unit::TestCase
18
+
19
+ def test_28_autofilter
20
+ @tests.each do |test|
21
+ expression = test[0]
22
+ expected = test[1]
23
+ tokens = @worksheet.extract_filter_tokens(expression)
24
+ result = @worksheet.parse_filter_expression(expression, tokens)
25
+
26
+ testname = expression || 'none'
27
+
28
+ assert_equal(expected, result, testname)
29
+ end
30
+ end
31
+
32
+ ###############################################################################
33
+ #
34
+ # Unpack the binary data into a format suitable for printing in tests.
35
+ #
36
+ def unpack_record(data)
37
+ data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
38
+ end
39
+
40
+ def setup
41
+ t = Time.now.strftime("%Y%m%d")
42
+ path = "temp#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
43
+ @test_file = File.join(Dir.tmpdir, path)
44
+ @workbook = Spreadsheet::WriteExcel.new(@test_file)
45
+ @worksheet = @workbook.add_worksheet
46
+ @tests = [
47
+ [
48
+ 'x = 2000',
49
+ [2, 2000],
50
+ ],
51
+
52
+ [
53
+ 'x == 2000',
54
+ [2, 2000],
55
+ ],
56
+
57
+ [
58
+ 'x =~ 2000',
59
+ [2, 2000],
60
+ ],
61
+
62
+ [
63
+ 'x eq 2000',
64
+ [2, 2000],
65
+ ],
66
+
67
+ [
68
+ 'x <> 2000',
69
+ [5, 2000],
70
+ ],
71
+
72
+ [
73
+ 'x != 2000',
74
+ [5, 2000],
75
+ ],
76
+
77
+ [
78
+ 'x ne 2000',
79
+ [5, 2000],
80
+ ],
81
+
82
+ [
83
+ 'x !~ 2000',
84
+ [5, 2000],
85
+ ],
86
+
87
+ [
88
+ 'x > 2000',
89
+ [4, 2000],
90
+ ],
91
+
92
+ [
93
+ 'x < 2000',
94
+ [1, 2000],
95
+ ],
96
+
97
+ [
98
+ 'x >= 2000',
99
+ [6, 2000],
100
+ ],
101
+
102
+ [
103
+ 'x <= 2000',
104
+ [3, 2000],
105
+ ],
106
+
107
+ [
108
+ 'x > 2000 and x < 5000',
109
+ [4, 2000, 0, 1, 5000],
110
+ ],
111
+
112
+ [
113
+ 'x > 2000 && x < 5000',
114
+ [4, 2000, 0, 1, 5000],
115
+ ],
116
+
117
+ [
118
+ 'x > 2000 or x < 5000',
119
+ [4, 2000, 1, 1, 5000],
120
+ ],
121
+
122
+ [
123
+ 'x > 2000 || x < 5000',
124
+ [4, 2000, 1, 1, 5000],
125
+ ],
126
+
127
+ [
128
+ 'x = Blanks',
129
+ [2, 'blanks'],
130
+ ],
131
+
132
+ [
133
+ 'x = NonBlanks',
134
+ [2, 'nonblanks'],
135
+ ],
136
+
137
+ [
138
+ 'x <> Blanks',
139
+ [2, 'nonblanks'],
140
+ ],
141
+
142
+ [
143
+ 'x <> NonBlanks',
144
+ [2, 'blanks'],
145
+ ],
146
+
147
+ [
148
+ 'Top 10 Items',
149
+ [30, 10],
150
+ ],
151
+
152
+ [
153
+ 'Top 20 %',
154
+ [31, 20],
155
+ ],
156
+
157
+ [
158
+ 'Bottom 5 Items',
159
+ [32, 5],
160
+ ],
161
+
162
+ [
163
+ 'Bottom 101 %',
164
+ [33, 101],
165
+ ],
166
+ ]
167
+ end
168
+
169
+ def teardown
170
+ @workbook.close
171
+ File.unlink(@test_file) if FileTest.exist?(@test_file)
172
+ end
173
+
174
+ end
@@ -0,0 +1,131 @@
1
+ ##########################################################################
2
+ # test_29_process_jpg.rb
3
+ #
4
+ # Tests for the JPEG width and height processing.
5
+ #
6
+ # reverse('©'), September 2005, 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
+
14
+ require "test/unit"
15
+ require 'writeexcel'
16
+
17
+ class TC_29_process_jpg < Test::Unit::TestCase
18
+
19
+ def setup
20
+ t = Time.now.strftime("%Y%m%d")
21
+ path = "temp#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
22
+ @test_file = File.join(Dir.tmpdir, path)
23
+ @workbook = Spreadsheet::WriteExcel.new(@test_file)
24
+ @type = 5 # Excel Blip type (MSOBLIPTYPE).
25
+ end
26
+
27
+ def teardown
28
+ @workbook.close
29
+ File.unlink(@test_file) if FileTest.exist?(@test_file)
30
+ end
31
+
32
+ def test_valid_jpg_image_1
33
+ testname = '3w x 5h jpeg image.'
34
+
35
+ data = %w(
36
+ FF D8 FF E0 00 10 4A 46 49 46 00 01 01 01 00 60
37
+ 00 60 00 00 FF DB 00 43 00 06 04 05 06 05 04 06
38
+ 06 05 06 07 07 06 08 0A 10 0A 0A 09 09 0A 14 0E
39
+ 0F 0C 10 17 14 18 18 17 14 16 16 1A 1D 25 1F 1A
40
+ 1B 23 1C 16 16 20 2C 20 23 26 27 29 2A 29 19 1F
41
+ 2D 30 2D 28 30 25 28 29 28 FF DB 00 43 01 07 07
42
+ 07 0A 08 0A 13 0A 0A 13 28 1A 16 1A 28 28 28 28
43
+ 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28
44
+ 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28
45
+ 28 28 28 28 28 28 28 28 28 28 28 28 28 28 FF C0
46
+ 00 11 08 00 05 00 03 03 01 22 00 02 11 01 03 11
47
+ 01 FF C4 00 15 00 01 01 00 00 00 00 00 00 00 00
48
+ 00 00 00 00 00 00 00 07 FF C4 00 14 10 01 00 00
49
+ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF C4
50
+ 00 15 01 01 01 00 00 00 00 00 00 00 00 00 00 00
51
+ 00 00 00 06 08 FF C4 00 14 11 01 00 00 00 00 00
52
+ 00 00 00 00 00 00 00 00 00 00 00 FF DA 00 0C 03
53
+ 01 00 02 11 03 11 00 3F 00 9D 00 1C A4 5F FF D9
54
+ )
55
+ image = [data.join('')].pack('H*')
56
+
57
+ expected = [@type, 3, 5]
58
+ result = @workbook.process_jpg(image, 'test.jpg')
59
+ assert_equal(expected, result, " \t" + testname)
60
+ end
61
+
62
+ def test_valid_jpg_image_2
63
+ testname = '5w x 3h jpeg image.'
64
+
65
+ data = %w(
66
+ FF D8 FF E0 00 10 4A 46 49 46 00 01 01 01 00 60
67
+ 00 60 00 00 FF DB 00 43 00 06 04 05 06 05 04 06
68
+ 06 05 06 07 07 06 08 0A 10 0A 0A 09 09 0A 14 0E
69
+ 0F 0C 10 17 14 18 18 17 14 16 16 1A 1D 25 1F 1A
70
+ 1B 23 1C 16 16 20 2C 20 23 26 27 29 2A 29 19 1F
71
+ 2D 30 2D 28 30 25 28 29 28 FF DB 00 43 01 07 07
72
+ 07 0A 08 0A 13 0A 0A 13 28 1A 16 1A 28 28 28 28
73
+ 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28
74
+ 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28
75
+ 28 28 28 28 28 28 28 28 28 28 28 28 28 28 FF C0
76
+ 00 11 08 00 03 00 05 03 01 22 00 02 11 01 03 11
77
+ 01 FF C4 00 15 00 01 01 00 00 00 00 00 00 00 00
78
+ 00 00 00 00 00 00 00 07 FF C4 00 14 10 01 00 00
79
+ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF C4
80
+ 00 15 01 01 01 00 00 00 00 00 00 00 00 00 00 00
81
+ 00 00 00 06 08 FF C4 00 14 11 01 00 00 00 00 00
82
+ 00 00 00 00 00 00 00 00 00 00 00 FF DA 00 0C 03
83
+ 01 00 02 11 03 11 00 3F 00 9D 00 1C A4 5F FF D9
84
+ )
85
+ image = [data.join('')].pack('H*')
86
+
87
+ expected = [@type, 5, 3]
88
+ result = @workbook.process_jpg(image, 'test.jpg')
89
+ assert_equal(expected, result, " \t" + testname)
90
+ end
91
+
92
+ def test_valid_jpg_image_3_ffco_marker_missing
93
+ testname = 'FFCO marker missing in image.'
94
+
95
+ data = %w(
96
+ FF D8 FF E0 00 10 4A 46 49 46 00 01 01 01 00 60
97
+ 00 60 00 00 FF DB 00 43 00 06 04 05 06 05 04 06
98
+ 06 05 06 07 07 06 08 0A 10 0A 0A 09 09 0A 14 0E
99
+ 0F 0C 10 17 14 18 18 17 14 16 16 1A 1D 25 1F 1A
100
+ 1B 23 1C 16 16 20 2C 20 23 26 27 29 2A 29 19 1F
101
+ 2D 30 2D 28 30 25 28 29 28 FF DB 00 43 01 07 07
102
+ 07 0A 08 0A 13 0A 0A 13 28 1A 16 1A 28 28 28 28
103
+ 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28
104
+ 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28
105
+ 28 28 28 28 28 28 28 28 28 28 28 28 28 28 FF C1
106
+ 00 11 08 00 03 00 05 03 01 22 00 02 11 01 03 11
107
+ 01 FF C4 00 15 00 01 01 00 00 00 00 00 00 00 00
108
+ 00 00 00 00 00 00 00 07 FF C4 00 14 10 01 00 00
109
+ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF C4
110
+ 00 15 01 01 01 00 00 00 00 00 00 00 00 00 00 00
111
+ 00 00 00 06 08 FF C4 00 14 11 01 00 00 00 00 00
112
+ 00 00 00 00 00 00 00 00 00 00 00 FF DA 00 0C 03
113
+ 01 00 02 11 03 11 00 3F 00 9D 00 1C A4 5F FF D9
114
+ )
115
+ image = [data.join('')].pack('H*')
116
+
117
+ assert_raise(RuntimeError, " \t" + testname) {
118
+ @workbook.process_jpg(image, 'test.jpg')
119
+ }
120
+ end
121
+
122
+ def test_invalid_jpeg_image
123
+ testname = 'empty image'
124
+ image = ''
125
+
126
+ assert_raise(RuntimeError, " \t" + testname) {
127
+ @workbook.process_jpg(image, 'test.jpg')
128
+ }
129
+ end
130
+
131
+ end
@@ -0,0 +1,82 @@
1
+ ##########################################################################
2
+ # test_30_validation_dval.rb
3
+ #
4
+ # Tests for the Excel DVAL structure used in data validation.
5
+ #
6
+ # reverse('©'), September 2005, 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
+
14
+ require "test/unit"
15
+ require 'writeexcel'
16
+
17
+ class TC_validation_dval < Test::Unit::TestCase
18
+
19
+ def setup
20
+ t = Time.now.strftime("%Y%m%d")
21
+ path = "temp#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
22
+ @test_file = File.join(Dir.tmpdir, path)
23
+ @workbook = Spreadsheet::WriteExcel.new(@test_file)
24
+ @worksheet = @workbook.add_worksheet
25
+ end
26
+
27
+ def teardown
28
+ @workbook.close
29
+ File.unlink(@test_file) if FileTest.exist?(@test_file)
30
+ end
31
+
32
+ def test_1
33
+ obj_id = 1
34
+ dv_count = 1
35
+
36
+ caption = " \tData validation: _store_dval(#{obj_id}, #{dv_count})"
37
+ target = %w(
38
+ B2 01 12 00 04 00 00 00 00 00 00 00 00 00 01 00
39
+ 00 00 01 00 00 00
40
+ ).join(' ')
41
+
42
+ result = unpack_record(@worksheet.store_dval(obj_id, dv_count))
43
+ assert_equal(target, result, caption)
44
+ end
45
+
46
+ def test_2
47
+ obj_id = -1
48
+ dv_count = 1
49
+
50
+ caption = " \tData validation: _store_dval(#{obj_id}, #{dv_count})"
51
+ target = %w(
52
+ B2 01 12 00 04 00 00 00 00 00 00 00 00 00 FF FF
53
+ FF FF 01 00 00 00
54
+ ).join(' ')
55
+
56
+ result = unpack_record(@worksheet.store_dval(obj_id, dv_count))
57
+ assert_equal(target, result, caption)
58
+ end
59
+
60
+ def test_3
61
+ obj_id = 1
62
+ dv_count = 2
63
+
64
+ caption = " \tData validation: _store_dval(#{obj_id}, #{dv_count})"
65
+ target = %w(
66
+ B2 01 12 00 04 00 00 00 00 00 00 00 00 00 01 00
67
+ 00 00 02 00 00 00
68
+ ).join(' ')
69
+
70
+ result = unpack_record(@worksheet.store_dval(obj_id, dv_count))
71
+ assert_equal(target, result, caption)
72
+ end
73
+
74
+ ###############################################################################
75
+ #
76
+ # Unpack the binary data into a format suitable for printing in tests.
77
+ #
78
+ def unpack_record(data)
79
+ data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
80
+ end
81
+
82
+ end
@@ -0,0 +1,131 @@
1
+ ##########################################################################
2
+ # test_31_validation_dv_strings.rb
3
+ #
4
+ # Tests for the packed caption/message strings used in the Excel DV structure
5
+ # as part of data validation.
6
+ #
7
+ # reverse('©'), September 2005, John McNamara, jmcnamara@cpan.org
8
+ #
9
+ # original written in Perl by John McNamara
10
+ # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
11
+ #
12
+ #########################################################################
13
+ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
14
+
15
+ require "test/unit"
16
+ require 'writeexcel'
17
+
18
+ class TC_validation_dv_strings < Test::Unit::TestCase
19
+
20
+ def setup
21
+ t = Time.now.strftime("%Y%m%d")
22
+ path = "temp#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
23
+ @test_file = File.join(Dir.tmpdir, path)
24
+ @workbook = Spreadsheet::WriteExcel.new(@test_file)
25
+ @worksheet = @workbook.add_worksheet
26
+ end
27
+
28
+ def teardown
29
+ @workbook.close
30
+ File.unlink(@test_file) if FileTest.exist?(@test_file)
31
+ end
32
+
33
+ def test_empty_string
34
+ string = ''
35
+ max_length = 32
36
+
37
+ caption = " \tData validation: _pack_dv_string('', #{max_length})"
38
+ target = %w(
39
+ 01 00 00 00
40
+ ).join(' ')
41
+ result = unpack_record(@worksheet.pack_dv_string(string, max_length))
42
+ assert_equal(target, result, caption)
43
+ end
44
+
45
+ def test_nil
46
+ string = nil
47
+ max_length = 32
48
+
49
+ caption = " \tData validation: _pack_dv_string('', #{max_length})"
50
+ target = %w(
51
+ 01 00 00 00
52
+ ).join(' ')
53
+ result = unpack_record(@worksheet.pack_dv_string(string, max_length))
54
+ assert_equal(target, result, caption)
55
+ end
56
+
57
+ def test_single_space
58
+ string = ' '
59
+ max_length = 32
60
+
61
+ caption = " \tData validation: _pack_dv_string('', #{max_length})"
62
+ target = %w(
63
+ 01 00 00 20
64
+ ).join(' ')
65
+ result = unpack_record(@worksheet.pack_dv_string(string, max_length))
66
+ assert_equal(target, result, caption)
67
+ end
68
+
69
+ def test_single_character
70
+ string = 'A'
71
+ max_length = 32
72
+
73
+ caption = " \tData validation: _pack_dv_string('', #{max_length})"
74
+ target = %w(
75
+ 01 00 00 41
76
+ ).join(' ')
77
+ result = unpack_record(@worksheet.pack_dv_string(string, max_length))
78
+ assert_equal(target, result, caption)
79
+ end
80
+
81
+ def test_string_longer_than_32_characters_for_dialog_captions
82
+ string = 'This string is longer than 32 characters'
83
+ max_length = 32
84
+
85
+ caption = " \tData validation: _pack_dv_string('', #{max_length})"
86
+ target = %w(
87
+ 20 00 00 54 68 69 73 20
88
+ 73 74 72 69 6E 67 20 69 73 20 6C 6F 6E 67 65 72
89
+ 20 74 68 61 6E 20 33 32 20 63 68
90
+ ).join(' ')
91
+ result = unpack_record(@worksheet.pack_dv_string(string, max_length))
92
+ assert_equal(target, result, caption)
93
+ end
94
+
95
+ def test_string_longer_than_32_characters_for_dialog_messages
96
+ string = 'ABCD' * 64
97
+ max_length = 255
98
+
99
+ caption = " \tData validation: _pack_dv_string('', #{max_length})"
100
+ target = %w(
101
+ FF 00 00 41 42 43 44 41 42 43 44 41 42 43 44 41
102
+ 42 43 44 41 42 43 44 41 42 43 44 41 42 43 44 41
103
+ 42 43 44 41 42 43 44 41 42 43 44 41 42 43 44 41
104
+ 42 43 44 41 42 43 44 41 42 43 44 41 42 43 44 41
105
+ 42 43 44 41 42 43 44 41 42 43 44 41 42 43 44 41
106
+ 42 43 44 41 42 43 44 41 42 43 44 41 42 43 44 41
107
+ 42 43 44 41 42 43 44 41 42 43 44 41 42 43 44 41
108
+ 42 43 44 41 42 43 44 41 42 43 44 41 42 43 44 41
109
+ 42 43 44 41 42 43 44 41 42 43 44 41 42 43 44 41
110
+ 42 43 44 41 42 43 44 41 42 43 44 41 42 43 44 41
111
+ 42 43 44 41 42 43 44 41 42 43 44 41 42 43 44 41
112
+ 42 43 44 41 42 43 44 41 42 43 44 41 42 43 44 41
113
+ 42 43 44 41 42 43 44 41 42 43 44 41 42 43 44 41
114
+ 42 43 44 41 42 43 44 41 42 43 44 41 42 43 44 41
115
+ 42 43 44 41 42 43 44 41 42 43 44 41 42 43 44 41
116
+ 42 43 44 41 42 43 44 41 42 43 44 41 42 43 44 41
117
+ 42 43
118
+ ).join(' ')
119
+ result = unpack_record(@worksheet.pack_dv_string(string, max_length))
120
+ assert_equal(target, result, caption)
121
+ end
122
+
123
+ ###############################################################################
124
+ #
125
+ # Unpack the binary data into a format suitable for printing in tests.
126
+ #
127
+ def unpack_record(data)
128
+ data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
129
+ end
130
+
131
+ end