@Test public final void testLoadArrayIndexIODataError() throws Exception { final JCGLAsyncResourceLoaderType loader = this.getLoader("main"); final CompletableFuture<JCGLAsyncBufferPairType> f = loader.loadArrayIndexBuffers( () -> { throw new UncheckedIOException(new IOException("IO failure")); }, (data) -> Long.valueOf(23L), JCGLUsageHint.USAGE_STATIC_DRAW, (data) -> Long.valueOf(42L), JCGLUnsignedType.TYPE_UNSIGNED_INT, JCGLUsageHint.USAGE_STATIC_DRAW, (data, array) -> JCGLBufferUpdates.newUpdateReplacingAll(array), (data, index) -> JCGLBufferUpdates.newUpdateReplacingAll(index) ); this.expected.expect(ExecutionException.class); this.expected.expectMessage("IO failure"); f.get(30L, TimeUnit.SECONDS); }
@Test public final void testLoadArrayIndexIOArraySizeError() throws Exception { final JCGLAsyncResourceLoaderType loader = this.getLoader("main"); final CompletableFuture<JCGLAsyncBufferPair> f = loader.loadArrayIndexBuffers( () -> "Hello", (data) -> { throw new UncheckedIOException(new IOException("IO failure")); }, JCGLUsageHint.USAGE_STATIC_DRAW, (data) -> Long.valueOf(42L), JCGLUnsignedType.TYPE_UNSIGNED_INT, JCGLUsageHint.USAGE_STATIC_DRAW, (data, array) -> JCGLBufferUpdates.newUpdateReplacingAll(array), (data, index) -> JCGLBufferUpdates.newUpdateReplacingAll(index) ); this.expected.expect(ExecutionException.class); this.expected.expectMessage("IO failure"); f.get(30L, TimeUnit.SECONDS); }
@Test public final void testLoadArrayIndexIOIndexUpdateError() throws Exception { final JCGLAsyncResourceLoaderType loader = this.getLoader("main"); final CompletableFuture<JCGLAsyncBufferPairType> f = loader.loadArrayIndexBuffers( () -> "Hello", (data) -> Long.valueOf(42L), JCGLUsageHint.USAGE_STATIC_DRAW, (data) -> Long.valueOf(42L), JCGLUnsignedType.TYPE_UNSIGNED_INT, JCGLUsageHint.USAGE_STATIC_DRAW, (data, array) -> JCGLBufferUpdates.newUpdateReplacingAll(array), (data, index) -> { throw new UncheckedIOException(new IOException("IO failure")); } ); this.expected.expect(ExecutionException.class); this.expected.expectMessage("IO failure"); f.get(30L, TimeUnit.SECONDS); }
@Test public final void testArrayRead() { final JCGLArrayBuffersType ga = this.getArrayBuffers("main"); final JCGLArrayBufferType a = ga.arrayBufferAllocate(100L, JCGLUsageHint.USAGE_STATIC_DRAW); final JCGLBufferUpdateType<JCGLArrayBufferType> u = JCGLBufferUpdates.newUpdateReplacingAll(a); final ByteBuffer b = u.data(); for (int index = 0; index < 100; ++index) { b.put(index, (byte) 0x50); } ga.arrayBufferUpdate(u); final ByteBuffer e = ga.arrayBufferRead(a, size -> ByteBuffer.allocateDirect((int) size)); for (int index = 0; index < 100; ++index) { final long bv = (long) b.get(index); final long ev = (long) e.get(index); Assert.assertEquals("index " + index, bv, ev); } }
@Test public final void testArrayRead() { final JCGLArrayBuffersType ga = this.getArrayBuffers("main"); final JCGLArrayBufferType a = ga.arrayBufferAllocate(100L, JCGLUsageHint.USAGE_STATIC_DRAW); final JCGLBufferUpdateType<JCGLArrayBufferType> u = JCGLBufferUpdates.newUpdateReplacingAll(a); final ByteBuffer b = u.getData(); for (int index = 0; index < 100; ++index) { b.put(index, (byte) 0x50); } ga.arrayBufferUpdate(u); final ByteBuffer e = ga.arrayBufferRead(a, size -> ByteBuffer.allocateDirect((int) size)); for (int index = 0; index < 100; ++index) { final long bv = (long) b.get(index); final long ev = (long) e.get(index); Assert.assertEquals("index " + index, bv, ev); } }
@Test public final void testIndexRead() { final Interfaces ii = this.getIndexBuffers("main"); final JCGLIndexBuffersType gi = ii.getIndexBuffers(); final JCGLIndexBufferType i = gi.indexBufferAllocate( 100L, JCGLUnsignedType.TYPE_UNSIGNED_BYTE, JCGLUsageHint.USAGE_STATIC_DRAW); final JCGLBufferUpdateType<JCGLIndexBufferType> u = JCGLBufferUpdates.newUpdateReplacingAll(i); final ByteBuffer b = u.getData(); for (int index = 0; index < 100; ++index) { b.put(index, (byte) 0x50); } gi.indexBufferUpdate(u); final ByteBuffer e = gi.indexBufferRead(i, size -> ByteBuffer.allocateDirect((int) size)); for (int index = 0; index < 100; ++index) { Assert.assertEquals((long) b.get(index), (long) e.get(index)); } }
@Test public final void testArrayUpdateDeleted() { final JCGLArrayBuffersType ga = this.getArrayBuffers("main"); final JCGLArrayBufferType a = ga.arrayBufferAllocate(100L, JCGLUsageHint.USAGE_STATIC_DRAW); final JCGLBufferUpdateType<JCGLArrayBufferType> u = JCGLBufferUpdates.newUpdateReplacingAll(a); ga.arrayBufferDelete(a); this.expected.expect(JCGLExceptionDeleted.class); ga.arrayBufferUpdate(u); Assert.fail(); }
@Test public final void testArrayUpdateDeleted() { final JCGLArrayBuffersType ga = this.getArrayBuffers("main"); final JCGLArrayBufferType a = ga.arrayBufferAllocate(100L, JCGLUsageHint.USAGE_STATIC_DRAW); final JCGLBufferUpdateType<JCGLArrayBufferType> u = JCGLBufferUpdates.newUpdateReplacingAll(a); ga.arrayBufferDelete(a); this.expected.expect(JCGLExceptionDeleted.class); ga.arrayBufferUpdate(u); Assert.fail(); }
@Test public final void testArrayUpdateNotBound() { final JCGLArrayBuffersType ga = this.getArrayBuffers("main"); final JCGLArrayBufferType a = ga.arrayBufferAllocate(100L, JCGLUsageHint.USAGE_STATIC_DRAW); final JCGLBufferUpdateType<JCGLArrayBufferType> u = JCGLBufferUpdates.newUpdateReplacingAll(a); ga.arrayBufferUnbind(); this.expected.expect(JCGLExceptionBufferNotBound.class); ga.arrayBufferUpdate(u); Assert.fail(); }
@Test public final void testArrayUpdateNotBound() { final JCGLArrayBuffersType ga = this.getArrayBuffers("main"); final JCGLArrayBufferType a = ga.arrayBufferAllocate(100L, JCGLUsageHint.USAGE_STATIC_DRAW); final JCGLBufferUpdateType<JCGLArrayBufferType> u = JCGLBufferUpdates.newUpdateReplacingAll(a); ga.arrayBufferUnbind(); this.expected.expect(JCGLExceptionBufferNotBound.class); ga.arrayBufferUpdate(u); Assert.fail(); }
@Test public final void testIndexUpdateDeleted() { final Interfaces ii = this.getIndexBuffers("main"); final JCGLIndexBuffersType gi = ii.getIndexBuffers(); final JCGLIndexBufferType i = gi.indexBufferAllocate( 100L, JCGLUnsignedType.TYPE_UNSIGNED_BYTE, JCGLUsageHint.USAGE_STATIC_DRAW); final JCGLBufferUpdateType<JCGLIndexBufferType> u = JCGLBufferUpdates.newUpdateReplacingAll(i); gi.indexBufferDelete(i); this.expected.expect(JCGLExceptionDeleted.class); gi.indexBufferUpdate(u); }
@Test public final void testIndexUpdateDeleted() { final Interfaces ii = this.getIndexBuffers("main"); final JCGLIndexBuffersType gi = ii.getIndexBuffers(); final JCGLIndexBufferType i = gi.indexBufferAllocate( 100L, JCGLUnsignedType.TYPE_UNSIGNED_BYTE, JCGLUsageHint.USAGE_STATIC_DRAW); final JCGLBufferUpdateType<JCGLIndexBufferType> u = JCGLBufferUpdates.newUpdateReplacingAll(i); gi.indexBufferDelete(i); this.expected.expect(JCGLExceptionDeleted.class); gi.indexBufferUpdate(u); }
@Test public final void testIndexUpdateNotBound() { final Interfaces ii = this.getIndexBuffers("main"); final JCGLIndexBuffersType gi = ii.getIndexBuffers(); final JCGLIndexBufferType i = gi.indexBufferAllocate( 100L, JCGLUnsignedType.TYPE_UNSIGNED_BYTE, JCGLUsageHint.USAGE_STATIC_DRAW); final JCGLBufferUpdateType<JCGLIndexBufferType> u = JCGLBufferUpdates.newUpdateReplacingAll(i); gi.indexBufferUnbind(); this.expected.expect(JCGLExceptionBufferNotBound.class); gi.indexBufferUpdate(u); }
@Test public final void testIndexUpdateNotBound() { final Interfaces ii = this.getIndexBuffers("main"); final JCGLIndexBuffersType gi = ii.getIndexBuffers(); final JCGLIndexBufferType i = gi.indexBufferAllocate( 100L, JCGLUnsignedType.TYPE_UNSIGNED_BYTE, JCGLUsageHint.USAGE_STATIC_DRAW); final JCGLBufferUpdateType<JCGLIndexBufferType> u = JCGLBufferUpdates.newUpdateReplacingAll(i); gi.indexBufferUnbind(); this.expected.expect(JCGLExceptionBufferNotBound.class); gi.indexBufferUpdate(u); }
@Test public final void testBufferUpdateAllIdentities() { final JCGLArrayBuffersType ga = this.getArrayBuffers("main"); final JCGLArrayBufferType a = ga.arrayBufferAllocate(100L, JCGLUsageHint.USAGE_STATIC_DRAW); final JCGLBufferUpdateType<JCGLArrayBufferType> u = JCGLBufferUpdates.newUpdateReplacingAll(a); Assert.assertSame(a, u.getBuffer()); final UnsignedRangeInclusiveL u_range = u.getDataUpdateRange(); final ByteBuffer u_data = u.getData(); Assert.assertEquals(a.getRange(), u_range); Assert.assertEquals(u_range.getInterval(), (long) u_data.capacity()); }
@Test public final void testBufferUpdateAllIdentities() { final JCGLArrayBuffersType ga = this.getArrayBuffers("main"); final JCGLArrayBufferType a = ga.arrayBufferAllocate(100L, JCGLUsageHint.USAGE_STATIC_DRAW); final JCGLBufferUpdateType<JCGLArrayBufferType> u = JCGLBufferUpdates.newUpdateReplacingAll(a); Assert.assertSame(a, u.buffer()); final UnsignedRangeInclusiveL u_range = u.dataUpdateRange(); final ByteBuffer u_data = u.data(); Assert.assertEquals(a.byteRange(), u_range); Assert.assertEquals(u_range.getInterval(), (long) u_data.capacity()); }
@Test public final void testArrayUpdateShared() { final JCGLSharedContextPair<JCGLArrayBuffersType> p = this.getArrayBuffersSharedWith("main", "alt"); final JCGLContextType ca = p.getMasterContext(); final JCGLContextType cb = p.getSlaveContext(); final JCGLArrayBuffersType ga = p.getMasterValue(); final JCGLArrayBuffersType gb = p.getSlaveValue(); Assert.assertTrue(ca.contextIsCurrent()); Assert.assertFalse(cb.contextIsCurrent()); final JCGLArrayBufferType a = ga.arrayBufferAllocate(100L, JCGLUsageHint.USAGE_STATIC_DRAW); final JCGLBufferUpdateType<JCGLArrayBufferType> u = JCGLBufferUpdates.newUpdateReplacingAll(a); ca.contextReleaseCurrent(); cb.contextMakeCurrent(); gb.arrayBufferBind(a); gb.arrayBufferUpdate(u); }
@Test public final void testArrayUpdateShared() { final JCGLSharedContextPair<JCGLArrayBuffersType> p = this.getArrayBuffersSharedWith("main", "alt"); final JCGLContextType ca = p.getMasterContext(); final JCGLContextType cb = p.getSlaveContext(); final JCGLArrayBuffersType ga = p.getMasterValue(); final JCGLArrayBuffersType gb = p.getSlaveValue(); Assert.assertTrue(ca.contextIsCurrent()); Assert.assertFalse(cb.contextIsCurrent()); final JCGLArrayBufferType a = ga.arrayBufferAllocate(100L, JCGLUsageHint.USAGE_STATIC_DRAW); final JCGLBufferUpdateType<JCGLArrayBufferType> u = JCGLBufferUpdates.newUpdateReplacingAll(a); ca.contextReleaseCurrent(); cb.contextMakeCurrent(); gb.arrayBufferBind(a); gb.arrayBufferUpdate(u); }
@Test public final void testIndexUpdateShared() { final JCGLSharedContextPair<JCGLIndexBuffersType> p = this.getIndexBuffersSharedWith("main", "alt"); final JCGLContextType ca = p.getMasterContext(); final JCGLContextType cb = p.getSlaveContext(); final JCGLIndexBuffersType gi = p.getMasterValue(); final JCGLIndexBuffersType gb = p.getSlaveValue(); Assert.assertTrue(ca.contextIsCurrent()); Assert.assertFalse(cb.contextIsCurrent()); final JCGLIndexBufferType i = gi.indexBufferAllocate( 100L, JCGLUnsignedType.TYPE_UNSIGNED_BYTE, JCGLUsageHint.USAGE_STATIC_DRAW); final JCGLBufferUpdateType<JCGLIndexBufferType> u = JCGLBufferUpdates.newUpdateReplacingAll(i); ca.contextReleaseCurrent(); cb.contextMakeCurrent(); gb.indexBufferBind(i); gb.indexBufferUpdate(u); }
@Test public final void testArrayUpdateWrongContext() { final JCGLUnsharedContextPair<JCGLArrayBuffersType> p = this.getArrayBuffersUnshared("main", "alt"); final JCGLContextType ca = p.getContextA(); final JCGLContextType cb = p.getContextB(); final JCGLArrayBuffersType ga = p.getValueA(); final JCGLArrayBuffersType gb = p.getValueB(); Assert.assertFalse(ca.contextIsCurrent()); Assert.assertTrue(cb.contextIsCurrent()); cb.contextReleaseCurrent(); ca.contextMakeCurrent(); final JCGLArrayBufferType a = ga.arrayBufferAllocate(100L, JCGLUsageHint.USAGE_STATIC_DRAW); final JCGLBufferUpdateType<JCGLArrayBufferType> u = JCGLBufferUpdates.newUpdateReplacingAll(a); ca.contextReleaseCurrent(); cb.contextMakeCurrent(); this.expected.expect(JCGLExceptionWrongContext.class); gb.arrayBufferUpdate(u); Assert.fail(); }