use of io.questdb.griffin.engine.TestBinarySequence in project questdb by bluestreak01.
the class CharsTest method testBase64Encode.
@Test
public void testBase64Encode() {
final StringSink sink = new StringSink();
final TestBinarySequence testBinarySequence = new TestBinarySequence();
sink.clear();
Chars.base64Encode(testBinarySequence.of("this is a test".getBytes()), 100, sink);
Assert.assertEquals(sink.toString(), "dGhpcyBpcyBhIHRlc3Q=");
sink.clear();
Chars.base64Encode(testBinarySequence.of("this is a test".getBytes()), 4, sink);
Assert.assertEquals(sink.toString(), "dGhpcw==");
// ignore the null
Chars.base64Encode(null, 4, sink);
Assert.assertEquals(sink.toString(), "dGhpcw==");
// random part
Random rand = new Random(System.currentTimeMillis());
int len = rand.nextInt(100) + 1;
byte[] bytes = new byte[len];
for (int i = 0; i < len; i++) {
bytes[i] = (byte) rand.nextInt(0xFF);
}
testBinarySequence.of(bytes);
sink.clear();
Chars.base64Encode(testBinarySequence, (int) testBinarySequence.length(), sink);
byte[] decoded = Base64.getDecoder().decode(sink.toString());
Assert.assertArrayEquals(bytes, decoded);
}
Aggregations