@Test public void testGetSomeDataPositionGreaterThanSize() { try { sb.getSomeData(1, new byte[1], 0, 1); fail("IndexOutOfBoundsException expected but not thrown"); } catch (IndexOutOfBoundsException expected) { } try { sb.getSomeData(100, new byte[1], 0, 1); fail("IndexOutOfBoundsException expected but not thrown"); } catch (IndexOutOfBoundsException expected) { } append(100); try { sb.getSomeData(101, new byte[1], 0, 1); fail("IndexOutOfBoundsException expected but not thrown"); } catch (IndexOutOfBoundsException expected) { } try { sb.getSomeData(200, new byte[1], 0, 1); fail("IndexOutOfBoundsException expected but not thrown"); } catch (IndexOutOfBoundsException expected) { } }
@Test public void testAppendIllegalBufferOrOffsetOrLength() { try { sb.append(new byte[0], 0, 1); fail("IndexOutOfBoundsException expected but not thrown"); } catch (IndexOutOfBoundsException expected) { } try { sb.append(new byte[0], 1, 0); fail("IndexOutOfBoundsException expected but not thrown"); } catch (IndexOutOfBoundsException expected) { } try { sb.append(new byte[10], 0, 11); fail("IndexOutOfBoundsException expected but not thrown"); } catch (IndexOutOfBoundsException expected) { } try { sb.append(new byte[10], 1, 10); fail("IndexOutOfBoundsException expected but not thrown"); } catch (IndexOutOfBoundsException expected) { } }
@Test public void testGetSomeDataZeroNativePointer() { sb.dispose(); try { sb.getSomeData(0, new byte[1], 0, 1); fail("IllegalStateException expected but not thrown"); } catch (IllegalStateException expected) { } sb = null; }
@Test public void testSizeZeroNativePointer() { sb.dispose(); try { sb.dispose(); fail("IllegalStateException but not thrown"); } catch (IllegalStateException expected) { } sb = null; }
@Test public void testAppendZeroNativePointer() { sb.dispose(); try { sb.append(new byte[1], 0, 1); fail("IllegalStateException expected but not thrown"); } catch (IllegalStateException expected) { } sb = null; }
@Test public void testSizeRandomIncrements() { int expected = 0; assertEquals(expected, sb.size()); for (int i = 0; i < 100; i++) { int increment = random.nextInt(SEGMENT_SIZE * 10); sb.append(new byte[increment], 0, increment); expected += increment; assertEquals(expected, sb.size()); } }
@Test public void testSizePredefinedIncrements() { int[] increments = new int[] { 1, 5, 10, 100, 1000, SEGMENT_SIZE, SEGMENT_SIZE * 2, SEGMENT_SIZE * 10, }; int expected = 0; assertEquals(expected, sb.size()); for (int increment : increments) { sb.append(new byte[increment], 0, increment); expected += increment; assertEquals(expected, sb.size()); } }
@Test public void testAppendNegativeLength() { try { sb.append(new byte[0], 0, -1); fail("IndexOutOfBoundsException expected but not thrown"); } catch (IndexOutOfBoundsException expected) { } }
@Test public void testAppendNullBuffer() { try { sb.append(null, 0, 1); fail("NullPointerException expected but not thrown"); } catch (NullPointerException expected) { } }
@Test public void testGetSomeDataNegativeLength() { try { sb.getSomeData(0, new byte[0], 0, -1); fail("IndexOutOfBoundsException expected but not thrown"); } catch (IndexOutOfBoundsException expected) { } }
@Test public void testGetSomeDataNullBuffer() { try { sb.getSomeData(0, null, 0, 0); fail("NullPointerException expected but not thrown"); } catch (NullPointerException expected) { } }
@Test public void testGetSomeDataNegativePosition() { try { sb.getSomeData(-1, new byte[1], 0, 1); fail("IndexOutOfBoundsException expected but not thrown"); } catch (IndexOutOfBoundsException expected) { } }
public void compute(SharedBuffer buffer, ImagePreset preset, int type) { if (getRenderScriptContext() == null) { return; } setupEnvironment(preset, false); Vector<FilterRepresentation> filters = preset.getFilters(); Bitmap result = mCachedProcessing.process(mOriginalBitmap, filters, mEnvironment); buffer.setProducer(result); mEnvironment.cache(result); }
private void assertSharedBufferContains(byte[]... expectedChunks) { ArrayList<byte[]> expectedChunkList = new ArrayList<byte[]>(Arrays.asList(expectedChunks)); expectedChunkList.add(new byte[0]); long position = 0; for (byte[] expectedChunk : expectedChunkList) { byte[] buffer = new byte[SEGMENT_SIZE + 1]; int len = sb.getSomeData(position, buffer, 0, buffer.length); byte[] actualChunk = new byte[len]; System.arraycopy(buffer, 0, actualChunk, 0, len); assertArrayEquals(expectedChunk, actualChunk); position += len; } }
private void append(byte[] data) { int offset = random.nextBoolean() ? random.nextInt(100) : 0; int extraLength = random.nextBoolean() ? random.nextInt(200) : 0; byte[] buffer = g(0, offset + data.length + extraLength); System.arraycopy(data, 0, buffer, offset, data.length); sb.append(buffer, offset, data.length); for (int i = 0; i < offset; i++) { assertEquals((byte) (i & 0xff), buffer[i]); } for (int i = offset + data.length; i < buffer.length; i++) { assertEquals((byte) (i & 0xff), buffer[i]); } }
private byte[] getSomeData(double position, int length) { int offset = random.nextBoolean() ? random.nextInt(100) : 0; int extraLength = random.nextBoolean() ? random.nextInt(200) : 0; byte[] buffer = g(0, offset + length + extraLength); int len = sb.getSomeData((long) position, buffer, offset, length); assertTrue("Unexpected len: " + len, len >= 0); for (int i = 0; i < offset; i++) { assertEquals((byte) (i & 0xff), buffer[i]); } for (int i = offset + len; i < buffer.length; i++) { assertEquals((byte) (i & 0xff), buffer[i]); } byte[] result = new byte[len]; System.arraycopy(buffer, offset, result, 0, len); return result; }
@Test public void testConstructor1() { sb.dispose(); sb = new SharedBuffer(); }
public boolean needsRepaint() { SharedBuffer buffer = MasterImage.getImage().getPreviewBuffer(); return buffer.checkRepaintNeeded(); }
@Test public void testDispose() { sb.dispose(); sb = null; }
private void append(double length) { byte[] data = g(0, (int) length); sb.append(data, 0, data.length); }
@After public void after() { if (sb != null) { sb.dispose(); } }