Search in sources :

Example 71 with UniqueTestUserGenerator

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

the class PostgreSQLLocalCodeNodeCommentTests method editLocalCodeNodeComment6.

@Test(expected = CouldntSaveDataException.class)
public void editLocalCodeNodeComment6() throws CouldntLoadDataException, CouldntSaveDataException {
    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 beforeEditCommentString = " EDIT LOCAL COMMENT BEFORE EDIT ";
    final int editedCommentId = getProvider().appendLocalCodeNodeComment(codeNode, beforeEditCommentString, user.getUserId());
    final IComment commentBeforeEdit = new CComment(editedCommentId, user, lastComment, beforeEditCommentString);
    final ArrayList<IComment> commentsFromDatabase = getProvider().loadCommentById(editedCommentId);
    assertNotNull(commentsFromDatabase);
    assertTrue(commentsFromDatabase.contains(commentBeforeEdit));
    assertEquals(storedComments.size() + 1, commentsFromDatabase.size());
    final IUser wrongUser = new UniqueTestUserGenerator(getProvider()).nextActiveUser();
    getProvider().editLocalCodeNodeComment(codeNode, editedCommentId, wrongUser.getUserId(), " FAIL ");
}
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 72 with UniqueTestUserGenerator

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

the class PostgreSQLLocalEdgeCommentTests method appendLocalEdgeComment4.

@Test
public void appendLocalEdgeComment4() throws CouldntLoadDataException, LoadCancelledException, CouldntSaveDataException, CPartialLoadException {
    final IUser user = new UniqueTestUserGenerator(getProvider()).nextActiveUser();
    final List<IComment> storedComments = edge.getLocalComment() == null ? new ArrayList<IComment>() : edge.getLocalComment();
    final IComment lastComment = storedComments.isEmpty() ? null : Iterables.getLast(storedComments);
    final String firstCommentString = " PASS LOCAL EDGE COMMENT WITHOUT PARENT ID ";
    final int firstCommentId = getProvider().appendLocalEdgeComment(edge, firstCommentString, user.getUserId());
    final IComment firstComment = new CComment(firstCommentId, user, lastComment, firstCommentString);
    final String secondCommentString = " PASS LOCAL EDGE COMMENT WITH PARENT ID ";
    final int secondCommentId = getProvider().appendLocalEdgeComment(edge, secondCommentString, user.getUserId());
    final IComment secondComment = new CComment(secondCommentId, user, firstComment, secondCommentString);
    final ArrayList<IComment> commentsFromDatabase = getProvider().loadCommentById(secondCommentId);
    assertNotNull(commentsFromDatabase);
    assertEquals(storedComments.size() + 2, commentsFromDatabase.size());
    assertTrue(commentsFromDatabase.contains(firstComment));
    assertTrue(commentsFromDatabase.contains(secondComment));
    final CNaviViewEdge callgraphEdge = (CNaviViewEdge) loadCallGraphEdge(getKernel32Module());
    getProvider().appendLocalEdgeComment(callgraphEdge, " PASS LOCAL CALLGRAPH EDGE COMMENT WITHOUT PARENT ID ", user.getUserId());
}
Also used : CComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment) IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) CNaviViewEdge(com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge) 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 73 with UniqueTestUserGenerator

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

the class PostgreSQLLocalEdgeCommentTests method deleteLocalEdgeComment8.

/**
   * This tests checks that a comment from another user can not be deleted by a different user id.
   */
@Test(expected = CouldntDeleteException.class)
public void deleteLocalEdgeComment8() throws CouldntLoadDataException, CouldntSaveDataException, CouldntDeleteException {
    final IUser user = new UniqueTestUserGenerator(getProvider()).nextActiveUser();
    final List<IComment> comments = edge.getLocalComment() == null ? new ArrayList<IComment>() : edge.getLocalComment();
    final IComment lastComment = comments.isEmpty() ? null : Iterables.getLast(comments);
    final String commentText = " COMMENT TO BE DELETED ";
    final Integer commentId = getProvider().appendLocalEdgeComment(edge, commentText, user.getUserId());
    final IComment commentToBeDelete = new CComment(commentId, user, lastComment, commentText);
    final ArrayList<IComment> commentsFromDatabase = getProvider().loadCommentById(commentId);
    assertNotNull(commentsFromDatabase);
    assertEquals(comments.size() + 1, commentsFromDatabase.size());
    assertTrue(commentsFromDatabase.contains(commentToBeDelete));
    final IUser wrongUser = new UniqueTestUserGenerator(getProvider()).nextActiveUser();
    assertFalse(wrongUser.equals(user));
    getProvider().deleteLocalEdgeComment(edge, commentId, wrongUser.getUserId());
}
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 74 with UniqueTestUserGenerator

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

