Search in sources :

Example 31 with MockView

use of com.google.security.zynamics.binnavi.disassembly.MockView in project binnavi by google.

the class GroupNodeTest method testConstructor.

@Test
public void testConstructor() {
    final Database database = new Database(new MockDatabase());
    final MockModule mockModule = new MockModule();
    final TagManager nodeTagManager = new TagManager(new MockTagManager(com.google.security.zynamics.binnavi.Tagging.TagType.NODE_TAG));
    final TagManager viewTagManager = new TagManager(new MockTagManager(com.google.security.zynamics.binnavi.Tagging.TagType.VIEW_TAG));
    final Module module = new Module(database, mockModule, nodeTagManager, viewTagManager);
    final MockView mockView = new MockView();
    final View view = new View(module, mockView, nodeTagManager, viewTagManager);
    final INaviGroupNode internalGroupNode = new CGroupNode(0, 0, 0, 0, 0, Color.RED, false, false, new HashSet<CTag>(), new ArrayList<IComment>(), false, new MockSqlProvider());
    final GroupNode node = new GroupNode(view, internalGroupNode, viewTagManager);
    assertEquals("Group Node [0 elements]", node.toString());
}
Also used : IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) CGroupNode(com.google.security.zynamics.binnavi.disassembly.CGroupNode) INaviGroupNode(com.google.security.zynamics.binnavi.disassembly.INaviGroupNode) MockTagManager(com.google.security.zynamics.binnavi.Tagging.MockTagManager) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) MockTagManager(com.google.security.zynamics.binnavi.Tagging.MockTagManager) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) INaviGroupNode(com.google.security.zynamics.binnavi.disassembly.INaviGroupNode) CGroupNode(com.google.security.zynamics.binnavi.disassembly.CGroupNode) Test(org.junit.Test)

Example 32 with MockView

use of com.google.security.zynamics.binnavi.disassembly.MockView in project binnavi by google.

the class GroupNodeTest method testSetText.

@Test
public void testSetText() throws CouldntSaveDataException, com.google.security.zynamics.binnavi.API.disassembly.CouldntSaveDataException, CouldntLoadDataException {
    final Database database = new Database(new MockDatabase());
    final SQLProvider provider = new MockSqlProvider();
    final MockModule mockModule = new MockModule();
    final TagManager nodeTagManager = new TagManager(new MockTagManager(com.google.security.zynamics.binnavi.Tagging.TagType.NODE_TAG));
    final TagManager viewTagManager = new TagManager(new MockTagManager(com.google.security.zynamics.binnavi.Tagging.TagType.VIEW_TAG));
    final Module module = new Module(database, mockModule, nodeTagManager, viewTagManager);
    final MockView mockView = new MockView();
    final View view = new View(module, mockView, nodeTagManager, viewTagManager);
    final INaviGroupNode internalGroupNode = new CGroupNode(0, 0, 0, 0, 0, Color.RED, false, false, new HashSet<CTag>(), new ArrayList<IComment>(), false, provider);
    final GroupNode node = new GroupNode(view, internalGroupNode, viewTagManager);
    final MockGroupNodeListener listener = new MockGroupNodeListener();
    final CUserManager userManager = CUserManager.get(provider);
    final IUser user = userManager.addUser(" TEST APPEND GROUP NODE COMMENT ");
    userManager.setCurrentActiveUser(user);
    node.addListener(listener);
    final List<IComment> comments = node.appendComment("Hannes");
    assertEquals("appendedComment;", listener.events);
    assertEquals(comments, node.getComment());
    node.removeListener(listener);
}
Also used : IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) CGroupNode(com.google.security.zynamics.binnavi.disassembly.CGroupNode) INaviGroupNode(com.google.security.zynamics.binnavi.disassembly.INaviGroupNode) MockTagManager(com.google.security.zynamics.binnavi.Tagging.MockTagManager) SQLProvider(com.google.security.zynamics.binnavi.Database.Interfaces.SQLProvider) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) CUserManager(com.google.security.zynamics.binnavi.Gui.Users.CUserManager) MockTagManager(com.google.security.zynamics.binnavi.Tagging.MockTagManager) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) IUser(com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) INaviGroupNode(com.google.security.zynamics.binnavi.disassembly.INaviGroupNode) CGroupNode(com.google.security.zynamics.binnavi.disassembly.CGroupNode) Test(org.junit.Test)

