ricardoo27-writeexcel 0.6.12.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitattributes +1 -0
- data/README.rdoc +136 -0
- data/Rakefile +52 -0
- data/VERSION +1 -0
- data/charts/chartex.rb +316 -0
- data/charts/demo1.rb +46 -0
- data/charts/demo101.bin +0 -0
- data/charts/demo2.rb +65 -0
- data/charts/demo201.bin +0 -0
- data/charts/demo3.rb +117 -0
- data/charts/demo301.bin +0 -0
- data/charts/demo4.rb +119 -0
- data/charts/demo401.bin +0 -0
- data/charts/demo5.rb +48 -0
- data/charts/demo501.bin +0 -0
- data/examples/a_simple.rb +43 -0
- data/examples/autofilter.rb +265 -0
- data/examples/bigfile.rb +30 -0
- data/examples/chart_area.rb +121 -0
- data/examples/chart_bar.rb +120 -0
- data/examples/chart_column.rb +120 -0
- data/examples/chart_line.rb +120 -0
- data/examples/chart_pie.rb +108 -0
- data/examples/chart_scatter.rb +121 -0
- data/examples/chart_stock.rb +148 -0
- data/examples/chess.rb +142 -0
- data/examples/colors.rb +129 -0
- data/examples/comments1.rb +27 -0
- data/examples/comments2.rb +352 -0
- data/examples/copyformat.rb +52 -0
- data/examples/data_validate.rb +279 -0
- data/examples/date_time.rb +87 -0
- data/examples/defined_name.rb +32 -0
- data/examples/demo.rb +124 -0
- data/examples/diag_border.rb +36 -0
- data/examples/formats.rb +490 -0
- data/examples/formula_result.rb +30 -0
- data/examples/header.rb +137 -0
- data/examples/hide_sheet.rb +29 -0
- data/examples/hyperlink.rb +43 -0
- data/examples/images.rb +63 -0
- data/examples/indent.rb +31 -0
- data/examples/merge1.rb +40 -0
- data/examples/merge2.rb +45 -0
- data/examples/merge3.rb +66 -0
- data/examples/merge4.rb +83 -0
- data/examples/merge5.rb +80 -0
- data/examples/merge6.rb +67 -0
- data/examples/outline.rb +255 -0
- data/examples/outline_collapsed.rb +209 -0
- data/examples/panes.rb +113 -0
- data/examples/password_protection.rb +33 -0
- data/examples/properties.rb +34 -0
- data/examples/properties_jp.rb +33 -0
- data/examples/protection.rb +47 -0
- data/examples/regions.rb +53 -0
- data/examples/repeat.rb +43 -0
- data/examples/republic.png +0 -0
- data/examples/right_to_left.rb +27 -0
- data/examples/row_wrap.rb +53 -0
- data/examples/set_first_sheet.rb +14 -0
- data/examples/stats.rb +74 -0
- data/examples/stocks.rb +81 -0
- data/examples/store_formula.rb +15 -0
- data/examples/tab_colors.rb +31 -0
- data/examples/utf8.rb +15 -0
- data/examples/write_arrays.rb +83 -0
- data/html/en/doc_en.html +5946 -0
- data/html/images/a_simple.jpg +0 -0
- data/html/images/area1.jpg +0 -0
- data/html/images/bar1.jpg +0 -0
- data/html/images/chart_area.xls +0 -0
- data/html/images/column1.jpg +0 -0
- data/html/images/data_validation.jpg +0 -0
- data/html/images/line1.jpg +0 -0
- data/html/images/pie1.jpg +0 -0
- data/html/images/regions.jpg +0 -0
- data/html/images/scatter1.jpg +0 -0
- data/html/images/stats.jpg +0 -0
- data/html/images/stock1.jpg +0 -0
- data/html/images/stocks.jpg +0 -0
- data/html/index.html +16 -0
- data/html/style.css +433 -0
- data/lib/writeexcel.rb +1159 -0
- data/lib/writeexcel/biffwriter.rb +223 -0
- data/lib/writeexcel/caller_info.rb +12 -0
- data/lib/writeexcel/cell_range.rb +332 -0
- data/lib/writeexcel/chart.rb +1968 -0
- data/lib/writeexcel/charts/area.rb +154 -0
- data/lib/writeexcel/charts/bar.rb +177 -0
- data/lib/writeexcel/charts/column.rb +156 -0
- data/lib/writeexcel/charts/external.rb +66 -0
- data/lib/writeexcel/charts/line.rb +154 -0
- data/lib/writeexcel/charts/pie.rb +169 -0
- data/lib/writeexcel/charts/scatter.rb +192 -0
- data/lib/writeexcel/charts/stock.rb +213 -0
- data/lib/writeexcel/col_info.rb +87 -0
- data/lib/writeexcel/colors.rb +68 -0
- data/lib/writeexcel/comments.rb +460 -0
- data/lib/writeexcel/compatibility.rb +65 -0
- data/lib/writeexcel/convert_date_time.rb +117 -0
- data/lib/writeexcel/data_validations.rb +370 -0
- data/lib/writeexcel/debug_info.rb +41 -0
- data/lib/writeexcel/embedded_chart.rb +35 -0
- data/lib/writeexcel/excelformula.y +139 -0
- data/lib/writeexcel/excelformulaparser.rb +587 -0
- data/lib/writeexcel/format.rb +1575 -0
- data/lib/writeexcel/formula.rb +987 -0
- data/lib/writeexcel/helper.rb +78 -0
- data/lib/writeexcel/image.rb +218 -0
- data/lib/writeexcel/olewriter.rb +305 -0
- data/lib/writeexcel/outline.rb +24 -0
- data/lib/writeexcel/properties.rb +242 -0
- data/lib/writeexcel/shared_string_table.rb +153 -0
- data/lib/writeexcel/storage_lite.rb +984 -0
- data/lib/writeexcel/workbook.rb +2478 -0
- data/lib/writeexcel/worksheet.rb +6925 -0
- data/lib/writeexcel/worksheets.rb +25 -0
- data/lib/writeexcel/write_file.rb +63 -0
- data/test/excelfile/Chart1.xls +0 -0
- data/test/excelfile/Chart2.xls +0 -0
- data/test/excelfile/Chart3.xls +0 -0
- data/test/excelfile/Chart4.xls +0 -0
- data/test/excelfile/Chart5.xls +0 -0
- data/test/helper.rb +31 -0
- data/test/perl_output/Chart1.xls.data +0 -0
- data/test/perl_output/Chart2.xls.data +0 -0
- data/test/perl_output/Chart3.xls.data +0 -0
- data/test/perl_output/Chart4.xls.data +0 -0
- data/test/perl_output/Chart5.xls.data +0 -0
- data/test/perl_output/README +31 -0
- data/test/perl_output/a_simple.xls +0 -0
- data/test/perl_output/autofilter.xls +0 -0
- data/test/perl_output/biff_add_continue_testdata +0 -0
- data/test/perl_output/chart_area.xls +0 -0
- data/test/perl_output/chart_bar.xls +0 -0
- data/test/perl_output/chart_column.xls +0 -0
- data/test/perl_output/chart_line.xls +0 -0
- data/test/perl_output/chess.xls +0 -0
- data/test/perl_output/colors.xls +0 -0
- data/test/perl_output/comments0.xls +0 -0
- data/test/perl_output/comments1.xls +0 -0
- data/test/perl_output/comments2.xls +0 -0
- data/test/perl_output/data_validate.xls +0 -0
- data/test/perl_output/date_time.xls +0 -0
- data/test/perl_output/defined_name.xls +0 -0
- data/test/perl_output/demo.xls +0 -0
- data/test/perl_output/demo101.bin +0 -0
- data/test/perl_output/demo201.bin +0 -0
- data/test/perl_output/demo301.bin +0 -0
- data/test/perl_output/demo401.bin +0 -0
- data/test/perl_output/demo501.bin +0 -0
- data/test/perl_output/diag_border.xls +0 -0
- data/test/perl_output/f_font_biff +0 -0
- data/test/perl_output/f_font_key +1 -0
- data/test/perl_output/f_xf_biff +0 -0
- data/test/perl_output/file_font_biff +0 -0
- data/test/perl_output/file_font_key +1 -0
- data/test/perl_output/file_xf_biff +0 -0
- data/test/perl_output/formula_result.xls +0 -0
- data/test/perl_output/headers.xls +0 -0
- data/test/perl_output/hidden.xls +0 -0
- data/test/perl_output/hide_zero.xls +0 -0
- data/test/perl_output/hyperlink.xls +0 -0
- data/test/perl_output/images.xls +0 -0
- data/test/perl_output/indent.xls +0 -0
- data/test/perl_output/merge1.xls +0 -0
- data/test/perl_output/merge2.xls +0 -0
- data/test/perl_output/merge3.xls +0 -0
- data/test/perl_output/merge4.xls +0 -0
- data/test/perl_output/merge5.xls +0 -0
- data/test/perl_output/merge6.xls +0 -0
- data/test/perl_output/ole_write_header +0 -0
- data/test/perl_output/outline.xls +0 -0
- data/test/perl_output/outline_collapsed.xls +0 -0
- data/test/perl_output/panes.xls +0 -0
- data/test/perl_output/password_protection.xls +0 -0
- data/test/perl_output/protection.xls +0 -0
- data/test/perl_output/regions.xls +0 -0
- data/test/perl_output/right_to_left.xls +0 -0
- data/test/perl_output/set_first_sheet.xls +0 -0
- data/test/perl_output/stats.xls +0 -0
- data/test/perl_output/stocks.xls +0 -0
- data/test/perl_output/store_formula.xls +0 -0
- data/test/perl_output/tab_colors.xls +0 -0
- data/test/perl_output/unicode_cyrillic.xls +0 -0
- data/test/perl_output/utf8.xls +0 -0
- data/test/perl_output/workbook1.xls +0 -0
- data/test/perl_output/workbook2.xls +0 -0
- data/test/perl_output/ws_colinfo +1 -0
- data/test/perl_output/ws_store_colinfo +0 -0
- data/test/perl_output/ws_store_dimensions +0 -0
- data/test/perl_output/ws_store_filtermode +0 -0
- data/test/perl_output/ws_store_filtermode_off +0 -0
- data/test/perl_output/ws_store_filtermode_on +0 -0
- data/test/perl_output/ws_store_selection +0 -0
- data/test/perl_output/ws_store_window2 +1 -0
- data/test/republic.png +0 -0
- data/test/test_00_IEEE_double.rb +13 -0
- data/test/test_01_add_worksheet.rb +10 -0
- data/test/test_02_merge_formats.rb +49 -0
- data/test/test_04_dimensions.rb +388 -0
- data/test/test_05_rows.rb +175 -0
- data/test/test_06_extsst.rb +74 -0
- data/test/test_11_date_time.rb +475 -0
- data/test/test_12_date_only.rb +525 -0
- data/test/test_13_date_seconds.rb +477 -0
- data/test/test_21_escher.rb +624 -0
- data/test/test_22_mso_drawing_group.rb +741 -0
- data/test/test_23_note.rb +57 -0
- data/test/test_24_txo.rb +74 -0
- data/test/test_25_position_object.rb +80 -0
- data/test/test_26_autofilter.rb +309 -0
- data/test/test_27_autofilter.rb +126 -0
- data/test/test_28_autofilter.rb +156 -0
- data/test/test_29_process_jpg.rb +670 -0
- data/test/test_30_validation_dval.rb +74 -0
- data/test/test_31_validation_dv_strings.rb +123 -0
- data/test/test_32_validation_dv_formula.rb +203 -0
- data/test/test_40_property_types.rb +188 -0
- data/test/test_41_properties.rb +235 -0
- data/test/test_42_set_properties.rb +434 -0
- data/test/test_50_name_stored.rb +295 -0
- data/test/test_51_name_print_area.rb +353 -0
- data/test/test_52_name_print_titles.rb +450 -0
- data/test/test_53_autofilter.rb +199 -0
- data/test/test_60_chart_generic.rb +574 -0
- data/test/test_61_chart_subclasses.rb +84 -0
- data/test/test_62_chart_formats.rb +268 -0
- data/test/test_63_chart_area_formats.rb +645 -0
- data/test/test_biff.rb +71 -0
- data/test/test_big_workbook.rb +17 -0
- data/test/test_compatibility.rb +12 -0
- data/test/test_example_match.rb +3246 -0
- data/test/test_format.rb +1189 -0
- data/test/test_formula.rb +61 -0
- data/test/test_ole.rb +102 -0
- data/test/test_storage_lite.rb +116 -0
- data/test/test_workbook.rb +146 -0
- data/test/test_worksheet.rb +106 -0
- data/utils/add_magic_comment.rb +80 -0
- data/writeexcel.gemspec +278 -0
- data/writeexcel.rdoc +1425 -0
- metadata +292 -0
@@ -0,0 +1,74 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
##########################################################################
|
3
|
+
# test_30_validation_dval.rb
|
4
|
+
#
|
5
|
+
# Tests for the Excel DVAL structure used in 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
|
+
require 'helper'
|
14
|
+
require 'stringio'
|
15
|
+
|
16
|
+
class TC_validation_dval < Test::Unit::TestCase
|
17
|
+
|
18
|
+
def setup
|
19
|
+
@workbook = WriteExcel.new(StringIO.new)
|
20
|
+
@worksheet = @workbook.add_worksheet
|
21
|
+
@validations = Writeexcel::Worksheet::DataValidations.new
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_1
|
25
|
+
obj_id = 1
|
26
|
+
dv_count = 1
|
27
|
+
|
28
|
+
caption = " \tData validation: _store_dval(#{obj_id}, #{dv_count})"
|
29
|
+
target = %w(
|
30
|
+
B2 01 12 00 04 00 00 00 00 00 00 00 00 00 01 00
|
31
|
+
00 00 01 00 00 00
|
32
|
+
).join(' ')
|
33
|
+
|
34
|
+
result = unpack_record(@validations.__send__("dval_record", obj_id, dv_count))
|
35
|
+
assert_equal(target, result, caption)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_2
|
39
|
+
obj_id = -1
|
40
|
+
dv_count = 1
|
41
|
+
|
42
|
+
caption = " \tData validation: _store_dval(#{obj_id}, #{dv_count})"
|
43
|
+
target = %w(
|
44
|
+
B2 01 12 00 04 00 00 00 00 00 00 00 00 00 FF FF
|
45
|
+
FF FF 01 00 00 00
|
46
|
+
).join(' ')
|
47
|
+
|
48
|
+
result = unpack_record(@validations.__send__("dval_record", obj_id, dv_count))
|
49
|
+
assert_equal(target, result, caption)
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_3
|
53
|
+
obj_id = 1
|
54
|
+
dv_count = 2
|
55
|
+
|
56
|
+
caption = " \tData validation: _store_dval(#{obj_id}, #{dv_count})"
|
57
|
+
target = %w(
|
58
|
+
B2 01 12 00 04 00 00 00 00 00 00 00 00 00 01 00
|
59
|
+
00 00 02 00 00 00
|
60
|
+
).join(' ')
|
61
|
+
|
62
|
+
result = unpack_record(@validations.__send__("dval_record", obj_id, dv_count))
|
63
|
+
assert_equal(target, result, caption)
|
64
|
+
end
|
65
|
+
|
66
|
+
###############################################################################
|
67
|
+
#
|
68
|
+
# Unpack the binary data into a format suitable for printing in tests.
|
69
|
+
#
|
70
|
+
def unpack_record(data)
|
71
|
+
data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
##########################################################################
|
3
|
+
# test_31_validation_dv_strings.rb
|
4
|
+
#
|
5
|
+
# Tests for the packed caption/message strings used in the Excel DV structure
|
6
|
+
# as part of data validation.
|
7
|
+
#
|
8
|
+
# reverse('©'), September 2005, John McNamara, jmcnamara@cpan.org
|
9
|
+
#
|
10
|
+
# original written in Perl by John McNamara
|
11
|
+
# converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
|
12
|
+
#
|
13
|
+
#########################################################################
|
14
|
+
require 'helper'
|
15
|
+
require 'stringio'
|
16
|
+
|
17
|
+
class TC_validation_dv_strings < Test::Unit::TestCase
|
18
|
+
|
19
|
+
def setup
|
20
|
+
workbook = WriteExcel.new(StringIO.new)
|
21
|
+
worksheet = workbook.add_worksheet
|
22
|
+
@data_validation = Writeexcel::Worksheet::DataValidation.new(worksheet.__send__("parser"), {})
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_empty_string
|
26
|
+
string = ''
|
27
|
+
max_length = 32
|
28
|
+
|
29
|
+
caption = " \tData validation: _pack_dv_string('', #{max_length})"
|
30
|
+
target = %w(
|
31
|
+
01 00 00 00
|
32
|
+
).join(' ')
|
33
|
+
result = unpack_record(@data_validation.__send__("pack_dv_string", string, max_length))
|
34
|
+
assert_equal(target, result, caption)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_nil
|
38
|
+
string = nil
|
39
|
+
max_length = 32
|
40
|
+
|
41
|
+
caption = " \tData validation: _pack_dv_string('', #{max_length})"
|
42
|
+
target = %w(
|
43
|
+
01 00 00 00
|
44
|
+
).join(' ')
|
45
|
+
result = unpack_record(@data_validation.__send__("pack_dv_string", string, max_length))
|
46
|
+
assert_equal(target, result, caption)
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_single_space
|
50
|
+
string = ' '
|
51
|
+
max_length = 32
|
52
|
+
|
53
|
+
caption = " \tData validation: _pack_dv_string('', #{max_length})"
|
54
|
+
target = %w(
|
55
|
+
01 00 00 20
|
56
|
+
).join(' ')
|
57
|
+
result = unpack_record(@data_validation.__send__("pack_dv_string", string, max_length))
|
58
|
+
assert_equal(target, result, caption)
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_single_character
|
62
|
+
string = 'A'
|
63
|
+
max_length = 32
|
64
|
+
|
65
|
+
caption = " \tData validation: _pack_dv_string('', #{max_length})"
|
66
|
+
target = %w(
|
67
|
+
01 00 00 41
|
68
|
+
).join(' ')
|
69
|
+
result = unpack_record(@data_validation.__send__("pack_dv_string", string, max_length))
|
70
|
+
assert_equal(target, result, caption)
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_string_longer_than_32_characters_for_dialog_captions
|
74
|
+
string = 'This string is longer than 32 characters'
|
75
|
+
max_length = 32
|
76
|
+
|
77
|
+
caption = " \tData validation: _pack_dv_string('', #{max_length})"
|
78
|
+
target = %w(
|
79
|
+
20 00 00 54 68 69 73 20
|
80
|
+
73 74 72 69 6E 67 20 69 73 20 6C 6F 6E 67 65 72
|
81
|
+
20 74 68 61 6E 20 33 32 20 63 68
|
82
|
+
).join(' ')
|
83
|
+
result = unpack_record(@data_validation.__send__("pack_dv_string", string, max_length))
|
84
|
+
assert_equal(target, result, caption)
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_string_longer_than_32_characters_for_dialog_messages
|
88
|
+
string = 'ABCD' * 64
|
89
|
+
max_length = 255
|
90
|
+
|
91
|
+
caption = " \tData validation: _pack_dv_string('', #{max_length})"
|
92
|
+
target = %w(
|
93
|
+
FF 00 00 41 42 43 44 41 42 43 44 41 42 43 44 41
|
94
|
+
42 43 44 41 42 43 44 41 42 43 44 41 42 43 44 41
|
95
|
+
42 43 44 41 42 43 44 41 42 43 44 41 42 43 44 41
|
96
|
+
42 43 44 41 42 43 44 41 42 43 44 41 42 43 44 41
|
97
|
+
42 43 44 41 42 43 44 41 42 43 44 41 42 43 44 41
|
98
|
+
42 43 44 41 42 43 44 41 42 43 44 41 42 43 44 41
|
99
|
+
42 43 44 41 42 43 44 41 42 43 44 41 42 43 44 41
|
100
|
+
42 43 44 41 42 43 44 41 42 43 44 41 42 43 44 41
|
101
|
+
42 43 44 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
|
110
|
+
).join(' ')
|
111
|
+
result = unpack_record(@data_validation.__send__("pack_dv_string", string, max_length))
|
112
|
+
assert_equal(target, result, caption)
|
113
|
+
end
|
114
|
+
|
115
|
+
###############################################################################
|
116
|
+
#
|
117
|
+
# Unpack the binary data into a format suitable for printing in tests.
|
118
|
+
#
|
119
|
+
def unpack_record(data)
|
120
|
+
data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|
@@ -0,0 +1,203 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
##########################################################################
|
3
|
+
# test_32_validation_dv_formula.rb
|
4
|
+
#
|
5
|
+
# Tests for the Excel DVAL structure used in 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
|
+
require 'helper'
|
14
|
+
require 'stringio'
|
15
|
+
|
16
|
+
class TC_validation_dv_formula < Test::Unit::TestCase
|
17
|
+
|
18
|
+
def setup
|
19
|
+
@workbook = WriteExcel.new(StringIO.new)
|
20
|
+
@worksheet = @workbook.add_worksheet
|
21
|
+
@worksheet2 = @workbook.add_worksheet
|
22
|
+
@data_validation = Writeexcel::Worksheet::DataValidation.new(@worksheet.__send__("parser"), {})
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_integer_values
|
26
|
+
formula = '10'
|
27
|
+
|
28
|
+
caption = " \tData validation: _pack_dv_formula('#{formula}')"
|
29
|
+
bytes = %w(
|
30
|
+
03 00 00 E0 1E 0A 00
|
31
|
+
)
|
32
|
+
|
33
|
+
# Zero out Excel's random unused word to allow comparison.
|
34
|
+
bytes[2] = '00'
|
35
|
+
bytes[3] = '00'
|
36
|
+
target = bytes.join(" ")
|
37
|
+
|
38
|
+
result = unpack_record(@data_validation.__send__("pack_dv_formula", formula))
|
39
|
+
assert_equal(target, result, caption)
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_decimal_values
|
43
|
+
formula = '1.2345'
|
44
|
+
|
45
|
+
caption = " \tData validation: _pack_dv_formula('#{formula}')"
|
46
|
+
bytes = %w(
|
47
|
+
09 00 E0 3F 1F 8D 97 6E 12 83 C0 F3 3F
|
48
|
+
)
|
49
|
+
|
50
|
+
# Zero out Excel's random unused word to allow comparison.
|
51
|
+
bytes[2] = '00'
|
52
|
+
bytes[3] = '00'
|
53
|
+
target = bytes.join(" ")
|
54
|
+
|
55
|
+
result = unpack_record(@data_validation.__send__("pack_dv_formula", formula))
|
56
|
+
assert_equal(target, result, caption)
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_date_values
|
60
|
+
formula = @worksheet.__send__("convert_date_time", '2008-07-24T')
|
61
|
+
|
62
|
+
caption = " \tData validation: _pack_dv_formula('2008-07-24T')"
|
63
|
+
bytes = %w(
|
64
|
+
03 00 E0 3F 1E E5 9A
|
65
|
+
)
|
66
|
+
|
67
|
+
# Zero out Excel's random unused word to allow comparison.
|
68
|
+
bytes[2] = '00'
|
69
|
+
bytes[3] = '00'
|
70
|
+
target = bytes.join(" ")
|
71
|
+
|
72
|
+
result = unpack_record(@data_validation.__send__("pack_dv_formula", formula))
|
73
|
+
assert_equal(target, result, caption)
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_time_values
|
77
|
+
formula = @worksheet.__send__("convert_date_time", 'T12:00')
|
78
|
+
|
79
|
+
caption = " \tData validation: _pack_dv_formula('T12:00')"
|
80
|
+
bytes = %w(
|
81
|
+
09 00 E0 3F 1F 00 00 00 00 00 00 E0 3F
|
82
|
+
)
|
83
|
+
|
84
|
+
# Zero out Excel's random unused word to allow comparison.
|
85
|
+
bytes[2] = '00'
|
86
|
+
bytes[3] = '00'
|
87
|
+
target = bytes.join(" ")
|
88
|
+
|
89
|
+
result = unpack_record(@data_validation.__send__("pack_dv_formula", formula))
|
90
|
+
assert_equal(target, result, caption)
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_cell_reference_value_C9
|
94
|
+
formula = '=C9'
|
95
|
+
|
96
|
+
caption = " \tData validation: _pack_dv_formula('#{formula}')"
|
97
|
+
bytes = %w(
|
98
|
+
05 00 E0 3F 44 08 00 02 C0
|
99
|
+
)
|
100
|
+
|
101
|
+
# Zero out Excel's random unused word to allow comparison.
|
102
|
+
bytes[2] = '00'
|
103
|
+
bytes[3] = '00'
|
104
|
+
target = bytes.join(" ")
|
105
|
+
|
106
|
+
result = unpack_record(@data_validation.__send__("pack_dv_formula", formula))
|
107
|
+
assert_equal(target, result, caption)
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_cell_reference_value_E3_E6
|
111
|
+
formula = '=E3:E6'
|
112
|
+
|
113
|
+
caption = " \tData validation: _pack_dv_formula('#{formula}')"
|
114
|
+
bytes = %w(
|
115
|
+
09 00 0C 00 25 02 00 05 00 04 C0 04 C0
|
116
|
+
)
|
117
|
+
|
118
|
+
# Zero out Excel's random unused word to allow comparison.
|
119
|
+
bytes[2] = '00'
|
120
|
+
bytes[3] = '00'
|
121
|
+
target = bytes.join(" ")
|
122
|
+
|
123
|
+
result = unpack_record(@data_validation.__send__("pack_dv_formula", formula))
|
124
|
+
assert_equal(target, result, caption)
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_cell_reference_value_E3_E6_absolute
|
128
|
+
formula = '=$E$3:$E$6'
|
129
|
+
|
130
|
+
caption = " \tData validation: _pack_dv_formula('#{formula}')"
|
131
|
+
bytes = %w(
|
132
|
+
09 00 0C 00 25 02 00 05 00 04 00 04 00
|
133
|
+
)
|
134
|
+
|
135
|
+
# Zero out Excel's random unused word to allow comparison.
|
136
|
+
bytes[2] = '00'
|
137
|
+
bytes[3] = '00'
|
138
|
+
target = bytes.join(" ")
|
139
|
+
|
140
|
+
result = unpack_record(@data_validation.__send__("pack_dv_formula", formula))
|
141
|
+
assert_equal(target, result, caption)
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_list_values
|
145
|
+
formula = ['a', 'bb', 'ccc']
|
146
|
+
|
147
|
+
caption = " \tData validation: _pack_dv_formula(['a', 'bb', 'ccc'])"
|
148
|
+
bytes = %w(
|
149
|
+
0B 00 0C 00 17 08 00 61 00 62 62 00 63 63 63
|
150
|
+
)
|
151
|
+
|
152
|
+
# Zero out Excel's random unused word to allow comparison.
|
153
|
+
bytes[2] = '00'
|
154
|
+
bytes[3] = '00'
|
155
|
+
target = bytes.join(" ")
|
156
|
+
|
157
|
+
result = unpack_record(@data_validation.__send__("pack_dv_formula", formula))
|
158
|
+
assert_equal(target, result, caption)
|
159
|
+
end
|
160
|
+
|
161
|
+
def test_empty_string
|
162
|
+
formula = ''
|
163
|
+
|
164
|
+
caption = " \tData validation: _pack_dv_formula('')"
|
165
|
+
bytes = %w(
|
166
|
+
00 00 00
|
167
|
+
)
|
168
|
+
|
169
|
+
# Zero out Excel's random unused word to allow comparison.
|
170
|
+
bytes[2] = '00'
|
171
|
+
bytes[3] = '00'
|
172
|
+
target = bytes.join(" ")
|
173
|
+
|
174
|
+
result = unpack_record(@data_validation.__send__("pack_dv_formula", formula))
|
175
|
+
assert_equal(target, result, caption)
|
176
|
+
end
|
177
|
+
|
178
|
+
def test_undefined_value
|
179
|
+
formula = nil
|
180
|
+
|
181
|
+
caption = " \tData validation: _pack_dv_formula(nil)"
|
182
|
+
bytes = %w(
|
183
|
+
00 00 00
|
184
|
+
)
|
185
|
+
|
186
|
+
# Zero out Excel's random unused word to allow comparison.
|
187
|
+
bytes[2] = '00'
|
188
|
+
bytes[3] = '00'
|
189
|
+
target = bytes.join(" ")
|
190
|
+
|
191
|
+
result = unpack_record(@data_validation.__send__("pack_dv_formula", formula))
|
192
|
+
assert_equal(target, result, caption)
|
193
|
+
end
|
194
|
+
|
195
|
+
###############################################################################
|
196
|
+
#
|
197
|
+
# Unpack the binary data into a format suitable for printing in tests.
|
198
|
+
#
|
199
|
+
def unpack_record(data)
|
200
|
+
data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
|
201
|
+
end
|
202
|
+
|
203
|
+
end
|
@@ -0,0 +1,188 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
##########################################################################
|
3
|
+
# test_40_property_types.rb
|
4
|
+
#
|
5
|
+
# Tests for the basic property types used in OLE property sets.
|
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
|
+
require 'helper'
|
14
|
+
|
15
|
+
class TC_property_types < Test::Unit::TestCase
|
16
|
+
|
17
|
+
def setup
|
18
|
+
@smiley = '☺' # chr 0x263A; in perl
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_pack_a_VT_I2
|
22
|
+
caption = " \tDoc properties: pack_VT_I2(1252)"
|
23
|
+
target = %w(
|
24
|
+
02 00 00 00 E4 04 00 00
|
25
|
+
).join(' ')
|
26
|
+
|
27
|
+
result = unpack_record(pack_VT_I2(1252))
|
28
|
+
assert_equal(target, result, caption)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_pack_a_VT_LPSTR_string_and_check_for_padding
|
32
|
+
string = ''
|
33
|
+
codepage = 0x04E4
|
34
|
+
caption = " \tDoc properties: _pack_VT_LPSTR('#{string}',\t#{codepage}')"
|
35
|
+
target = %w(
|
36
|
+
1E 00 00 00 01 00 00 00 00 00 00 00
|
37
|
+
).join(' ')
|
38
|
+
|
39
|
+
result = unpack_record(pack_VT_LPSTR(string, codepage))
|
40
|
+
assert_equal(target, result, caption)
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_pack_a_VT_LPSTR_string_and_check_for_padding_2
|
44
|
+
string = 'a'
|
45
|
+
codepage = 0x04E4
|
46
|
+
caption = " \tDoc properties: _pack_VT_LPSTR('#{string}',\t#{codepage}')"
|
47
|
+
target = %w(
|
48
|
+
1E 00 00 00 02 00 00 00 61 00 00 00
|
49
|
+
).join(' ')
|
50
|
+
|
51
|
+
result = unpack_record(pack_VT_LPSTR(string, codepage))
|
52
|
+
assert_equal(target, result, caption)
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_pack_a_VT_LPSTR_string_and_check_for_padding_3
|
56
|
+
string = 'bb'
|
57
|
+
codepage = 0x04E4
|
58
|
+
caption = " \tDoc properties: _pack_VT_LPSTR('#{string}',\t#{codepage}')"
|
59
|
+
target = %w(
|
60
|
+
1E 00 00 00 03 00 00 00 62 62 00 00
|
61
|
+
).join(' ')
|
62
|
+
|
63
|
+
result = unpack_record(pack_VT_LPSTR(string, codepage))
|
64
|
+
assert_equal(target, result, caption)
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_pack_a_VT_LPSTR_string_and_check_for_padding_4
|
68
|
+
string = 'ccc'
|
69
|
+
codepage = 0x04E4
|
70
|
+
caption = " \tDoc properties: _pack_VT_LPSTR('#{string}',\t#{codepage}')"
|
71
|
+
target = %w(
|
72
|
+
1E 00 00 00 04 00 00 00 63 63 63 00
|
73
|
+
).join(' ')
|
74
|
+
|
75
|
+
result = unpack_record(pack_VT_LPSTR(string, codepage))
|
76
|
+
assert_equal(target, result, caption)
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_pack_a_VT_LPSTR_string_and_check_for_padding_5
|
80
|
+
string = 'dddd'
|
81
|
+
codepage = 0x04E4
|
82
|
+
caption = " \tDoc properties: _pack_VT_LPSTR('#{string}',\t#{codepage}')"
|
83
|
+
target = %w(
|
84
|
+
1E 00 00 00 05 00 00 00 64 64 64 64 00 00 00 00
|
85
|
+
).join(' ')
|
86
|
+
|
87
|
+
result = unpack_record(pack_VT_LPSTR(string, codepage))
|
88
|
+
assert_equal(target, result, caption)
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_pack_a_VT_LPSTR_string_and_check_for_padding_6
|
92
|
+
string = 'Username'
|
93
|
+
codepage = 0x04E4
|
94
|
+
caption = " \tDoc properties: _pack_VT_LPSTR('#{string}',\t#{codepage}')"
|
95
|
+
target = %w(
|
96
|
+
1E 00 00 00 09 00 00 00 55 73 65 72 6E 61 6D 65
|
97
|
+
00 00 00 00
|
98
|
+
).join(' ')
|
99
|
+
|
100
|
+
result = unpack_record(pack_VT_LPSTR(string, codepage))
|
101
|
+
assert_equal(target, result, caption)
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_pack_a_VT_LPSTR_UTF8_string
|
105
|
+
string = @smiley
|
106
|
+
codepage = 0xFDE9
|
107
|
+
caption = " \tDoc properties: _pack_VT_LPSTR('#{@smiley}',\t#{codepage}')"
|
108
|
+
target = %w(
|
109
|
+
1E 00 00 00 04 00 00 00 E2 98 BA 00
|
110
|
+
).join(' ')
|
111
|
+
|
112
|
+
result = unpack_record(pack_VT_LPSTR(string, codepage))
|
113
|
+
assert_equal(target, result, caption)
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_pack_a_VT_LPSTR_UTF8_string_2
|
117
|
+
string = "a" + @smiley
|
118
|
+
codepage = 0xFDE9
|
119
|
+
caption = " \tDoc properties: _pack_VT_LPSTR('a#{@smiley}',\t#{codepage}')"
|
120
|
+
target = %w(
|
121
|
+
1E 00 00 00 05 00 00 00 61 E2 98 BA 00 00 00 00
|
122
|
+
).join(' ')
|
123
|
+
|
124
|
+
result = unpack_record(pack_VT_LPSTR(string, codepage))
|
125
|
+
assert_equal(target, result, caption)
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_pack_a_VT_LPSTR_UTF8_string_3
|
129
|
+
string = "aa" + @smiley
|
130
|
+
codepage = 0xFDE9
|
131
|
+
caption = " \tDoc properties: _pack_VT_LPSTR('#{string}',\t#{codepage}')"
|
132
|
+
target = %w(
|
133
|
+
1E 00 00 00 06 00 00 00 61 61 E2 98 BA 00 00 00
|
134
|
+
).join(' ')
|
135
|
+
|
136
|
+
result = unpack_record( pack_VT_LPSTR(string, codepage) )
|
137
|
+
assert_equal(target, result, caption)
|
138
|
+
end
|
139
|
+
|
140
|
+
def test_pack_a_VT_LPSTR_UTF8_string_4
|
141
|
+
string = "aaa" + @smiley
|
142
|
+
codepage = 0xFDE9
|
143
|
+
caption = " \tDoc properties: _pack_VT_LPSTR('#{string}',\t#{codepage}')"
|
144
|
+
target = %w(
|
145
|
+
1E 00 00 00 07 00 00 00 61 61 61 E2 98 BA 00 00
|
146
|
+
).join(' ')
|
147
|
+
|
148
|
+
result = unpack_record( pack_VT_LPSTR(string, codepage) )
|
149
|
+
assert_equal(target, result, caption)
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_pack_a_VT_LPSTR_UTF8_string_5
|
153
|
+
string = "aaaa" + @smiley
|
154
|
+
codepage = 0xFDE9
|
155
|
+
caption = " \tDoc properties: _pack_VT_LPSTR('#{string}',\t#{codepage}')"
|
156
|
+
target = %w(
|
157
|
+
1E 00 00 00 08 00 00 00 61 61 61 61 E2 98 BA 00
|
158
|
+
).join(' ')
|
159
|
+
|
160
|
+
result = unpack_record( pack_VT_LPSTR(string, codepage) )
|
161
|
+
assert_equal(target, result, caption)
|
162
|
+
end
|
163
|
+
|
164
|
+
def test_pack_a_VT_FILETIME
|
165
|
+
# Wed Aug 13 00:40:00 2008
|
166
|
+
# $sec,$min,$hour,$mday,$mon,$year
|
167
|
+
# We normalise the time using timegm() so that the tests don't fail due to
|
168
|
+
# different timezones.
|
169
|
+
filetime = Time.gm(2008,8,13,0,40,0)
|
170
|
+
|
171
|
+
caption = " \tDoc properties: _pack_VT_FILETIME()"
|
172
|
+
target = %w(
|
173
|
+
40 00 00 00 00 70 EB 1D DD FC C8 01
|
174
|
+
).join(' ')
|
175
|
+
|
176
|
+
result = unpack_record( pack_VT_FILETIME(filetime) )
|
177
|
+
assert_equal(target, result, caption)
|
178
|
+
end
|
179
|
+
|
180
|
+
###############################################################################
|
181
|
+
#
|
182
|
+
# Unpack the binary data into a format suitable for printing in tests.
|
183
|
+
#
|
184
|
+
def unpack_record(data)
|
185
|
+
data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
|
186
|
+
end
|
187
|
+
|
188
|
+
end
|