commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aherb...@apache.org
Subject [commons-codec] 05/08: Test encode of null and empty array with an offset
Date Thu, 27 Aug 2020 23:19:05 GMT
This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-codec.git

commit 3535c17eccb2251fc518aa545a800b4922c8dc35
Author: Alex Herbert <aherbert@apache.org>
AuthorDate: Thu Aug 27 23:25:27 2020 +0100

    Test encode of null and empty array with an offset
---
 .../org/apache/commons/codec/binary/Base16Test.java   |  3 +++
 .../org/apache/commons/codec/binary/Base32Test.java   | 19 +++++++++++++++++++
 .../org/apache/commons/codec/binary/Base64Test.java   |  3 +++
 3 files changed, 25 insertions(+)

diff --git a/src/test/java/org/apache/commons/codec/binary/Base16Test.java b/src/test/java/org/apache/commons/codec/binary/Base16Test.java
index fc7249f..f60709d 100644
--- a/src/test/java/org/apache/commons/codec/binary/Base16Test.java
+++ b/src/test/java/org/apache/commons/codec/binary/Base16Test.java
@@ -141,6 +141,9 @@ public class Base16Test {
         byte[] result = new Base16().encode(empty);
         assertEquals("empty Base16 encode", 0, result.length);
         assertEquals("empty Base16 encode", null, new Base16().encode(null));
+        result = new Base16().encode(empty, 0, 1);
+        assertEquals("empty Base16 encode with offset", 0, result.length);
+        assertEquals("empty Base16 encode with offset", null, new Base16().encode(null));
 
         empty = new byte[0];
         result = new Base16().decode(empty);
diff --git a/src/test/java/org/apache/commons/codec/binary/Base32Test.java b/src/test/java/org/apache/commons/codec/binary/Base32Test.java
index 7634f46..41ee709 100644
--- a/src/test/java/org/apache/commons/codec/binary/Base32Test.java
+++ b/src/test/java/org/apache/commons/codec/binary/Base32Test.java
@@ -240,6 +240,25 @@ public class Base32Test {
         assertNotNull(codec);
     }
 
+    /**
+     * Test encode and decode of empty byte array.
+     */
+    @Test
+    public void testEmptyBase32() {
+        byte[] empty = new byte[0];
+        byte[] result = new Base32().encode(empty);
+        assertEquals("empty Base32 encode", 0, result.length);
+        assertEquals("empty Base32 encode", null, new Base32().encode(null));
+        result = new Base32().encode(empty, 0, 1);
+        assertEquals("empty Base32 encode with offset", 0, result.length);
+        assertEquals("empty Base32 encode with offset", null, new Base32().encode(null));
+
+        empty = new byte[0];
+        result = new Base32().decode(empty);
+        assertEquals("empty Base32 decode", 0, result.length);
+        assertEquals("empty Base32 encode", null, new Base32().decode((byte[]) null));
+    }
+
     @Test
     public void testRandomBytes() {
         for (int i = 0; i < 20; i++) {
diff --git a/src/test/java/org/apache/commons/codec/binary/Base64Test.java b/src/test/java/org/apache/commons/codec/binary/Base64Test.java
index 82671ff..448d633 100644
--- a/src/test/java/org/apache/commons/codec/binary/Base64Test.java
+++ b/src/test/java/org/apache/commons/codec/binary/Base64Test.java
@@ -400,6 +400,9 @@ public class Base64Test {
         byte[] result = Base64.encodeBase64(empty);
         assertEquals("empty base64 encode", 0, result.length);
         assertEquals("empty base64 encode", null, Base64.encodeBase64(null));
+        result = new Base64().encode(empty, 0, 1);
+        assertEquals("empty base64 encode", 0, result.length);
+        assertEquals("empty base64 encode", null, new Base64().encode(null, 0, 1));
 
         empty = new byte[0];
         result = Base64.decodeBase64(empty);


Mime
View raw message