summaryrefslogtreecommitdiff
path: root/core/src/test/java
diff options
context:
space:
mode:
authorSean Owen <srowen@gmail.com>2020-12-09 20:29:07 +0300
committerSean Owen <srowen@gmail.com>2020-12-09 20:29:07 +0300
commitfd364d9338efcb97536edf9c5162f2db88281666 (patch)
treea72fc2635b77d5a4faae67e9d0bbebb6db493563 /core/src/test/java
parente7ed6aee2ffeaae1fb3b608352a62e7d5588cb13 (diff)
downloadzxing-fd364d9338efcb97536edf9c5162f2db88281666.tar.xz
Improve test coverage
Diffstat (limited to 'core/src/test/java')
-rw-r--r--core/src/test/java/com/google/zxing/InvertedLuminanceSourceTestCase.java39
-rw-r--r--core/src/test/java/com/google/zxing/common/BitMatrixTestCase.java21
-rw-r--r--core/src/test/java/com/google/zxing/common/StringUtilsTestCase.java11
3 files changed, 70 insertions, 1 deletions
diff --git a/core/src/test/java/com/google/zxing/InvertedLuminanceSourceTestCase.java b/core/src/test/java/com/google/zxing/InvertedLuminanceSourceTestCase.java
new file mode 100644
index 000000000..932a7e2ab
--- /dev/null
+++ b/core/src/test/java/com/google/zxing/InvertedLuminanceSourceTestCase.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2020 ZXing authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.google.zxing;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.awt.image.BufferedImage;
+
+/**
+ * Tests {@link InvertedLuminanceSource}.
+ */
+public final class InvertedLuminanceSourceTestCase extends Assert {
+
+ @Test
+ public void testInverted() {
+ BufferedImage image = new BufferedImage(2, 1, BufferedImage.TYPE_INT_RGB);
+ image.setRGB(0, 0, 0xFFFFFF);
+ LuminanceSource source = new BufferedImageLuminanceSource(image);
+ assertArrayEquals(new byte[] { (byte) 0xFF, 0 }, source.getRow(0, null));
+ LuminanceSource inverted = new InvertedLuminanceSource(source);
+ assertArrayEquals(new byte[] { 0, (byte) 0xFF }, inverted.getRow(0, null));
+ }
+
+}
diff --git a/core/src/test/java/com/google/zxing/common/BitMatrixTestCase.java b/core/src/test/java/com/google/zxing/common/BitMatrixTestCase.java
index 2aeca625b..b92705e3a 100644
--- a/core/src/test/java/com/google/zxing/common/BitMatrixTestCase.java
+++ b/core/src/test/java/com/google/zxing/common/BitMatrixTestCase.java
@@ -19,6 +19,8 @@ package com.google.zxing.common;
import org.junit.Assert;
import org.junit.Test;
+import java.util.Arrays;
+
/**
* @author Sean Owen
* @author dswitkin@google.com (Daniel Switkin)
@@ -227,6 +229,25 @@ public final class BitMatrixTestCase extends Assert {
}
@Test
+ public void testParseBoolean() {
+ BitMatrix emptyMatrix = new BitMatrix(3, 3);
+ BitMatrix fullMatrix = new BitMatrix(3, 3);
+ fullMatrix.setRegion(0, 0, 3, 3);
+ BitMatrix centerMatrix = new BitMatrix(3, 3);
+ centerMatrix.setRegion(1, 1, 1, 1);
+ BitMatrix emptyMatrix24 = new BitMatrix(2, 4);
+
+ boolean[][] matrix = new boolean[3][3];
+ assertEquals(emptyMatrix, BitMatrix.parse(matrix));
+ matrix[1][1] = true;
+ assertEquals(centerMatrix, BitMatrix.parse(matrix));
+ for (boolean[] arr : matrix) {
+ Arrays.fill(arr, true);
+ }
+ assertEquals(fullMatrix, BitMatrix.parse(matrix));
+ }
+
+ @Test
public void testUnset() {
BitMatrix emptyMatrix = new BitMatrix(3, 3);
BitMatrix matrix = emptyMatrix.clone();
diff --git a/core/src/test/java/com/google/zxing/common/StringUtilsTestCase.java b/core/src/test/java/com/google/zxing/common/StringUtilsTestCase.java
index 6440209b9..355586935 100644
--- a/core/src/test/java/com/google/zxing/common/StringUtilsTestCase.java
+++ b/core/src/test/java/com/google/zxing/common/StringUtilsTestCase.java
@@ -19,8 +19,9 @@ package com.google.zxing.common;
import org.junit.Assert;
import org.junit.Test;
-import java.nio.charset.StandardCharsets;
import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+import java.util.Random;
/**
* Tests {@link StringUtils}.
@@ -28,6 +29,14 @@ import java.nio.charset.Charset;
public final class StringUtilsTestCase extends Assert {
@Test
+ public void testRandom() {
+ Random r = new Random(1234L);
+ byte[] bytes = new byte[1000];
+ r.nextBytes(bytes);
+ assertEquals(Charset.defaultCharset(), StringUtils.guessCharset(bytes, null));
+ }
+
+ @Test
public void testShortShiftJIS1() {
// 金魚
doTest(new byte[] { (byte) 0x8b, (byte) 0xe0, (byte) 0x8b, (byte) 0x9b, }, StringUtils.SHIFT_JIS_CHARSET, "SJIS");