diff options
| author | cdcarloschacon <cdcarloschacon@gmail.com> | 2024-05-02 07:11:39 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-02 07:11:39 +0300 |
| commit | 539733e5c9ea00ecd24295c822a17ae784ea4ff0 (patch) | |
| tree | 36e7ff43024f0f85b81c7650d4a633299e09670e /core/src/test/java/com/google | |
| parent | 2326dd4ff3adb9cd7ecd0d2937e37b4babe0a1fe (diff) | |
| download | zxing-539733e5c9ea00ecd24295c822a17ae784ea4ff0.tar.xz | |
Promote renderResult method to public (#1801)
This small commit makes public the "renderResult" method of the
"QRCodeWriter" class.
The reason to promote this method as public is that I'm facing
Business Case where, besides of generating the QR code as a PNG image,
I also need to print information about the QR code itself (specifically,
the QR version). Navigating through the code of zxing library, I noticed
that the com.google.zxing.qrcode.encoder.Encoder allows me to have that
(the QR metadata); however, by invoking that class I only have part of
the equation (the QRCode DTO) ... I'm still needing to generate the
BitMatrix in order to produce the QR image.
Here, I have two alternatives: either I invoke the Encoder.encode
class by myself and repeat the same logic when invoking the
QRCodeWriter.encode method; or I make the renderResult Public, call the
Encoder.encode and then I proceed to call the QRCodeWriter.renderResult
method with the previous result.
Diffstat (limited to 'core/src/test/java/com/google')
| -rw-r--r-- | core/src/test/java/com/google/zxing/qrcode/QRCodeWriterTestCase.java | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/core/src/test/java/com/google/zxing/qrcode/QRCodeWriterTestCase.java b/core/src/test/java/com/google/zxing/qrcode/QRCodeWriterTestCase.java index c16d2957c..0b82430ff 100644 --- a/core/src/test/java/com/google/zxing/qrcode/QRCodeWriterTestCase.java +++ b/core/src/test/java/com/google/zxing/qrcode/QRCodeWriterTestCase.java @@ -22,6 +22,9 @@ import com.google.zxing.Writer; import com.google.zxing.WriterException; import com.google.zxing.common.BitMatrix; import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; +import com.google.zxing.qrcode.encoder.ByteMatrix; +import com.google.zxing.qrcode.encoder.QRCode; + import org.junit.Assert; import org.junit.Test; @@ -133,4 +136,55 @@ public final class QRCodeWriterTestCase extends Assert { "renderer-test-01.png"); } + @Test + public void renderResultScalesNothing() { + final int expectedSize = 33; // Original Size (25) + quietZone + BitMatrix result; + ByteMatrix matrix; + QRCode code; + + matrix = new ByteMatrix(25, 25); // QR Version 2! It's all white + // but it doesn't matter here + + code = new QRCode(); + code.setMatrix(matrix); + + // Test: + result = QRCodeWriter.renderResult(code, -1, -1, 4); + + assertNotNull(result); + assertEquals(result.getHeight(), expectedSize); + assertEquals(result.getWidth(), expectedSize); + } + + @Test + public void renderResultScalesWhenRequired() { + final int expectedSize = 66; + BitMatrix result; + ByteMatrix matrix; + QRCode code; + + matrix = new ByteMatrix(25, 25); // QR Version 2! It's all white + // but it doesn't matter here + + code = new QRCode(); + code.setMatrix(matrix); + + // Test: + result = QRCodeWriter.renderResult(code, 66, 66, 4); + + assertNotNull(result); + assertEquals(result.getHeight(), expectedSize); + assertEquals(result.getWidth(), expectedSize); + } + + @Test(expected = NullPointerException.class) + public void renderResultThrowsExIfCcodeIsNull() { + QRCodeWriter.renderResult(null, 0, 0, 0); + } + + @Test(expected = IllegalStateException.class) + public void renderResultThrowsExIfCodeIsIncomplete() { + QRCodeWriter.renderResult(new QRCode(), 0, 0, 0); + } } |