Example 33 with MockView

use of com.google.security.zynamics.binnavi.disassembly.MockView in project binnavi by google.

the class ModuleHelpersTest method testGetFunction_1.

@Test
public void testGetFunction_1() {
    final Database database = new Database(new MockDatabase());
    @SuppressWarnings("unused") final MockModule mockModule = new MockModule();
    final MockSqlProvider provider = new MockSqlProvider();
    final CModule internalModule = new CModule(1, "", "", new Date(), new Date(), "00000000000000000000000000000000", "0000000000000000000000000000000000000000", 0, 0, new CAddress(0), new CAddress(0), null, null, Integer.MAX_VALUE, false, provider);
    try {
        internalModule.load();
    } catch (final CouldntLoadDataException exception) {
        CUtilityFunctions.logException(exception);
    } catch (final LoadCancelledException exception) {
        CUtilityFunctions.logException(exception);
    }
    @SuppressWarnings("unused") final CFunction parentFunction = new CFunction(internalModule, new MockView(), new CAddress(0x123), "Mock Function", "Mock Function", "Mock Description", 0, 0, 0, 0, FunctionType.NORMAL, "", 0, null, null, null, provider);
    final TagManager nodeTagManager = new TagManager(new MockTagManager(com.google.security.zynamics.binnavi.Tagging.TagType.NODE_TAG));
    final TagManager viewTagManager = new TagManager(new MockTagManager(com.google.security.zynamics.binnavi.Tagging.TagType.VIEW_TAG));
    final Module module = new Module(database, internalModule, nodeTagManager, viewTagManager);
    assertEquals(module.getFunctions().get(0), ModuleHelpers.getFunction(module, 0x123));
    assertNull(ModuleHelpers.getFunction(module, 0x1235));
    try {
        ModuleHelpers.getFunction(null, -1);
        fail();
    } catch (final NullPointerException e) {
    }
    try {
        ModuleHelpers.getFunction(module, -1);
        fail();
    } catch (final IllegalArgumentException e) {
    }
}
Also used : MockView(com.google.security.zynamics.binnavi.disassembly.MockView) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) CFunction(com.google.security.zynamics.binnavi.disassembly.CFunction) MockTagManager(com.google.security.zynamics.binnavi.Tagging.MockTagManager) Date(java.util.Date) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) MockTagManager(com.google.security.zynamics.binnavi.Tagging.MockTagManager) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) LoadCancelledException(com.google.security.zynamics.binnavi.Database.Exceptions.LoadCancelledException) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) Test(org.junit.Test)

Example 34 with MockView

use of com.google.security.zynamics.binnavi.disassembly.MockView in project binnavi by google.

the class ModuleHelpersTest method testGetFunction_3.

@Test
public void testGetFunction_3() throws IllegalArgumentException, SecurityException, IllegalAccessException, NoSuchFieldException {
    final Database database = new Database(new MockDatabase());
    final MockModule mockModule = new MockModule();
    final MockSqlProvider provider = new MockSqlProvider();
    final CModule internalModule = new CModule(1, "", "", new Date(), new Date(), "00000000000000000000000000000000", "0000000000000000000000000000000000000000", 0, 0, new CAddress(0), new CAddress(0), null, null, Integer.MAX_VALUE, false, provider);
    final CFunction parentFunction = new CFunction(internalModule, new MockView(), new CAddress(0x123), "Mock Function", "Mock Function", "Mock Description", 0, 0, 0, 0, FunctionType.NORMAL, "", 0, null, null, null, provider);
    new CFunctionContainer(mockModule, Lists.<INaviFunction>newArrayList(parentFunction));
    CFunctionContainerHelper.addFunction(mockModule.getContent().getFunctionContainer(), parentFunction);
    final TagManager nodeTagManager = new TagManager(new MockTagManager(com.google.security.zynamics.binnavi.Tagging.TagType.NODE_TAG));
    final TagManager viewTagManager = new TagManager(new MockTagManager(com.google.security.zynamics.binnavi.Tagging.TagType.VIEW_TAG));
    final Module module = new Module(database, mockModule, nodeTagManager, viewTagManager);
    assertEquals(module.getFunctions().get(0), ModuleHelpers.getFunction(module, "Mock Function"));
    assertNull(ModuleHelpers.getFunction(module, ""));
    try {
        ModuleHelpers.getFunction(null, (String) null);
        fail();
    } catch (final NullPointerException e) {
    }
    try {
        ModuleHelpers.getFunction(module, (String) null);
        fail();
    } catch (final NullPointerException e) {
    }
}
Also used : MockView(com.google.security.zynamics.binnavi.disassembly.MockView) CFunction(com.google.security.zynamics.binnavi.disassembly.CFunction) MockTagManager(com.google.security.zynamics.binnavi.Tagging.MockTagManager) Date(java.util.Date) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) MockTagManager(com.google.security.zynamics.binnavi.Tagging.MockTagManager) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) CFunctionContainer(com.google.security.zynamics.binnavi.disassembly.Modules.CFunctionContainer) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) Test(org.junit.Test)

