diff options
| author | Sean Owen <srowen@gmail.com> | 2016-09-05 19:29:59 +0300 |
|---|---|---|
| committer | Sean Owen <srowen@gmail.com> | 2016-09-05 19:29:59 +0300 |
| commit | 0895b3cefa8f38ae80d9f2d53dce9deb42240678 (patch) | |
| tree | 0fcf2b8423326f1fd752604309a66097f40acc32 /core/src/test/java/com | |
| parent | 39da9273620561aaa204addba74e326cdcf39446 (diff) | |
| download | zxing-0895b3cefa8f38ae80d9f2d53dce9deb42240678.tar.xz | |
Improve code coverage in some core classes, plus fix a small BitMatrix bug
Diffstat (limited to 'core/src/test/java/com')
3 files changed, 125 insertions, 0 deletions
diff --git a/core/src/test/java/com/google/zxing/RGBLuminanceSourceTestCase.java b/core/src/test/java/com/google/zxing/RGBLuminanceSourceTestCase.java new file mode 100644 index 000000000..c210df1be --- /dev/null +++ b/core/src/test/java/com/google/zxing/RGBLuminanceSourceTestCase.java @@ -0,0 +1,54 @@ +/* + * Copyright 2014 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; + +public final class RGBLuminanceSourceTestCase extends Assert { + + private static final RGBLuminanceSource SOURCE = new RGBLuminanceSource(3, 3, new int[] { + 0x000000, 0x7F7F7F, 0xFFFFFF, + 0xFF0000, 0x00FF00, 0x0000FF, + 0x0000FF, 0x00FF00, 0xFF0000}); + + @Test + public void testCrop() { + assertTrue(SOURCE.isCropSupported()); + LuminanceSource cropped = SOURCE.crop(1, 1, 1, 1); + assertEquals(1, cropped.getHeight()); + assertEquals(1, cropped.getWidth()); + assertArrayEquals(new byte[] { 0x7F }, cropped.getRow(0, null)); + } + + @Test + public void testMatrix() { + assertArrayEquals(new byte[] { 0x00, 0x7F, (byte) 0xFF, 0x3F, 0x7F, 0x3F, 0x3F, 0x7F, 0x3F }, + SOURCE.getMatrix()); + } + + @Test + public void testGetRow() { + assertArrayEquals(new byte[] { 0x3F, 0x7F, 0x3F }, SOURCE.getRow(2, new byte[3])); + } + + @Test + public void testToString() { + assertEquals("#+ \n#+#\n#+#\n", SOURCE.toString()); + } + +} diff --git a/core/src/test/java/com/google/zxing/common/BitArrayTestCase.java b/core/src/test/java/com/google/zxing/common/BitArrayTestCase.java index 1c23ca85f..84fe4f5e5 100644 --- a/core/src/test/java/com/google/zxing/common/BitArrayTestCase.java +++ b/core/src/test/java/com/google/zxing/common/BitArrayTestCase.java @@ -134,6 +134,17 @@ public final class BitArrayTestCase extends Assert { } @Test + public void testSetRange() { + BitArray array = new BitArray(64); + array.setRange(28, 36); + assertFalse(array.get(27)); + for (int i = 28; i < 36; i++) { + assertTrue(array.get(i)); + } + assertFalse(array.get(36)); + } + + @Test public void testClear() { BitArray array = new BitArray(32); for (int i = 0; i < 32; i++) { @@ -146,6 +157,16 @@ public final class BitArrayTestCase extends Assert { } @Test + public void testFlip() { + BitArray array = new BitArray(32); + assertFalse(array.get(5)); + array.flip(5); + assertTrue(array.get(5)); + array.flip(5); + assertFalse(array.get(5)); + } + + @Test public void testGetArray() { BitArray array = new BitArray(64); array.set(0); @@ -189,6 +210,28 @@ public final class BitArrayTestCase extends Assert { } } + @Test + public void testClone() { + BitArray array = new BitArray(32); + array.clone().set(0); + assertFalse(array.get(0)); + } + + @Test + public void testEquals() { + BitArray a = new BitArray(32); + BitArray b = new BitArray(32); + assertEquals(a, b); + assertEquals(a.hashCode(), b.hashCode()); + assertNotEquals(a, new BitArray(31)); + a.set(16); + assertNotEquals(a, new BitArray(31)); + assertNotEquals(a.hashCode(), b.hashCode()); + b.set(16); + assertEquals(a, b); + assertEquals(a.hashCode(), b.hashCode()); + } + private static int[] reverseOriginal(int[] oldBits, int size) { int[] newBits = new int[oldBits.length]; for (int i = 0; i < size; i++) { 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 b2a3c9ccf..5fa248366 100644 --- a/core/src/test/java/com/google/zxing/common/BitMatrixTestCase.java +++ b/core/src/test/java/com/google/zxing/common/BitMatrixTestCase.java @@ -57,6 +57,34 @@ public final class BitMatrixTestCase extends Assert { } @Test + public void testEnclosing() { + BitMatrix matrix = new BitMatrix(5); + assertNull(matrix.getEnclosingRectangle()); + matrix.setRegion(1, 1, 1, 1); + assertArrayEquals(new int[] { 1, 1, 1, 1 }, matrix.getEnclosingRectangle()); + matrix.setRegion(1, 1, 3, 2); + assertArrayEquals(new int[] { 1, 1, 3, 2 }, matrix.getEnclosingRectangle()); + matrix.setRegion(0, 0, 5, 5); + assertArrayEquals(new int[] { 0, 0, 5, 5 }, matrix.getEnclosingRectangle()); + } + + @Test + public void testOnBit() { + BitMatrix matrix = new BitMatrix(5); + assertNull(matrix.getTopLeftOnBit()); + assertNull(matrix.getBottomRightOnBit()); + matrix.setRegion(1, 1, 1, 1); + assertArrayEquals(new int[] { 1, 1 }, matrix.getTopLeftOnBit()); + assertArrayEquals(new int[] { 1, 1 }, matrix.getBottomRightOnBit()); + matrix.setRegion(1, 1, 3, 2); + assertArrayEquals(new int[] { 1, 1 }, matrix.getTopLeftOnBit()); + assertArrayEquals(new int[] { 3, 2 }, matrix.getBottomRightOnBit()); + matrix.setRegion(0, 0, 5, 5); + assertArrayEquals(new int[] { 0, 0 }, matrix.getTopLeftOnBit()); + assertArrayEquals(new int[] { 4, 4 }, matrix.getBottomRightOnBit()); + } + + @Test public void testRectangularMatrix() { BitMatrix matrix = new BitMatrix(75, 20); assertEquals(75, matrix.getWidth()); |
