Package ghidra.test

Class AbstractProgramBasedTest


  • public abstract class AbstractProgramBasedTest
    extends AbstractGhidraHeadedIntegrationTest
    A convenience base class for creating tests that use the default tool and open a program. This class will create for you a tool, a TestEnv and will open the program specified by getProgramName().

    To use this class, you must call initialize() from your test or setUp method.

    Note: if you are loading a pre-existing program, then simply override getProgramName(). Alternatively, if you are building a program, then override getProgram() and return it there.

    • Field Detail

      • program

        protected Program program
      • codeBrowser

        protected ghidra.app.plugin.core.codebrowser.CodeBrowserPlugin codeBrowser
    • Constructor Detail

      • AbstractProgramBasedTest

        public AbstractProgramBasedTest()
    • Method Detail

      • getProgramName

        protected java.lang.String getProgramName()
      • initialize

        protected void initialize()
                           throws java.lang.Exception
        Throws:
        java.lang.Exception
      • getProgram

        protected Program getProgram()
                              throws java.lang.Exception
        Override this method if you need to build your own program.
        Returns:
        the program to use for this test.
        Throws:
        java.lang.Exception - if an exception is thrown opening the program
      • tearDown

        public void tearDown()
                      throws java.lang.Exception
        Throws:
        java.lang.Exception
      • assertCurrentAddress

        public void assertCurrentAddress​(Address expected)
      • addr

        public Address addr​(long offset)
      • addr

        public Address addr​(java.lang.String offset)
      • goTo

        public void goTo​(long offset)
      • goTo

        public void goTo​(java.lang.String offset)
      • range

        public AddressRange range​(long from,
                                  long to)
      • showProvider

        public void showProvider​(java.lang.String name)
      • addrs

        public java.util.List<Address> addrs​(long... offsets)
      • toAddressSet

        public AddressSet toAddressSet​(long... offsets)
      • goTo

        public void goTo​(Address a)
      • modifyProgram

        public <E extends java.lang.Exception> void modifyProgram​(ExceptionalConsumer<Program,​E> callback)
        Provides a convenient method for modifying the current program, handling the transaction logic.
        Parameters:
        callback - the code to execute
      • createInProgram

        public <R,​E extends java.lang.Exception> R createInProgram​(ExceptionalFunction<Program,​R,​E> f)
        Provides a convenient method for modifying the current program, handling the transaction logic and returning a new item as a result.
        Parameters:
        f - the function for modifying the program and creating the desired result
        Returns:
        the result