Small style stuff
[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.io.IOException;
32 import java.util.Hashtable;
33
34 import javax.imageio.ImageIO;
35
36 import com.google.zxing.BarcodeFormat;
37 import com.google.zxing.BinaryBitmap;
38 import com.google.zxing.NotFoundException;
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 import org.junit.Assert;
44 import org.junit.Test;
45
46 /**
47  * @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
48  * @author Eduardo Castillejo, University of Deusto (eduardo.castillejo@deusto.es)
49  */
50 public final class RSSExpandedImage2stringTestCase extends Assert {
51
52   @Test
53   public void testDecodeRow2string_1() throws Exception {
54     String path = "test/data/blackbox/rssexpanded-1/1.jpg";
55     String expected = "(11)100224(17)110224(3102)000100";
56
57     assertCorrectImage2string(path, expected);
58   }
59
60   @Test
61   public void testDecodeRow2string_2() throws Exception {
62     String path = "test/data/blackbox/rssexpanded-1/2.jpg";
63     String expected = "(01)90012345678908(3103)001750";
64
65     assertCorrectImage2string(path, expected);
66   }
67
68   @Test
69   public void testDecodeRow2string_3() throws Exception {
70     String path = "test/data/blackbox/rssexpanded-1/3.jpg";
71     String expected = "(10)12A";
72
73     assertCorrectImage2string(path, expected);
74   }
75
76   @Test
77   public void testDecodeRow2string_4() throws Exception {
78     String path = "test/data/blackbox/rssexpanded-1/4.jpg";
79     String expected = "(01)98898765432106(3202)012345(15)991231";
80
81     assertCorrectImage2string(path, expected);
82   }
83
84   @Test
85   public void testDecodeRow2string_5() throws Exception {
86     String path = "test/data/blackbox/rssexpanded-1/5.jpg";
87     String expected = "(01)90614141000015(3202)000150";
88
89     assertCorrectImage2string(path, expected);
90   }
91
92   @Test
93   public void testDecodeRow2string_7() throws Exception {
94     String path = "test/data/blackbox/rssexpanded-1/7.png";
95     String expected = "(10)567(11)010101";
96
97     assertCorrectImage2string(path, expected);
98   }
99
100   @Test
101   public void testDecodeRow2string_10() throws Exception {
102     String path = "test/data/blackbox/rssexpanded-1/10.png";
103     String expected = "(01)98898765432106(15)991231(3103)001750(10)12A(422)123(21)123456(423)012345678901";
104
105     assertCorrectImage2string(path, expected);
106   }
107
108   @Test
109   public void testDecodeRow2string_11() throws Exception {
110     String expected = "(01)98898765432106(15)991231(3103)001750(10)12A(422)123(21)123456";
111     String path = "test/data/blackbox/rssexpanded-1/11.png";
112
113     assertCorrectImage2string(path, expected);
114   }
115
116   @Test
117   public void testDecodeRow2string_12() throws Exception {
118     String expected = "(01)98898765432106(3103)001750";
119     String path = "test/data/blackbox/rssexpanded-1/12.jpg";
120
121     assertCorrectImage2string(path, expected);
122   }
123
124   @Test
125   public void testDecodeRow2string_13() throws Exception {
126     String expected = "(01)90012345678908(3922)795";
127     String path = "test/data/blackbox/rssexpanded-1/13.png";
128
129     assertCorrectImage2string(path, expected);
130   }
131
132   @Test
133   public void testDecodeRow2string_14() throws Exception {
134     String expected = "(01)90012345678908(3932)0401234";
135     String path = "test/data/blackbox/rssexpanded-1/14.png";
136
137     assertCorrectImage2string(path, expected);
138   }
139
140   @Test
141   public void testDecodeRow2string_15() throws Exception {
142     String expected = "(01)90012345678908(3102)001750(11)100312";
143     String path = "test/data/blackbox/rssexpanded-1/15.jpg";
144
145     assertCorrectImage2string(path, expected);
146   }
147
148   @Test
149   public void testDecodeRow2string_16() throws Exception {
150     String expected = "(01)90012345678908(3202)001750(11)100312";
151     String path = "test/data/blackbox/rssexpanded-1/16.jpg";
152
153     assertCorrectImage2string(path, expected);
154   }
155
156   @Test
157   public void testDecodeRow2string_17() throws Exception {
158     String expected = "(01)90012345678908(3102)001750(13)100312";
159     String path = "test/data/blackbox/rssexpanded-1/17.jpg";
160
161     assertCorrectImage2string(path, expected);
162   }
163
164   @Test
165   public void testDecodeRow2string_18() throws Exception {
166     String expected = "(01)90012345678908(3202)001750(13)100312";
167     String path = "test/data/blackbox/rssexpanded-1/18.jpg";
168
169     assertCorrectImage2string(path, expected);
170   }
171
172   @Test
173   public void testDecodeRow2string_19() throws Exception {
174     String expected = "(01)90012345678908(3102)001750(15)100312";
175     String path = "test/data/blackbox/rssexpanded-1/19.jpg";
176
177     assertCorrectImage2string(path, expected);
178   }
179
180   @Test
181   public void testDecodeRow2string_20() throws Exception {
182     String expected = "(01)90012345678908(3202)001750(15)100312";
183     String path = "test/data/blackbox/rssexpanded-1/20.jpg";
184
185     assertCorrectImage2string(path, expected);
186   }
187
188   @Test
189   public void testDecodeRow2string_21() throws Exception {
190     String expected = "(01)90012345678908(3102)001750(17)100312";
191     String path = "test/data/blackbox/rssexpanded-1/21.jpg";
192
193     assertCorrectImage2string(path, expected);
194   }
195
196   @Test
197   public void testDecodeRow2string_22() throws Exception {
198     String expected = "(01)90012345678908(3202)001750(17)100312";
199     String path = "test/data/blackbox/rssexpanded-1/22.jpg";
200
201     assertCorrectImage2string(path, expected);
202   }
203
204   @Test
205   public void testDecodeRow2string_25() throws Exception {
206     String expected = "(10)123";
207     String path = "test/data/blackbox/rssexpanded-1/25.png";
208
209     assertCorrectImage2string(path, expected);
210   }
211
212   @Test
213   public void testDecodeRow2string_26() throws Exception {
214     String expected = "(10)5678(11)010101";
215     String path = "test/data/blackbox/rssexpanded-1/26.png";
216
217     assertCorrectImage2string(path, expected);
218   }
219
220   @Test
221   public void testDecodeRow2string_27() throws Exception {
222     String expected = "(10)1098-1234";
223     String path = "test/data/blackbox/rssexpanded-1/27.png";
224
225     assertCorrectImage2string(path, expected);
226   }
227
228   @Test
229   public void testDecodeRow2string_28() throws Exception {
230     String expected = "(10)1098/1234";
231     String path = "test/data/blackbox/rssexpanded-1/28.png";
232
233     assertCorrectImage2string(path, expected);
234   }
235
236   @Test
237   public void testDecodeRow2string_29() throws Exception {
238     String expected = "(10)1098.1234";
239     String path = "test/data/blackbox/rssexpanded-1/29.png";
240
241     assertCorrectImage2string(path, expected);
242   }
243
244   @Test
245   public void testDecodeRow2string_30() throws Exception {
246     String expected = "(10)1098*1234";
247     String path = "test/data/blackbox/rssexpanded-1/30.png";
248
249     assertCorrectImage2string(path, expected);
250   }
251
252   @Test
253   public void testDecodeRow2string_31() throws Exception {
254     String expected = "(10)1098,1234";
255     String path = "test/data/blackbox/rssexpanded-1/31.png";
256
257     assertCorrectImage2string(path, expected);
258   }
259
260   @Test
261   public void testDecodeRow2string_32() throws Exception {
262     String expected = "(15)991231(3103)001750(10)12A(422)123(21)123456(423)0123456789012";
263     String path = "test/data/blackbox/rssexpanded-1/32.png";
264
265     assertCorrectImage2string(path, expected);
266   }
267
268   private static void assertCorrectImage2string(String path, String expected) throws IOException, NotFoundException {
269     RSSExpandedReader rssExpandedReader = new RSSExpandedReader();
270
271     BufferedImage image = ImageIO.read(new File(path));
272     BinaryBitmap binaryMap = new BinaryBitmap(new GlobalHistogramBinarizer(new BufferedImageLuminanceSource(image)));
273     int rowNumber = binaryMap.getHeight() / 2;
274     BitArray row = binaryMap.getBlackRow(rowNumber, null);
275
276     Result result = rssExpandedReader.decodeRow(rowNumber, row, new Hashtable());
277
278     assertSame(BarcodeFormat.RSS_EXPANDED, result.getBarcodeFormat());
279     assertEquals(expected, result.getText());
280   }
281
282 }