Search in sources :

Example 81 with UniqueTestUserGenerator

use of com.google.security.zynamics.binnavi.Database.PostgreSQL.UniqueTestUserGenerator in project binnavi by google.

the class PostgreSQLGroupNodeCommentTests method appendInstructionCommentInGroupNode.

@Test
public void appendInstructionCommentInGroupNode() throws CouldntLoadDataException, LoadCancelledException, MaybeNullException, CPartialLoadException, CouldntSaveDataException {
    final INaviModule module = getProvider().loadModules().get(0);
    module.load();
    final INaviFunction function = module.getContent().getFunctionContainer().getFunction("sub_1004565");
    final INaviView view = module.getContent().getViewContainer().getView(function);
    view.load();
    assertEquals(42, view.getNodeCount());
    final INaviViewNode node1 = view.getContent().getBasicBlocks().get(1);
    final INaviViewNode node2 = view.getContent().getBasicBlocks().get(2);
    view.getContent().createGroupNode(Lists.newArrayList(node1, node2));
    final ZyGraph graph = CGraphBuilder.buildGraph(view);
    final INaviView nonNativeView = graph.saveAs(new CModuleContainer(getDatabase(), module), " TEST INSTRUCTION COMMENTS IN GROUP NODE ", " TESTING GROUP NODE COMMENTS ");
    final INaviInstruction instruction = view.getContent().getBasicBlocks().get(0).getLastInstruction();
    final IUser user = new UniqueTestUserGenerator(getProvider()).nextActiveUser();
    final String firstCommentString = "TEST INSTRUCTION COMMENT PROPAGATION";
    final int firstCommentId = getProvider().appendGlobalInstructionComment(instruction, firstCommentString, user.getUserId());
    final IComment firstComment = new CComment(firstCommentId, user, null, firstCommentString);
    final ArrayList<IComment> commentsFromDatabase = getProvider().loadCommentById(firstCommentId);
    assertNotNull(commentsFromDatabase);
    assertEquals(1, commentsFromDatabase.size());
    assertTrue(commentsFromDatabase.contains(firstComment));
    final INaviInstruction instruction2 = nonNativeView.getBasicBlocks().get(0).getLastInstruction();
    assertEquals(1, instruction2.getGlobalComment().size());
}
Also used : IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) ZyGraph(com.google.security.zynamics.binnavi.yfileswrap.zygraph.ZyGraph) CModuleContainer(com.google.security.zynamics.binnavi.disassembly.Modules.CModuleContainer) UniqueTestUserGenerator(com.google.security.zynamics.binnavi.Database.PostgreSQL.UniqueTestUserGenerator) CComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) IUser(com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction) ExpensiveBaseTest(com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest) Test(org.junit.Test)

Example 82 with UniqueTestUserGenerator

use of com.google.security.zynamics.binnavi.Database.PostgreSQL.UniqueTestUserGenerator in project binnavi by google.

the class PostgreSQLLocalCodeNodeCommentTests method deleteLocalCodeNodeComment4.

@Test
public void deleteLocalCodeNodeComment4() throws CouldntLoadDataException, CouldntSaveDataException, CouldntDeleteException {
    final List<IComment> comments = codeNode.getComments().getLocalCodeNodeComment() == null ? new ArrayList<IComment>() : codeNode.getComments().getLocalCodeNodeComment();
    final IComment lastComment = comments.size() == 0 ? null : Iterables.getLast(comments);
    final String commentString = " TEST DELETE LOCAL CODE NODE COMMENT ";
    final IUser user = new UniqueTestUserGenerator(getProvider()).nextActiveUser();
    final int commentId = getProvider().appendLocalCodeNodeComment(codeNode, commentString, user.getUserId());
    final IComment newComment = new CComment(commentId, user, lastComment, commentString);
    final ArrayList<IComment> storedComments = getProvider().loadCommentById(commentId);
    assertNotNull(storedComments);
    assertEquals(comments.size() + 1, storedComments.size());
    assertEquals(newComment, Iterables.getLast(storedComments));
    getProvider().deleteLocalCodeNodeComment(codeNode, commentId, newComment.getUser().getUserId());
    final ArrayList<IComment> commentsAfterDelete = getProvider().loadCommentById(commentId);
    assertNotNull(commentsAfterDelete);
    assertTrue(commentsAfterDelete.isEmpty());
}
Also used : CComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment) IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) IUser(com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser) UniqueTestUserGenerator(com.google.security.zynamics.binnavi.Database.PostgreSQL.UniqueTestUserGenerator) ExpensiveBaseTest(com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest) Test(org.junit.Test)

