mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
javase/test/matrix: check format support (#1668)
This commit is contained in:
parent
6d1543b3dd
commit
4a59188a2e
|
@ -17,7 +17,9 @@
|
||||||
package com.google.zxing.client.j2se;
|
package com.google.zxing.client.j2se;
|
||||||
|
|
||||||
import com.google.zxing.common.BitMatrix;
|
import com.google.zxing.common.BitMatrix;
|
||||||
|
import org.hamcrest.CoreMatchers;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
import org.junit.Assume;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
|
@ -25,12 +27,13 @@ import java.awt.image.BufferedImage;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link MatrixToImageWriter}.
|
* Tests {@link MatrixToImageWriter}.
|
||||||
*/
|
*/
|
||||||
public final class MatrixToImageWriterTestCase extends Assert {
|
public final class MatrixToImageWriterTestCase extends Assert {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBlackAndWhite() throws Exception {
|
public void testBlackAndWhite() throws Exception {
|
||||||
doTest(new MatrixToImageConfig());
|
doTest(new MatrixToImageConfig());
|
||||||
|
@ -45,20 +48,22 @@ public final class MatrixToImageWriterTestCase extends Assert {
|
||||||
public void testAlpha() throws Exception {
|
public void testAlpha() throws Exception {
|
||||||
doTest(new MatrixToImageConfig(0x7F102030, 0x7F405060));
|
doTest(new MatrixToImageConfig(0x7F102030, 0x7F405060));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void doTest(MatrixToImageConfig config) throws IOException {
|
private static void doTest(MatrixToImageConfig config) throws IOException {
|
||||||
doTestFormat("tiff", config);
|
doTestFormat("tiff", config);
|
||||||
doTestFormat("png", config);
|
doTestFormat("png", config);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void doTestFormat(String format, MatrixToImageConfig config) throws IOException {
|
private static void doTestFormat(String format, MatrixToImageConfig config) throws IOException {
|
||||||
|
Assume.assumeThat(Arrays.asList(ImageIO.getWriterFormatNames()), CoreMatchers.hasItem(format));
|
||||||
|
|
||||||
int width = 2;
|
int width = 2;
|
||||||
int height = 3;
|
int height = 3;
|
||||||
BitMatrix matrix = new BitMatrix(width, height);
|
BitMatrix matrix = new BitMatrix(width, height);
|
||||||
matrix.set(0, 0);
|
matrix.set(0, 0);
|
||||||
matrix.set(0, 1);
|
matrix.set(0, 1);
|
||||||
matrix.set(1, 2);
|
matrix.set(1, 2);
|
||||||
|
|
||||||
BufferedImage newImage;
|
BufferedImage newImage;
|
||||||
Path tempFile = Files.createTempFile(null, "." + format);
|
Path tempFile = Files.createTempFile(null, "." + format);
|
||||||
try {
|
try {
|
||||||
|
@ -76,11 +81,11 @@ public final class MatrixToImageWriterTestCase extends Assert {
|
||||||
int expected = matrix.get(x, y) ? config.getPixelOnColor() : config.getPixelOffColor();
|
int expected = matrix.get(x, y) ? config.getPixelOnColor() : config.getPixelOffColor();
|
||||||
int actual = newImage.getRGB(x, y);
|
int actual = newImage.getRGB(x, y);
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"At " + x + "," + y + " expected " + Integer.toHexString(expected) +
|
"At " + x + "," + y + " expected " + Integer.toHexString(expected) +
|
||||||
" but got " + Integer.toHexString(actual),
|
" but got " + Integer.toHexString(actual),
|
||||||
expected, actual);
|
expected, actual);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue