At last update to JUnit 4.x
[zxing.git] / core / test / src / com / google / zxing / oned / rss / expanded / RSSExpandedImage2binaryTestCase.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.Vector;
33
34 import javax.imageio.ImageIO;
35
36 import com.google.zxing.BinaryBitmap;
37 import com.google.zxing.NotFoundException;
38 import com.google.zxing.client.j2se.BufferedImageLuminanceSource;
39 import com.google.zxing.common.BitArray;
40 import com.google.zxing.common.GlobalHistogramBinarizer;
41 import org.junit.Assert;
42 import org.junit.Test;
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 RSSExpandedImage2binaryTestCase extends Assert {
49
50   @Test
51   public void testDecodeRow2binary_1() throws Exception {
52     // (11)100224(17)110224(3102)000100
53     String path = "test/data/blackbox/rssexpanded-1/1.jpg";
54     String expected = " ...X...X .X....X. .XX...X. X..X...X ...XX.X. ..X.X... ..X.X..X ...X..X. X.X....X .X....X. .....X.. X...X...";
55
56     assertCorrectImage2binary(path, expected);
57   }
58
59   @Test
60   public void testDecodeRow2binary_2() throws Exception {
61     // (01)90012345678908(3103)001750
62     String path = "test/data/blackbox/rssexpanded-1/2.jpg";
63     String expected = " ..X..... ......X. .XXX.X.X .X...XX. XXXXX.XX XX.X.... .XX.XX.X .XX.";
64
65     assertCorrectImage2binary(path, expected);
66
67   }
68
69   @Test
70   public void testDecodeRow2binary_3() throws Exception {
71     // (10)12A
72     String path = "test/data/blackbox/rssexpanded-1/3.jpg";
73     String expected = " .......X ..XX..X. X.X....X .......X ....";
74
75     assertCorrectImage2binary(path, expected);
76   }
77
78   @Test
79   public void testDecodeRow2binary_4() throws Exception {
80     // (01)98898765432106(3202)012345(15)991231
81     String path = "test/data/blackbox/rssexpanded-1/4.jpg";
82     String expected = " ..XXXX.X XX.XXXX. .XXX.XX. XX..X... .XXXXX.. XX.X..X. ..XX..XX XX.X.XXX X..XX..X .X.XXXXX XXXX";
83
84     assertCorrectImage2binary(path, expected);
85   }
86
87   @Test
88   public void testDecodeRow2binary_5() throws Exception {
89     // (01)90614141000015(3202)000150
90     String path = "test/data/blackbox/rssexpanded-1/5.jpg";
91     String expected = " ..X.X... .XXXX.X. XX..XXXX ....XX.. X....... ....X... ....X..X .XX.";
92
93     assertCorrectImage2binary(path, expected);
94   }
95
96   @Test
97   public void testDecodeRow2binary_10() throws Exception {
98     // (01)98898765432106(15)991231(3103)001750(10)12A(422)123(21)123456(423)0123456789012
99     String path = "test/data/blackbox/rssexpanded-1/10.png";
100     String expected = " .X.XX..X XX.XXXX. .XXX.XX. XX..X... .XXXXX.. XX.X..X. ..XX...X XX.X.... X.X.X.X. X.X..X.X .X....X. XX...X.. ...XX.X. .XXXXXX. .X..XX.. X.X.X... .X...... XXXX.... XX.XX... XXXXX.X. ...XXXXX .....X.X ...X.... X.XXX..X X.X.X... XX.XX..X .X..X..X .X.X.X.X X.XX...X .XX.XXX. XXX.X.XX ..X.";
101
102     assertCorrectImage2binary(path, expected);
103   }
104
105   @Test
106   public void testDecodeRow2binary_11() throws Exception {
107     // (01)98898765432106(15)991231(3103)001750(10)12A(422)123(21)123456
108     String expected = " .X.XX..X XX.XXXX. .XXX.XX. XX..X... .XXXXX.. XX.X..X. ..XX...X XX.X.... X.X.X.X. X.X..X.X .X....X. XX...X.. ...XX.X. .XXXXXX. .X..XX.. X.X.X... .X...... XXXX.... XX.XX... XXXXX.X. ...XXXXX .....X.X ...X.... X.XXX..X X.X.X... ....";
109     String path = "test/data/blackbox/rssexpanded-1/11.png";
110
111     assertCorrectImage2binary(path, expected);
112   }
113
114   @Test
115   public void testDecodeRow2binary_12() throws Exception {
116     // (01)98898765432106(3103)001750
117
118     String expected = " ..X..XX. XXXX..XX X.XX.XX. .X....XX XXX..XX. X..X.... .XX.XX.X .XX.";
119     String path = "test/data/blackbox/rssexpanded-1/12.jpg";
120
121     assertCorrectImage2binary(path, expected);
122   }
123
124   @Test
125   public void testDecodeRow2binary_13() throws Exception {
126     // (01)90012345678908(3922)795
127
128     String expected = " ..XX..X. ........ .X..XXX. X.X.X... XX.XXXXX .XXXX.X. X.X.XXXX .X..X..X ......X.";
129     String path = "test/data/blackbox/rssexpanded-1/13.png";
130
131     assertCorrectImage2binary(path, expected);
132   }
133
134   @Test
135   public void testDecodeRow2binary_14() throws Exception {
136     // (01)90012345678908(3932)0401234
137
138     String expected = " ..XX.X.. ........ .X..XXX. X.X.X... XX.XXXXX .XXXX.X. X.....X. X.....X. X.X.X.XX .X...... X...";
139     String path = "test/data/blackbox/rssexpanded-1/14.png";
140
141     assertCorrectImage2binary(path, expected);
142   }
143
144   @Test
145   public void testDecodeRow2binary_15() throws Exception {
146     // (01)90012345678908(3102)001750(11)100312
147
148     String expected = " ..XXX... ........ .X..XXX. X.X.X... XX.XXXXX .XXXX.X. ..XX...X .X.....X .XX..... XXXX.X.. XX..";
149     String path = "test/data/blackbox/rssexpanded-1/15.jpg";
150
151     assertCorrectImage2binary(path, expected);
152   }
153
154   @Test
155   public void testDecodeRow2binary_16() throws Exception {
156     // (01)90012345678908(3202)001750(11)100312
157
158     String expected = " ..XXX..X ........ .X..XXX. X.X.X... XX.XXXXX .XXXX.X. ..XX...X .X.....X .XX..... XXXX.X.. XX..";
159     String path = "test/data/blackbox/rssexpanded-1/16.jpg";
160
161     assertCorrectImage2binary(path, expected);
162   }
163
164   @Test
165   public void testDecodeRow2binary_17() throws Exception {
166     // (01)90012345678908(3102)001750(13)100312
167
168     String expected = " ..XXX.X. ........ .X..XXX. X.X.X... XX.XXXXX .XXXX.X. ..XX...X .X.....X .XX..... XXXX.X.. XX..";
169     String path = "test/data/blackbox/rssexpanded-1/17.jpg";
170
171     assertCorrectImage2binary(path, expected);
172   }
173
174   @Test
175   public void testDecodeRow2binary_18() throws Exception {
176     // (01)90012345678908(3202)001750(13)100312
177
178     String expected = " ..XXX.XX ........ .X..XXX. X.X.X... XX.XXXXX .XXXX.X. ..XX...X .X.....X .XX..... XXXX.X.. XX..";
179     String path = "test/data/blackbox/rssexpanded-1/18.jpg";
180
181     assertCorrectImage2binary(path, expected);
182   }
183
184   @Test
185   public void testDecodeRow2binary_19() throws Exception {
186     // (01)90012345678908(3102)001750(15)100312
187
188     String expected = " ..XXXX.. ........ .X..XXX. X.X.X... XX.XXXXX .XXXX.X. ..XX...X .X.....X .XX..... XXXX.X.. XX..";
189     String path = "test/data/blackbox/rssexpanded-1/19.jpg";
190
191     assertCorrectImage2binary(path, expected);
192   }
193
194   @Test
195   public void testDecodeRow2binary_20() throws Exception {
196     // (01)90012345678908(3202)001750(15)100312
197
198     String expected = " ..XXXX.X ........ .X..XXX. X.X.X... XX.XXXXX .XXXX.X. ..XX...X .X.....X .XX..... XXXX.X.. XX..";
199     String path = "test/data/blackbox/rssexpanded-1/20.jpg";
200
201     assertCorrectImage2binary(path, expected);
202   }
203
204   @Test
205   public void testDecodeRow2binary_21() throws Exception {
206     // (01)90012345678908(3102)001750(17)100312
207
208     String expected = " ..XXXXX. ........ .X..XXX. X.X.X... XX.XXXXX .XXXX.X. ..XX...X .X.....X .XX..... XXXX.X.. XX..";
209     String path = "test/data/blackbox/rssexpanded-1/21.jpg";
210
211     assertCorrectImage2binary(path, expected);
212   }
213
214   @Test
215   public void testDecodeRow2binary_22() throws Exception {
216     // (01)90012345678908(3202)001750(17)100312
217
218     String expected = " ..XXXXXX ........ .X..XXX. X.X.X... XX.XXXXX .XXXX.X. ..XX...X .X.....X .XX..... XXXX.X.. XX..";
219     String path = "test/data/blackbox/rssexpanded-1/22.jpg";
220
221     assertCorrectImage2binary(path, expected);
222   }
223
224   private static void assertCorrectImage2binary(String path, String expected) throws IOException, NotFoundException {
225     RSSExpandedReader rssExpandedReader = new RSSExpandedReader();
226
227     BufferedImage image = ImageIO.read(new File(path));
228     BinaryBitmap binaryMap = new BinaryBitmap(new GlobalHistogramBinarizer(new BufferedImageLuminanceSource(image)));
229     int rowNumber = binaryMap.getHeight() / 2;
230     BitArray row = binaryMap.getBlackRow(rowNumber, null);
231
232     Vector<ExpandedPair> pairs = rssExpandedReader.decodeRow2pairs(rowNumber, row);
233     BitArray binary = BitArrayBuilder.buildBitArray(pairs);
234     assertEquals(expected, binary.toString());
235   }
236 }