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.ReaderException;
20 import com.google.zxing.common.BitSourceBuilder;
21 import junit.framework.TestCase;
24 * Tests {@link com.google.zxing.qrcode.decoder.DecodedBitStreamParser}.
28 public final class DecodedBitStreamParserTestCase extends TestCase {
30 public void testSimpleByteMode() throws ReaderException {
31 BitSourceBuilder builder = new BitSourceBuilder();
32 builder.write(0x04, 4); // Byte mode
33 builder.write(0x03, 8); // 3 bytes
34 builder.write(0xF1, 8);
35 builder.write(0xF2, 8);
36 builder.write(0xF3, 8);
37 String result = DecodedBitStreamParser.decode(builder.toByteArray(), Version.getVersionForNumber(1)).getText();
38 assertEquals("\u00f1\u00f2\u00f3", result);
41 public void testSimpleSJIS() throws ReaderException {
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(), Version.getVersionForNumber(1)).getText();
49 assertEquals("\uff61\uff62\uff63", result);
52 public void testECI() throws ReaderException {
53 BitSourceBuilder builder = new BitSourceBuilder();
54 builder.write(0x07, 4); // ECI mode
55 builder.write(0x02, 8); // ECI 2 = CP437 encoding
56 builder.write(0x04, 4); // Byte mode
57 builder.write(0x03, 8); // 3 bytes
58 builder.write(0xA1, 8);
59 builder.write(0xA2, 8);
60 builder.write(0xA3, 8);
61 String result = DecodedBitStreamParser.decode(builder.toByteArray(), Version.getVersionForNumber(1)).getText();
62 assertEquals("\u00ed\u00f3\u00fa", result);
65 // TODO definitely need more tests here