diff options
| author | germinator <jeremykarlson@gmail.com> | 2016-08-08 13:22:35 +0300 |
|---|---|---|
| committer | Sean Owen <srowen@gmail.com> | 2016-08-08 13:22:35 +0300 |
| commit | d60c0f14bda2a2b6f9a1f24ca4c17236a52125df (patch) | |
| tree | e1a0f925eaf3fb157da564815f1a8c94f12d293d /core/src/test/java | |
| parent | f6a1e20e1bc1fcc986452c15d9683e87cdc4e453 (diff) | |
| download | zxing-d60c0f14bda2a2b6f9a1f24ca4c17236a52125df.tar.xz | |
Add ability to specify a QR code version hint. (#637)
* Add ability to specify a QR code version hint.
* Checkstyle.
Diffstat (limited to 'core/src/test/java')
| -rw-r--r-- | core/src/test/java/com/google/zxing/qrcode/encoder/EncoderTestCase.java | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/core/src/test/java/com/google/zxing/qrcode/encoder/EncoderTestCase.java b/core/src/test/java/com/google/zxing/qrcode/encoder/EncoderTestCase.java index b4e343319..51d4003df 100644 --- a/core/src/test/java/com/google/zxing/qrcode/encoder/EncoderTestCase.java +++ b/core/src/test/java/com/google/zxing/qrcode/encoder/EncoderTestCase.java @@ -22,11 +22,13 @@ import com.google.zxing.common.BitArray; import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; import com.google.zxing.qrcode.decoder.Mode; import com.google.zxing.qrcode.decoder.Version; + import org.junit.Assert; import org.junit.Test; import java.io.UnsupportedEncodingException; import java.util.EnumMap; +import java.util.HashMap; import java.util.Map; /** @@ -126,6 +128,26 @@ public final class EncoderTestCase extends Assert { ">>\n"; assertEquals(expected, qrCode.toString()); } + + @Test + public void testEncodeWithVersion() throws WriterException { + Map<EncodeHintType, Object> hints = new HashMap<>(); + hints.put(EncodeHintType.QR_VERSION, 7); + QRCode qrCode = Encoder.encode("ABCDEF", ErrorCorrectionLevel.H, hints); + assertTrue(qrCode.toString().contains(" version: 7\n")); + } + + @Test + public void testEncodeWithVersionTooSmall() throws WriterException { + Map<EncodeHintType, Object> hints = new HashMap<>(); + hints.put(EncodeHintType.QR_VERSION, 3); + try { + Encoder.encode("THISMESSAGEISTOOLONGFORAQRCODEVERSION3", ErrorCorrectionLevel.H, hints); + fail(); + } catch (WriterException e) { + assertEquals("Data too big for requested version", e.getMessage()); + } + } @Test public void testSimpleUTF8ECI() throws WriterException { |