Example 35 with MockView

use of com.google.security.zynamics.binnavi.disassembly.MockView in project binnavi by google.

the class ViewTest method testCreateCodeNode.

@Test
public void testCreateCodeNode() throws PartialLoadException, com.google.security.zynamics.binnavi.API.disassembly.CouldntLoadDataException {
    final MockViewListener listener = new MockViewListener();
    m_view.addListener(listener);
    final CModule internalModule = new CModule(1, "", "", new Date(), new Date(), "00000000000000000000000000000000", "0000000000000000000000000000000000000000", 0, 0, new CAddress(0), new CAddress(0), null, null, Integer.MAX_VALUE, false, m_provider);
    final CFunction parentFunction = new CFunction(internalModule, new MockView(), new CAddress(0x123), "Mock Function", "Mock Function", "Mock Description", 0, 0, 0, 0, FunctionType.NORMAL, "", 0, null, null, null, m_provider);
    final Function function = new Function(module, parentFunction);
    final List<Instruction> instructions = Lists.newArrayList(new Instruction(new MockInstruction()));
    m_view.load();
    final CodeNode node = m_view.createCodeNode(function, instructions);
    assertEquals(node, m_view.getGraph().getNodes().get(0));
    assertEquals(listener.events, "addedNode;changedGraphType;");
    assertEquals(com.google.security.zynamics.binnavi.API.disassembly.GraphType.Flowgraph, m_view.getGraphType());
    m_view.removeListener(listener);
}
Also used : INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) CFunction(com.google.security.zynamics.binnavi.disassembly.CFunction) MockInstruction(com.google.security.zynamics.binnavi.disassembly.MockInstruction) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) CFunction(com.google.security.zynamics.binnavi.disassembly.CFunction) MockInstruction(com.google.security.zynamics.binnavi.disassembly.MockInstruction) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) Date(java.util.Date) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) Test(org.junit.Test)

Aggregations

MockView (com.google.security.zynamics.binnavi.disassembly.MockView)38 Test (org.junit.Test)32 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)27 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)25 CFunction (com.google.security.zynamics.binnavi.disassembly.CFunction)25 CModule (com.google.security.zynamics.binnavi.disassembly.Modules.CModule)24 Date (java.util.Date)21 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)19 MockModule (com.google.security.zynamics.binnavi.disassembly.Modules.MockModule)14 MockDatabase (com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase)13 MockTagManager (com.google.security.zynamics.binnavi.Tagging.MockTagManager)13 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)11 MockInstruction (com.google.security.zynamics.binnavi.disassembly.MockInstruction)10 CCodeNode (com.google.security.zynamics.binnavi.disassembly.CCodeNode)9 ArrayList (java.util.ArrayList)9 INaviCodeNode (com.google.security.zynamics.binnavi.disassembly.INaviCodeNode)8 INaviView (com.google.security.zynamics.binnavi.disassembly.views.INaviView)7 IComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment)6 CFunctionNode (com.google.security.zynamics.binnavi.disassembly.CFunctionNode)6 INaviEdge (com.google.security.zynamics.binnavi.disassembly.INaviEdge)6