Search in sources :

Example 61 with IUser

use of com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser in project binnavi by google.

the class PostgreSQLTypeInstancesCommentTests method deleteTypeInstanceComment5.

@Test
public void deleteTypeInstanceComment5() throws CouldntDeleteException, CouldntSaveDataException, CouldntLoadDataException {
    final List<IComment> comments = instanceContainer.getComments(typeInstance);
    final IComment lastComment = comments.size() == 0 ? null : Iterables.getLast(comments);
    final String commentString = " TEST DELETE TypeInstance COMMENT ";
    final IUser user = new UniqueTestUserGenerator(getProvider()).nextActiveUser();
    final int commentId = getProvider().appendTypeInstanceComment(typeInstance.getModule().getConfiguration().getId(), typeInstance.getId(), 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().deleteTypeInstanceComment(typeInstance.getModule().getConfiguration().getId(), typeInstance.getId(), 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 62 with IUser

use of com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser in project binnavi by google.

the class CCodeNodeTest method testMiscFunctions.

@Test
public void testMiscFunctions() throws MaybeNullException, CouldntSaveDataException, CouldntLoadDataException {
    final MockSqlProvider provider = new MockSqlProvider();
    final CUserManager userManager = CUserManager.get(provider);
    final IUser currentUser = userManager.addUser("TEST USER 1");
    userManager.setCurrentActiveUser(currentUser);
    final CModule internalModule = new CModule(1, "", "", new Date(), new Date(), CommonTestObjects.MD5, CommonTestObjects.SHA1, 0, 0, new CAddress(0), new CAddress(0), null, null, Integer.MAX_VALUE, false, provider);
    final CFunction parentFunction = 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 CCodeNode node = new CCodeNode(1, 0, 0, 0, 0, Color.BLACK, Color.BLACK, false, true, Lists.<IComment>newArrayList(new CComment(null, CommonTestObjects.TEST_USER_1, null, "foobar")), parentFunction, new LinkedHashSet<CTag>(), provider);
    final MockInstruction i1 = new MockInstruction(new CAddress(0x123), "nop", new ArrayList<COperandTree>(), null);
    final MockInstruction i2 = new MockInstruction(new CAddress(0x124), "nop", new ArrayList<COperandTree>(), null);
    final MockInstruction i3 = new MockInstruction(new CAddress(0x125), "nop", new ArrayList<COperandTree>(), null);
    final MockInstruction i4 = new MockInstruction(new CAddress(0x126), "nop", new ArrayList<COperandTree>(), m_globalComment);
    final MockInstruction i5 = new MockInstruction(new CAddress(0x127), "nop", new ArrayList<COperandTree>(), null);
    node.addInstruction(i1, Lists.<IComment>newArrayList(new CComment(null, currentUser, null, "Foo\nBar")));
    node.addInstruction(i2, Lists.<IComment>newArrayList(new CComment(null, currentUser, null, "\n")));
    node.addInstruction(i3, null);
    node.addInstruction(i4, null);
    final INaviCodeNodeListener listener = new CNaviCodeNodeListenerAdapter();
    node.addListener(listener);
    node.addInstruction(i5, null);
    assertNotNull(node.cloneNode());
    assertFalse(CCodeNodeHelpers.containsAddress(node, new CAddress(0xFFFFFFFEL)));
    assertEquals(null, node.getComments().getGlobalCodeNodeComment());
    assertEquals(new CAddress(0x123L), node.getAddress());
    assertEquals(0, CCodeNodeHelpers.getInstruction(node, new CAddress(0x123L)));
    assertEquals(-1, CCodeNodeHelpers.getInstruction(node, new CAddress(0x129L)));
    assertEquals(i1, Iterables.getFirst(node.getInstructions(), null));
    assertEquals(5, Iterables.size(node.getInstructions()));
    assertEquals(5, node.instructionCount());
    assertNotNull(node.getParentFunction());
    node.removeInstruction(i5);
    assertEquals(4, node.instructionCount());
    try {
        node.removeInstruction(null);
        fail();
    } catch (final NullPointerException e) {
    }
    try {
        node.removeInstruction(i5);
        fail();
    } catch (final IllegalArgumentException e) {
    }
    final List<IComment> comments = node.getComments().appendGlobalCodeNodeComment("barfoos");
    assertEquals(comments, node.getComments().getGlobalCodeNodeComment());
    try {
        node.getComments().appendGlobalCodeNodeComment(null);
        fail();
    } catch (final Exception e) {
    }
    node.setInstructionColor(i4, 0, Color.YELLOW);
    try {
        node.setInstructionColor(null, 0, null);
        fail();
    } catch (final Exception e) {
    }
    try {
        node.setInstructionColor(i5, 0, null);
        fail();
    } catch (final Exception e) {
    }
    node.setBorderColor(Color.GRAY);
    assertEquals(Color.GRAY, node.getBorderColor());
    final List<IComment> comments2 = node.getComments().appendLocalCodeNodeComment("barfoos2");
    assertEquals(comments2, node.getComments().getLocalCodeNodeComment());
    final List<IComment> appendedComments = node.getComments().appendLocalInstructionComment(i4, "foo");
    assertEquals(appendedComments, node.getComments().getLocalInstructionComment(i4));
    try {
        node.getComments().appendLocalInstructionComment(i5, " INSTRUCTION i5 COMMENT ");
        fail();
    } catch (final IllegalArgumentException e) {
    }
    node.getComments().appendLocalCodeNodeComment("foo");
    node.toString();
    node.removeListener(listener);
    node.close();
}
Also used : IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) CUserManager(com.google.security.zynamics.binnavi.Gui.Users.CUserManager) Date(java.util.Date) MaybeNullException(com.google.security.zynamics.binnavi.Exceptions.MaybeNullException) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) CComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) IUser(com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) Test(org.junit.Test)

Example 63 with IUser

use of com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser in project binnavi by google.

the class CUserManagerTest method editUserWrongArgumentsTest3.

@Test(expected = IllegalStateException.class)
public void editUserWrongArgumentsTest3() throws CouldntSaveDataException {
    final CUserManager manager = CUserManager.get(m_sql);
    final IUser user = new CUser(2123, "TEST USER 12412");
    manager.editUserName(user, "FOOBAR");
}
Also used : CUser(com.google.security.zynamics.binnavi.Gui.Users.CUser) IUser(com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser) CUserManager(com.google.security.zynamics.binnavi.Gui.Users.CUserManager) Test(org.junit.Test)

Example 64 with IUser

use of com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser in project binnavi by google.

the class CUserManagerTest method getCurrentActiveUserTest.

@Test
public void getCurrentActiveUserTest() throws CouldntSaveDataException {
    final CUserManager manager = CUserManager.get(m_sql);
    final IUser activeUser = manager.addUser(" ACTIVE USER ");
    manager.setCurrentActiveUser(activeUser);
    assertEquals(activeUser, manager.getCurrentActiveUser());
}
Also used : IUser(com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser) CUserManager(com.google.security.zynamics.binnavi.Gui.Users.CUserManager) Test(org.junit.Test)

Example 65 with IUser

use of com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser in project binnavi by google.

the class CUserManagerTest method deleteUserCorrectArgumentTest.

@Test
public void deleteUserCorrectArgumentTest() throws CouldntSaveDataException, CouldntDeleteException {
    final CUserManager manager = CUserManager.get(m_sql);
    final IUser user = manager.addUser("ONE");
    manager.deleteUser(user);
}
Also used : IUser(com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser) CUserManager(com.google.security.zynamics.binnavi.Gui.Users.CUserManager) Test(org.junit.Test)

Aggregations

IUser (com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser)120 Test (org.junit.Test)109 ExpensiveBaseTest (com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest)99 IComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment)97 CComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment)96 UniqueTestUserGenerator (com.google.security.zynamics.binnavi.Database.PostgreSQL.UniqueTestUserGenerator)95 CUserManager (com.google.security.zynamics.binnavi.Gui.Users.CUserManager)11 INaviGroupNode (com.google.security.zynamics.binnavi.disassembly.INaviGroupNode)9 INaviTextNode (com.google.security.zynamics.binnavi.disassembly.INaviTextNode)8 CouldntLoadDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException)6 CouldntSaveDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException)4 CouldntDeleteException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException)3 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)3 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)3 CNaviViewEdge (com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge)3 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)3 INaviViewNode (com.google.security.zynamics.binnavi.disassembly.INaviViewNode)3 ArrayList (java.util.ArrayList)3 CUser (com.google.security.zynamics.binnavi.Gui.Users.CUser)2 IUserManagerListener (com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUserManagerListener)2