Merge pull request #8 from wslbal/master

임창현
pull/90/head
gerzees 5 years ago committed by GitHub
commit 5f425380df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,61 +1,61 @@
package io.nayuki.qrcodegen;
/**
* The error correction level in a QR Code symbol.
*/
public class Ecc {
/** The QR Code can tolerate about 7% erroneous codewords. */
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,
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,
14, 15, 16, 17, 18, 19, 19, 20, 21, 22, 24, 25 });
/** The QR Code can tolerate about 15% erroneous codewords. */
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,
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,
25, 26, 28, 29, 31, 33, 35, 37, 38, 40, 43, 45, 47, 49 });
/** The QR Code can tolerate about 25% erroneous codewords. */
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,
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,
34, 34, 35, 38, 40, 43, 45, 48, 51, 53, 56, 59, 62, 65, 68 });
/** The QR Code can tolerate about 30% erroneous codewords. */
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,
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,
37, 40, 42, 45, 48, 51, 54, 57, 60, 63, 66, 70, 74, 77, 81 });
private final int formatBits;
private final byte[] blockLength;
private final byte[] numberOfBlocks;
// For formatBits and blockLength, array index is Version: (note that index 0 is
// for padding, and is set to an illegal value)
private Ecc(int formatBits, byte[] blockLength, byte[] numberOfBlocks) {
this.formatBits = formatBits;
this.blockLength = blockLength;
this.numberOfBlocks = numberOfBlocks;
}
public int getFormatBits() {
return formatBits;
}
public byte getBlockLength(int version) {
return blockLength[version];
}
public byte getNumberOfBlock(int version) {
return numberOfBlocks[version];
}
// Must in ascending order of error protection
// so that values() work properly
public static Ecc[] values() {
return new Ecc[] { LOW, MEDIUM, QUARTILE, HIGH };
}
}
package io.nayuki.qrcodegen;
/**
* The error correction level in a QR Code symbol.
*/
public class Ecc {
/** The QR Code can tolerate about 7% erroneous codewords. */
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,
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,
14, 15, 16, 17, 18, 19, 19, 20, 21, 22, 24, 25 });
/** The QR Code can tolerate about 15% erroneous codewords. */
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,
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,
25, 26, 28, 29, 31, 33, 35, 37, 38, 40, 43, 45, 47, 49 });
/** The QR Code can tolerate about 25% erroneous codewords. */
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,
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,
34, 34, 35, 38, 40, 43, 45, 48, 51, 53, 56, 59, 62, 65, 68 });
/** The QR Code can tolerate about 30% erroneous codewords. */
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,
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,
37, 40, 42, 45, 48, 51, 54, 57, 60, 63, 66, 70, 74, 77, 81 });
private final int formatBits;
private final byte[] blockLength;
private final byte[] numberOfBlocks;
// For formatBits and blockLength, array index is Version: (note that index 0 is
// for padding, and is set to an illegal value)
private Ecc(int formatBits, byte[] blockLength, byte[] numberOfBlocks) {
this.formatBits = formatBits;
this.blockLength = blockLength;
this.numberOfBlocks = numberOfBlocks;
}
public int getFormatBits() {
return formatBits;
}
public byte getBlockLength(int version) {
return blockLength[version];
}
public byte getNumberOfBlock(int version) {
return numberOfBlocks[version];
}
// Must in ascending order of error protection
// so that values() work properly
public static Ecc[] values() {
return new Ecc[] { LOW, MEDIUM, QUARTILE, HIGH };
}
}

@ -20,5 +20,5 @@ public class KanjiMode extends QrMode {
public QrSegment making(String str) {
return QrSegmentAdvanced.makeKanji(str);
}
}
}

