Search in sources :

Example 66 with IComment

use of com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment in project binnavi by google.

the class PostgreSQLNotificationProviderTest method testAppendFunctionNodeCommentSync.

@Test
public void testAppendFunctionNodeCommentSync() throws CouldntLoadDataException, CPartialLoadException, LoadCancelledException, CouldntSaveDataException, InterruptedException {
    databaseOneCallGraph = databaseOneModuleTwo.getContent().getViewContainer().getNativeCallgraphView();
    databaseOneCallGraph.load();
    final INaviFunctionNode databaseOneFunctionNode = (INaviFunctionNode) databaseOneCallGraph.getGraph().getNodes().get(1);
    databaseTwoCallGraph = databaseTwoModuleTwo.getContent().getViewContainer().getNativeCallgraphView();
    databaseTwoCallGraph.load();
    final INaviFunctionNode databaseTwoFunctionNode = (INaviFunctionNode) databaseTwoCallGraph.getGraph().getNodes().get(1);
    final List<IComment> oneBefore = databaseOneFunctionNode.getLocalFunctionComment() == null ? new ArrayList<IComment>() : databaseOneFunctionNode.getLocalFunctionComment();
    final List<IComment> twoBefore = databaseTwoFunctionNode.getLocalFunctionComment() == null ? new ArrayList<IComment>() : databaseTwoFunctionNode.getLocalFunctionComment();
    assertEquals(oneBefore, twoBefore);
    databaseOneFunctionNode.appendLocalFunctionComment(" TEST NOTIFICATION PROVIDER TESTS (LOCAL FUNCTION NODE COMMENT) ");
    // database one to two over the PostgreSQL back end.
    synchronized (lock) {
        lock.await(1000, TimeUnit.MILLISECONDS);
    }
    final List<IComment> oneAfter = databaseOneFunctionNode.getLocalFunctionComment();
    final List<IComment> twoAfter = databaseTwoFunctionNode.getLocalFunctionComment();
    assertNotNull(oneAfter);
    assertNotNull(twoAfter);
    assertEquals(oneBefore.size() + 1, oneAfter.size());
    assertEquals(twoBefore.size() + 1, twoAfter.size());
    assertEquals(oneAfter, twoAfter);
}
Also used : IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) INaviFunctionNode(com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode) Test(org.junit.Test)

Example 67 with IComment

use of com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment in project binnavi by google.

the class PostgreSQLNotificationProviderTest method testEditLocalCodeNodeCommentSync.

@Test
public void testEditLocalCodeNodeCommentSync() throws CouldntSaveDataException, CouldntLoadDataException, InterruptedException {
    final INaviCodeNode databaseOnecodeNode = databaseOneView.getContent().getBasicBlocks().get(2);
    final INaviCodeNode databaseTwocodeNode = databaseTwoView.getContent().getBasicBlocks().get(2);
    final List<IComment> oneBefore = databaseOnecodeNode.getComments().getLocalCodeNodeComment() == null ? new ArrayList<IComment>() : databaseOnecodeNode.getComments().getLocalCodeNodeComment();
    final List<IComment> twoBefore = databaseTwocodeNode.getComments().getLocalCodeNodeComment() == null ? new ArrayList<IComment>() : databaseTwocodeNode.getComments().getLocalCodeNodeComment();
    assertEquals(oneBefore, twoBefore);
    final List<IComment> comments = databaseOnecodeNode.getComments().appendLocalCodeNodeComment(" TEST NOTIFICATION PROVIDER TESTS (LOCAL CODE NODE COMMENT) BEFORE ");
    // database one to two over the PostgreSQL back end.
    synchronized (lock) {
        lock.await(1000, TimeUnit.MILLISECONDS);
    }
    final List<IComment> oneAfter = databaseOnecodeNode.getComments().getLocalCodeNodeComment();
    final List<IComment> twoAfter = databaseTwocodeNode.getComments().getLocalCodeNodeComment();
    assertNotNull(oneAfter);
    assertNotNull(twoAfter);
    assertEquals(oneBefore.size() + 1, oneAfter.size());
    assertEquals(twoBefore.size() + 1, twoAfter.size());
    assertEquals(oneAfter, twoAfter);
    final int oneTwoSize = oneAfter.size();
    final int twoTwoSize = twoAfter.size();
    databaseOnecodeNode.getComments().editLocalCodeNodeComment(Iterables.getLast(comments), " TEST NOTIFICATION PROVIDER TESTS (LOCAL CODE NODE COMMENT) AFTER ");
    // database one to two over the PostgreSQL back end.
    synchronized (lock) {
        lock.await(1000, TimeUnit.MILLISECONDS);
    }
    final List<IComment> oneThree = databaseOnecodeNode.getComments().getLocalCodeNodeComment();
    final List<IComment> twoThree = databaseTwocodeNode.getComments().getLocalCodeNodeComment();
    assertEquals(oneTwoSize, oneThree.size());
    assertEquals(twoTwoSize, twoThree.size());
    assertEquals(oneThree, twoThree);
    assertEquals(" TEST NOTIFICATION PROVIDER TESTS (LOCAL CODE NODE COMMENT) AFTER ", Iterables.getLast(oneThree).getComment());
    assertEquals(" TEST NOTIFICATION PROVIDER TESTS (LOCAL CODE NODE COMMENT) AFTER ", Iterables.getLast(twoThree).getComment());
}
Also used : INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) Test(org.junit.Test)

