|
9 | 9 |
|
10 | 10 | import org.junit.jupiter.api.*; |
11 | 11 |
|
| 12 | +import ghidra.program.model.listing.Function; |
| 13 | + |
| 14 | +import java.lang.reflect.Field; |
| 15 | + |
| 16 | +import java.nio.file.Files; |
| 17 | +import java.nio.file.Path; |
| 18 | + |
| 19 | +import java.util.Collections; |
| 20 | +import java.util.List; |
| 21 | + |
12 | 22 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) |
13 | 23 | public class PatchestryListFunctionsTest extends BaseTest { |
14 | 24 | private PatchestryListFunctions listingScript = new PatchestryListFunctions(); |
| 25 | + private Path outputFile; |
| 26 | + |
| 27 | + @BeforeAll |
| 28 | + public void setUp() throws Exception { |
| 29 | + super.setUp(); |
| 30 | + |
| 31 | + Field monitorField = findFieldInHierarchy(listingScript.getClass(), "monitor"); |
| 32 | + monitorField.setAccessible(true); |
| 33 | + monitorField.set(listingScript, fakeMonitor); |
| 34 | + } |
| 35 | + |
| 36 | + @BeforeEach |
| 37 | + protected void finalizeSetUp() throws Exception { |
| 38 | + outputFile = Files.createTempFile("test-list-and-serialize", ".json"); |
| 39 | + String[] args = { |
| 40 | + outputFile.toString() |
| 41 | + }; |
| 42 | + listingScript.setScriptArgs(args); |
| 43 | + listingScript.setProgram(program); |
| 44 | + assertEquals(listingScript.getScriptArgs(), args); |
| 45 | + assertNotNull(listingScript.getCurrentProgram()); |
| 46 | + assertFalse(listingScript.getCurrentProgram().isClosed()); |
| 47 | + } |
| 48 | + |
| 49 | + @Test |
| 50 | + public void testGetAllFunctions() throws Exception { |
| 51 | + List<Function> functions = listingScript.getAllFunctions(); |
| 52 | + assertNotNull(functions); |
| 53 | + assertFalse(functions.isEmpty()); |
| 54 | + |
| 55 | + // should match with testGetAllFunctions in the PatchestryDecompileFunctionsTest. |
| 56 | + assertEquals(functions.size(), 262); |
| 57 | + } |
| 58 | + |
| 59 | + @Test |
| 60 | + public void testSerializeToFile() throws Exception { |
| 61 | + List<Function> functions = listingScript.getAllFunctions(); |
| 62 | + assertEquals(functions.size(), 262); |
| 63 | + |
| 64 | + assertThrows(IllegalArgumentException.class, () -> { |
| 65 | + listingScript.serializeToFile((Path) null, functions); |
| 66 | + }); |
| 67 | + |
| 68 | + assertThrows(IllegalArgumentException.class, () -> { |
| 69 | + listingScript.serializeToFile(outputFile, (List<Function>) null); |
| 70 | + }); |
| 71 | + |
| 72 | + assertThrows(IllegalArgumentException.class, () -> { |
| 73 | + listingScript.serializeToFile(outputFile, Collections.emptyList()); |
| 74 | + }); |
| 75 | + |
| 76 | + listingScript.serializeToFile(outputFile, functions); |
| 77 | + } |
15 | 78 | } |
0 commit comments