|
21 | 21 |
|
22 | 22 | package at.favre.lib.bytes; |
23 | 23 |
|
| 24 | +import org.junit.Ignore; |
24 | 25 | import org.junit.Test; |
25 | 26 |
|
26 | 27 | import java.nio.ByteOrder; |
@@ -48,8 +49,47 @@ public void encodeBaseRadix() throws Exception { |
48 | 49 | assertNotEquals(new BinaryToTextEncoding.BaseRadix(2).encode(new byte[]{1, 2, 3}, ByteOrder.LITTLE_ENDIAN), new BinaryToTextEncoding.BaseRadix(2).encode(new byte[]{1, 2, 3}, ByteOrder.BIG_ENDIAN)); |
49 | 50 | } |
50 | 51 |
|
| 52 | + @Test |
| 53 | + @Ignore |
| 54 | + public void encodeDecodeRadix() throws Exception { |
| 55 | + for (int i = 0; i < 32; i++) { |
| 56 | + Bytes rnd = Bytes.random(i); |
| 57 | + System.out.println("\n\nNEW TEST: " + i + " bytes\n"); |
| 58 | + for (int j = 16; j < 36; j++) { |
| 59 | + BinaryToTextEncoding.EncoderDecoder encoding = new BinaryToTextEncoding.BaseRadix(j); |
| 60 | + String encodedBigEndian = encoding.encode(rnd.array(), ByteOrder.BIG_ENDIAN); |
| 61 | + byte[] decoded = encoding.decode(encodedBigEndian); |
| 62 | + System.out.println("radix" + j + ":\t" + encodedBigEndian); |
| 63 | + System.out.println("orig :\t" + rnd.encodeHex()); |
| 64 | + System.out.println("enc :\t" + Bytes.wrap(decoded).encodeHex()); |
| 65 | + } |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + @Test |
| 70 | + public void encodeDecodeBase64() throws Exception { |
| 71 | + for (int i = 4; i < 32; i += 4) { |
| 72 | + Bytes rnd = Bytes.random(i); |
| 73 | + BinaryToTextEncoding.EncoderDecoder encoding = new BinaryToTextEncoding.Base64Encoding(); |
| 74 | + String encodedBigEndian = encoding.encode(rnd.array(), ByteOrder.BIG_ENDIAN); |
| 75 | + byte[] decoded = encoding.decode(encodedBigEndian); |
| 76 | + assertEquals(rnd, Bytes.wrap(decoded)); |
| 77 | + } |
| 78 | + } |
| 79 | + |
| 80 | + @Test |
| 81 | + public void encodeDecodeHex() throws Exception { |
| 82 | + for (int i = 4; i < 32; i += 4) { |
| 83 | + Bytes rnd = Bytes.random(i); |
| 84 | + BinaryToTextEncoding.EncoderDecoder encoding = new BinaryToTextEncoding.Hex(); |
| 85 | + String encodedBigEndian = encoding.encode(rnd.array(), ByteOrder.BIG_ENDIAN); |
| 86 | + byte[] decoded = encoding.decode(encodedBigEndian); |
| 87 | + assertEquals(rnd, Bytes.wrap(decoded)); |
| 88 | + } |
| 89 | + } |
| 90 | + |
51 | 91 | @Test(expected = IllegalArgumentException.class) |
52 | | - public void decodeInvalidRadix116() throws Exception { |
| 92 | + public void decodeInvalidRadix16() throws Exception { |
53 | 93 | new BinaryToTextEncoding.BaseRadix(16).decode("AAI="); |
54 | 94 | } |
55 | 95 |
|
|
0 commit comments