Search in sources :

Example 11 with UniqueTestUserGenerator

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

the class PostgreSQLFunctionCommentTests method deleteFunctionComment4.

@Test
public void deleteFunctionComment4() throws CouldntLoadDataException, CouldntSaveDataException, CouldntDeleteException {
    final List<IComment> comments = function.getGlobalComment() == null ? new ArrayList<IComment>() : function.getGlobalComment();
    final IComment lastComment = comments.size() == 0 ? null : Iterables.getLast(comments);
    final String commentString = " TEST DELETE FUNCTION COMMENT ";
    final IUser user = new UniqueTestUserGenerator(getProvider()).nextActiveUser();
    final int commentId = getProvider().appendFunctionComment(function, 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, storedComments.get(storedComments.size() - 1));
    getProvider().deleteFunctionComment(function, 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 12 with UniqueTestUserGenerator

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

the class PostgreSQLFunctionCommentTests method appendFunctionComment4.

@Test
public void appendFunctionComment4() throws CouldntLoadDataException, LoadCancelledException, CouldntSaveDataException {
    final INaviModule module = getProvider().loadModules().get(0);
    module.load();
    final INaviFunction function = module.getContent().getFunctionContainer().getFunctions().get(123);
    function.load();
    final IUser user = new UniqueTestUserGenerator(getProvider()).nextActiveUser();
    final java.util.List<IComment> storedComments = function.getGlobalComment() == null ? new ArrayList<IComment>() : function.getGlobalComment();
    final IComment lastComment = storedComments.isEmpty() ? null : Iterables.getLast(storedComments);
    final String firstCommentString = " PASS FUNCTION NODE COMMENT 1 ";
    final int firstCommentId = getProvider().appendFunctionComment(function, firstCommentString, user.getUserId());
    final IComment firstComment = new CComment(firstCommentId, user, lastComment, firstCommentString);
    final String secondCommentString = " PASS FUNCTION NODE COMMENT 2 ";
    final int secondCommentId = getProvider().appendFunctionComment(function, 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));
    function.close();
    module.close();
}
Also used : CComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment) IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) IUser(com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) UniqueTestUserGenerator(com.google.security.zynamics.binnavi.Database.PostgreSQL.UniqueTestUserGenerator) ExpensiveBaseTest(com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest) Test(org.junit.Test)

Example 13 with UniqueTestUserGenerator

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

the class PostgreSQLFunctionCommentTests method appendFunctionComment3.

@Test(expected = NullPointerException.class)
public void appendFunctionComment3() throws CouldntSaveDataException {
    getProvider().appendFunctionComment(function, " FAIL ", null);
    final IUser user = new UniqueTestUserGenerator(getProvider()).nextActiveUser();
    getProvider().appendFunctionComment(function, " PASS FUNCTION NODE COMMENT ", user.getUserId());
}
Also used : 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 14 with UniqueTestUserGenerator

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

the class PostgreSQLFunctionCommentTests method editFunctionComment6.

@Test(expected = CouldntSaveDataException.class)
public void editFunctionComment6() throws CouldntLoadDataException, CouldntSaveDataException {
    final IUser user = new UniqueTestUserGenerator(getProvider()).nextActiveUser();
    final List<IComment> storedComments = function.getGlobalComment() == null ? new ArrayList<IComment>() : function.getGlobalComment();
    final IComment lastComment = storedComments.isEmpty() ? null : Iterables.getLast(storedComments);
    final String beforeEditCommentString = " EDIT COMMENT BEFORE EDIT ";
    final int editedCommentId = getProvider().appendFunctionComment(function, 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().editFunctionComment(function, 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 15 with UniqueTestUserGenerator

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

the class PostgreSQLFunctionNodeCommentTests method editFunctionNodeComment6.

@Test(expected = CouldntSaveDataException.class)
public void editFunctionNodeComment6() throws CouldntLoadDataException, CouldntSaveDataException {
    final IUser user = new UniqueTestUserGenerator(getProvider()).nextActiveUser();
    final List<IComment> storedComments = functionNode.getLocalFunctionComment() == null ? new ArrayList<IComment>() : functionNode.getLocalFunctionComment();
    final IComment lastComment = storedComments.isEmpty() ? null : Iterables.getLast(storedComments);
    final String beforeEditCommentString = " EDIT LOCAL COMMENT BEFORE EDIT ";
    final int editedCommentId = getProvider().appendFunctionNodeComment(functionNode, 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().editFunctionNodeComment(functionNode, 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)

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