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,211 @@
1
+ ##########################################################################
2
+ # test_32_validation_dv_formula.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_dv_formula < 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
+ @worksheet2 = @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_integer_values
34
+ formula = '10'
35
+
36
+ caption = " \tData validation: _pack_dv_formula('#{formula}')"
37
+ bytes = %w(
38
+ 03 00 00 E0 1E 0A 00
39
+ )
40
+
41
+ # Zero out Excel's random unused word to allow comparison.
42
+ bytes[2] = '00'
43
+ bytes[3] = '00'
44
+ target = bytes.join(" ")
45
+
46
+ result = unpack_record(@worksheet.pack_dv_formula(formula))
47
+ assert_equal(target, result, caption)
48
+ end
49
+
50
+ def test_decimal_values
51
+ formula = '1.2345'
52
+
53
+ caption = " \tData validation: _pack_dv_formula('#{formula}')"
54
+ bytes = %w(
55
+ 09 00 E0 3F 1F 8D 97 6E 12 83 C0 F3 3F
56
+ )
57
+
58
+ # Zero out Excel's random unused word to allow comparison.
59
+ bytes[2] = '00'
60
+ bytes[3] = '00'
61
+ target = bytes.join(" ")
62
+
63
+ result = unpack_record(@worksheet.pack_dv_formula(formula))
64
+ assert_equal(target, result, caption)
65
+ end
66
+
67
+ def test_date_values
68
+ formula = @worksheet.convert_date_time('2008-07-24T')
69
+
70
+ caption = " \tData validation: _pack_dv_formula('2008-07-24T')"
71
+ bytes = %w(
72
+ 03 00 E0 3F 1E E5 9A
73
+ )
74
+
75
+ # Zero out Excel's random unused word to allow comparison.
76
+ bytes[2] = '00'
77
+ bytes[3] = '00'
78
+ target = bytes.join(" ")
79
+
80
+ result = unpack_record(@worksheet.pack_dv_formula(formula))
81
+ assert_equal(target, result, caption)
82
+ end
83
+
84
+ def test_time_values
85
+ formula = @worksheet.convert_date_time('T12:00')
86
+
87
+ caption = " \tData validation: _pack_dv_formula('T12:00')"
88
+ bytes = %w(
89
+ 09 00 E0 3F 1F 00 00 00 00 00 00 E0 3F
90
+ )
91
+
92
+ # Zero out Excel's random unused word to allow comparison.
93
+ bytes[2] = '00'
94
+ bytes[3] = '00'
95
+ target = bytes.join(" ")
96
+
97
+ result = unpack_record(@worksheet.pack_dv_formula(formula))
98
+ assert_equal(target, result, caption)
99
+ end
100
+
101
+ def test_cell_reference_value_C9
102
+ formula = '=C9'
103
+
104
+ caption = " \tData validation: _pack_dv_formula('#{formula}')"
105
+ bytes = %w(
106
+ 05 00 E0 3F 44 08 00 02 C0
107
+ )
108
+
109
+ # Zero out Excel's random unused word to allow comparison.
110
+ bytes[2] = '00'
111
+ bytes[3] = '00'
112
+ target = bytes.join(" ")
113
+
114
+ result = unpack_record(@worksheet.pack_dv_formula(formula))
115
+ assert_equal(target, result, caption)
116
+ end
117
+
118
+ def test_cell_reference_value_E3_E6
119
+ formula = '=E3:E6'
120
+
121
+ caption = " \tData validation: _pack_dv_formula('#{formula}')"
122
+ bytes = %w(
123
+ 09 00 0C 00 25 02 00 05 00 04 C0 04 C0
124
+ )
125
+
126
+ # Zero out Excel's random unused word to allow comparison.
127
+ bytes[2] = '00'
128
+ bytes[3] = '00'
129
+ target = bytes.join(" ")
130
+
131
+ result = unpack_record(@worksheet.pack_dv_formula(formula))
132
+ assert_equal(target, result, caption)
133
+ end
134
+
135
+ def test_cell_reference_value_E3_E6_absolute
136
+ formula = '=$E$3:$E$6'
137
+
138
+ caption = " \tData validation: _pack_dv_formula('#{formula}')"
139
+ bytes = %w(
140
+ 09 00 0C 00 25 02 00 05 00 04 00 04 00
141
+ )
142
+
143
+ # Zero out Excel's random unused word to allow comparison.
144
+ bytes[2] = '00'
145
+ bytes[3] = '00'
146
+ target = bytes.join(" ")
147
+
148
+ result = unpack_record(@worksheet.pack_dv_formula(formula))
149
+ assert_equal(target, result, caption)
150
+ end
151
+
152
+ def test_list_values
153
+ formula = ['a', 'bb', 'ccc']
154
+
155
+ caption = " \tData validation: _pack_dv_formula(['a', 'bb', 'ccc'])"
156
+ bytes = %w(
157
+ 0B 00 0C 00 17 08 00 61 00 62 62 00 63 63 63
158
+ )
159
+
160
+ # Zero out Excel's random unused word to allow comparison.
161
+ bytes[2] = '00'
162
+ bytes[3] = '00'
163
+ target = bytes.join(" ")
164
+
165
+ result = unpack_record(@worksheet.pack_dv_formula(formula))
166
+ assert_equal(target, result, caption)
167
+ end
168
+
169
+ def test_empty_string
170
+ formula = ''
171
+
172
+ caption = " \tData validation: _pack_dv_formula('')"
173
+ bytes = %w(
174
+ 00 00 00
175
+ )
176
+
177
+ # Zero out Excel's random unused word to allow comparison.
178
+ bytes[2] = '00'
179
+ bytes[3] = '00'
180
+ target = bytes.join(" ")
181
+
182
+ result = unpack_record(@worksheet.pack_dv_formula(formula))
183
+ assert_equal(target, result, caption)
184
+ end
185
+
186
+ def test_undefined_value
187
+ formula = nil
188
+
189
+ caption = " \tData validation: _pack_dv_formula(nil)"
190
+ bytes = %w(
191
+ 00 00 00
192
+ )
193
+
194
+ # Zero out Excel's random unused word to allow comparison.
195
+ bytes[2] = '00'
196
+ bytes[3] = '00'
197
+ target = bytes.join(" ")
198
+
199
+ result = unpack_record(@worksheet.pack_dv_formula(formula))
200
+ assert_equal(target, result, caption)
201
+ end
202
+
203
+ ###############################################################################
204
+ #
205
+ # Unpack the binary data into a format suitable for printing in tests.
206
+ #
207
+ def unpack_record(data)
208
+ data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
209
+ end
210
+
211
+ end
@@ -0,0 +1,191 @@
1
+ ##########################################################################
2
+ # test_40_property_types.rb
3
+ #
4
+ # Tests for the basic property types used in OLE property sets.
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 'rubygems'
16
+ require 'writeexcel'
17
+
18
+ class TC_property_types < Test::Unit::TestCase
19
+
20
+ def setup
21
+ @smiley = '☺' # chr 0x263A; in perl
22
+ end
23
+
24
+ def test_pack_a_VT_I2
25
+ caption = " \tDoc properties: pack_VT_I2(1252)"
26
+ target = %w(
27
+ 02 00 00 00 E4 04 00 00
28
+ ).join(' ')
29
+
30
+ result = unpack_record( pack_VT_I2(1252) )
31
+ assert_equal(target, result, caption)
32
+ end
33
+
34
+ def test_pack_a_VT_LPSTR_string_and_check_for_padding
35
+ string = ''
36
+ codepage = 0x04E4
37
+ caption = " \tDoc properties: _pack_VT_LPSTR('#{string}',\t#{codepage}')"
38
+ target = %w(
39
+ 1E 00 00 00 01 00 00 00 00 00 00 00
40
+ ).join(' ')
41
+
42
+ result = unpack_record( pack_VT_LPSTR(string, codepage) )
43
+ assert_equal(target, result, caption)
44
+ end
45
+
46
+ def test_pack_a_VT_LPSTR_string_and_check_for_padding_2
47
+ string = 'a'
48
+ codepage = 0x04E4
49
+ caption = " \tDoc properties: _pack_VT_LPSTR('#{string}',\t#{codepage}')"
50
+ target = %w(
51
+ 1E 00 00 00 02 00 00 00 61 00 00 00
52
+ ).join(' ')
53
+
54
+ result = unpack_record( pack_VT_LPSTR(string, codepage) )
55
+ assert_equal(target, result, caption)
56
+ end
57
+
58
+ def test_pack_a_VT_LPSTR_string_and_check_for_padding_3
59
+ string = 'bb'
60
+ codepage = 0x04E4
61
+ caption = " \tDoc properties: _pack_VT_LPSTR('#{string}',\t#{codepage}')"
62
+ target = %w(
63
+ 1E 00 00 00 03 00 00 00 62 62 00 00
64
+ ).join(' ')
65
+
66
+ result = unpack_record( pack_VT_LPSTR(string, codepage) )
67
+ assert_equal(target, result, caption)
68
+ end
69
+
70
+ def test_pack_a_VT_LPSTR_string_and_check_for_padding_4
71
+ string = 'ccc'
72
+ codepage = 0x04E4
73
+ caption = " \tDoc properties: _pack_VT_LPSTR('#{string}',\t#{codepage}')"
74
+ target = %w(
75
+ 1E 00 00 00 04 00 00 00 63 63 63 00
76
+ ).join(' ')
77
+
78
+ result = unpack_record( pack_VT_LPSTR(string, codepage) )
79
+ assert_equal(target, result, caption)
80
+ end
81
+
82
+ def test_pack_a_VT_LPSTR_string_and_check_for_padding_5
83
+ string = 'dddd'
84
+ codepage = 0x04E4
85
+ caption = " \tDoc properties: _pack_VT_LPSTR('#{string}',\t#{codepage}')"
86
+ target = %w(
87
+ 1E 00 00 00 05 00 00 00 64 64 64 64 00 00 00 00
88
+ ).join(' ')
89
+
90
+ result = unpack_record( pack_VT_LPSTR(string, codepage) )
91
+ assert_equal(target, result, caption)
92
+ end
93
+
94
+ def test_pack_a_VT_LPSTR_string_and_check_for_padding_5
95
+ string = 'Username'
96
+ codepage = 0x04E4
97
+ caption = " \tDoc properties: _pack_VT_LPSTR('#{string}',\t#{codepage}')"
98
+ target = %w(
99
+ 1E 00 00 00 09 00 00 00 55 73 65 72 6E 61 6D 65
100
+ 00 00 00 00
101
+ ).join(' ')
102
+
103
+ result = unpack_record( pack_VT_LPSTR(string, codepage) )
104
+ assert_equal(target, result, caption)
105
+ end
106
+
107
+ def test_pack_a_VT_LPSTR_UTF8_string
108
+ string = @smiley
109
+ codepage = 0xFDE9
110
+ caption = " \tDoc properties: _pack_VT_LPSTR('#{@smiley}',\t#{codepage}')"
111
+ target = %w(
112
+ 1E 00 00 00 04 00 00 00 E2 98 BA 00
113
+ ).join(' ')
114
+
115
+ result = unpack_record( pack_VT_LPSTR(string, codepage) )
116
+ assert_equal(target, result, caption)
117
+ end
118
+
119
+ def test_pack_a_VT_LPSTR_UTF8_string_2
120
+ string = "a" + @smiley
121
+ codepage = 0xFDE9
122
+ caption = " \tDoc properties: _pack_VT_LPSTR('a#{@smiley}',\t#{codepage}')"
123
+ target = %w(
124
+ 1E 00 00 00 05 00 00 00 61 E2 98 BA 00 00 00 00
125
+ ).join(' ')
126
+
127
+ result = unpack_record( pack_VT_LPSTR(string, codepage) )
128
+ assert_equal(target, result, caption)
129
+ end
130
+
131
+ def test_pack_a_VT_LPSTR_UTF8_string_3
132
+ string = "aa" + @smiley
133
+ codepage = 0xFDE9
134
+ caption = " \tDoc properties: _pack_VT_LPSTR('#{string}',\t#{codepage}')"
135
+ target = %w(
136
+ 1E 00 00 00 06 00 00 00 61 61 E2 98 BA 00 00 00
137
+ ).join(' ')
138
+
139
+ result = unpack_record( pack_VT_LPSTR(string, codepage) )
140
+ assert_equal(target, result, caption)
141
+ end
142
+
143
+ def test_pack_a_VT_LPSTR_UTF8_string_4
144
+ string = "aaa" + @smiley
145
+ codepage = 0xFDE9
146
+ caption = " \tDoc properties: _pack_VT_LPSTR('#{string}',\t#{codepage}')"
147
+ target = %w(
148
+ 1E 00 00 00 07 00 00 00 61 61 61 E2 98 BA 00 00
149
+ ).join(' ')
150
+
151
+ result = unpack_record( pack_VT_LPSTR(string, codepage) )
152
+ assert_equal(target, result, caption)
153
+ end
154
+
155
+ def test_pack_a_VT_LPSTR_UTF8_string_5
156
+ string = "aaaa" + @smiley
157
+ codepage = 0xFDE9
158
+ caption = " \tDoc properties: _pack_VT_LPSTR('#{string}',\t#{codepage}')"
159
+ target = %w(
160
+ 1E 00 00 00 08 00 00 00 61 61 61 61 E2 98 BA 00
161
+ ).join(' ')
162
+
163
+ result = unpack_record( pack_VT_LPSTR(string, codepage) )
164
+ assert_equal(target, result, caption)
165
+ end
166
+
167
+ def test_pack_a_VT_FILETIME
168
+ # Wed Aug 13 00:40:00 2008
169
+ # $sec,$min,$hour,$mday,$mon,$year
170
+ # We normalise the time using timegm() so that the tests don't fail due to
171
+ # different timezones.
172
+ filetime = Time.gm(2008,8,13,0,40,0)
173
+
174
+ caption = " \tDoc properties: _pack_VT_FILETIME()"
175
+ target = %w(
176
+ 40 00 00 00 00 70 EB 1D DD FC C8 01
177
+ ).join(' ')
178
+
179
+ result = unpack_record( pack_VT_FILETIME(filetime) )
180
+ assert_equal(target, result, caption)
181
+ end
182
+
183
+ ###############################################################################
184
+ #
185
+ # Unpack the binary data into a format suitable for printing in tests.
186
+ #
187
+ def unpack_record(data)
188
+ data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
189
+ end
190
+
191
+ end
@@ -0,0 +1,238 @@
1
+ ##########################################################################
2
+ # test_41_properties.rb
3
+ #
4
+ # Tests for OLE property sets.
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 'rubygems'
16
+ require 'writeexcel'
17
+
18
+ class TC_properties < Test::Unit::TestCase
19
+
20
+ def setup
21
+ @smiley = '☺' # chr 0x263A; in perl
22
+ end
23
+
24
+ def test_codepage_only
25
+ properties = [[0x0001, 'VT_I2', 0x04E4]]
26
+ caption = " \tDoc properties: _create_property_set('Code page')"
27
+ target = %w(
28
+ FE FF 00 00 05 01 02 00 00 00 00 00 00 00 00 00
29
+ 00 00 00 00 00 00 00 00 01 00 00 00 E0 85 9F F2
30
+ F9 4F 68 10 AB 91 08 00 2B 27 B3 D9 30 00 00 00
31
+ 18 00 00 00 01 00 00 00 01 00 00 00 10 00 00 00
32
+ 02 00 00 00 E4 04 00 00
33
+ ).join(' ')
34
+
35
+ result = unpack_record( create_summary_property_set(properties))
36
+ assert_equal(target, result, caption)
37
+ end
38
+
39
+ def test_same_as_previous_plus_title
40
+ properties = [
41
+ [0x0001, 'VT_I2', 0x04E4 ],
42
+ [0x0002, 'VT_LPSTR', 'Title'],
43
+ ]
44
+ caption = " \tDoc properties: _create_property_set('+ Title')"
45
+ target = %w(
46
+ FE FF 00 00 05 01 02 00 00 00 00 00 00 00 00 00
47
+ 00 00 00 00 00 00 00 00 01 00 00 00 E0 85 9F F2
48
+ F9 4F 68 10 AB 91 08 00 2B 27 B3 D9 30 00 00 00
49
+ 30 00 00 00 02 00 00 00 01 00 00 00 18 00 00 00
50
+ 02 00 00 00 20 00 00 00 02 00 00 00 E4 04 00 00
51
+ 1E 00 00 00 06 00 00 00 54 69 74 6C 65 00 00 00
52
+ ).join(' ')
53
+
54
+ result = unpack_record( create_summary_property_set(properties))
55
+ assert_equal(target, result, caption)
56
+ end
57
+
58
+ def test_same_as_previous_plus_subject
59
+ properties = [
60
+ [0x0001, 'VT_I2', 0x04E4 ],
61
+ [0x0002, 'VT_LPSTR', 'Title'],
62
+ [0x0003, 'VT_LPSTR', 'Subject'],
63
+ ]
64
+ caption = " \tDoc properties: _create_property_set('+ Subject')"
65
+ target = %w(
66
+ FE FF 00 00 05 01 02 00 00 00 00 00 00 00 00 00
67
+ 00 00 00 00 00 00 00 00 01 00 00 00 E0 85 9F F2
68
+ F9 4F 68 10 AB 91 08 00 2B 27 B3 D9 30 00 00 00
69
+ 48 00 00 00 03 00 00 00 01 00 00 00 20 00 00 00
70
+ 02 00 00 00 28 00 00 00 03 00 00 00 38 00 00 00
71
+ 02 00 00 00 E4 04 00 00 1E 00 00 00 06 00 00 00
72
+ 54 69 74 6C 65 00 00 00 1E 00 00 00 08 00 00 00
73
+ 53 75 62 6A 65 63 74 00
74
+ ).join(' ')
75
+
76
+ result = unpack_record( create_summary_property_set(properties))
77
+ assert_equal(target, result, caption)
78
+ end
79
+
80
+ def test_same_as_previous_plus_author
81
+ properties = [
82
+ [0x0001, 'VT_I2', 0x04E4 ],
83
+ [0x0002, 'VT_LPSTR', 'Title'],
84
+ [0x0003, 'VT_LPSTR', 'Subject'],
85
+ [0x0004, 'VT_LPSTR', 'Author' ],
86
+ ]
87
+ caption = " \tDoc properties: _create_property_set('+ Keywords')"
88
+ target = %w(
89
+ FE FF 00 00 05 01 02 00 00 00 00 00 00 00 00 00
90
+ 00 00 00 00 00 00 00 00 01 00 00 00 E0 85 9F F2
91
+ F9 4F 68 10 AB 91 08 00 2B 27 B3 D9 30 00 00 00
92
+ 60 00 00 00 04 00 00 00 01 00 00 00 28 00 00 00
93
+ 02 00 00 00 30 00 00 00 03 00 00 00 40 00 00 00
94
+ 04 00 00 00 50 00 00 00 02 00 00 00 E4 04 00 00
95
+ 1E 00 00 00 06 00 00 00 54 69 74 6C 65 00 00 00
96
+ 1E 00 00 00 08 00 00 00 53 75 62 6A 65 63 74 00
97
+ 1E 00 00 00 07 00 00 00 41 75 74 68 6F 72 00 00
98
+ ).join(' ')
99
+
100
+ result = unpack_record( create_summary_property_set(properties))
101
+ assert_equal(target, result, caption)
102
+ end
103
+
104
+ def test_same_as_previous_plus_keywords
105
+ properties = [
106
+ [0x0001, 'VT_I2', 0x04E4 ],
107
+ [0x0002, 'VT_LPSTR', 'Title'],
108
+ [0x0003, 'VT_LPSTR', 'Subject'],
109
+ [0x0004, 'VT_LPSTR', 'Author' ],
110
+ [0x0005, 'VT_LPSTR', 'Keywords'],
111
+ ]
112
+ caption = " \tDoc properties: _create_property_set('+ Keywords')"
113
+ target = %w(
114
+ FE FF 00 00 05 01 02 00 00 00 00 00 00 00 00 00
115
+ 00 00 00 00 00 00 00 00 01 00 00 00 E0 85 9F F2
116
+ F9 4F 68 10 AB 91 08 00 2B 27 B3 D9 30 00 00 00
117
+ 7C 00 00 00 05 00 00 00 01 00 00 00 30 00 00 00
118
+ 02 00 00 00 38 00 00 00 03 00 00 00 48 00 00 00
119
+ 04 00 00 00 58 00 00 00 05 00 00 00 68 00 00 00
120
+ 02 00 00 00 E4 04 00 00 1E 00 00 00 06 00 00 00
121
+ 54 69 74 6C 65 00 00 00 1E 00 00 00 08 00 00 00
122
+ 53 75 62 6A 65 63 74 00 1E 00 00 00 07 00 00 00
123
+ 41 75 74 68 6F 72 00 00 1E 00 00 00 09 00 00 00
124
+ 4B 65 79 77 6F 72 64 73 00 00 00 00
125
+ ).join(' ')
126
+
127
+ result = unpack_record( create_summary_property_set(properties))
128
+ assert_equal(target, result, caption)
129
+ end
130
+
131
+ def test_same_as_previous_plus_comments
132
+ properties = [
133
+ [0x0001, 'VT_I2', 0x04E4 ],
134
+ [0x0002, 'VT_LPSTR', 'Title'],
135
+ [0x0003, 'VT_LPSTR', 'Subject'],
136
+ [0x0004, 'VT_LPSTR', 'Author' ],
137
+ [0x0005, 'VT_LPSTR', 'Keywords'],
138
+ [0x0006, 'VT_LPSTR', 'Comments'],
139
+ ]
140
+ caption = " \tDoc properties: _create_property_set('+ Comments')"
141
+ target = %w(
142
+ FE FF 00 00 05 01 02 00 00 00 00 00 00 00 00 00
143
+ 00 00 00 00 00 00 00 00 01 00 00 00 E0 85 9F F2
144
+ F9 4F 68 10 AB 91 08 00 2B 27 B3 D9 30 00 00 00
145
+ 98 00 00 00 06 00 00 00 01 00 00 00 38 00 00 00
146
+ 02 00 00 00 40 00 00 00 03 00 00 00 50 00 00 00
147
+ 04 00 00 00 60 00 00 00 05 00 00 00 70 00 00 00
148
+ 06 00 00 00 84 00 00 00 02 00 00 00 E4 04 00 00
149
+ 1E 00 00 00 06 00 00 00 54 69 74 6C 65 00 00 00
150
+ 1E 00 00 00 08 00 00 00 53 75 62 6A 65 63 74 00
151
+ 1E 00 00 00 07 00 00 00 41 75 74 68 6F 72 00 00
152
+ 1E 00 00 00 09 00 00 00 4B 65 79 77 6F 72 64 73
153
+ 00 00 00 00 1E 00 00 00 09 00 00 00 43 6F 6D 6D
154
+ 65 6E 74 73 00 00 00 00
155
+ ).join(' ')
156
+
157
+ result = unpack_record( create_summary_property_set(properties))
158
+ assert_equal(target, result, caption)
159
+ end
160
+
161
+ def test_same_as_previous_plus_last_author
162
+ properties = [
163
+ [0x0001, 'VT_I2', 0x04E4 ],
164
+ [0x0002, 'VT_LPSTR', 'Title'],
165
+ [0x0003, 'VT_LPSTR', 'Subject'],
166
+ [0x0004, 'VT_LPSTR', 'Author' ],
167
+ [0x0005, 'VT_LPSTR', 'Keywords'],
168
+ [0x0006, 'VT_LPSTR', 'Comments'],
169
+ [0x0008, 'VT_LPSTR', 'Username'],
170
+ ]
171
+ caption = " \tDoc properties: _create_property_set('+ Comments')"
172
+ target = %w(
173
+ FE FF 00 00 05 01 02 00 00 00 00 00 00 00 00 00
174
+ 00 00 00 00 00 00 00 00 01 00 00 00 E0 85 9F F2
175
+ F9 4F 68 10 AB 91 08 00 2B 27 B3 D9 30 00 00 00
176
+ B4 00 00 00 07 00 00 00 01 00 00 00 40 00 00 00
177
+ 02 00 00 00 48 00 00 00 03 00 00 00 58 00 00 00
178
+ 04 00 00 00 68 00 00 00 05 00 00 00 78 00 00 00
179
+ 06 00 00 00 8C 00 00 00 08 00 00 00 A0 00 00 00
180
+ 02 00 00 00 E4 04 00 00 1E 00 00 00 06 00 00 00
181
+ 54 69 74 6C 65 00 00 00 1E 00 00 00 08 00 00 00
182
+ 53 75 62 6A 65 63 74 00 1E 00 00 00 07 00 00 00
183
+ 41 75 74 68 6F 72 00 00 1E 00 00 00 09 00 00 00
184
+ 4B 65 79 77 6F 72 64 73 00 00 00 00 1E 00 00 00
185
+ 09 00 00 00 43 6F 6D 6D 65 6E 74 73 00 00 00 00
186
+ 1E 00 00 00 09 00 00 00 55 73 65 72 6E 61 6D 65
187
+ 00 00 00 00
188
+ ).join(' ')
189
+
190
+ result = unpack_record( create_summary_property_set(properties))
191
+ assert_equal(target, result, caption)
192
+ end
193
+
194
+ def test_same_as_previous_plus_creation_date
195
+ filetime = Time.gm(2008,8,19,23,20,13)
196
+ properties = [
197
+ [0x0001, 'VT_I2', 0x04E4 ],
198
+ [0x0002, 'VT_LPSTR', 'Title'],
199
+ [0x0003, 'VT_LPSTR', 'Subject'],
200
+ [0x0004, 'VT_LPSTR', 'Author' ],
201
+ [0x0005, 'VT_LPSTR', 'Keywords'],
202
+ [0x0006, 'VT_LPSTR', 'Comments'],
203
+ [0x0008, 'VT_LPSTR', 'Username'],
204
+ [0x000C, 'VT_FILETIME', filetime ],
205
+ ]
206
+ caption = " \tDoc properties: _create_property_set('+ Comments')"
207
+ target = %w(
208
+ FE FF 00 00 05 01 02 00 00 00 00 00 00 00 00 00
209
+ 00 00 00 00 00 00 00 00 01 00 00 00 E0 85 9F F2
210
+ F9 4F 68 10 AB 91 08 00 2B 27 B3 D9 30 00 00 00
211
+ C8 00 00 00 08 00 00 00 01 00 00 00 48 00 00 00
212
+ 02 00 00 00 50 00 00 00 03 00 00 00 60 00 00 00
213
+ 04 00 00 00 70 00 00 00 05 00 00 00 80 00 00 00
214
+ 06 00 00 00 94 00 00 00 08 00 00 00 A8 00 00 00
215
+ 0C 00 00 00 BC 00 00 00 02 00 00 00 E4 04 00 00
216
+ 1E 00 00 00 06 00 00 00 54 69 74 6C 65 00 00 00
217
+ 1E 00 00 00 08 00 00 00 53 75 62 6A 65 63 74 00
218
+ 1E 00 00 00 07 00 00 00 41 75 74 68 6F 72 00 00
219
+ 1E 00 00 00 09 00 00 00 4B 65 79 77 6F 72 64 73
220
+ 00 00 00 00 1E 00 00 00 09 00 00 00 43 6F 6D 6D
221
+ 65 6E 74 73 00 00 00 00 1E 00 00 00 09 00 00 00
222
+ 55 73 65 72 6E 61 6D 65 00 00 00 00 40 00 00 00
223
+ 80 74 89 21 52 02 C9 01
224
+ ).join(' ')
225
+
226
+ result = unpack_record( create_summary_property_set(properties))
227
+ assert_equal(target, result, caption)
228
+ end
229
+
230
+ ###############################################################################
231
+ #
232
+ # Unpack the binary data into a format suitable for printing in tests.
233
+ #
234
+ def unpack_record(data)
235
+ data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
236
+ end
237
+
238
+ end