@Test public void subBufferTest02FloatBuffer() { out.println(" - - - subBufferTest - - - "); @SuppressWarnings("unchecked") final CLPlatform platform = CLPlatform.getDefault(version(CL_1_1)); if (platform == null) { out.println("aborting subBufferTest"); return; } final CLContext context = CLContext.create(platform); try { final int subelements = 5; final long lMaxAlignment = context.getMaxMemBaseAddrAlign(); final int iMaxAlignment = Bitstream.uint32LongToInt(lMaxAlignment); System.err.println( "XXX: maxAlignment " + lMaxAlignment + ", 0x" + Long.toHexString(lMaxAlignment) + ", (int)" + iMaxAlignment + ", (int)0x" + Integer.toHexString(iMaxAlignment)); if (-1 == iMaxAlignment) { throw new RuntimeException( "Cannot handle MaxMemBaseAddrAlign > MAX_INT, has 0x" + Long.toHexString(lMaxAlignment)); } // FIXME: See Bug 979: Offset/Alignment via offset calculation per element-count is faulty! final int floatsPerAlignment = iMaxAlignment / Buffers.SIZEOF_FLOAT; // device + direct buffer final CLBuffer<FloatBuffer> buffer = context.createFloatBuffer(floatsPerAlignment + subelements); assertFalse(buffer.isSubBuffer()); assertNotNull(buffer.getSubBuffers()); assertTrue(buffer.getSubBuffers().isEmpty()); final CLSubBuffer<FloatBuffer> subBuffer = buffer.createSubBuffer(floatsPerAlignment, subelements); assertTrue(subBuffer.isSubBuffer()); assertEquals(subelements, subBuffer.getBuffer().capacity()); assertEquals(floatsPerAlignment, subBuffer.getOffset()); assertEquals(iMaxAlignment, subBuffer.getCLOffset()); assertEquals(buffer, subBuffer.getParent()); assertEquals(1, buffer.getSubBuffers().size()); assertEquals(subBuffer.getCLCapacity(), subBuffer.getBuffer().capacity()); subBuffer.release(); assertEquals(0, buffer.getSubBuffers().size()); } finally { context.release(); } }
@Test public void subBufferTest01ByteBuffer() { out.println(" - - - subBufferTest - - - "); @SuppressWarnings("unchecked") final CLPlatform platform = CLPlatform.getDefault(version(CL_1_1)); if (platform == null) { out.println("aborting subBufferTest"); return; } final CLContext context = CLContext.create(platform); try { final int subelements = 5; final long lMaxAlignment = context.getMaxMemBaseAddrAlign(); final int iMaxAlignment = Bitstream.uint32LongToInt(lMaxAlignment); System.err.println( "XXX: maxAlignment " + lMaxAlignment + ", 0x" + Long.toHexString(lMaxAlignment) + ", (int)" + iMaxAlignment + ", (int)0x" + Integer.toHexString(iMaxAlignment)); if (-1 == iMaxAlignment) { throw new RuntimeException( "Cannot handle MaxMemBaseAddrAlign > MAX_INT, has 0x" + Long.toHexString(lMaxAlignment)); } // device only final CLBuffer<?> buffer = context.createBuffer(iMaxAlignment + subelements); assertFalse(buffer.isSubBuffer()); assertNotNull(buffer.getSubBuffers()); assertTrue(buffer.getSubBuffers().isEmpty()); final CLSubBuffer<?> subBuffer = buffer.createSubBuffer(iMaxAlignment, subelements); assertTrue(subBuffer.isSubBuffer()); assertEquals(subelements, subBuffer.getCLSize()); assertEquals(iMaxAlignment, subBuffer.getOffset()); assertEquals(iMaxAlignment, subBuffer.getCLOffset()); assertEquals(buffer, subBuffer.getParent()); assertEquals(1, buffer.getSubBuffers().size()); subBuffer.release(); assertEquals(0, buffer.getSubBuffers().size()); } finally { context.release(); } }
@Test public void testParseHexOrDefaultOk() throws Exception { long i = 0x12; String s = "0x" + Long.toHexString(i); int def = 14; assertEquals(i, ParseLong.parseHexOrDefault(s, def)); }
@Test public void testParseHexOptionalOk() throws Exception { long i = 0x14; String s = Long.toHexString(i); OptionalLong ret = ParseLong.parseHexOptional(s); assertTrue(ret.isPresent()); assertEquals(i, ret.getAsLong()); }
@Test public void testParseHexPrefixEquals() throws Exception { long i = 123456; String s = Long.toHexString(i); String s1 = "0x" + s; String s2 = "0X" + s; // Transitive property means we only have to test twice assertEquals(ParseLong.parseHex(s), ParseLong.parseHex(s1)); assertEquals(ParseLong.parseHex(s1), ParseLong.parseHex(s2)); }
private String getUniqueId() { return Long.toHexString(Double.doubleToLongBits(Math.random())); }
// Test dec/hex hex trimming @Test public void testParse_HexTrim() throws Exception { long i = 0x123ABC; String s = WHITESPACE + "0x" + Long.toHexString(i) + WHITESPACE; assertEquals(i, ParseLong.parse(s)); }
// Test dec/hex picking @Test public void testParse_Hex() throws Exception { long i = 0x123ABC; String s = "0x" + Long.toHexString(i); assertEquals(i, ParseLong.parse(s)); }
// Technically this is the same as MaxUnsigned @Test public void testParseHexMinSigned() throws Exception { long i = Long.MIN_VALUE; String s = "0x" + Long.toHexString(i); assertEquals(i, ParseLong.parseHex(s)); }
@Test public void testParseHex() throws Exception { long i = 123456; String s = Long.toHexString(i); assertEquals(i, ParseLong.parseHex(s)); }