Example 83 with UniqueTestUserGenerator

use of com.google.security.zynamics.binnavi.Database.PostgreSQL.UniqueTestUserGenerator in project binnavi by google.

the class PostgreSQLLocalCodeNodeCommentTests method deleteLocalCodeNodeComment5.

/**
   * This test checks if the delete of a comment in a series of comments works if the comment is the
   * last comment.
   *
   * <pre>
   * Comment 1:      Comment 1:
   * Comment 2:  ->  Comment 2:
   * Comment 3:
   * </pre>
   *
   */
@Test
public void deleteLocalCodeNodeComment5() throws CouldntLoadDataException, CouldntSaveDataException, CouldntDeleteException {
    final IUser user = new UniqueTestUserGenerator(getProvider()).nextActiveUser();
    final List<IComment> storedComments = codeNode.getComments().getLocalCodeNodeComment() == null ? new ArrayList<IComment>() : codeNode.getComments().getLocalCodeNodeComment();
    final IComment lastComment = storedComments.isEmpty() ? null : Iterables.getLast(storedComments);
    final String comment1String = " Comment 1: ";
    final int comment1Id = getProvider().appendLocalCodeNodeComment(codeNode, comment1String, user.getUserId());
    final IComment comment1 = new CComment(comment1Id, user, lastComment, comment1String);
    final String comment2String = " Comment 2: ";
    final int comment2Id = getProvider().appendLocalCodeNodeComment(codeNode, comment2String, user.getUserId());
    final IComment comment2 = new CComment(comment2Id, user, comment1, comment2String);
    final String comment3String = " Comment 3: ";
    final int comment3Id = getProvider().appendLocalCodeNodeComment(codeNode, comment3String, user.getUserId());
    final IComment comment3 = new CComment(comment3Id, user, comment2, comment3String);
    final ArrayList<IComment> commentsBeforeDelete = getProvider().loadCommentById(comment3Id);
    assertNotNull(commentsBeforeDelete);
    assertEquals(storedComments.size() + 3, commentsBeforeDelete.size());
    assertTrue(commentsBeforeDelete.contains(comment1));
    assertTrue(commentsBeforeDelete.contains(comment2));
    assertTrue(commentsBeforeDelete.contains(comment3));
    assertEquals(comment3, Iterables.getLast(commentsBeforeDelete));
    assertEquals(comment2, commentsBeforeDelete.get(commentsBeforeDelete.size() - 2));
    assertEquals(comment1, commentsBeforeDelete.get(commentsBeforeDelete.size() - 3));
    getProvider().deleteLocalCodeNodeComment(codeNode, comment3Id, user.getUserId());
    final ArrayList<IComment> commentsAfterDelete1 = getProvider().loadCommentById(comment3Id);
    assertNotNull(commentsAfterDelete1);
    assertTrue(commentsAfterDelete1.isEmpty());
    final ArrayList<IComment> commentsAfterDelete2 = getProvider().loadCommentById(comment2Id);
    assertNotNull(commentsAfterDelete2);
    assertEquals(storedComments.size() + 2, commentsAfterDelete2.size());
    assertTrue(commentsAfterDelete2.contains(comment2));
    assertTrue(commentsAfterDelete2.contains(comment1));
    assertEquals(comment2, Iterables.getLast(commentsAfterDelete2));
    assertEquals(comment1, commentsAfterDelete2.get(commentsAfterDelete2.size() - 2));
}
Also used : CComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment) IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) IUser(com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser) UniqueTestUserGenerator(com.google.security.zynamics.binnavi.Database.PostgreSQL.UniqueTestUserGenerator) ExpensiveBaseTest(com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest) Test(org.junit.Test)

Example 84 with UniqueTestUserGenerator

use of com.google.security.zynamics.binnavi.Database.PostgreSQL.UniqueTestUserGenerator in project binnavi by google.

the class PostgreSQLLocalCodeNodeCommentTests method editLocalCodeNodeComment5.

