2 * Copyright 2008 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.
17 package com.google.zxing.qrcode.decoder;
19 import com.google.zxing.common.BitSourceBuilder;
20 import org.junit.Assert;
21 import org.junit.Test;
24 * Tests {@link com.google.zxing.qrcode.decoder.DecodedBitStreamParser}.
28 public final class DecodedBitStreamParserTestCase extends Assert {
31 public void testSimpleByteMode() throws Exception {
32 BitSourceBuilder builder = new BitSourceBuilder();
33 builder.write(0x04, 4); // Byte mode
34 builder.write(0x03, 8); // 3 bytes
35 builder.write(0xF1, 8);
36 builder.write(0xF2, 8);
37 builder.write(0xF3, 8);
38 String result = DecodedBitStreamParser.decode(builder.toByteArray(),
39 Version.getVersionForNumber(1), null, null).getText();
40 assertEquals("\u00f1\u00f2\u00f3", result);
44 public void testSimpleSJIS() throws Exception {
45 BitSourceBuilder builder = new BitSourceBuilder();
46 builder.write(0x04, 4); // Byte mode
47 builder.write(0x04, 8); // 4 bytes
48 builder.write(0xA1, 8);
49 builder.write(0xA2, 8);
50 builder.write(0xA3, 8);
51 builder.write(0xD0, 8);
52 String result = DecodedBitStreamParser.decode(builder.toByteArray(),
53 Version.getVersionForNumber(1), null, null).getText();
54 assertEquals("\uff61\uff62\uff63\uff90", result);
58 public void testECI() throws Exception {
59 BitSourceBuilder builder = new BitSourceBuilder();
60 builder.write(0x07, 4); // ECI mode
61 builder.write(0x02, 8); // ECI 2 = CP437 encoding
62 builder.write(0x04, 4); // Byte mode
63 builder.write(0x03, 8); // 3 bytes
64 builder.write(0xA1, 8);
65 builder.write(0xA2, 8);
66 builder.write(0xA3, 8);
67 String result = DecodedBitStreamParser.decode(builder.toByteArray(),
68 Version.getVersionForNumber(1), null, null).getText();
69 assertEquals("\u00ed\u00f3\u00fa", result);
72 // TODO definitely need more tests here