FileDocCategorySizeDatePackage
ByteArrayPoolTest.javaAPI DocAndroid 5.1 API2156Thu Mar 12 22:22:56 GMT 2015com.android.volley.toolbox

ByteArrayPoolTest

public class ByteArrayPoolTest extends android.test.AndroidTestCase

Fields Summary
Constructors Summary
Methods Summary
public voidtestObeysSizeLimit()

        ByteArrayPool pool = new ByteArrayPool(32);

        byte[] buf1 = pool.getBuf(16);
        byte[] buf2 = pool.getBuf(16);
        byte[] buf3 = pool.getBuf(16);

        pool.returnBuf(buf1);
        pool.returnBuf(buf2);
        pool.returnBuf(buf3);

        byte[] buf4 = pool.getBuf(16);
        byte[] buf5 = pool.getBuf(16);
        byte[] buf6 = pool.getBuf(16);

        assertTrue(buf4 == buf2 || buf4 == buf3);
        assertTrue(buf5 == buf2 || buf5 == buf3);
        assertTrue(buf4 != buf5);
        assertTrue(buf6 != buf1 && buf6 != buf2 && buf6 != buf3);
    
public voidtestReturnsBufferWithRightSize()

        ByteArrayPool pool = new ByteArrayPool(32);

        byte[] buf1 = pool.getBuf(16);
        pool.returnBuf(buf1);

        byte[] buf2 = pool.getBuf(17);
        assertNotSame(buf2, buf1);

        byte[] buf3 = pool.getBuf(15);
        assertSame(buf3, buf1);
    
public voidtestReusesBuffer()

        ByteArrayPool pool = new ByteArrayPool(32);

        byte[] buf1 = pool.getBuf(16);
        byte[] buf2 = pool.getBuf(16);

        pool.returnBuf(buf1);
        pool.returnBuf(buf2);

        byte[] buf3 = pool.getBuf(16);
        byte[] buf4 = pool.getBuf(16);
        assertTrue(buf3 == buf1 || buf3 == buf2);
        assertTrue(buf4 == buf1 || buf4 == buf2);
        assertTrue(buf3 != buf4);