mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-05 10:49:34 +02:00
GT-3126 corrected FileBytes issue with undo/redo. Also corrected
FileBytes bug which could result in empty DBBuffer.
This commit is contained in:
parent
20ac7ece0a
commit
cbd270cec2
8 changed files with 157 additions and 73 deletions
|
@ -37,7 +37,11 @@ import ghidra.util.task.TaskMonitor;
|
|||
|
||||
public class FileBytesTest extends AbstractGenericTest {
|
||||
|
||||
// Use of small buffer size will not exercise use of indexed ChainedBuffer,
|
||||
// therefor those tests which need to exercise this should use a size which
|
||||
// exceeds 16-KBytes.
|
||||
private static final int MAX_BUFFER_SIZE_FOR_TESTING = 200;
|
||||
|
||||
private Program program;
|
||||
private Memory mem;
|
||||
private int transactionID;
|
||||
|
@ -186,6 +190,59 @@ public class FileBytesTest extends AbstractGenericTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLayeredBytesAfterUndo() throws Exception {
|
||||
// NOTE: need to induce use of indexed ChainedBuffer
|
||||
FileBytesAdapter.setMaxBufferSize(FileBytesAdapter.MAX_BUF_SIZE);
|
||||
FileBytes fileBytes = createFileBytes("file1", 20000);
|
||||
|
||||
program.endTransaction(transactionID, true);
|
||||
transactionID = program.startTransaction("modify");
|
||||
|
||||
incrementFileBytes(fileBytes, 0, 10);
|
||||
incrementFileBytes(fileBytes, 18999, 10);
|
||||
|
||||
// undo layered buffer changes
|
||||
program.endTransaction(transactionID, true);
|
||||
program.undo();
|
||||
transactionID = program.startTransaction("resume");
|
||||
|
||||
// check that the layered bytes are unchanged from the originals
|
||||
assertEquals(1, fileBytes.getOriginalByte(1));
|
||||
assertEquals(1, fileBytes.getModifiedByte(1));
|
||||
|
||||
byte b = (byte) 19000;
|
||||
assertEquals(b, fileBytes.getOriginalByte(19000));
|
||||
assertEquals(b, fileBytes.getModifiedByte(19000));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLayeredBytesAfterUndoRedo() throws Exception {
|
||||
// NOTE: need to induce use of indexed ChainedBuffer
|
||||
FileBytesAdapter.setMaxBufferSize(FileBytesAdapter.MAX_BUF_SIZE);
|
||||
FileBytes fileBytes = createFileBytes("file1", 20000);
|
||||
|
||||
program.endTransaction(transactionID, true);
|
||||
transactionID = program.startTransaction("modify");
|
||||
|
||||
incrementFileBytes(fileBytes, 0, 10);
|
||||
incrementFileBytes(fileBytes, 18999, 10);
|
||||
|
||||
// undo layered buffer changes
|
||||
program.endTransaction(transactionID, true);
|
||||
program.undo();
|
||||
program.redo();
|
||||
transactionID = program.startTransaction("resume");
|
||||
|
||||
// check that the layered bytes are unchanged from the originals
|
||||
assertEquals(1, fileBytes.getOriginalByte(1));
|
||||
assertEquals(2, fileBytes.getModifiedByte(1));
|
||||
|
||||
byte b = (byte) 19000;
|
||||
assertEquals(b, fileBytes.getOriginalByte(19000));
|
||||
assertEquals((byte) (b + 1), fileBytes.getModifiedByte(19000));
|
||||
}
|
||||
|
||||
private FileBytes createFileBytes(String name, int size) throws Exception {
|
||||
byte[] bytes = new byte[size];
|
||||
for (int i = 0; i < size; i++) {
|
||||
|
|
|
@ -64,7 +64,7 @@ public class MemBlockDBTest extends AbstractGenericTest {
|
|||
|
||||
MemoryMapDBAdapter adapter =
|
||||
new MemoryMapDBAdapterV3(handle, mem, MAX_SUB_BLOCK_SIZE, true);
|
||||
FileBytesAdapter fileBytesAdapter = new FileBytesAdapterV0(handle, mem, true);
|
||||
FileBytesAdapter fileBytesAdapter = new FileBytesAdapterV0(handle, true);
|
||||
|
||||
mem.init(adapter, fileBytesAdapter);
|
||||
mem.setProgram(program);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue