b5120906939f9b6383d3cabcb2949eb88ed529b1
[zxing.git] / core / test / src / com / google / zxing / oned / rss / expanded / RSSExpandedImage2stringTestCase.java
1 /*
2  * Copyright (C) 2010 ZXing authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 /*
18  * These authors would like to acknowledge the Spanish Ministry of Industry,
19  * Tourism and Trade, for the support in the project TSI020301-2008-2
20  * "PIRAmIDE: Personalizable Interactions with Resources on AmI-enabled
21  * Mobile Dynamic Environments", led by Treelogic
22  * ( http://www.treelogic.com/ ):
23  *
24  *   http://www.piramidepse.com/
25  */
26
27 package com.google.zxing.oned.rss.expanded;
28
29 import java.awt.image.BufferedImage;
30 import java.io.File;
31 import java.util.Hashtable;
32
33 import javax.imageio.ImageIO;
34
35 import junit.framework.TestCase;
36
37 import com.google.zxing.BarcodeFormat;
38 import com.google.zxing.BinaryBitmap;
39 import com.google.zxing.Result;
40 import com.google.zxing.client.j2se.BufferedImageLuminanceSource;
41 import com.google.zxing.common.BitArray;
42 import com.google.zxing.common.GlobalHistogramBinarizer;
43
44 /**
45  * @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
46  * @author Eduardo Castillejo, University of Deusto (eduardo.castillejo@deusto.es)
47  */
48 public final class RSSExpandedImage2stringTestCase extends TestCase {
49
50   public void testDecodeRow2string_1() throws Exception{
51     String path = "test/data/blackbox/rssexpanded-1/1.jpg";
52     String expected = "(11)100224(17)110224(3102)000100";
53
54     assertCorrectImage2string(path, expected);
55   }
56
57   public void testDecodeRow2string_2() throws Exception{
58     String path = "test/data/blackbox/rssexpanded-1/2.jpg";
59     String expected = "(01)90012345678908(3103)001750";
60
61     assertCorrectImage2string(path, expected);
62   }
63
64   public void testDecodeRow2string_3() throws Exception{
65     String path = "test/data/blackbox/rssexpanded-1/3.jpg";
66     String expected = "(10)12A";
67
68     assertCorrectImage2string(path, expected);
69   }
70
71   public void testDecodeRow2string_4() throws Exception{
72     String path = "test/data/blackbox/rssexpanded-1/4.jpg";
73     String expected = "(01)98898765432106(3202)012345(15)991231";
74
75     assertCorrectImage2string(path, expected);
76   }
77
78   public void testDecodeRow2string_5() throws Exception{
79     String path = "test/data/blackbox/rssexpanded-1/5.jpg";
80     String expected = "(01)90614141000015(3202)000150";
81
82     assertCorrectImage2string(path, expected);
83   }
84
85   public void testDecodeRow2string_7() throws Exception{
86     String path = "test/data/blackbox/rssexpanded-1/7.png";
87     String expected = "(10)567(11)010101";
88
89     assertCorrectImage2string(path, expected);
90   }
91
92   public void testDecodeRow2string_10() throws Exception{
93     String path = "test/data/blackbox/rssexpanded-1/10.png";
94     String expected = "(01)98898765432106(15)991231(3103)001750(10)12A(422)123(21)123456(423)012345678901";
95
96     assertCorrectImage2string(path, expected);
97   }
98
99   public void testDecodeRow2string_11() throws Exception{
100     String expected = "(01)98898765432106(15)991231(3103)001750(10)12A(422)123(21)123456";
101     String path = "test/data/blackbox/rssexpanded-1/11.png";
102
103     assertCorrectImage2string(path, expected);
104   }
105
106   public void testDecodeRow2string_12() throws Exception{
107     String expected = "(01)98898765432106(3103)001750";
108     String path = "test/data/blackbox/rssexpanded-1/12.jpg";
109
110     assertCorrectImage2string(path, expected);
111   }
112
113   public void testDecodeRow2string_13() throws Exception{
114     String expected = "(01)90012345678908(3922)795";
115     String path = "test/data/blackbox/rssexpanded-1/13.png";
116
117     assertCorrectImage2string(path, expected);
118   }
119
120   public void testDecodeRow2string_14() throws Exception{
121     String expected = "(01)90012345678908(3932)0401234";
122     String path = "test/data/blackbox/rssexpanded-1/14.png";
123
124     assertCorrectImage2string(path, expected);
125   }
126
127   public void testDecodeRow2string_15() throws Exception{
128     String expected = "(01)90012345678908(3102)001750(11)100312";
129     String path = "test/data/blackbox/rssexpanded-1/15.jpg";
130
131     assertCorrectImage2string(path, expected);
132   }
133
134   public void testDecodeRow2string_16() throws Exception{
135     String expected = "(01)90012345678908(3202)001750(11)100312";
136     String path = "test/data/blackbox/rssexpanded-1/16.jpg";
137
138     assertCorrectImage2string(path, expected);
139   }
140
141   public void testDecodeRow2string_17() throws Exception{
142     String expected = "(01)90012345678908(3102)001750(13)100312";
143     String path = "test/data/blackbox/rssexpanded-1/17.jpg";
144
145     assertCorrectImage2string(path, expected);
146   }
147
148   public void testDecodeRow2string_18() throws Exception{
149     String expected = "(01)90012345678908(3202)001750(13)100312";
150     String path = "test/data/blackbox/rssexpanded-1/18.jpg";
151
152     assertCorrectImage2string(path, expected);
153   }
154
155   public void testDecodeRow2string_19() throws Exception{
156     String expected = "(01)90012345678908(3102)001750(15)100312";
157     String path = "test/data/blackbox/rssexpanded-1/19.jpg";
158
159     assertCorrectImage2string(path, expected);
160   }
161
162   public void testDecodeRow2string_20() throws Exception{
163     String expected = "(01)90012345678908(3202)001750(15)100312";
164     String path = "test/data/blackbox/rssexpanded-1/20.jpg";
165
166     assertCorrectImage2string(path, expected);
167   }
168
169   public void testDecodeRow2string_21() throws Exception{
170     String expected = "(01)90012345678908(3102)001750(17)100312";
171     String path = "test/data/blackbox/rssexpanded-1/21.jpg";
172
173     assertCorrectImage2string(path, expected);
174   }
175
176   public void testDecodeRow2string_22() throws Exception{
177     String expected = "(01)90012345678908(3202)001750(17)100312";
178     String path = "test/data/blackbox/rssexpanded-1/22.jpg";
179
180     assertCorrectImage2string(path, expected);
181   }
182
183   public void testDecodeRow2string_25() throws Exception{
184     String expected = "(10)123";
185     String path = "test/data/blackbox/rssexpanded-1/25.png";
186
187     assertCorrectImage2string(path, expected);
188   }
189
190   public void testDecodeRow2string_26() throws Exception{
191     String expected = "(10)5678(11)010101";
192     String path = "test/data/blackbox/rssexpanded-1/26.png";
193
194     assertCorrectImage2string(path, expected);
195   }
196
197   public void testDecodeRow2string_27() throws Exception{
198     String expected = "(10)1098-1234";
199     String path = "test/data/blackbox/rssexpanded-1/27.png";
200
201     assertCorrectImage2string(path, expected);
202   }
203
204   public void testDecodeRow2string_28() throws Exception{
205     String expected = "(10)1098/1234";
206     String path = "test/data/blackbox/rssexpanded-1/28.png";
207
208     assertCorrectImage2string(path, expected);
209   }
210
211   public void testDecodeRow2string_29() throws Exception{
212     String expected = "(10)1098.1234";
213     String path = "test/data/blackbox/rssexpanded-1/29.png";
214
215     assertCorrectImage2string(path, expected);
216   }
217
218   public void testDecodeRow2string_30() throws Exception{
219     String expected = "(10)1098*1234";
220     String path = "test/data/blackbox/rssexpanded-1/30.png";
221
222     assertCorrectImage2string(path, expected);
223   }
224
225   public void testDecodeRow2string_31() throws Exception{
226     String expected = "(10)1098,1234";
227     String path = "test/data/blackbox/rssexpanded-1/31.png";
228
229     assertCorrectImage2string(path, expected);
230   }
231
232   public void testDecodeRow2string_32() throws Exception{
233     String expected = "(15)991231(3103)001750(10)12A(422)123(21)123456(423)0123456789012";
234     String path = "test/data/blackbox/rssexpanded-1/32.png";
235
236     assertCorrectImage2string(path, expected);
237   }
238
239   private static void assertCorrectImage2string(String path, String expected) throws Exception {
240     RSSExpandedReader rssExpandedReader = new RSSExpandedReader();
241
242     BufferedImage image = ImageIO.read(new File(path));
243     BinaryBitmap binaryMap = new BinaryBitmap(new GlobalHistogramBinarizer(new BufferedImageLuminanceSource(image)));
244     int rowNumber = binaryMap.getHeight() / 2;
245     BitArray row = binaryMap.getBlackRow(rowNumber, null);
246
247     Result result = rssExpandedReader.decodeRow(rowNumber, row, new Hashtable());
248
249     assertEquals(BarcodeFormat.RSS_EXPANDED, result.getBarcodeFormat());
250     assertEquals(expected, result.getText());
251   }
252
253 }