the class PostgreSQLLocalInstructionCommentTests method deleteLocalInstructionComment7.

/**
   * This test checks if the delete of a comment in a series of comments works if the comment is a
   * comment in the middle.
   *
   * <pre>
   * Comment 1:      Comment 1:
   * Comment 2:  ->  
   * Comment 3:      Comment 3:
   * </pre>
   *
   */
@Test
public void deleteLocalInstructionComment7() throws CouldntLoadDataException, CouldntSaveDataException, CouldntDeleteException {
    final IUser user = new UniqueTestUserGenerator(getProvider()).nextActiveUser();
    final List<IComment> storedComments = codeNode.getComments().getLocalInstructionComment(instruction) == null ? new ArrayList<IComment>() : codeNode.getComments().getLocalInstructionComment(instruction);
    final IComment lastComment = storedComments.isEmpty() ? null : Iterables.getLast(storedComments);
    final String comment1String = " Comment 1: ";
    final int comment1Id = getProvider().appendLocalInstructionComment(codeNode, instruction, comment1String, user.getUserId());
    final IComment comment1 = new CComment(comment1Id, user, lastComment, comment1String);
    final String comment2String = " Comment 2: ";
    final int comment2Id = getProvider().appendLocalInstructionComment(codeNode, instruction, comment2String, user.getUserId());
    final IComment comment2 = new CComment(comment2Id, user, comment1, comment2String);
    final String comment3String = " Comment 3: ";
    final int comment3Id = getProvider().appendLocalInstructionComment(codeNode, instruction, 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().deleteLocalInstructionComment(codeNode, instruction, comment2Id, user.getUserId());
    final ArrayList<IComment> commentsAfterDelete1 = getProvider().loadCommentById(comment2Id);
    assertNotNull(commentsAfterDelete1);
    assertTrue(commentsAfterDelete1.isEmpty());
    final ArrayList<IComment> commentsAfterDelete2 = getProvider().loadCommentById(comment3Id);
    assertNotNull(commentsAfterDelete2);
    assertEquals(storedComments.size() + 2, commentsAfterDelete2.size());
    final IComment comment3AfterDelete = new CComment(comment3Id, user, comment1, comment3String);
    assertTrue(commentsAfterDelete2.contains(comment3AfterDelete));
    assertTrue(commentsAfterDelete2.contains(comment1));
    assertEquals(comment3AfterDelete, 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 75 with UniqueTestUserGenerator

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

the class PostgreSQLLocalInstructionCommentTests method deleteLocalInstructionComment6.

/**
   * 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 deleteLocalInstructionComment6() throws CouldntLoadDataException, CouldntSaveDataException, CouldntDeleteException {
    final IUser user = new UniqueTestUserGenerator(getProvider()).nextActiveUser();
    final List<IComment> storedComments = codeNode.getComments().getLocalInstructionComment(instruction) == null ? new ArrayList<IComment>() : codeNode.getComments().getLocalInstructionComment(instruction);
    final IComment lastComment = storedComments.isEmpty() ? null : Iterables.getLast(storedComments);
    final String comment1String = " Comment 1: ";
    final int comment1Id = getProvider().appendLocalInstructionComment(codeNode, instruction, comment1String, user.getUserId());
    final IComment comment1 = new CComment(comment1Id, user, lastComment, comment1String);
    final String comment2String = " Comment 2: ";
    final int comment2Id = getProvider().appendLocalInstructionComment(codeNode, instruction, comment2String, user.getUserId());
    final IComment comment2 = new CComment(comment2Id, user, comment1, comment2String);
    final String comment3String = " Comment 3: ";
    final int comment3Id = getProvider().appendLocalInstructionComment(codeNode, instruction, 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().deleteLocalInstructionComment(codeNode, instruction, 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)

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