9b5339011c3054bd28103ecdc80c39159aaa470f
[zxing.git] / core / test / src / com / google / zxing / common / BitSourceTestCase.java
1 /*
2  * Copyright 2007 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 package com.google.zxing.common;
18
19 import junit.framework.TestCase;
20
21 /**
22  * @author Sean Owen
23  */
24 public final class BitSourceTestCase extends TestCase {
25
26   public void testSource() {
27     byte[] bytes = {(byte) 1, (byte) 2, (byte) 3, (byte) 4, (byte) 5};
28     BitSource source = new BitSource(bytes);
29     assertEquals(40, source.available());
30     assertEquals(0, source.readBits(1));
31     assertEquals(39, source.available());
32     assertEquals(0, source.readBits(6));
33     assertEquals(33, source.available());
34     assertEquals(1, source.readBits(1));
35     assertEquals(32, source.available());
36     assertEquals(2, source.readBits(8));
37     assertEquals(24, source.available());
38     assertEquals(12, source.readBits(10));
39     assertEquals(14, source.available());
40     assertEquals(16, source.readBits(8));
41     assertEquals(6, source.available());
42     assertEquals(5, source.readBits(6));
43     assertEquals(0, source.available());
44   }
45
46 }