Skip to content

Commit

Permalink
Test the codec policy property
Browse files Browse the repository at this point in the history
  • Loading branch information
aherbert committed Aug 27, 2020
1 parent 4c542d7 commit 5365879
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
2 changes: 2 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 @@ -587,6 +587,7 @@ public void testStrictDecoding() {
final String encoded = "aabbccdde"; // Note the trailing `e` which does not make up a hex-pair and so is only 1/2 byte

final Base16 b16 = new Base16(true, CodecPolicy.STRICT);
assertEquals(CodecPolicy.STRICT, b16.getCodecPolicy());
b16.decode(StringUtils.getBytesUtf8(encoded));
}

Expand All @@ -595,6 +596,7 @@ public void testLenientDecoding() {
final String encoded = "aabbccdde"; // Note the trailing `e` which does not make up a hex-pair and so is only 1/2 byte

final Base16 b16 = new Base16(true, CodecPolicy.LENIENT);
assertEquals(CodecPolicy.LENIENT, b16.getCodecPolicy());

final byte[] decoded = b16.decode(StringUtils.getBytesUtf8(encoded));
assertArrayEquals(new byte[] {(byte)0xaa, (byte)0xbb, (byte)0xcc, (byte)0xdd}, decoded);
Expand Down
2 changes: 2 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 @@ -367,9 +367,11 @@ private static void assertBase32DecodingOfTrailingBits(final int nbits) {
// Requires strict decoding
final Base32 codec = new Base32(0, null, false, BaseNCodec.PAD_DEFAULT, CodecPolicy.STRICT);
assertTrue(codec.isStrictDecoding());
assertEquals(CodecPolicy.STRICT, codec.getCodecPolicy());
// A lenient decoder should not re-encode to the same bytes
final Base32 defaultCodec = new Base32();
assertFalse(defaultCodec.isStrictDecoding());
assertEquals(CodecPolicy.LENIENT, defaultCodec.getCodecPolicy());

// Create the encoded bytes. The first characters must be valid so fill with 'zero'
// then pad to the block size.
Expand Down
2 changes: 2 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 @@ -1363,9 +1363,11 @@ private static void assertBase64DecodingOfTrailingBits(final int nbits) {
final Base64 codec = new Base64(0, null, false, CodecPolicy.STRICT);
// Requires strict decoding
assertTrue(codec.isStrictDecoding());
assertEquals(CodecPolicy.STRICT, codec.getCodecPolicy());
// A lenient decoder should not re-encode to the same bytes
final Base64 defaultCodec = new Base64();
assertFalse(defaultCodec.isStrictDecoding());
assertEquals(CodecPolicy.LENIENT, defaultCodec.getCodecPolicy());

// Create the encoded bytes. The first characters must be valid so fill with 'zero'
// then pad to the block size.
Expand Down

0 comments on commit 5365879

Please sign in to comment.