MCPcopy Index your code
hub / github.com/java-native-access/jna / testGetSharedMemory

Method testGetSharedMemory

test/com/sun/jna/MemoryTest.java:184–219  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

182 }
183
184 public void testGetSharedMemory() {
185 Memory mem1 = new Memory(512);
186 Memory mem2 = new Memory(512);
187
188 // Get pointers into the two memory objects
189 Pointer stringStart1 = mem1.share(128);
190 Pointer stringStart2 = mem2.share(128);
191
192 mem1.setPointer(10 * POINTER_SIZE, stringStart1);
193 mem1.setPointer(11 * POINTER_SIZE, stringStart2);
194
195 // The pointer in mem1 at offset 10 * POINTER_SIZE points into the
196 // memory region of mem1, while the pointer at offset 11 * POINTER_SIZE
197 // points to the second memory region
198
199 // It is expected, that resolution of the first pointer results in
200 // an instance of SharedMemory (a subclass of Memory, that retains a
201 // reference on the originating Memory object)
202 Assert.assertThat(mem1.getPointer(10 * POINTER_SIZE), instanceOf(Pointer.class));
203 Assert.assertThat(mem1.getPointer(10 * POINTER_SIZE), instanceOf(Memory.class));
204 // The second pointer lies outside of memory 1, so it must not be a
205 // Memory object, but a raw pointer
206 Assert.assertThat(mem1.getPointer(11 * POINTER_SIZE), instanceOf(Pointer.class));
207 Assert.assertThat(mem1.getPointer(11 * POINTER_SIZE), not(instanceOf(Memory.class)));
208
209 // It is expected, that Memory#read called for pointers shows the same
210 // behaviour as direct calls to getPointer calls with the corresponding
211 // offsets
212 Pointer[] pointers = new Pointer[2];
213 mem1.read(10 * POINTER_SIZE, pointers, 0, 2);
214
215 Assert.assertThat(pointers[0], instanceOf(Pointer.class));
216 Assert.assertThat(pointers[0], instanceOf(Memory.class));
217 Assert.assertThat(pointers[1], instanceOf(Pointer.class));
218 Assert.assertThat(pointers[1], not(instanceOf(Memory.class)));
219 }
220
221 public void testBoundsChecking() throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
222 // Test the bounds checking of the Memory#read invocations

Callers

nothing calls this directly

Calls 4

shareMethod · 0.95
setPointerMethod · 0.95
getPointerMethod · 0.95
readMethod · 0.95

Tested by

no test coverage detected