barby 0.6.9 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +4 -0
- data/README.md +2 -1
- data/barby.gemspec +17 -17
- data/lib/barby/barcode/data_matrix.rb +42 -7
- data/lib/barby/version.rb +2 -2
- data/test/bookland_test.rb +10 -8
- data/test/codabar_test.rb +7 -4
- data/test/code_128_test.rb +134 -128
- data/test/code_25_iata_test.rb +2 -2
- data/test/code_25_interleaved_test.rb +24 -18
- data/test/code_25_test.rb +36 -26
- data/test/code_39_test.rb +35 -32
- data/test/code_93_test.rb +31 -28
- data/test/data_matrix_test.rb +19 -8
- data/test/ean13_test.rb +31 -28
- data/test/ean8_test.rb +10 -10
- data/test/outputter/cairo_outputter_test.rb +31 -29
- data/test/outputter/html_outputter_test.rb +1 -2
- data/test/outputter/pdfwriter_outputter_test.rb +7 -7
- data/test/outputter/png_outputter_test.rb +9 -9
- data/test/outputter/prawn_outputter_test.rb +22 -22
- data/test/outputter/rmagick_outputter_test.rb +22 -22
- data/test/outputter/svg_outputter_test.rb +32 -31
- data/test/outputter_test.rb +30 -32
- data/test/pdf_417_test.rb +23 -23
- data/test/qr_code_test.rb +42 -37
- data/test/test_helper.rb +1 -1
- data/test/upc_supplemental_test.rb +39 -39
- metadata +24 -24
data/test/ean13_test.rb
CHANGED
@@ -29,7 +29,9 @@ class EAN13Test < Barby::TestCase
|
|
29
29
|
end
|
30
30
|
|
31
31
|
it "should raise an exception when data is invalid" do
|
32
|
-
|
32
|
+
assert_raises ArgumentError do
|
33
|
+
EAN13.new('123')
|
34
|
+
end
|
33
35
|
end
|
34
36
|
|
35
37
|
end
|
@@ -42,40 +44,41 @@ class EAN13Test < Barby::TestCase
|
|
42
44
|
end
|
43
45
|
|
44
46
|
it "should have the same data as was passed to it" do
|
45
|
-
@
|
47
|
+
assert_equal @data, @code.data
|
46
48
|
end
|
47
49
|
|
48
50
|
it "should have the expected characters" do
|
49
|
-
|
51
|
+
assert_equal @data.split(//), @code.characters
|
50
52
|
end
|
51
53
|
|
52
54
|
it "should have the expected numbers" do
|
53
|
-
|
55
|
+
assert_equal @data.split(//).map{|s| s.to_i }, @code.numbers
|
54
56
|
end
|
55
57
|
|
56
58
|
it "should have the expected odd_and_even_numbers" do
|
57
|
-
|
59
|
+
assert_equal [[2,4,1,7,5,0], [1,6,8,6,7,0]], @code.odd_and_even_numbers
|
58
60
|
end
|
59
61
|
|
60
62
|
it "should have the expected left_numbers" do
|
61
|
-
|
62
|
-
|
63
|
+
# 0=second number in number system code
|
64
|
+
assert_equal [0,7,5,6,7,8], @code.left_numbers
|
63
65
|
end
|
64
66
|
|
65
67
|
it "should have the expected right_numbers" do
|
66
|
-
|
68
|
+
# 5=checksum
|
69
|
+
assert_equal [1,6,4,1,2,5], @code.right_numbers
|
67
70
|
end
|
68
71
|
|
69
72
|
it "should have the expected numbers_with_checksum" do
|
70
|
-
|
73
|
+
assert_equal @data.split(//).map{|s| s.to_i } + [5], @code.numbers_with_checksum
|
71
74
|
end
|
72
75
|
|
73
76
|
it "should have the expected data_with_checksum" do
|
74
|
-
|
77
|
+
assert_equal @data+'5', @code.data_with_checksum
|
75
78
|
end
|
76
79
|
|
77
80
|
it "should return all digits and the checksum on to_s" do
|
78
|
-
@code.to_s
|
81
|
+
assert_equal '0075678164125', @code.to_s
|
79
82
|
end
|
80
83
|
|
81
84
|
end
|
@@ -87,19 +90,19 @@ class EAN13Test < Barby::TestCase
|
|
87
90
|
end
|
88
91
|
|
89
92
|
it "should have the expected weighted_sum" do
|
90
|
-
@code.weighted_sum
|
93
|
+
assert_equal 85, @code.weighted_sum
|
91
94
|
@code.data = '007567816413'
|
92
|
-
@code.weighted_sum
|
95
|
+
assert_equal 88, @code.weighted_sum
|
93
96
|
end
|
94
97
|
|
95
98
|
it "should have the correct checksum" do
|
96
|
-
@code.checksum
|
99
|
+
assert_equal 5, @code.checksum
|
97
100
|
@code.data = '007567816413'
|
98
|
-
@code.checksum
|
101
|
+
assert_equal 2, @code.checksum
|
99
102
|
end
|
100
103
|
|
101
104
|
it "should have the correct checksum_encoding" do
|
102
|
-
@code.checksum_encoding
|
105
|
+
assert_equal '1001110', @code.checksum_encoding
|
103
106
|
end
|
104
107
|
|
105
108
|
end
|
@@ -111,36 +114,36 @@ class EAN13Test < Barby::TestCase
|
|
111
114
|
end
|
112
115
|
|
113
116
|
it "should have the expected checksum" do
|
114
|
-
@code.checksum
|
117
|
+
assert_equal 9, @code.checksum
|
115
118
|
end
|
116
119
|
|
117
120
|
it "should have the expected checksum_encoding" do
|
118
|
-
@code.checksum_encoding
|
121
|
+
assert_equal '1110100', @code.checksum_encoding
|
119
122
|
end
|
120
123
|
|
121
124
|
it "should have the expected left_parity_map" do
|
122
|
-
|
125
|
+
assert_equal [:odd, :even, :odd, :even, :odd, :even], @code.left_parity_map
|
123
126
|
end
|
124
127
|
|
125
128
|
it "should have the expected left_encodings" do
|
126
|
-
|
129
|
+
assert_equal %w(0110001 0100111 0011001 0100111 0111101 0110011), @code.left_encodings
|
127
130
|
end
|
128
131
|
|
129
132
|
it "should have the expected right_encodings" do
|
130
|
-
|
133
|
+
assert_equal %w(1000010 1100110 1100110 1000010 1110010 1110100), @code.right_encodings
|
131
134
|
end
|
132
135
|
|
133
136
|
it "should have the expected left_encoding" do
|
134
|
-
@code.left_encoding
|
137
|
+
assert_equal '011000101001110011001010011101111010110011', @code.left_encoding
|
135
138
|
end
|
136
139
|
|
137
140
|
it "should have the expected right_encoding" do
|
138
|
-
@code.right_encoding
|
141
|
+
assert_equal '100001011001101100110100001011100101110100', @code.right_encoding
|
139
142
|
end
|
140
143
|
|
141
144
|
it "should have the expected encoding" do
|
142
|
-
|
143
|
-
|
145
|
+
# Start Left Center Right Stop
|
146
|
+
assert_equal '101' + '011000101001110011001010011101111010110011' + '01010' + '100001011001101100110100001011100101110100' + '101', @code.encoding
|
144
147
|
end
|
145
148
|
|
146
149
|
end
|
@@ -152,15 +155,15 @@ class EAN13Test < Barby::TestCase
|
|
152
155
|
end
|
153
156
|
|
154
157
|
it "should have the expected start_encoding" do
|
155
|
-
@code.start_encoding
|
158
|
+
assert_equal '101', @code.start_encoding
|
156
159
|
end
|
157
160
|
|
158
161
|
it "should have the expected stop_encoding" do
|
159
|
-
@code.stop_encoding
|
162
|
+
assert_equal '101', @code.stop_encoding
|
160
163
|
end
|
161
164
|
|
162
165
|
it "should have the expected center_encoding" do
|
163
|
-
@code.center_encoding
|
166
|
+
assert_equal '01010', @code.center_encoding
|
164
167
|
end
|
165
168
|
|
166
169
|
end
|
data/test/ean8_test.rb
CHANGED
@@ -37,11 +37,11 @@ class EAN8Test < Barby::TestCase
|
|
37
37
|
end
|
38
38
|
|
39
39
|
it "should have the expected weighted_sum" do
|
40
|
-
@code.weighted_sum
|
40
|
+
assert_equal 53, @code.weighted_sum
|
41
41
|
end
|
42
42
|
|
43
43
|
it "should have the expected checksum" do
|
44
|
-
@code.checksum
|
44
|
+
assert_equal 7, @code.checksum
|
45
45
|
end
|
46
46
|
|
47
47
|
end
|
@@ -54,24 +54,24 @@ class EAN8Test < Barby::TestCase
|
|
54
54
|
end
|
55
55
|
|
56
56
|
it "should have the expected data" do
|
57
|
-
@
|
57
|
+
assert_equal @data, @code.data
|
58
58
|
end
|
59
59
|
|
60
60
|
it "should have the expected odd_and_even_numbers" do
|
61
|
-
|
61
|
+
assert_equal [[5,3,1,5],[4,2,5]], @code.odd_and_even_numbers
|
62
62
|
end
|
63
63
|
|
64
64
|
it "should have the expected left_numbers" do
|
65
65
|
#EAN-8 includes the first character in the left-hand encoding, unlike EAN-13
|
66
|
-
|
66
|
+
assert_equal [5,5,1,2], @code.left_numbers
|
67
67
|
end
|
68
68
|
|
69
69
|
it "should have the expected right_numbers" do
|
70
|
-
|
70
|
+
assert_equal [3,4,5,7], @code.right_numbers
|
71
71
|
end
|
72
72
|
|
73
73
|
it "should return the data with checksum on to_s" do
|
74
|
-
@code.to_s
|
74
|
+
assert_equal '55123457', @code.to_s
|
75
75
|
end
|
76
76
|
|
77
77
|
end
|
@@ -83,15 +83,15 @@ class EAN8Test < Barby::TestCase
|
|
83
83
|
end
|
84
84
|
|
85
85
|
it "should have the expected left_parity_map" do
|
86
|
-
|
86
|
+
assert_equal [:odd, :odd, :odd, :odd], @code.left_parity_map
|
87
87
|
end
|
88
88
|
|
89
89
|
it "should have the expected left_encoding" do
|
90
|
-
@code.left_encoding
|
90
|
+
assert_equal '0110001011000100110010010011', @code.left_encoding
|
91
91
|
end
|
92
92
|
|
93
93
|
it "should have the expected right_encoding" do
|
94
|
-
@code.right_encoding
|
94
|
+
assert_equal '1000010101110010011101000100', @code.right_encoding
|
95
95
|
end
|
96
96
|
|
97
97
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
class CairoOutputterTest < Barby::TestCase
|
4
|
-
|
4
|
+
|
5
5
|
def ps_available?
|
6
6
|
Cairo.const_defined?(:PSSurface)
|
7
7
|
end
|
@@ -29,62 +29,62 @@ class CairoOutputterTest < Barby::TestCase
|
|
29
29
|
end
|
30
30
|
|
31
31
|
it "should have defined the render_to_cairo_context method" do
|
32
|
-
@outputters.
|
32
|
+
assert @outputters.include?(:render_to_cairo_context)
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should have defined the to_png method" do
|
36
|
-
@outputters.
|
36
|
+
assert @outputters.include?(:to_png)
|
37
37
|
end
|
38
38
|
|
39
39
|
it "should have defined the to_ps and to_eps method if available" do
|
40
40
|
if ps_available?
|
41
|
-
@outputters.
|
41
|
+
assert @outputters.include?(:to_ps)
|
42
42
|
if eps_available?
|
43
|
-
@outputters.
|
43
|
+
assert @outputters.include?(:to_eps)
|
44
44
|
else
|
45
|
-
@outputters.
|
45
|
+
refute @outputters.include?(:to_eps)
|
46
46
|
end
|
47
47
|
else
|
48
|
-
@outputters.
|
49
|
-
@outputters.
|
48
|
+
refute @outputters.include?(:to_ps)
|
49
|
+
refute @outputters.include?(:to_eps)
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
53
|
it "should have defined the to_pdf method if available" do
|
54
54
|
if pdf_available?
|
55
|
-
@outputters.
|
55
|
+
assert @outputters.include?(:to_pdf)
|
56
56
|
else
|
57
|
-
@outputters.
|
57
|
+
refute @outputters.include?(:to_pdf)
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
61
|
it "should have defined the to_svg method if available" do
|
62
62
|
if svg_available?
|
63
|
-
@outputters.
|
63
|
+
assert @outputters.include?(:to_svg)
|
64
64
|
else
|
65
|
-
@outputters.
|
65
|
+
refute @outputters.include?(:to_svg)
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
69
|
it "should return the cairo context object it was given in render_to_cairo_context" do
|
70
|
-
@barcode.render_to_cairo_context(@context).object_id
|
70
|
+
assert_equal @context.object_id, @barcode.render_to_cairo_context(@context).object_id
|
71
71
|
end
|
72
72
|
|
73
73
|
it "should return PNG image by the to_png method" do
|
74
74
|
png = @barcode.to_png
|
75
75
|
data = ruby_19_or_greater? ? png.force_encoding('BINARY') : png
|
76
|
-
|
76
|
+
assert_match /\A\x89PNG/n, data
|
77
77
|
end
|
78
78
|
|
79
79
|
it "should return PS document by the to_ps method" do
|
80
80
|
if ps_available?
|
81
|
-
|
81
|
+
assert_match /\A%!PS-Adobe-[\d.]/, @barcode.to_ps
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
85
85
|
it "should return EPS document by the to_eps method" do
|
86
86
|
if eps_available?
|
87
|
-
|
87
|
+
assert_match /\A%!PS-Adobe-[\d.]+ EPSF-[\d.]+/, @barcode.to_eps
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
@@ -92,38 +92,40 @@ class CairoOutputterTest < Barby::TestCase
|
|
92
92
|
if pdf_available?
|
93
93
|
pdf = @barcode.to_pdf
|
94
94
|
data = ruby_19_or_greater? ? pdf.force_encoding('BINARY') : pdf
|
95
|
-
|
95
|
+
assert_match /\A%PDF-[\d.]+/n, data
|
96
96
|
end
|
97
97
|
end
|
98
98
|
|
99
99
|
it "should return SVG document by the to_svg method" do
|
100
100
|
if svg_available?
|
101
|
-
|
101
|
+
assert_match /<\/svg>\s*\Z/m, @barcode.to_svg
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
105
105
|
it "should have x, y, width, height, full_width, full_height, xdim and margin attributes" do
|
106
|
-
@outputter.
|
107
|
-
@outputter.
|
108
|
-
@outputter.
|
109
|
-
@outputter.
|
110
|
-
@outputter.
|
111
|
-
@outputter.
|
112
|
-
@outputter.
|
113
|
-
@outputter.
|
106
|
+
assert @outputter.respond_to?(:x)
|
107
|
+
assert @outputter.respond_to?(:y)
|
108
|
+
assert @outputter.respond_to?(:width)
|
109
|
+
assert @outputter.respond_to?(:height)
|
110
|
+
assert @outputter.respond_to?(:full_width)
|
111
|
+
assert @outputter.respond_to?(:full_height)
|
112
|
+
assert @outputter.respond_to?(:xdim)
|
113
|
+
assert @outputter.respond_to?(:margin)
|
114
114
|
end
|
115
115
|
|
116
116
|
it "should not change attributes when given an options hash to render" do
|
117
117
|
%w(x y height xdim).each do |m|
|
118
118
|
@outputter.send("#{m}=", 10)
|
119
|
-
@outputter.send(m)
|
119
|
+
assert_equal 10, @outputter.send(m)
|
120
120
|
end
|
121
121
|
@outputter.render_to_cairo_context(@context,
|
122
122
|
:x => 20,
|
123
123
|
:y => 20,
|
124
124
|
:height => 20,
|
125
125
|
:xdim => 20)
|
126
|
-
%w(x y height xdim).each
|
126
|
+
%w(x y height xdim).each do |m|
|
127
|
+
assert_equal 10, @outputter.send(m)
|
128
|
+
end
|
127
129
|
end
|
128
|
-
|
130
|
+
|
129
131
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
require 'barby/barcode/code_128'
|
3
|
-
#require 'barby/outputter/html_outputter'
|
4
3
|
|
5
4
|
class HtmlOutputterTest < Barby::TestCase
|
6
5
|
|
@@ -21,7 +20,7 @@ class HtmlOutputterTest < Barby::TestCase
|
|
21
20
|
end
|
22
21
|
|
23
22
|
it "should register to_html" do
|
24
|
-
Barcode.outputters.
|
23
|
+
assert Barcode.outputters.include?(:to_html)
|
25
24
|
end
|
26
25
|
|
27
26
|
it 'should have the expected start HTML' do
|
@@ -14,22 +14,22 @@ unless RUBY_VERSION >= '1.9'
|
|
14
14
|
end
|
15
15
|
|
16
16
|
it "should have registered annotate_pdf" do
|
17
|
-
Barcode.outputters.
|
17
|
+
assert Barcode.outputters.include?(:annotate_pdf)
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should have defined the annotate_pdf method" do
|
21
|
-
@outputter.
|
21
|
+
assert @outputter.respond_to?(:annotate_pdf)
|
22
22
|
end
|
23
23
|
|
24
24
|
it "should return the pdf object it was given in annotate_pdf" do
|
25
|
-
@barcode.annotate_pdf(@pdf).object_id
|
25
|
+
assert_equal @pdf.object_id, @barcode.annotate_pdf(@pdf).object_id
|
26
26
|
end
|
27
27
|
|
28
28
|
it "should have x, y, height and xdim attributes" do
|
29
|
-
@outputter.
|
30
|
-
@outputter.
|
31
|
-
@outputter.
|
32
|
-
@outputter.
|
29
|
+
assert @outputter.respond_to?(:x)
|
30
|
+
assert @outputter.respond_to?(:y)
|
31
|
+
assert @outputter.respond_to?(:height)
|
32
|
+
assert @outputter.respond_to?(:xdim)
|
33
33
|
end
|
34
34
|
|
35
35
|
end
|
@@ -16,34 +16,34 @@ class PngOutputterTest < Barby::TestCase
|
|
16
16
|
@barcode = PngTestBarcode.new('10110011100011110000')
|
17
17
|
@outputter = PngOutputter.new(@barcode)
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
it "should register to_png and to_image" do
|
21
|
-
Barcode.outputters.
|
22
|
-
Barcode.outputters.
|
21
|
+
assert Barcode.outputters.include?(:to_png)
|
22
|
+
assert Barcode.outputters.include?(:to_image)
|
23
23
|
end
|
24
24
|
|
25
25
|
it "should return a ChunkyPNG::Datastream on to_datastream" do
|
26
|
-
@barcode.to_datastream.
|
26
|
+
assert @barcode.to_datastream.is_a?(ChunkyPNG::Datastream)
|
27
27
|
end
|
28
28
|
|
29
29
|
it "should return a string on to_png" do
|
30
|
-
@barcode.to_png.
|
30
|
+
assert @barcode.to_png.is_a?(String)
|
31
31
|
end
|
32
32
|
|
33
33
|
it "should return a ChunkyPNG::Image on to_canvas" do
|
34
|
-
@barcode.to_image.
|
34
|
+
assert @barcode.to_image.is_a?(ChunkyPNG::Image)
|
35
35
|
end
|
36
36
|
|
37
37
|
it "should have a width equal to Xdim * barcode_string.length" do
|
38
|
-
|
38
|
+
assert_equal @outputter.barcode.encoding.length * @outputter.xdim, @outputter.width
|
39
39
|
end
|
40
40
|
|
41
41
|
it "should have a full_width which is the sum of width + (margin*2)" do
|
42
|
-
@outputter.
|
42
|
+
assert_equal(@outputter.width + (@outputter.margin*2), @outputter.full_width)
|
43
43
|
end
|
44
44
|
|
45
45
|
it "should have a full_height which is the sum of height + (margin*2)" do
|
46
|
-
@outputter.
|
46
|
+
assert_equal(@outputter.height + (@outputter.margin*2), @outputter.full_height)
|
47
47
|
end
|
48
48
|
|
49
49
|
end
|
@@ -10,70 +10,70 @@ class PrawnOutputterTest < Barby::TestCase
|
|
10
10
|
end
|
11
11
|
|
12
12
|
it "should register to_pdf and annotate_pdf" do
|
13
|
-
Barcode.outputters.
|
14
|
-
Barcode.outputters.
|
13
|
+
assert Barcode.outputters.include?(:to_pdf)
|
14
|
+
assert Barcode.outputters.include?(:annotate_pdf)
|
15
15
|
end
|
16
16
|
|
17
17
|
it "should have a to_pdf method" do
|
18
|
-
@outputter.
|
18
|
+
assert @outputter.respond_to?(:to_pdf)
|
19
19
|
end
|
20
20
|
|
21
21
|
it "should return a PDF document in a string on to_pdf" do
|
22
|
-
@barcode.to_pdf.
|
22
|
+
assert @barcode.to_pdf.is_a?(String)
|
23
23
|
end
|
24
24
|
|
25
25
|
it "should return the same Prawn::Document on annotate_pdf" do
|
26
26
|
doc = Prawn::Document.new
|
27
|
-
@barcode.annotate_pdf(doc).object_id
|
27
|
+
assert_equal doc.object_id, @barcode.annotate_pdf(doc).object_id
|
28
28
|
end
|
29
29
|
|
30
30
|
it "should default x and y to margin value" do
|
31
31
|
@outputter.margin = 123
|
32
|
-
@outputter.x
|
33
|
-
@outputter.y
|
32
|
+
assert_equal 123, @outputter.x
|
33
|
+
assert_equal 123, @outputter.y
|
34
34
|
end
|
35
35
|
|
36
36
|
it "should default ydim to xdim value" do
|
37
37
|
@outputter.xdim = 321
|
38
|
-
@outputter.ydim
|
38
|
+
assert_equal 321, @outputter.ydim
|
39
39
|
end
|
40
40
|
|
41
41
|
it "should be able to calculate width required" do
|
42
|
-
|
42
|
+
assert_equal @barcode.encoding.length, @outputter.width
|
43
43
|
@outputter.xdim = 2
|
44
|
-
|
45
|
-
|
44
|
+
assert_equal @barcode.encoding.length * 2, @outputter.width
|
45
|
+
assert_equal @barcode.encoding.length * 2, @outputter.full_width
|
46
46
|
@outputter.margin = 5
|
47
|
-
|
47
|
+
assert_equal((@barcode.encoding.length * 2) + 10, @outputter.full_width)
|
48
48
|
|
49
49
|
#2D
|
50
50
|
barcode = Barcode2D.new
|
51
51
|
def barcode.encoding; ['111', '000', '111'] end
|
52
52
|
outputter = PrawnOutputter.new(barcode)
|
53
|
-
outputter.width
|
53
|
+
assert_equal 3, outputter.width
|
54
54
|
outputter.xdim = 2
|
55
55
|
outputter.margin = 5
|
56
|
-
outputter.width
|
57
|
-
outputter.full_width
|
56
|
+
assert_equal 6, outputter.width
|
57
|
+
assert_equal 16, outputter.full_width
|
58
58
|
end
|
59
59
|
|
60
60
|
it "should be able to calculate height required" do
|
61
|
-
@outputter.
|
61
|
+
assert_equal @outputter.height, @outputter.full_height
|
62
62
|
@outputter.margin = 5
|
63
|
-
|
63
|
+
assert_equal @outputter.height + 10, @outputter.full_height
|
64
64
|
|
65
65
|
#2D
|
66
66
|
barcode = Barcode2D.new
|
67
67
|
def barcode.encoding; ['111', '000', '111'] end
|
68
68
|
outputter = PrawnOutputter.new(barcode)
|
69
|
-
outputter.height
|
69
|
+
assert_equal 3, outputter.height
|
70
70
|
outputter.xdim = 2 #ydim defaults to xdim
|
71
71
|
outputter.margin = 5
|
72
|
-
outputter.height
|
73
|
-
outputter.full_height
|
72
|
+
assert_equal 6, outputter.height
|
73
|
+
assert_equal 16, outputter.full_height
|
74
74
|
outputter.ydim = 3 #ydim overrides xdim when set
|
75
|
-
outputter.height
|
76
|
-
outputter.full_height
|
75
|
+
assert_equal 9, outputter.height
|
76
|
+
assert_equal 19, outputter.full_height
|
77
77
|
end
|
78
78
|
|
79
79
|
end
|
@@ -18,49 +18,49 @@ class RmagickOutputterTest < Barby::TestCase
|
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should register to_png, to_gif, to_jpg, to_image" do
|
21
|
-
Barcode.outputters.
|
22
|
-
Barcode.outputters.
|
23
|
-
Barcode.outputters.
|
24
|
-
Barcode.outputters.
|
21
|
+
assert Barcode.outputters.include?(:to_png)
|
22
|
+
assert Barcode.outputters.include?(:to_gif)
|
23
|
+
assert Barcode.outputters.include?(:to_jpg)
|
24
|
+
assert Barcode.outputters.include?(:to_image)
|
25
25
|
end
|
26
26
|
|
27
27
|
it "should have defined to_png, to_gif, to_jpg, to_image" do
|
28
|
-
@outputter.
|
29
|
-
@outputter.
|
30
|
-
@outputter.
|
31
|
-
@outputter.
|
28
|
+
assert @outputter.respond_to?(:to_png)
|
29
|
+
assert @outputter.respond_to?(:to_gif)
|
30
|
+
assert @outputter.respond_to?(:to_jpg)
|
31
|
+
assert @outputter.respond_to?(:to_image)
|
32
32
|
end
|
33
33
|
|
34
34
|
it "should return a string on to_png and to_gif" do
|
35
|
-
@outputter.to_png.
|
36
|
-
@outputter.to_gif.
|
35
|
+
assert @outputter.to_png.is_a?(String)
|
36
|
+
assert @outputter.to_gif.is_a?(String)
|
37
37
|
end
|
38
38
|
|
39
39
|
it "should return a Magick::Image instance on to_image" do
|
40
|
-
@outputter.to_image.
|
40
|
+
assert @outputter.to_image.is_a?(Magick::Image)
|
41
41
|
end
|
42
42
|
|
43
43
|
it "should have a width equal to the length of the barcode encoding string * x dimension" do
|
44
|
-
@outputter.xdim
|
45
|
-
|
44
|
+
assert_equal 1, @outputter.xdim #Default
|
45
|
+
assert_equal @outputter.barcode.encoding.length, @outputter.width
|
46
46
|
@outputter.xdim = 2
|
47
|
-
|
47
|
+
assert_equal @outputter.barcode.encoding.length * 2, @outputter.width
|
48
48
|
end
|
49
49
|
|
50
50
|
it "should have a full_width equal to the width + left and right margins" do
|
51
|
-
@outputter.xdim
|
52
|
-
@outputter.margin
|
53
|
-
|
51
|
+
assert_equal 1, @outputter.xdim
|
52
|
+
assert_equal 10, @outputter.margin
|
53
|
+
assert_equal((@outputter.width + 10 + 10), @outputter.full_width)
|
54
54
|
end
|
55
55
|
|
56
56
|
it "should have a default height of 100" do
|
57
|
-
@outputter.height
|
57
|
+
assert_equal 100, @outputter.height
|
58
58
|
@outputter.height = 200
|
59
|
-
@outputter.height
|
59
|
+
assert_equal 200, @outputter.height
|
60
60
|
end
|
61
61
|
|
62
62
|
it "should have a full_height equal to the height + top and bottom margins" do
|
63
|
-
@outputter.
|
63
|
+
assert_equal(@outputter.height + (@outputter.margin * 2), @outputter.full_height)
|
64
64
|
end
|
65
65
|
|
66
66
|
describe "#to_image" do
|
@@ -72,8 +72,8 @@ class RmagickOutputterTest < Barby::TestCase
|
|
72
72
|
end
|
73
73
|
|
74
74
|
it "should have a width and height equal to the outputter's full_width and full_height" do
|
75
|
-
@
|
76
|
-
@
|
75
|
+
assert_equal @outputter.full_width, @image.columns
|
76
|
+
assert_equal @outputter.full_height, @image.rows
|
77
77
|
end
|
78
78
|
|
79
79
|
end
|