Skip to content

Commit

Permalink
Test encode of null and empty array with an offset
Browse files Browse the repository at this point in the history
  • Loading branch information
aherbert committed Aug 27, 2020
1 parent e42dfe1 commit 3535c17
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/test/java/org/apache/commons/codec/binary/Base16Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ public void testEmptyBase16() {
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);
Expand Down
19 changes: 19 additions & 0 deletions src/test/java/org/apache/commons/codec/binary/Base32Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,25 @@ public void testCodec200() {
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++) {
Expand Down
3 changes: 3 additions & 0 deletions src/test/java/org/apache/commons/codec/binary/Base64Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,9 @@ public void testEmptyBase64() {
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);
Expand Down

0 comments on commit 3535c17

Please sign in to comment.