commit
5f425380df
@ -1,61 +1,61 @@
|
|||||||
package io.nayuki.qrcodegen;
|
package io.nayuki.qrcodegen;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The error correction level in a QR Code symbol.
|
* The error correction level in a QR Code symbol.
|
||||||
*/
|
*/
|
||||||
public class Ecc {
|
public class Ecc {
|
||||||
/** The QR Code can tolerate about 7% erroneous codewords. */
|
/** The QR Code can tolerate about 7% erroneous codewords. */
|
||||||
public static final Ecc LOW = new Ecc(1,
|
public static final Ecc LOW = new Ecc(1,
|
||||||
new byte[] { -1, 7, 10, 15, 20, 26, 18, 20, 24, 30, 18, 20, 24, 26, 30, 22, 24, 28, 30, 28, 28, 28, 28, 30,
|
new byte[] { -1, 7, 10, 15, 20, 26, 18, 20, 24, 30, 18, 20, 24, 26, 30, 22, 24, 28, 30, 28, 28, 28, 28, 30,
|
||||||
30, 26, 28, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30 },
|
30, 26, 28, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30 },
|
||||||
new byte[] { -1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 4, 4, 4, 4, 4, 6, 6, 6, 6, 7, 8, 8, 9, 9, 10, 12, 12, 12, 13,
|
new byte[] { -1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 4, 4, 4, 4, 4, 6, 6, 6, 6, 7, 8, 8, 9, 9, 10, 12, 12, 12, 13,
|
||||||
14, 15, 16, 17, 18, 19, 19, 20, 21, 22, 24, 25 });
|
14, 15, 16, 17, 18, 19, 19, 20, 21, 22, 24, 25 });
|
||||||
/** The QR Code can tolerate about 15% erroneous codewords. */
|
/** The QR Code can tolerate about 15% erroneous codewords. */
|
||||||
public static final Ecc MEDIUM = new Ecc(0,
|
public static final Ecc MEDIUM = new Ecc(0,
|
||||||
new byte[] { -1, 10, 16, 26, 18, 24, 16, 18, 22, 22, 26, 30, 22, 22, 24, 24, 28, 28, 26, 26, 26, 26, 28, 28,
|
new byte[] { -1, 10, 16, 26, 18, 24, 16, 18, 22, 22, 26, 30, 22, 22, 24, 24, 28, 28, 26, 26, 26, 26, 28, 28,
|
||||||
28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28 },
|
28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28 },
|
||||||
new byte[] { -1, 1, 1, 1, 2, 2, 4, 4, 4, 5, 5, 5, 8, 9, 9, 10, 10, 11, 13, 14, 16, 17, 17, 18, 20, 21, 23,
|
new byte[] { -1, 1, 1, 1, 2, 2, 4, 4, 4, 5, 5, 5, 8, 9, 9, 10, 10, 11, 13, 14, 16, 17, 17, 18, 20, 21, 23,
|
||||||
25, 26, 28, 29, 31, 33, 35, 37, 38, 40, 43, 45, 47, 49 });
|
25, 26, 28, 29, 31, 33, 35, 37, 38, 40, 43, 45, 47, 49 });
|
||||||
/** The QR Code can tolerate about 25% erroneous codewords. */
|
/** The QR Code can tolerate about 25% erroneous codewords. */
|
||||||
public static final Ecc QUARTILE = new Ecc(3,
|
public static final Ecc QUARTILE = new Ecc(3,
|
||||||
new byte[] { -1, 13, 22, 18, 26, 18, 24, 18, 22, 20, 24, 28, 26, 24, 20, 30, 24, 28, 28, 26, 30, 28, 30, 30,
|
new byte[] { -1, 13, 22, 18, 26, 18, 24, 18, 22, 20, 24, 28, 26, 24, 20, 30, 24, 28, 28, 26, 30, 28, 30, 30,
|
||||||
30, 30, 28, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30 },
|
30, 30, 28, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30 },
|
||||||
new byte[] { -1, 1, 1, 2, 2, 4, 4, 6, 6, 8, 8, 8, 10, 12, 16, 12, 17, 16, 18, 21, 20, 23, 23, 25, 27, 29,
|
new byte[] { -1, 1, 1, 2, 2, 4, 4, 6, 6, 8, 8, 8, 10, 12, 16, 12, 17, 16, 18, 21, 20, 23, 23, 25, 27, 29,
|
||||||
34, 34, 35, 38, 40, 43, 45, 48, 51, 53, 56, 59, 62, 65, 68 });
|
34, 34, 35, 38, 40, 43, 45, 48, 51, 53, 56, 59, 62, 65, 68 });
|
||||||
/** The QR Code can tolerate about 30% erroneous codewords. */
|
/** The QR Code can tolerate about 30% erroneous codewords. */
|
||||||
public static final Ecc HIGH = new Ecc(2,
|
public static final Ecc HIGH = new Ecc(2,
|
||||||
new byte[] { -1, 17, 28, 22, 16, 22, 28, 26, 26, 24, 28, 24, 28, 22, 24, 24, 30, 28, 28, 26, 28, 30, 24, 30,
|
new byte[] { -1, 17, 28, 22, 16, 22, 28, 26, 26, 24, 28, 24, 28, 22, 24, 24, 30, 28, 28, 26, 28, 30, 24, 30,
|
||||||
30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30 },
|
30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30 },
|
||||||
new byte[] { -1, 1, 1, 2, 4, 4, 4, 5, 6, 8, 8, 11, 11, 16, 16, 18, 16, 19, 21, 25, 25, 25, 34, 30, 32, 35,
|
new byte[] { -1, 1, 1, 2, 4, 4, 4, 5, 6, 8, 8, 11, 11, 16, 16, 18, 16, 19, 21, 25, 25, 25, 34, 30, 32, 35,
|
||||||
37, 40, 42, 45, 48, 51, 54, 57, 60, 63, 66, 70, 74, 77, 81 });
|
37, 40, 42, 45, 48, 51, 54, 57, 60, 63, 66, 70, 74, 77, 81 });
|
||||||
|
|
||||||
private final int formatBits;
|
private final int formatBits;
|
||||||
private final byte[] blockLength;
|
private final byte[] blockLength;
|
||||||
private final byte[] numberOfBlocks;
|
private final byte[] numberOfBlocks;
|
||||||
|
|
||||||
// For formatBits and blockLength, array index is Version: (note that index 0 is
|
// For formatBits and blockLength, array index is Version: (note that index 0 is
|
||||||
// for padding, and is set to an illegal value)
|
// for padding, and is set to an illegal value)
|
||||||
private Ecc(int formatBits, byte[] blockLength, byte[] numberOfBlocks) {
|
private Ecc(int formatBits, byte[] blockLength, byte[] numberOfBlocks) {
|
||||||
this.formatBits = formatBits;
|
this.formatBits = formatBits;
|
||||||
this.blockLength = blockLength;
|
this.blockLength = blockLength;
|
||||||
this.numberOfBlocks = numberOfBlocks;
|
this.numberOfBlocks = numberOfBlocks;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getFormatBits() {
|
public int getFormatBits() {
|
||||||
return formatBits;
|
return formatBits;
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte getBlockLength(int version) {
|
public byte getBlockLength(int version) {
|
||||||
return blockLength[version];
|
return blockLength[version];
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte getNumberOfBlock(int version) {
|
public byte getNumberOfBlock(int version) {
|
||||||
return numberOfBlocks[version];
|
return numberOfBlocks[version];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Must in ascending order of error protection
|
// Must in ascending order of error protection
|
||||||
// so that values() work properly
|
// so that values() work properly
|
||||||
public static Ecc[] values() {
|
public static Ecc[] values() {
|
||||||
return new Ecc[] { LOW, MEDIUM, QUARTILE, HIGH };
|
return new Ecc[] { LOW, MEDIUM, QUARTILE, HIGH };
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,34 +1,34 @@
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public class MakeAlphaNumericToSegment implements MakeSegment {
|
public class MakeAlphaNumericToSegment implements MakeSegment {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a segment representing the specified text string encoded in alphanumeric mode.
|
* Returns a segment representing the specified text string encoded in alphanumeric mode.
|
||||||
* The characters allowed are: 0 to 9, A to Z (uppercase only), space,
|
* The characters allowed are: 0 to 9, A to Z (uppercase only), space,
|
||||||
* dollar, percent, asterisk, plus, hyphen, period, slash, colon.
|
* dollar, percent, asterisk, plus, hyphen, period, slash, colon.
|
||||||
* @param text the text (not {@code null}), with only certain characters allowed
|
* @param text the text (not {@code null}), with only certain characters allowed
|
||||||
* @return a segment (not {@code null}) containing the text
|
* @return a segment (not {@code null}) containing the text
|
||||||
* @throws NullPointerException if the string is {@code null}
|
* @throws NullPointerException if the string is {@code null}
|
||||||
* @throws IllegalArgumentException if the string contains non-encodable characters
|
* @throws IllegalArgumentException if the string contains non-encodable characters
|
||||||
*/
|
*/
|
||||||
public QrSegment excute(String text) {
|
public QrSegment excute(String text) {
|
||||||
Objects.requireNonNull(text);
|
Objects.requireNonNull(text);
|
||||||
if (!QrSegment.ALPHANUMERIC_REGEX.matcher(text).matches())
|
if (!QrSegment.ALPHANUMERIC_REGEX.matcher(text).matches())
|
||||||
throw new IllegalArgumentException("String contains unencodable characters in alphanumeric mode");
|
throw new IllegalArgumentException("String contains unencodable characters in alphanumeric mode");
|
||||||
|
|
||||||
BitBuffer bitBuffer = new BitBuffer();
|
BitBuffer bitBuffer = new BitBuffer();
|
||||||
changeAlphaNumericStringToSegment(text, bitBuffer);
|
changeAlphaNumericStringToSegment(text, bitBuffer);
|
||||||
return new QrSegment(QrSegment.Mode.ALPHANUMERIC, text.length(), bitBuffer);
|
return new QrSegment(QrSegment.Mode.ALPHANUMERIC, text.length(), bitBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void changeAlphaNumericStringToSegment(String text, BitBuffer bitBuffer) {
|
public static void changeAlphaNumericStringToSegment(String text, BitBuffer bitBuffer) {
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i <= text.length() - 2; i += 2) { // Process groups of 2
|
for (i = 0; i <= text.length() - 2; i += 2) { // Process groups of 2
|
||||||
int temp = QrSegment.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i)) * 45;
|
int temp = QrSegment.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i)) * 45;
|
||||||
temp += QrSegment.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i + 1));
|
temp += QrSegment.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i + 1));
|
||||||
bitBuffer.appendBits(temp, 11);
|
bitBuffer.appendBits(temp, 11);
|
||||||
}
|
}
|
||||||
if (i < text.length()) // 1 character remaining
|
if (i < text.length()) // 1 character remaining
|
||||||
bitBuffer.appendBits(QrSegment.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i)), 6);
|
bitBuffer.appendBits(QrSegment.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i)), 6);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,36 +1,37 @@
|
|||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public class MakeBytesToSegment implements MakeSegment {
|
public class MakeBytesToSegment implements MakeSegment {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a segment representing the specified binary data
|
* Returns a segment representing the specified binary data
|
||||||
* encoded in byte mode. All input byte arrays are acceptable.
|
* encoded in byte mode. All input byte arrays are acceptable.
|
||||||
* <p>Any text string can be converted to UTF-8 bytes ({@code
|
* <p>Any text string can be converted to UTF-8 bytes ({@code
|
||||||
* s.getBytes(StandardCharsets.UTF_8)}) and encoded as a byte mode segment.</p>
|
* s.getBytes(StandardCharsets.UTF_8)}) and encoded as a byte mode segment.</p>
|
||||||
* @param data the binary data (not {@code null})
|
* @param data the binary data (not {@code null})
|
||||||
* @return a segment (not {@code null}) containing the data
|
* @return a segment (not {@code null}) containing the data
|
||||||
* @throws NullPointerException if the array is {@code null}
|
* @throws NullPointerException if the array is {@code null}
|
||||||
*/
|
*/
|
||||||
public QrSegment excute(String text) {
|
public QrSegment excute(String text) {
|
||||||
byte[] data = text.getBytes(StandardCharsets.UTF_8));
|
byte[] data = text.getBytes(StandardCharsets.UTF_8));
|
||||||
|
|
||||||
Objects.requireNonNull(data);
|
Objects.requireNonNull(data);
|
||||||
BitBuffer bitBuffer = new BitBuffer();
|
BitBuffer bitBuffer = new BitBuffer();
|
||||||
for (byte bits : data)
|
for (byte bits : data)
|
||||||
changeByteToSegment(bitBuffer, bits);
|
changeByteToSegment(bitBuffer, bits);
|
||||||
return new QrSegment(QrSegment.Mode.BYTE, data.length, bitBuffer);
|
return new QrSegment(QrSegment.Mode.BYTE, data.length, bitBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public QrSegment excuteForBytedata(byte[] data) {
|
public QrSegment excuteForBytedata(byte[] data) {
|
||||||
Objects.requireNonNull(data);
|
Objects.requireNonNull(data);
|
||||||
BitBuffer bitBuffer = new BitBuffer();
|
BitBuffer bitBuffer = new BitBuffer();
|
||||||
for (byte bits : data)
|
for (byte bits : data)
|
||||||
changeByteToSegment(bitBuffer, bits);
|
changeByteToSegment(bitBuffer, bits);
|
||||||
return new QrSegment(QrSegment.Mode.BYTE, data.length, bitBuffer);
|
return new QrSegment(QrSegment.Mode.BYTE, data.length, bitBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void changeByteToSegment(BitBuffer bitBuffer, byte bits) {
|
public static void changeByteToSegment(BitBuffer bitBuffer, byte bits) {
|
||||||
bitBuffer.appendBits(bits & 0xFF, 8);
|
bitBuffer.appendBits(bits & 0xFF, 8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,33 +1,33 @@
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public class MakeNumericToSegment implements MakeSegment {
|
public class MakeNumericToSegment implements MakeSegment {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a segment representing the specified string of decimal digits encoded in numeric mode.
|
* Returns a segment representing the specified string of decimal digits encoded in numeric mode.
|
||||||
* @param digits the text (not {@code null}), with only digits from 0 to 9 allowed
|
* @param digits the text (not {@code null}), with only digits from 0 to 9 allowed
|
||||||
* @return a segment (not {@code null}) containing the text
|
* @return a segment (not {@code null}) containing the text
|
||||||
* @throws NullPointerException if the string is {@code null}
|
* @throws NullPointerException if the string is {@code null}
|
||||||
* @throws IllegalArgumentException if the string contains non-digit characters
|
* @throws IllegalArgumentException if the string contains non-digit characters
|
||||||
*/
|
*/
|
||||||
public QrSegment excute(String digits) {
|
public QrSegment excute(String digits) {
|
||||||
Objects.requireNonNull(digits);
|
Objects.requireNonNull(digits);
|
||||||
if (containNonNumericCharaters(digits))
|
if (containNonNumericCharaters(digits))
|
||||||
throw new IllegalArgumentException("String contains non-numeric characters");
|
throw new IllegalArgumentException("String contains non-numeric characters");
|
||||||
|
|
||||||
BitBuffer bitBuffer = new BitBuffer();
|
BitBuffer bitBuffer = new BitBuffer();
|
||||||
changeNumericToSegment(digits, bitBuffer);
|
changeNumericToSegment(digits, bitBuffer);
|
||||||
return new QrSegment(QrSegment.Mode.NUMERIC, digits.length(), bitBuffer);
|
return new QrSegment(QrSegment.Mode.NUMERIC, digits.length(), bitBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void changeNumericToSegment(String digits, BitBuffer bitBuffer) {
|
public static void changeNumericToSegment(String digits, BitBuffer bitBuffer) {
|
||||||
for (int i = 0; i < digits.length(); ) { // Consume up to 3 digits per iteration
|
for (int i = 0; i < digits.length(); ) { // Consume up to 3 digits per iteration
|
||||||
int n = Math.min(digits.length() - i, 3);
|
int n = Math.min(digits.length() - i, 3);
|
||||||
bitBuffer.appendBits(Integer.parseInt(digits.substring(i, i + n)), n * 3 + 1);
|
bitBuffer.appendBits(Integer.parseInt(digits.substring(i, i + n)), n * 3 + 1);
|
||||||
i += n;
|
i += n;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean containNonNumericCharaters(String digits) {
|
public static boolean containNonNumericCharaters(String digits) {
|
||||||
return !QrSegment.NUMERIC_REGEX.matcher(digits).matches();
|
return !QrSegment.NUMERIC_REGEX.matcher(digits).matches();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
|
|
||||||
public interface MakeSegment {
|
public interface MakeSegment {
|
||||||
public QrSegment excute(String text);
|
public QrSegment excute(String text);
|
||||||
}
|
}
|
@ -1,15 +1,15 @@
|
|||||||
public class MakeSegmentFactory {
|
public class MakeSegmentFactory {
|
||||||
public static MakeSegment getMakeSegment(String text) {
|
public static MakeSegment getMakeSegment(String text) {
|
||||||
MakeSegment makeSegment = null;
|
MakeSegment makeSegment = null;
|
||||||
|
|
||||||
if (text.equals("")); // Leave result empty
|
if (text.equals("")); // Leave result empty
|
||||||
else if (QrSegment.NUMERIC_REGEX.matcher(text).matches())
|
else if (QrSegment.NUMERIC_REGEX.matcher(text).matches())
|
||||||
makeSegment = new MakeNumericToSegment();
|
makeSegment = new MakeNumericToSegment();
|
||||||
else if (QrSegment.ALPHANUMERIC_REGEX.matcher(text).matches())
|
else if (QrSegment.ALPHANUMERIC_REGEX.matcher(text).matches())
|
||||||
makeSegment = new MakeAlphaNumericToSegment();
|
makeSegment = new MakeAlphaNumericToSegment();
|
||||||
else
|
else
|
||||||
makeSegment = new MakeBytesToSegment();
|
makeSegment = new MakeBytesToSegment();
|
||||||
|
|
||||||
return makeSegment;
|
return makeSegment;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,165 @@
|
|||||||
|
package io.nayuki.qrcodegen;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
import org.junit.*;
|
||||||
|
|
||||||
|
public class QrCodeTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFactory() {
|
||||||
|
Command mskCommand0 = MskCommandFactory.getCommand(0);
|
||||||
|
Button button0 = new Button(mskCommand0);
|
||||||
|
assertEquals(true, button0.pressed(0, 2, 1));
|
||||||
|
|
||||||
|
Command mskCommand1 = MskCommandFactory.getCommand(1);
|
||||||
|
Button button1 = new Button(mskCommand1);
|
||||||
|
assertEquals(true, button1.pressed(0, 2, 1));
|
||||||
|
|
||||||
|
Command mskCommand2 = MskCommandFactory.getCommand(2);
|
||||||
|
Button button2 = new Button(mskCommand2);
|
||||||
|
assertEquals(true, button2.pressed(0, 3, 1));
|
||||||
|
|
||||||
|
Command mskCommand3 = MskCommandFactory.getCommand(3);
|
||||||
|
Button button3 = new Button(mskCommand3);
|
||||||
|
assertEquals(true, button3.pressed(1, 2, 1));
|
||||||
|
|
||||||
|
Command mskCommand4 = MskCommandFactory.getCommand(4);
|
||||||
|
Button button4 = new Button(mskCommand4);
|
||||||
|
assertEquals(true, button4.pressed(0, 2, 1));
|
||||||
|
|
||||||
|
Command mskCommand5 = MskCommandFactory.getCommand(5);
|
||||||
|
Button button5 = new Button(mskCommand5);
|
||||||
|
assertEquals(true, button5.pressed(0, 2, 1));
|
||||||
|
|
||||||
|
Command mskCommand6 = MskCommandFactory.getCommand(6);
|
||||||
|
Button button6 = new Button(mskCommand6);
|
||||||
|
assertEquals(true, button6.pressed(0, 2, 1));
|
||||||
|
|
||||||
|
Command mskCommand7 = MskCommandFactory.getCommand(7);
|
||||||
|
Button button7 = new Button(mskCommand7);
|
||||||
|
assertEquals(true, button7.pressed(0, 4, 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = AssertionError.class)
|
||||||
|
public void testAssertionError() {
|
||||||
|
|
||||||
|
Command mskCommand = MskCommandFactory.getCommand(9);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testApplyMask() {
|
||||||
|
Ecc errCorLvl = Ecc.LOW;
|
||||||
|
Ecc errCorLv2 = Ecc.MEDIUM;
|
||||||
|
Ecc errCorLv3 = Ecc.QUARTILE;
|
||||||
|
Ecc errCorLv4 = Ecc.HIGH;
|
||||||
|
|
||||||
|
int version1 = 1;
|
||||||
|
int version2 = 2;
|
||||||
|
int version3 = 39;
|
||||||
|
int version4 = 40;
|
||||||
|
|
||||||
|
int size1 = version1 * 4 + 17;
|
||||||
|
int size2 = version2 * 4 + 17;
|
||||||
|
int size3 = version3 * 4 + 17;
|
||||||
|
int size4 = version4 * 4 + 17;
|
||||||
|
|
||||||
|
String text = "Hello, world!";
|
||||||
|
|
||||||
|
QrCode qrcodeLOW = QrCode.encodeText(text, errCorLvl);
|
||||||
|
QrCode qrcodeMEDIUM = QrCode.encodeText(text, errCorLv2);
|
||||||
|
QrCode qrcodeQUARTILE = QrCode.encodeText(text, errCorLv3);
|
||||||
|
QrCode qrcodeHIGH = QrCode.encodeText(text, errCorLv4);
|
||||||
|
|
||||||
|
qrcodeLOW.excuteGetNumRawDataModules(version1);
|
||||||
|
qrcodeMEDIUM.excuteGetNumRawDataModules(version2);
|
||||||
|
qrcodeQUARTILE.excuteGetNumRawDataModules(version3);
|
||||||
|
qrcodeHIGH.excuteGetNumRawDataModules(version4);
|
||||||
|
|
||||||
|
qrcodeLOW.executeReedSolomonComputeDivisor(1);
|
||||||
|
qrcodeMEDIUM.executeReedSolomonComputeDivisor(2);
|
||||||
|
qrcodeQUARTILE.executeReedSolomonComputeDivisor(254);
|
||||||
|
qrcodeHIGH.executeReedSolomonComputeDivisor(255);
|
||||||
|
|
||||||
|
qrcodeLOW.setModules(size1);
|
||||||
|
qrcodeLOW.setIsFunction(size1);
|
||||||
|
qrcodeMEDIUM.setModules(size2);
|
||||||
|
qrcodeMEDIUM.setIsFunction(size2);
|
||||||
|
qrcodeQUARTILE.setModules(size3);
|
||||||
|
qrcodeQUARTILE.setIsFunction(size3);
|
||||||
|
qrcodeHIGH.setModules(size4);
|
||||||
|
qrcodeHIGH.setIsFunction(size4);
|
||||||
|
|
||||||
|
qrcodeLOW.applyMask(0);
|
||||||
|
qrcodeMEDIUM.applyMask(1);
|
||||||
|
qrcodeQUARTILE.applyMask(6);
|
||||||
|
qrcodeHIGH.applyMask(7);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void testIllegalArgumentException_applyMask_MAXBound() {
|
||||||
|
|
||||||
|
Ecc errCorLvl = Ecc.LOW;
|
||||||
|
String text = "Hello, world!";
|
||||||
|
|
||||||
|
QrCode qrcodeLOW = QrCode.encodeText(text, errCorLvl);
|
||||||
|
qrcodeLOW.applyMask(8);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void testIllegalArgumentException_applyMask_MINBouond() {
|
||||||
|
|
||||||
|
Ecc errCorLvl = Ecc.LOW;
|
||||||
|
String text = "Hello, world!";
|
||||||
|
|
||||||
|
QrCode qrcodeLOW = QrCode.encodeText(text, errCorLvl);
|
||||||
|
qrcodeLOW.applyMask(-1);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void testIllegalArgumentException_getNumRawDataModules_MINBound() {
|
||||||
|
|
||||||
|
Ecc errCorLvl = Ecc.LOW;
|
||||||
|
String text = "Hello, world!";
|
||||||
|
|
||||||
|
QrCode qrcodeLOW = QrCode.encodeText(text, errCorLvl);
|
||||||
|
qrcodeLOW.excuteGetNumRawDataModules(0);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void testIllegalArgumentException_getNumRawDataModules_MAXBound() {
|
||||||
|
|
||||||
|
Ecc errCorLvl = Ecc.LOW;
|
||||||
|
String text = "Hello, world!";
|
||||||
|
|
||||||
|
QrCode qrcodeLOW = QrCode.encodeText(text, errCorLvl);
|
||||||
|
qrcodeLOW.excuteGetNumRawDataModules(41);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void testIllegalArgumentException_ReedSolomonComputeDivisor_MINBound() {
|
||||||
|
|
||||||
|
Ecc errCorLvl = Ecc.LOW;
|
||||||
|
String text = "Hello, world!";
|
||||||
|
|
||||||
|
QrCode qrcodeLOW = QrCode.encodeText(text, errCorLvl);
|
||||||
|
qrcodeLOW.executeReedSolomonComputeDivisor(0);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void testIllegalArgumentException_ReedSolomonComputeDivisor_MAXBound() {
|
||||||
|
|
||||||
|
Ecc errCorLvl = Ecc.LOW;
|
||||||
|
String text = "Hello, world!";
|
||||||
|
|
||||||
|
QrCode qrcodeLOW = QrCode.encodeText(text, errCorLvl);
|
||||||
|
qrcodeLOW.executeReedSolomonComputeDivisor(256);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue