use of com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment 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));
}
use of com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment in project binnavi by google.
the class PostgreSQLLocalInstructionCommentTests method appendLocalInstructionComment5.
@Test
public void appendLocalInstructionComment5() throws CouldntLoadDataException, CouldntSaveDataException {
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 firstCommentString = " PASS LOCAL INSTRUCTION COMMENT 1 ";
final int firstCommentId = getProvider().appendLocalInstructionComment(codeNode, instruction, firstCommentString, user.getUserId());
final IComment firstComment = new CComment(firstCommentId, user, lastComment, firstCommentString);
final String secondCommentString = " PASS LOCAL INSTRUCTION COMMENT 2 ";
final int secondCommentId = getProvider().appendLocalInstructionComment(codeNode, instruction, 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));
}
use of com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment in project binnavi by google.
the class CGraphDebuggerTest method testGetDebugger2.
@Test
public void testGetDebugger2() {
final MockModule module = new MockModule();
module.getConfiguration().setDebugger(m_debugger);
final DebugTargetSettings target = new ModuleTargetSettings(module);
final DebuggerProvider debuggerProvider = new DebuggerProvider(target);
debuggerProvider.addDebugger(m_debugger);
final CFunction function = new CFunction(module, new MockView(), new CAddress(0x123), "Mock Function", "Mock Function", "Mock Description", 0, 0, 0, 0, FunctionType.NORMAL, "", 0, null, null, null, m_provider);
final ArrayList<IComment> comments = Lists.<IComment>newArrayList(new CComment(null, CommonTestObjects.TEST_USER_1, null, "Mock Comment"));
final INaviCodeNode codeNode = new CCodeNode(0, 0, 0, 0, 0, Color.RED, Color.RED, false, false, comments, function, new HashSet<CTag>(), new MockSqlProvider());
codeNode.addInstruction(new CInstruction(true, module, new CAddress(0x123), "nop", new ArrayList<COperandTree>(), new byte[] { (byte) 0x90 }, "x86-32", m_provider), null);
assertEquals(m_debugger, CGraphDebugger.getDebugger(debuggerProvider, Iterables.getFirst(codeNode.getInstructions(), null)));
}
use of com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment in project binnavi by google.
the class PostgreSQLNotificationParserTest method testCommentTableNotificationParser1.
@Test
public void testCommentTableNotificationParser1() {
CommentManager.get(provider).initializeGlobalInstructionComment(instruction, Lists.newArrayList(comment1, comment2, comment3));
final String COMMENTS_TABLE_NOTIFICATION_1 = "bn_comments UPDATE 3333 2222 " + CommonTestObjects.TEST_USER_3.getUserId() + " AAA";
final CommentNotification result = PostgreSQLCommentNotificationParser.processCommentNotification(new MockPGNotification("comment_changes", COMMENTS_TABLE_NOTIFICATION_1), provider);
assertNotNull(result);
final CommentNotificationContainer container = (CommentNotificationContainer) result;
final IComment comment = container.getCurrentComment();
assertEquals(comment3, comment);
final IComment testComment = new CComment(3333, CommonTestObjects.TEST_USER_3, comment2, "AAA");
assertEquals(testComment, container.getNewComment());
}
use of com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment in project binnavi by google.
the class FunctionNodeTest method testSetComment.
@Test
public void testSetComment() throws CouldntLoadDataException, CouldntLoadDataException, com.google.security.zynamics.binnavi.API.disassembly.CouldntLoadDataException, LoadCancelledException {
final MockSqlProvider provider = new MockSqlProvider();
final Database database = new Database(new MockDatabase());
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);
internalModule.load();
final CFunction internalFunction = 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 CView internalView = internalModule.getContent().getViewContainer().createView("", "");
@SuppressWarnings("unused") final CFunctionNode internalFunctionNode = internalView.getContent().createFunctionNode(internalFunction);
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 Function function = new Function(ModuleFactory.get(), internalFunction);
final Module module = new Module(database, internalModule, nodeTagManager, viewTagManager) {
@Override
public Function getFunction(final INaviFunction internalFunction) {
return function;
}
@Override
public boolean isLoaded() {
return true;
}
};
module.load();
final View view = module.getViews().get(2);
final FunctionNode node = (FunctionNode) view.getGraph().getNodes().get(0);
final MockFunctionNodeListener listener = new MockFunctionNodeListener();
node.addListener(listener);
final ArrayList<IComment> comment = Lists.<IComment>newArrayList(new CComment(null, CommonTestObjects.TEST_USER_1, null, "Fark"));
node.initializeComment(comment);
assertEquals("initializedComment;", listener.events);
assertEquals(comment, node.getComment());
node.removeListener(listener);
}
Aggregations