@Test
public void editLocalCodeNodeComment5() throws CouldntLoadDataException, CouldntSaveDataException {
    final List<IComment> comments = codeNode.getComments().getLocalCodeNodeComment() == null ? new ArrayList<IComment>() : codeNode.getComments().getLocalCodeNodeComment();
    final IComment lastComment = comments.size() == 0 ? null : Iterables.getLast(comments);
    final IUser user = new UniqueTestUserGenerator(getProvider()).nextActiveUser();
    final String commentText = " CODE NODE COMMENT TEST BEFORE EDIT ";
    final Integer commentId = getProvider().appendLocalCodeNodeComment(codeNode, commentText, user.getUserId());
    final IComment newComment = new CComment(commentId, user, lastComment, commentText);
    final ArrayList<IComment> newComments = getProvider().loadCommentById(commentId);
    assertNotNull(newComments);
    assertEquals(comments.size() + 1, newComments.size());
    assertEquals(newComment, Iterables.getLast(newComments));
    final String commentAfterEdit = " CODE NODE COMMENT TEST AFTER EDIT ";
    getProvider().editLocalCodeNodeComment(codeNode, commentId, user.getUserId(), commentAfterEdit);
    final ArrayList<IComment> commentsAfterEdit = PostgreSQLCommentFunctions.loadCommentByCommentId(getProvider(), commentId);
    assertEquals(commentAfterEdit, Iterables.getLast(commentsAfterEdit).getComment());
    assertEquals(commentsAfterEdit.size(), newComments.size());
}
Also used : CComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment) IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) IUser(com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser) UniqueTestUserGenerator(com.google.security.zynamics.binnavi.Database.PostgreSQL.UniqueTestUserGenerator) ExpensiveBaseTest(com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest) Test(org.junit.Test)

Example 85 with UniqueTestUserGenerator

use of com.google.security.zynamics.binnavi.Database.PostgreSQL.UniqueTestUserGenerator in project binnavi by google.

the class PostgreSQLTextNodeCommentTests method appendTextNodeComment4.

@Test
public void appendTextNodeComment4() throws CouldntLoadDataException, LoadCancelledException, MaybeNullException, CPartialLoadException, CouldntSaveDataException {
    final INaviTextNode textNode = setupTextNode();
    final IUser user = new UniqueTestUserGenerator(getProvider()).nextActiveUser();
    final String firstCommentString = " APPEND GROUP NODE COMMENT WITHOUT PARENT ID ";
    final Integer firstCommentId = getProvider().appendTextNodeComment(textNode, firstCommentString, user.getUserId());
    final IComment firstComment = new CComment(firstCommentId, user, null, firstCommentString);
    final String secondCommentString = " APPEND GROUP NODE COMMENT WITH PARENT ID ";
    final Integer secondCommentId = getProvider().appendTextNodeComment(textNode, secondCommentString, user.getUserId());
    final IComment secondComment = new CComment(secondCommentId, user, firstComment, secondCommentString);
    final ArrayList<IComment> commentsFromDatabase = getProvider().loadCommentById(secondCommentId);
    assertNotNull(commentsFromDatabase);
    assertEquals(2, commentsFromDatabase.size());
    assertTrue(commentsFromDatabase.contains(firstComment));
    assertTrue(commentsFromDatabase.contains(secondComment));
    globalView.close();
    globalView.load();
    INaviTextNode savedTextNode;
    for (final INaviViewNode node : globalView.getGraph().getNodes()) {
        if (node instanceof INaviTextNode) {
            savedTextNode = (INaviTextNode) node;
            assertNotNull(savedTextNode.getComments());
            assertEquals(2, (savedTextNode.getComments().size()));
            assertTrue(savedTextNode.getComments().contains(firstComment));
            assertTrue(savedTextNode.getComments().contains(secondComment));
        }
    }
}
Also used : CComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment) IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) INaviTextNode(com.google.security.zynamics.binnavi.disassembly.INaviTextNode) IUser(com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) UniqueTestUserGenerator(com.google.security.zynamics.binnavi.Database.PostgreSQL.UniqueTestUserGenerator) ExpensiveBaseTest(com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest) Test(org.junit.Test)

Aggregations

UniqueTestUserGenerator (com.google.security.zynamics.binnavi.Database.PostgreSQL.UniqueTestUserGenerator)96 IUser (com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser)95 ExpensiveBaseTest (com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest)95 Test (org.junit.Test)95 CComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment)89 IComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment)89 INaviGroupNode (com.google.security.zynamics.binnavi.disassembly.INaviGroupNode)8 INaviTextNode (com.google.security.zynamics.binnavi.disassembly.INaviTextNode)8 CNaviViewEdge (com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge)2 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)2 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)2 INaviViewNode (com.google.security.zynamics.binnavi.disassembly.INaviViewNode)2 INaviInstruction (com.google.security.zynamics.binnavi.disassembly.INaviInstruction)1 CModuleContainer (com.google.security.zynamics.binnavi.disassembly.Modules.CModuleContainer)1 INaviView (com.google.security.zynamics.binnavi.disassembly.views.INaviView)1 ZyGraph (com.google.security.zynamics.binnavi.yfileswrap.zygraph.ZyGraph)1 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)1 Before (org.junit.Before)1