2 * Copyright (C) 2010 ZXing authors
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
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/ ):
24 * http://www.piramidepse.com/
27 package com.google.zxing.oned.rss.expanded;
29 import java.awt.image.BufferedImage;
31 import java.util.Hashtable;
33 import javax.imageio.ImageIO;
35 import junit.framework.TestCase;
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;
45 * @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
46 * @author Eduardo Castillejo, University of Deusto (eduardo.castillejo@deusto.es)
48 public final class RSSExpandedImage2stringTestCase extends TestCase {
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";
54 assertCorrectImage2string(path, expected);
57 public void testDecodeRow2string_2() throws Exception{
58 String path = "test/data/blackbox/rssexpanded-1/2.jpg";
59 String expected = "(01)90012345678908(3103)001750";
61 assertCorrectImage2string(path, expected);
64 public void testDecodeRow2string_3() throws Exception{
65 String path = "test/data/blackbox/rssexpanded-1/3.jpg";
66 String expected = "(10)12A";
68 assertCorrectImage2string(path, expected);
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";
75 assertCorrectImage2string(path, expected);
78 public void testDecodeRow2string_5() throws Exception{
79 String path = "test/data/blackbox/rssexpanded-1/5.jpg";
80 String expected = "(01)90614141000015(3202)000150";
82 assertCorrectImage2string(path, expected);
85 public void testDecodeRow2string_7() throws Exception{
86 String path = "test/data/blackbox/rssexpanded-1/7.png";
87 String expected = "(10)567(11)010101";
89 assertCorrectImage2string(path, expected);
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";
96 assertCorrectImage2string(path, expected);
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";
103 assertCorrectImage2string(path, expected);
106 public void testDecodeRow2string_12() throws Exception{
107 String expected = "(01)98898765432106(3103)001750";
108 String path = "test/data/blackbox/rssexpanded-1/12.jpg";
110 assertCorrectImage2string(path, expected);
113 public void testDecodeRow2string_13() throws Exception{
114 String expected = "(01)90012345678908(3922)795";
115 String path = "test/data/blackbox/rssexpanded-1/13.png";
117 assertCorrectImage2string(path, expected);
120 public void testDecodeRow2string_14() throws Exception{
121 String expected = "(01)90012345678908(3932)0401234";
122 String path = "test/data/blackbox/rssexpanded-1/14.png";
124 assertCorrectImage2string(path, expected);
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";
131 assertCorrectImage2string(path, expected);
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";
138 assertCorrectImage2string(path, expected);
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";
145 assertCorrectImage2string(path, expected);
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";
152 assertCorrectImage2string(path, expected);
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";
159 assertCorrectImage2string(path, expected);
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";
166 assertCorrectImage2string(path, expected);
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";
173 assertCorrectImage2string(path, expected);
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";
180 assertCorrectImage2string(path, expected);
183 public void testDecodeRow2string_25() throws Exception{
184 String expected = "(10)123";
185 String path = "test/data/blackbox/rssexpanded-1/25.png";
187 assertCorrectImage2string(path, expected);
190 public void testDecodeRow2string_26() throws Exception{
191 String expected = "(10)5678(11)010101";
192 String path = "test/data/blackbox/rssexpanded-1/26.png";
194 assertCorrectImage2string(path, expected);
197 public void testDecodeRow2string_27() throws Exception{
198 String expected = "(10)1098-1234";
199 String path = "test/data/blackbox/rssexpanded-1/27.png";
201 assertCorrectImage2string(path, expected);
204 public void testDecodeRow2string_28() throws Exception{
205 String expected = "(10)1098/1234";
206 String path = "test/data/blackbox/rssexpanded-1/28.png";
208 assertCorrectImage2string(path, expected);
211 public void testDecodeRow2string_29() throws Exception{
212 String expected = "(10)1098.1234";
213 String path = "test/data/blackbox/rssexpanded-1/29.png";
215 assertCorrectImage2string(path, expected);
218 public void testDecodeRow2string_30() throws Exception{
219 String expected = "(10)1098*1234";
220 String path = "test/data/blackbox/rssexpanded-1/30.png";
222 assertCorrectImage2string(path, expected);
225 public void testDecodeRow2string_31() throws Exception{
226 String expected = "(10)1098,1234";
227 String path = "test/data/blackbox/rssexpanded-1/31.png";
229 assertCorrectImage2string(path, expected);
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";
236 assertCorrectImage2string(path, expected);
239 private static void assertCorrectImage2string(String path, String expected) throws Exception {
240 RSSExpandedReader rssExpandedReader = new RSSExpandedReader();
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);
247 Result result = rssExpandedReader.decodeRow(rowNumber, row, new Hashtable());
249 assertEquals(BarcodeFormat.RSS_EXPANDED, result.getBarcodeFormat());
250 assertEquals(expected, result.getText());