@ -1,34 +1,34 @@
import java.util.Objects;
public class MakeAlphaNumericToSegment implements MakeSegment {
/**
* 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,
* dollar, percent, asterisk, plus, hyphen, period, slash, colon.
* @param text the text (not {@code null}), with only certain characters allowed
* @return a segment (not {@code null}) containing the text
* @throws NullPointerException if the string is {@code null}
* @throws IllegalArgumentException if the string contains non-encodable characters
*/
public QrSegment excute(String text) {
Objects.requireNonNull(text);
if (!QrSegment.ALPHANUMERIC_REGEX.matcher(text).matches())
throw new IllegalArgumentException("String contains unencodable characters in alphanumeric mode");
BitBuffer bitBuffer = new BitBuffer();
changeAlphaNumericStringToSegment(text, bitBuffer);
return new QrSegment(QrSegment.Mode.ALPHANUMERIC, text.length(), bitBuffer);
}
public static void changeAlphaNumericStringToSegment(String text, BitBuffer bitBuffer) {
int i;
for (i = 0; i <= text.length() - 2; i += 2) { // Process groups of 2
int temp = QrSegment.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i)) * 45;
temp += QrSegment.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i + 1));
bitBuffer.appendBits(temp, 11);
}
if (i < text.length()) // 1 character remaining
bitBuffer.appendBits(QrSegment.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i)), 6);
}
}
import java.util.Objects;
public class MakeAlphaNumericToSegment implements MakeSegment {
/**
* 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,
* dollar, percent, asterisk, plus, hyphen, period, slash, colon.
* @param text the text (not {@code null}), with only certain characters allowed
* @return a segment (not {@code null}) containing the text
* @throws NullPointerException if the string is {@code null}
* @throws IllegalArgumentException if the string contains non-encodable characters
*/
public QrSegment excute(String text) {
Objects.requireNonNull(text);
if (!QrSegment.ALPHANUMERIC_REGEX.matcher(text).matches())
throw new IllegalArgumentException("String contains unencodable characters in alphanumeric mode");
BitBuffer bitBuffer = new BitBuffer();
changeAlphaNumericStringToSegment(text, bitBuffer);
return new QrSegment(QrSegment.Mode.ALPHANUMERIC, text.length(), bitBuffer);
}
public static void changeAlphaNumericStringToSegment(String text, BitBuffer bitBuffer) {
int i;
for (i = 0; i <= text.length() - 2; i += 2) { // Process groups of 2
int temp = QrSegment.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i)) * 45;
temp += QrSegment.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i + 1));
bitBuffer.appendBits(temp, 11);
}
if (i < text.length()) // 1 character remaining
bitBuffer.appendBits(QrSegment.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i)), 6);
}
}

@ -1,36 +1,37 @@
import java.nio.charset.StandardCharsets;
import java.util.Objects;
public class MakeBytesToSegment implements MakeSegment {
/**
* Returns a segment representing the specified binary data
* encoded in byte mode. All input byte arrays are acceptable.
* <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>
* @param data the binary data (not {@code null})
* @return a segment (not {@code null}) containing the data
* @throws NullPointerException if the array is {@code null}
*/
public QrSegment excute(String text) {
byte[] data = text.getBytes(StandardCharsets.UTF_8));
Objects.requireNonNull(data);
BitBuffer bitBuffer = new BitBuffer();
for (byte bits : data)
changeByteToSegment(bitBuffer, bits);
return new QrSegment(QrSegment.Mode.BYTE, data.length, bitBuffer);
}
public QrSegment excuteForBytedata(byte[] data) {
Objects.requireNonNull(data);
BitBuffer bitBuffer = new BitBuffer();
for (byte bits : data)
changeByteToSegment(bitBuffer, bits);
return new QrSegment(QrSegment.Mode.BYTE, data.length, bitBuffer);
}
public static void changeByteToSegment(BitBuffer bitBuffer, byte bits) {
bitBuffer.appendBits(bits & 0xFF, 8);
}
}
import java.nio.charset.StandardCharsets;
import java.util.Objects;
public class MakeBytesToSegment implements MakeSegment {
/**
* Returns a segment representing the specified binary data
* encoded in byte mode. All input byte arrays are acceptable.
* <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>
* @param data the binary data (not {@code null})
* @return a segment (not {@code null}) containing the data
* @throws NullPointerException if the array is {@code null}
*/
public QrSegment excute(String text) {
byte[] data = text.getBytes(StandardCharsets.UTF_8));
Objects.requireNonNull(data);
BitBuffer bitBuffer = new BitBuffer();
for (byte bits : data)
changeByteToSegment(bitBuffer, bits);
return new QrSegment(QrSegment.Mode.BYTE, data.length, bitBuffer);
}
public QrSegment excuteForBytedata(byte[] data) {
Objects.requireNonNull(data);
BitBuffer bitBuffer = new BitBuffer();
for (byte bits : data)
changeByteToSegment(bitBuffer, bits);
return new QrSegment(QrSegment.Mode.BYTE, data.length, bitBuffer);
}
public static void changeByteToSegment(BitBuffer bitBuffer, byte bits) {
bitBuffer.appendBits(bits & 0xFF, 8);
}
}

