29a5b28241719420e67595ed2bec0080766601cb
[zxing.git] / core / test / src / com / google / zxing / oned / rss / expanded / decoders / AbstractDecoderTest.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.decoders;
28
29 import com.google.zxing.NotFoundException;
30 import com.google.zxing.common.BitArray;
31 import com.google.zxing.oned.rss.expanded.BinaryUtil;
32
33 import junit.framework.TestCase;
34
35 /**
36  * @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
37  */
38 public abstract class AbstractDecoderTest extends TestCase {
39
40         protected static final String numeric_10                     = "..X..XX";
41         protected static final String numeric_12                     = "..X.X.X";
42         protected static final String numeric_1FNC1                  = "..XXX.X";
43         protected static final String numeric_FNC11                  = "XXX.XXX";
44                                                                      
45         protected static final String numeric2alpha                  = "....";
46                                                                      
47         protected static final String alpha_A                        = "X.....";
48         protected static final String alpha_FNC1                      = ".XXXX";
49         protected static final String alpha2numeric                  = "...";
50         protected static final String alpha2isoiec646                = "..X..";
51                                                                      
52         protected static final String i646_B                         = "X.....X";
53         protected static final String i646_C                         = "X....X.";
54         protected static final String i646_FNC1                      = ".XXXX";
55         protected static final String isoiec646_2alpha               = "..X..";
56         
57         protected static final String compressedGtin_900123456798908 = ".........X..XXX.X.X.X...XX.XXXXX.XXXX.X.";
58         protected static final String compressedGtin_900000000000008 = "........................................";
59         
60         protected static final String compressed15bitWeight_1750     = "....XX.XX.X.XX.";
61         protected static final String compressed15bitWeight_11750    = ".X.XX.XXXX..XX.";
62         protected static final String compressed15bitWeight_0        = "...............";
63         
64         protected static final String compressed20bitWeight_1750     = ".........XX.XX.X.XX.";
65         
66         protected static final String compressedDate_March_12th_2010 = "....XXXX.X..XX..";
67         protected static final String compressedDate_End             = "X..X.XX.........";
68
69         protected void assertCorrectBinaryString(String binaryString, String expectedNumber) throws NotFoundException {
70                 BitArray binary = BinaryUtil.buildBitArrayFromStringWithoutSpaces(binaryString);
71                 AbstractExpandedDecoder decoder = AbstractExpandedDecoder.createDecoder(binary);
72                 String result = decoder.parseInformation();
73                 assertEquals(expectedNumber, result);
74         }
75 }