Search in sources :

Example 6 with TestBinarySequence

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);
}
Also used : TestBinarySequence(io.questdb.griffin.engine.TestBinarySequence) Random(java.util.Random) StringSink(io.questdb.std.str.StringSink) Test(org.junit.Test)

Aggregations

TestBinarySequence (io.questdb.griffin.engine.TestBinarySequence)6 Test (org.junit.Test)3 Function (io.questdb.cairo.sql.Function)2 ToStrTimestampFunctionFactory (io.questdb.griffin.engine.functions.date.ToStrTimestampFunctionFactory)2 MemoryARW (io.questdb.cairo.vm.api.MemoryARW)1 BinarySequence (io.questdb.std.BinarySequence)1 Long256 (io.questdb.std.Long256)1 Rnd (io.questdb.std.Rnd)1 StringSink (io.questdb.std.str.StringSink)1 Random (java.util.Random)1