Fix memoryChunk with large offset and size zero

This commit is contained in:
nicksavers 2014-10-20 13:39:26 +02:00
parent a2e8b18126
commit 9110a7a602
2 changed files with 38 additions and 50 deletions

View File

@ -213,7 +213,7 @@ public class Program {
allocateMemory(offset, size);
byte[] chunk;
if (memory != null)
if (memory != null && size != 0)
chunk = Arrays.copyOfRange(memory.array(), offset, offset+size);
else
chunk = new byte[size];

View File

@ -40,18 +40,29 @@ public class ProgramMemoryTest {
}
@Test
@Ignore
public void testMemoryChunk() {
fail("Not yet implemented");
public void testMemoryChunk1() {
program.memory = ByteBuffer.allocate(64);
int offset = 128;
int size = 32;
program.memoryChunk(offset, size);
assertEquals(160, program.getMemSize());
}
@Test // size 0 doesn't increate memory
public void testMemoryChunk2() {
program.memory = ByteBuffer.allocate(64);
int offset = 96;
int size = 0;
program.memoryChunk(offset, size);
assertEquals(64, program.getMemSize());
}
@Test
public void testAllocateMemory1() {
memory = ByteBuffer.allocate(64);
program.memory = ByteBuffer.allocate(64);
int offset = 32;
int size = 32;
program.memory = memory;
program.allocateMemory(offset, size);
assertEquals(64, program.getMemSize());
}
@ -61,10 +72,9 @@ public class ProgramMemoryTest {
// memory.limit() > offset, == size
// memory.limit() < offset + size
memory = ByteBuffer.allocate(64);
program.memory = ByteBuffer.allocate(64);
int offset = 32;
int size = 64;
program.memory = memory;
program.allocateMemory(offset, size);
assertEquals(96, program.getMemSize());
}
@ -73,10 +83,9 @@ public class ProgramMemoryTest {
public void testAllocateMemory3() {
// memory.limit() > offset, > size
memory = ByteBuffer.allocate(64);
program.memory = ByteBuffer.allocate(64);
int offset = 0;
int size = 32;
program.memory = memory;
program.allocateMemory(offset, size);
assertEquals(64, program.getMemSize());
}
@ -84,10 +93,9 @@ public class ProgramMemoryTest {
@Test
public void testAllocateMemory4() {
memory = ByteBuffer.allocate(64);;
program.memory = ByteBuffer.allocate(64);;
int offset = 0;
int size = 64;
program.memory = memory;
program.allocateMemory(offset, size);
assertEquals(64, program.getMemSize());
}
@ -95,10 +103,9 @@ public class ProgramMemoryTest {
@Test
public void testAllocateMemory5() {
memory = ByteBuffer.allocate(64);
program.memory = ByteBuffer.allocate(64);
int offset = 0;
int size = 0;
program.memory = memory;
program.allocateMemory(offset, size);
assertEquals(64, program.getMemSize());
}
@ -107,10 +114,9 @@ public class ProgramMemoryTest {
public void testAllocateMemory6() {
// memory.limit() == offset, > size
memory = ByteBuffer.allocate(64);
program.memory = ByteBuffer.allocate(64);
int offset = 64;
int size = 32;
program.memory = memory;
program.allocateMemory(offset, size);
assertEquals(96, program.getMemSize());
}
@ -119,10 +125,9 @@ public class ProgramMemoryTest {
public void testAllocateMemory7() {
// memory.limit() == offset - size
memory = ByteBuffer.allocate(64);
program.memory = ByteBuffer.allocate(64);
int offset = 96;
int size = 32;
program.memory = memory;
program.allocateMemory(offset, size);
assertEquals(128, program.getMemSize());
}
@ -130,10 +135,9 @@ public class ProgramMemoryTest {
@Test
public void testAllocateMemory8() {
memory = ByteBuffer.allocate(64);
program.memory = ByteBuffer.allocate(64);
int offset = 0;
int size = 96;
program.memory = memory;
program.allocateMemory(offset, size);
assertEquals(96, program.getMemSize());
}
@ -143,10 +147,9 @@ public class ProgramMemoryTest {
// memory.limit() < offset, > size
// memory.limit() < offset - size
memory = ByteBuffer.allocate(64);
program.memory = ByteBuffer.allocate(64);
int offset = 96;
int size = 0;
program.memory = memory;
program.allocateMemory(offset, size);
assertEquals(64, program.getMemSize());
}
@ -160,7 +163,6 @@ public class ProgramMemoryTest {
// memory = null, offset > size
int offset = 32;
int size = 0;
program.memory = memory;
program.allocateMemory(offset, size);
assertEquals(0, program.getMemSize());
}
@ -171,7 +173,6 @@ public class ProgramMemoryTest {
// memory = null, offset < size
int offset = 0;
int size = 32;
program.memory = memory;
program.allocateMemory(offset, size);
assertEquals(32, program.getMemSize());
}
@ -180,10 +181,9 @@ public class ProgramMemoryTest {
public void testAllocateMemory12() {
// memory.limit() < offset, < size
memory = ByteBuffer.allocate(32);
program.memory = ByteBuffer.allocate(32);
int offset = 64;
int size = 96;
program.memory = memory;
program.allocateMemory(offset, size);
assertEquals(160, program.getMemSize());
}
@ -192,10 +192,9 @@ public class ProgramMemoryTest {
public void testAllocateMemory13() {
// memory.limit() > offset, < size
memory = ByteBuffer.allocate(64);
program.memory = ByteBuffer.allocate(64);
int offset = 32;
int size = 128;
program.memory = memory;
program.allocateMemory(offset, size);
assertEquals(160, program.getMemSize());
}
@ -204,10 +203,9 @@ public class ProgramMemoryTest {
public void testAllocateMemory14() {
// memory.limit() < offset, == size
memory = ByteBuffer.allocate(64);
program.memory = ByteBuffer.allocate(64);
int offset = 96;
int size = 64;
program.memory = memory;
program.allocateMemory(offset, size);
assertEquals(160, program.getMemSize());
}
@ -216,10 +214,9 @@ public class ProgramMemoryTest {
public void testAllocateMemory15() {
// memory.limit() == offset, < size
memory = ByteBuffer.allocate(64);
program.memory = ByteBuffer.allocate(64);
int offset = 64;
int size = 96;
program.memory = memory;
program.allocateMemory(offset, size);
assertEquals(160, program.getMemSize());
}
@ -229,10 +226,9 @@ public class ProgramMemoryTest {
// memory.limit() == offset, == size
// memory.limit() > offset - size
memory = ByteBuffer.allocate(64);
program.memory = ByteBuffer.allocate(64);
int offset = 64;
int size = 64;
program.memory = memory;
program.allocateMemory(offset, size);
assertEquals(128, program.getMemSize());
}
@ -241,10 +237,9 @@ public class ProgramMemoryTest {
public void testAllocateMemory17() {
// memory.limit() > offset + size
memory = ByteBuffer.allocate(96);
program.memory = ByteBuffer.allocate(96);
int offset = 32;
int size = 32;
program.memory = memory;
program.allocateMemory(offset, size);
assertEquals(96, program.getMemSize());
}
@ -253,10 +248,9 @@ public class ProgramMemoryTest {
public void testAllocateMemoryUnrounded1() {
// memory unrounded
memory = ByteBuffer.allocate(16);
program.memory = ByteBuffer.allocate(16);
int offset = 64;
int size = 32;
program.memory = memory;
program.allocateMemory(offset, size);
assertEquals(96, program.getMemSize());
}
@ -265,10 +259,9 @@ public class ProgramMemoryTest {
public void testAllocateMemoryUnrounded2() {
// offset unrounded
memory = ByteBuffer.allocate(32);
program.memory = ByteBuffer.allocate(32);
int offset = 16;
int size = 32;
program.memory = memory;
program.allocateMemory(offset, size);
assertEquals(64, program.getMemSize());
}
@ -277,10 +270,9 @@ public class ProgramMemoryTest {
public void testAllocateMemoryUnrounded3() {
// size unrounded
memory = ByteBuffer.allocate(32);
program.memory = ByteBuffer.allocate(32);
int offset = 64;
int size = 16;
program.memory = memory;
program.allocateMemory(offset, size);
assertEquals(96, program.getMemSize());
}
@ -289,10 +281,9 @@ public class ProgramMemoryTest {
public void testAllocateMemoryUnrounded4() {
// memory + offset unrounded
memory = ByteBuffer.allocate(16);
program.memory = ByteBuffer.allocate(16);
int offset = 16;
int size = 32;
program.memory = memory;
program.allocateMemory(offset, size);
assertEquals(64 , program.getMemSize());
}
@ -301,10 +292,9 @@ public class ProgramMemoryTest {
public void testAllocateMemoryUnrounded5() {
// memory + size unrounded
memory = ByteBuffer.allocate(16);
program.memory = ByteBuffer.allocate(16);
int offset = 32;
int size = 16;
program.memory = memory;
program.allocateMemory(offset, size);
assertEquals(64, program.getMemSize());
}
@ -313,10 +303,9 @@ public class ProgramMemoryTest {
public void testAllocateMemoryUnrounded6() {
// offset + size unrounded
memory = ByteBuffer.allocate(32);
program.memory = ByteBuffer.allocate(32);
int offset = 16;
int size = 16;
program.memory = memory;
program.allocateMemory(offset, size);
assertEquals(32, program.getMemSize());
}
@ -325,10 +314,9 @@ public class ProgramMemoryTest {
public void testAllocateMemoryUnrounded7() {
// memory + offset + size unrounded
memory = ByteBuffer.allocate(16);
program.memory = ByteBuffer.allocate(16);
int offset = 16;
int size = 16;
program.memory = memory;
program.allocateMemory(offset, size);
assertEquals(32,program.getMemSize());
}