Move character encoding logic out to common, try again to improve its handling of...
[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(0x04, 8); // 4 bytes
45     builder.write(0xA1, 8);
46     builder.write(0xA2, 8);
47     builder.write(0xA3, 8);
48     builder.write(0xD0, 8);
49     String result = DecodedBitStreamParser.decode(builder.toByteArray(),
50         Version.getVersionForNumber(1), null, null).getText();
51     assertEquals("\uff61\uff62\uff63\uff90", result);
52   }
53
54   public void testECI() throws Exception {
55     BitSourceBuilder builder = new BitSourceBuilder();
56     builder.write(0x07, 4); // ECI mode
57     builder.write(0x02, 8); // ECI 2 = CP437 encoding
58     builder.write(0x04, 4); // Byte mode
59     builder.write(0x03, 8); // 3 bytes
60     builder.write(0xA1, 8);
61     builder.write(0xA2, 8);
62     builder.write(0xA3, 8);
63     String result = DecodedBitStreamParser.decode(builder.toByteArray(),
64         Version.getVersionForNumber(1), null, null).getText();
65     assertEquals("\u00ed\u00f3\u00fa", result);
66   }
67
68   // TODO definitely need more tests here
69
70 }