Example 68 with IComment

use of com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment in project binnavi by google.

the class PostgreSQLNotificationProviderTest method testEditGlobalCodeNodeCommentSync.

@Test
public void testEditGlobalCodeNodeCommentSync() throws CouldntSaveDataException, CouldntLoadDataException, InterruptedException {
    final INaviCodeNode databaseOnecodeNode = databaseOneView.getContent().getBasicBlocks().get(1);
    final INaviCodeNode databaseTwocodeNode = databaseTwoView.getContent().getBasicBlocks().get(1);
    final List<IComment> oneBefore = databaseOnecodeNode.getComments().getGlobalCodeNodeComment() == null ? new ArrayList<IComment>() : databaseOnecodeNode.getComments().getGlobalCodeNodeComment();
    final List<IComment> twoBefore = databaseTwocodeNode.getComments().getGlobalCodeNodeComment() == null ? new ArrayList<IComment>() : databaseTwocodeNode.getComments().getGlobalCodeNodeComment();
    assertEquals(oneBefore, twoBefore);
    databaseOnecodeNode.getComments().appendGlobalCodeNodeComment(" TEST NOTIFICATION PROVIDER TESTS (GLOBAL CODE NODE COMMENT) BEFORE ");
    // database one to two over the PostgreSQL back end.
    synchronized (lock) {
        lock.await(1000, TimeUnit.MILLISECONDS);
    }
    final List<IComment> oneAfter = databaseOnecodeNode.getComments().getGlobalCodeNodeComment();
    final List<IComment> twoAfter = databaseTwocodeNode.getComments().getGlobalCodeNodeComment();
    assertNotNull(oneAfter);
    assertNotNull(twoAfter);
    assertEquals(oneBefore.size() + 1, oneAfter.size());
    assertEquals(twoBefore.size() + 1, twoAfter.size());
    assertEquals(oneAfter, twoAfter);
    final int oneTwoSize = oneAfter.size();
    final int twoTwoSize = twoAfter.size();
    databaseOnecodeNode.getComments().editGlobalCodeNodeComment(Iterables.getLast(databaseOnecodeNode.getComments().getGlobalCodeNodeComment()), " TEST NOTIFICATION PROVIDER TESTS (GLOBAL CODE NODE COMMENT) AFTER ");
    // database one to two over the PostgreSQL back end.
    synchronized (lock) {
        lock.await(1000, TimeUnit.MILLISECONDS);
    }
    final List<IComment> oneThree = databaseOnecodeNode.getComments().getGlobalCodeNodeComment();
    final List<IComment> twoThree = databaseTwocodeNode.getComments().getGlobalCodeNodeComment();
    assertEquals(oneTwoSize, oneThree.size());
    assertEquals(twoTwoSize, twoThree.size());
    assertEquals(oneThree, twoThree);
    assertEquals(" TEST NOTIFICATION PROVIDER TESTS (GLOBAL CODE NODE COMMENT) AFTER ", Iterables.getLast(oneThree).getComment());
    assertEquals(" TEST NOTIFICATION PROVIDER TESTS (GLOBAL CODE NODE COMMENT) AFTER ", Iterables.getLast(twoThree).getComment());
}
Also used : INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) Test(org.junit.Test)

Example 69 with IComment

use of com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment in project binnavi by google.

