< prev index next >

test/jdk/java/foreign/TestMemoryCopy.java

Print this page
rev 57245 : [mq]: 8234049_v4

*** 26,39 **** --- 26,42 ---- * @test * @run testng TestMemoryCopy */ import jdk.incubator.foreign.MemoryAddress; + import jdk.incubator.foreign.MemoryHandles; + import jdk.incubator.foreign.MemoryLayouts; import jdk.incubator.foreign.MemorySegment; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; + import java.lang.invoke.VarHandle; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.function.IntFunction; import java.util.stream.Collectors;
*** 41,59 **** import static org.testng.Assert.*; public class TestMemoryCopy { @Test(dataProvider = "slices") ! public void testBadCopy(SegmentSlice s1, SegmentSlice s2) { MemoryAddress addr1 = s1.segment.baseAddress(); MemoryAddress addr2 = s2.segment.baseAddress(); int size = Math.min(s1.size(), s2.size()); boolean overlap = SegmentSlice.overlap(s1, s2, size); try { MemoryAddress.copy(addr1, addr2, size); assertFalse(overlap); } catch (IllegalArgumentException ex) { assertTrue(overlap); } } --- 44,74 ---- import static org.testng.Assert.*; public class TestMemoryCopy { + final static VarHandle BYTE_HANDLE = MemoryLayouts.JAVA_BYTE.varHandle(byte.class); + @Test(dataProvider = "slices") ! public void testCopy(SegmentSlice s1, SegmentSlice s2) { MemoryAddress addr1 = s1.segment.baseAddress(); MemoryAddress addr2 = s2.segment.baseAddress(); int size = Math.min(s1.size(), s2.size()); boolean overlap = SegmentSlice.overlap(s1, s2, size); + //prepare source and target segments + for (int i = 0 ; i < size ; i++) { + BYTE_HANDLE.set(addr1.offset(i), (byte)i); + BYTE_HANDLE.set(addr2.offset(i), (byte)0); + } try { MemoryAddress.copy(addr1, addr2, size); assertFalse(overlap); + //check that copy actually worked + for (int i = 0 ; i < size ; i++) { + assertEquals((byte)i, BYTE_HANDLE.get(addr2.offset(i))); + } + } catch (IllegalArgumentException ex) { assertTrue(overlap); } }
< prev index next >