import com.google.zxing.common.BitArray;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import com.google.zxing.qrcode.decoder.Mode;
-import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Test;
import java.io.UnsupportedEncodingException;
* @author satorux@google.com (Satoru Takabayashi) - creator
* @author mysen@google.com (Chris Mysen) - ported from C++
*/
-public final class EncoderTestCase extends TestCase {
+public final class EncoderTestCase extends Assert {
+ @Test
public void testGetAlphanumericCode() {
// The first ten code points are numbers.
for (int i = 0; i < 10; ++i) {
assertEquals(-1, Encoder.getAlphanumericCode('\0'));
}
+ @Test
public void testChooseMode() throws WriterException {
// Numeric mode.
assertSame(Mode.NUMERIC, Encoder.chooseMode("0"));
assertSame(Mode.BYTE, Encoder.chooseMode(shiftJISString(new byte[]{0xe, 0x4, 0x9, 0x5, 0x9, 0x61})));
}
+ @Test
public void testEncode() throws WriterException {
QRCode qrCode = new QRCode();
Encoder.encode("ABCDEF", ErrorCorrectionLevel.H, qrCode);
assertEquals(expected, qrCode.toString());
}
+ @Test
public void testAppendModeInfo() {
BitArray bits = new BitArray();
Encoder.appendModeInfo(Mode.NUMERIC, bits);
assertEquals(" ...X", bits.toString());
}
+ @Test
public void testAppendLengthInfo() throws WriterException {
{
BitArray bits = new BitArray();
Encoder.appendLengthInfo(1, // 1 letter (1/1).
- 1, // version 1.
- Mode.NUMERIC,
- bits);
+ 1, // version 1.
+ Mode.NUMERIC,
+ bits);
assertEquals(" ........ .X", bits.toString()); // 10 bits.
}
{
BitArray bits = new BitArray();
Encoder.appendLengthInfo(2, // 2 letters (2/1).
- 10, // version 10.
- Mode.ALPHANUMERIC,
- bits);
+ 10, // version 10.
+ Mode.ALPHANUMERIC,
+ bits);
assertEquals(" ........ .X.", bits.toString()); // 11 bits.
}
{
BitArray bits = new BitArray();
Encoder.appendLengthInfo(255, // 255 letter (255/1).
- 27, // version 27.
- Mode.BYTE,
- bits);
+ 27, // version 27.
+ Mode.BYTE,
+ bits);
assertEquals(" ........ XXXXXXXX", bits.toString()); // 16 bits.
}
{
BitArray bits = new BitArray();
Encoder.appendLengthInfo(512, // 512 letters (1024/2).
- 40, // version 40.
- Mode.KANJI,
- bits);
+ 40, // version 40.
+ Mode.KANJI,
+ bits);
assertEquals(" ..X..... ....", bits.toString()); // 12 bits.
}
}
+ @Test
public void testAppendBytes() throws WriterException {
{
// Should use appendNumericBytes.
}
}
+ @Test
public void testTerminateBits() throws WriterException {
{
BitArray v = new BitArray();
}
}
+ @Test
public void testGetNumDataBytesAndNumECBytesForBlockID() throws WriterException {
int[] numDataBytes = new int[1];
int[] numEcBytes = new int[1];
assertEquals(30, numEcBytes[0]);
}
+ @Test
public void testInterleaveWithECBytes() throws WriterException {
{
byte[] dataBytes = {32, 65, (byte)205, 69, 41, (byte)220, 46, (byte)128, (byte)236};
}
}
+ @Test
public void testAppendNumericBytes() {
{
// 1 = 01 = 0001 in 4 bits.
}
}
+ @Test
public void testAppendAlphanumericBytes() throws WriterException {
{
// A = 10 = 0xa = 001010 in 6 bits
}
}
+ @Test
public void testAppend8BitBytes() throws WriterException {
{
// 0x61, 0x62, 0x63
}
// Numbers are from page 21 of JISX0510:2004
+ @Test
public void testAppendKanjiBytes() throws WriterException {
BitArray bits = new BitArray();
Encoder.appendKanjiBytes(shiftJISString(new byte[] {(byte)0x93,0x5f}), bits);
// Numbers are from http://www.swetake.com/qr/qr3.html and
// http://www.swetake.com/qr/qr9.html
+ @Test
public void testGenerateECBytes() {
{
byte[] dataBytes = {32, 65, (byte)205, 69, 41, (byte)220, 46, (byte)128, (byte)236};
}
}
+ @Test
public void testBugInBitVectorNumBytes() throws WriterException {
// There was a bug in BitVector.sizeInBytes() that caused it to return a
// smaller-by-one value (ex. 1465 instead of 1466) if the number of bits