the class PostgreSQLCommentFunctions method loadCommentByCommentId.

/**
   * Loads comments by a comment root id it returns all ancestors of the comment.
   *
   * @param provider The provider used to access the database.
   * @param commentRootId The comment root id where to start the recursive query.
   * @return An array of comments from and including the comment referenced by the comment root id.
   *
   * @throws CouldntLoadDataException if the data could not be loaded from the database.
   */
public static ArrayList<IComment> loadCommentByCommentId(final SQLProvider provider, final int commentRootId) throws CouldntLoadDataException {
    Preconditions.checkNotNull(provider, "IE00440: connection argument can not be null");
    final HashMap<Integer, IComment> commentIdToComment = new HashMap<>();
    final ArrayList<IComment> comments = new ArrayList<>();
    final String commentQuery = "SELECT * FROM get_all_comment_ancestors(" + commentRootId + ");";
    try (ResultSet resultSet = provider.getConnection().executeQuery(commentQuery, true)) {
        while (resultSet.next()) {
            resultSet.getInt("level");
            final int commentId = resultSet.getInt("id");
            Integer parentId = resultSet.getInt("parent_id");
            if (resultSet.wasNull()) {
                parentId = null;
            }
            final int userId = resultSet.getInt("user_id");
            final String commentText = resultSet.getString("comment");
            final CComment comment = new CComment(commentId, CUserManager.get(provider).getUserById(userId), commentIdToComment.get(parentId), commentText);
            commentIdToComment.put(commentId, comment);
            comments.add(comment);
        }
    } catch (final SQLException exception) {
        throw new CouldntLoadDataException(exception);
    }
    return comments;
}
Also used : CComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment) IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) HashMap(java.util.HashMap) SQLException(java.sql.SQLException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet)

Example 70 with IComment

use of com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment in project binnavi by google.

the class GlobalCodeNodeCommentSynchronizer method updateOpenViews.

/**
   * Pushes a new global code node comment to all open views.
   * 
   * @param module The module whose views require updating.
   * @param codeNode The code node that has the new comment.
   * @param comments The new comment of the code node.
   * 
   * @throws CouldntSaveDataException Thrown if updating the code node comments failed.
   */
public static void updateOpenViews(final INaviModule module, final INaviCodeNode codeNode, final ArrayList<IComment> comments) throws CouldntSaveDataException {
    if (module.isLoaded()) {
        final List<INaviCodeNode> nodelist = new ArrayList<INaviCodeNode>();
        for (final INaviView view : module.getContent().getViewContainer().getViews()) {
            if (view.isLoaded()) {
                nodelist.addAll(collectNodes(view, codeNode));
            }
        }
        final List<IComment> codeNodeComments = codeNode.getComments().getGlobalCodeNodeComment();
        for (final INaviCodeNode currentCodeNode : nodelist) {
            final List<IComment> currentNodeComments = currentCodeNode.getComments().getGlobalCodeNodeComment();
            if (codeNodeComments.equals(currentNodeComments)) {
                continue;
            } else {
                currentCodeNode.getComments().initializeGlobalCodeNodeComment(comments);
            }
        }
    }
}
Also used : INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) ArrayList(java.util.ArrayList)

Aggregations

IComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment)167 Test (org.junit.Test)129 CComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment)114 IUser (com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser)97 UniqueTestUserGenerator (com.google.security.zynamics.binnavi.Database.PostgreSQL.UniqueTestUserGenerator)89 ExpensiveBaseTest (com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest)89 ArrayList (java.util.ArrayList)20 INaviCodeNode (com.google.security.zynamics.binnavi.disassembly.INaviCodeNode)18 INaviGroupNode (com.google.security.zynamics.binnavi.disassembly.INaviGroupNode)16 INaviTextNode (com.google.security.zynamics.binnavi.disassembly.INaviTextNode)13 CouldntSaveDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException)12 INaviView (com.google.security.zynamics.binnavi.disassembly.views.INaviView)11 CouldntLoadDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException)10 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)10 INaviInstruction (com.google.security.zynamics.binnavi.disassembly.INaviInstruction)9 INaviViewNode (com.google.security.zynamics.binnavi.disassembly.INaviViewNode)9 PreparedStatement (java.sql.PreparedStatement)8 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)7 INaviEdge (com.google.security.zynamics.binnavi.disassembly.INaviEdge)7 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)7