@ -1,33 +1,33 @@
import java.util.Objects;
public class MakeNumericToSegment implements MakeSegment {
/**
* 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
* @return a segment (not {@code null}) containing the text
* @throws NullPointerException if the string is {@code null}
* @throws IllegalArgumentException if the string contains non-digit characters
*/
public QrSegment excute(String digits) {
Objects.requireNonNull(digits);
if (containNonNumericCharaters(digits))
throw new IllegalArgumentException("String contains non-numeric characters");
BitBuffer bitBuffer = new BitBuffer();
changeNumericToSegment(digits, bitBuffer);
return new QrSegment(QrSegment.Mode.NUMERIC, digits.length(), bitBuffer);
}
public static void changeNumericToSegment(String digits, BitBuffer bitBuffer) {
for (int i = 0; i < digits.length(); ) { // Consume up to 3 digits per iteration
int n = Math.min(digits.length() - i, 3);
bitBuffer.appendBits(Integer.parseInt(digits.substring(i, i + n)), n * 3 + 1);
i += n;
}
}
public static boolean containNonNumericCharaters(String digits) {
return !QrSegment.NUMERIC_REGEX.matcher(digits).matches();
}
}
import java.util.Objects;
public class MakeNumericToSegment implements MakeSegment {
/**
* 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
* @return a segment (not {@code null}) containing the text
* @throws NullPointerException if the string is {@code null}
* @throws IllegalArgumentException if the string contains non-digit characters
*/
public QrSegment excute(String digits) {
Objects.requireNonNull(digits);
if (containNonNumericCharaters(digits))
throw new IllegalArgumentException("String contains non-numeric characters");
BitBuffer bitBuffer = new BitBuffer();
changeNumericToSegment(digits, bitBuffer);
return new QrSegment(QrSegment.Mode.NUMERIC, digits.length(), bitBuffer);
}
public static void changeNumericToSegment(String digits, BitBuffer bitBuffer) {
for (int i = 0; i < digits.length(); ) { // Consume up to 3 digits per iteration
int n = Math.min(digits.length() - i, 3);
bitBuffer.appendBits(Integer.parseInt(digits.substring(i, i + n)), n * 3 + 1);
i += n;
}
}
public static boolean containNonNumericCharaters(String digits) {
return !QrSegment.NUMERIC_REGEX.matcher(digits).matches();
}
}

@ -1,4 +1,4 @@
public interface MakeSegment {
public QrSegment excute(String text);
}
public interface MakeSegment {
public QrSegment excute(String text);
}

@ -1,15 +1,15 @@
public class MakeSegmentFactory {
public static MakeSegment getMakeSegment(String text) {
MakeSegment makeSegment = null;
if (text.equals("")); // Leave result empty
else if (QrSegment.NUMERIC_REGEX.matcher(text).matches())
makeSegment = new MakeNumericToSegment();
else if (QrSegment.ALPHANUMERIC_REGEX.matcher(text).matches())
makeSegment = new MakeAlphaNumericToSegment();
else
makeSegment = new MakeBytesToSegment();
return makeSegment;
}
}
public class MakeSegmentFactory {
public static MakeSegment getMakeSegment(String text) {
MakeSegment makeSegment = null;
if (text.equals("")); // Leave result empty
else if (QrSegment.NUMERIC_REGEX.matcher(text).matches())
makeSegment = new MakeNumericToSegment();
else if (QrSegment.ALPHANUMERIC_REGEX.matcher(text).matches())
makeSegment = new MakeAlphaNumericToSegment();
else
makeSegment = new MakeBytesToSegment();
return makeSegment;
}
}

