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 com.google.zxing.common.BitArray;
31 import junit.framework.TestCase;
34 * @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
36 public final class BinaryUtilTest extends TestCase{
38 public void testBuildBitArrayFromString(){
40 String data = " ..X..X.. ..XXX... XXXXXXXX ........";
49 data = " ....XX.. ..XX";
52 data = " ....XX.. ..XX..XX ....X.X. ........";
56 private static void check(String data){
57 BitArray binary = BinaryUtil.buildBitArrayFromString(data);
58 assertEquals(data, binary.toString());
61 public void testBuildBitArrayFromStringWithoutSpaces(){
64 data = " ..X..X.. ..XXX... XXXXXXXX ........";
65 checkWithoutSpaces(data);
68 checkWithoutSpaces(data);
71 checkWithoutSpaces(data);
73 data = " ....XX.. ..XX";
74 checkWithoutSpaces(data);
76 data = " ....XX.. ..XX..XX ....X.X. ........";
77 checkWithoutSpaces(data);
80 private static void checkWithoutSpaces(String data){
81 String dataWithoutSpaces = data.replaceAll(" ", "");
82 BitArray binary = BinaryUtil.buildBitArrayFromStringWithoutSpaces(dataWithoutSpaces);
83 assertEquals(data, binary.toString());