Backing out this change for the Droid on suspicion that it's interfering with at...
[zxing.git] / core / test / src / com / google / zxing / qrcode / decoder / DecodedBitStreamParserTestCase.java
1 /*
2  * Copyright 2008 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.qrcode.decoder;
18
19 import com.google.zxing.common.BitSourceBuilder;
20 import junit.framework.TestCase;
21
22 /**
23  * Tests {@link com.google.zxing.qrcode.decoder.DecodedBitStreamParser}.
24  *
25  * @author Sean Owen
26  */
27 public final class DecodedBitStreamParserTestCase extends TestCase {
28
29   public void testSimpleByteMode() throws Exception {
30     BitSourceBuilder builder = new BitSourceBuilder();
31     builder.write(0x04, 4); // Byte mode
32     builder.write(0x03, 8); // 3 bytes
33     builder.write(0xF1, 8);
34     builder.write(0xF2, 8);
35     builder.write(0xF3, 8);
36     String result = DecodedBitStreamParser.decode(builder.toByteArray(),
37         Version.getVersionForNumber(1), null, null).getText();
38     assertEquals("\u00f1\u00f2\u00f3", result);
39   }
40
41   public void testSimpleSJIS() throws Exception {
42     BitSourceBuilder builder = new BitSourceBuilder();
43     builder.write(0x04, 4); // Byte mode
44     builder.write(0x03, 8); // 3 bytes
45     builder.write(0xA1, 8);
46     builder.write(0xA2, 8);
47     builder.write(0xA3, 8);
48     String result = DecodedBitStreamParser.decode(builder.toByteArray(),
49         Version.getVersionForNumber(1), null, null).getText();
50     assertEquals("\uff61\uff62\uff63", result);
51   }
52
53   public void testECI() throws Exception {
54     BitSourceBuilder builder = new BitSourceBuilder();
55     builder.write(0x07, 4); // ECI mode
56     builder.write(0x02, 8); // ECI 2 = CP437 encoding
57     builder.write(0x04, 4); // Byte mode
58     builder.write(0x03, 8); // 3 bytes
59     builder.write(0xA1, 8);
60     builder.write(0xA2, 8);
61     builder.write(0xA3, 8);
62     String result = DecodedBitStreamParser.decode(builder.toByteArray(),
63         Version.getVersionForNumber(1), null, null).getText();
64     assertEquals("\u00ed\u00f3\u00fa", result);
65   }
66
67   // TODO definitely need more tests here
68
69 }