@ -190,7 +190,7 @@ public final class QrCode {
BitBuffer bitBuffer = new BitBuffer();
for (QrSegment segment : segments) {
bitBuffer.appendBits(segment.mode.modeBits, 4);
bitBuffer.appendBits(segment.numChars, segment.mode.numCharCountBits(version));
bitBuffer.appendBits(segment.numberOfCharacters, segment.mode.numCharCountBits(version));
bitBuffer.appendData(segment.data);
}
return bitBuffer;
@ -258,7 +258,13 @@ public final class QrCode {
// Indicates function modules that are not subjected to masking. Discarded when constructor finishes.
private boolean[][] isFunction;
public void setModules(int size) {
this.modules = new boolean [size][size];
}
public void setIsFunction(int size) {
this.isFunction = new boolean [size][size];
}
/*---- Constructor (low level) ----*/
@ -581,9 +587,7 @@ public final class QrCode {
// the same mask value a second time will undo the mask. A final well-formed
// QR Code needs exactly one (not zero, two, etc.) mask applied.
private void applyMask(int msk) {
public void applyMask(int msk) {
if (msk < 0 || msk > 7)
throw new IllegalArgumentException("Mask value out of range");
for (int y = 0; y < size; y++) {
@ -593,7 +597,7 @@ public final class QrCode {
Command mskCommand = MskCommandFactory.getCommand(msk);
Button button = new Button(mskCommand);
invert = button.pressed(y, x, msk);
modules[y][x] ^= invert & !isFunction[y][x];
}
}
@ -612,7 +616,10 @@ public final class QrCode {
drawFormatBits(mask); // Overwrite old format bits
return mask; // The caller shall assign this value to the final-declared field
}
public int executeHandleConstructorMasking(int mask) {
return handleConstructorMasking(mask);
}
// Automatically choose best mask
private int findBestMask() {
@ -749,7 +756,11 @@ public final class QrCode {
assert 208 <= result && result <= 29648;
return result;
}
public int excuteGetNumRawDataModules(int ver) {
return getNumRawDataModules(ver);
}
private static int calculateNumOfModules(int ver) {
int size = ver * 4 + 17;
int result = size * size; // Number of modules in the whole QR Code square
@ -794,7 +805,9 @@ public final class QrCode {
return result;
}
public byte[] executeReedSolomonComputeDivisor(int degree) {
return reedSolomonComputeDivisor(degree);
}
// Returns the Reed-Solomon error correction codeword for the given data and divisor polynomials.
private static byte[] reedSolomonComputeRemainder(byte[] data, byte[] divisor) {
Objects.requireNonNull(data);

@ -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);
}
}

@ -7,7 +7,7 @@ public abstract class QrMode {
int modeBits;
// Number of character count bits for three different version ranges.
protected int[] numBitsCharCount = new int[4];
protected int[] numBitsCharCount;
int headCost;
/*-- Method --*/

@ -32,6 +32,7 @@ import java.util.regex.Pattern;
import QrSegment.Mode;
/**
* A segment of character/binary/control data in a QR Code symbol.
* Instances of this class are immutable.
@ -145,7 +146,7 @@ public final class QrSegment {
/** The length of this segment's unencoded data. Measured in characters for
* numeric/alphanumeric/kanji mode, bytes for byte mode, and 0 for ECI mode.
* Always zero or positive. Not the same as the data's bit length. */
public final int numChars;
public final int numberOfCharacters;
// The data bits of this segment. Not null. Accessed through getData().
final BitBuffer data;

Loading…
Cancel
Save