Search in sources :

Example 41 with CTagManager

use of com.google.security.zynamics.binnavi.Tagging.CTagManager in project binnavi by google.

the class AddressSpaceTest method setUp.

@Before
public void setUp() {
    final MockSqlProvider provider = new MockSqlProvider();
    creationDate = new Date();
    modificationDate = new Date();
    final MockDatabase mockDb = new MockDatabase();
    database = new Database(mockDb);
    internalAddressSpace = new CAddressSpace(1, "Mock Space", "Mock Space Description", creationDate, modificationDate, new LinkedHashMap<INaviModule, IAddress>(), null, provider, new MockProject());
    addressSpace = new AddressSpace(database, null, internalAddressSpace);
    final Date creationDate = new Date();
    final Date modificationDate = new Date();
    final CModule internalModule = new CModule(123, "Name", "Comment", creationDate, modificationDate, "12345678123456781234567812345678", "1234567812345678123456781234567812345678", 55, 66, new CAddress(0x555), new CAddress(0x666), new com.google.security.zynamics.binnavi.debug.debugger.DebuggerTemplate(1, "Mock Debugger", "localhaus", 88, provider), null, Integer.MAX_VALUE, false, provider);
    mockDb.getContent().addModule(internalModule);
    final TagManager nodeTagManager = new TagManager(new CTagManager(new Tree<CTag>(new TreeNode<CTag>(new CTag(0, "", "", TagType.NODE_TAG, provider))), TagType.NODE_TAG, provider));
    final TagManager viewTagManager = new TagManager(new CTagManager(new Tree<CTag>(new TreeNode<CTag>(new CTag(0, "", "", TagType.VIEW_TAG, provider))), TagType.VIEW_TAG, provider));
    module = new Module(database, internalModule, nodeTagManager, viewTagManager);
}
Also used : CTag(com.google.security.zynamics.binnavi.Tagging.CTag) CTagManager(com.google.security.zynamics.binnavi.Tagging.CTagManager) Date(java.util.Date) LinkedHashMap(java.util.LinkedHashMap) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) MockProject(com.google.security.zynamics.binnavi.disassembly.MockProject) CTagManager(com.google.security.zynamics.binnavi.Tagging.CTagManager) MockTagManager(com.google.security.zynamics.binnavi.Tagging.MockTagManager) CAddressSpace(com.google.security.zynamics.binnavi.disassembly.AddressSpaces.CAddressSpace) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) Tree(com.google.security.zynamics.zylib.types.trees.Tree) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) CAddressSpace(com.google.security.zynamics.binnavi.disassembly.AddressSpaces.CAddressSpace) Before(org.junit.Before)

Example 42 with CTagManager

use of com.google.security.zynamics.binnavi.Tagging.CTagManager in project binnavi by google.

the class ProjectTest method setUp.

@SuppressWarnings("deprecation")
@Before
public void setUp() {
    modificationDate.setYear(creationDate.getYear() + 1);
    m_internalProject = new CProject(1, "Project Name", "Project Description", creationDate, modificationDate, 1, new ArrayList<com.google.security.zynamics.binnavi.debug.debugger.DebuggerTemplate>(), provider);
    final TagManager nodeTagManager = new TagManager(new CTagManager(new Tree<CTag>(new TreeNode<CTag>(new CTag(1, "", "", TagType.NODE_TAG, provider))), TagType.NODE_TAG, provider));
    final TagManager viewTagManager = new TagManager(new CTagManager(new Tree<CTag>(new TreeNode<CTag>(new CTag(1, "", "", TagType.VIEW_TAG, provider))), TagType.VIEW_TAG, provider));
    m_project = new Project(database, m_internalProject, nodeTagManager, viewTagManager);
}
Also used : CProject(com.google.security.zynamics.binnavi.disassembly.CProject) CProject(com.google.security.zynamics.binnavi.disassembly.CProject) CTagManager(com.google.security.zynamics.binnavi.Tagging.CTagManager) ArrayList(java.util.ArrayList) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) Tree(com.google.security.zynamics.zylib.types.trees.Tree) CTagManager(com.google.security.zynamics.binnavi.Tagging.CTagManager) Before(org.junit.Before)

Example 43 with CTagManager

use of com.google.security.zynamics.binnavi.Tagging.CTagManager in project binnavi by google.

the class CTagManagerTest method test_C_Constructors.

@Test
public void test_C_Constructors() {
    try {
        new CTagManager(null, TagType.VIEW_TAG, new MockSqlProvider());
        fail();
    } catch (final NullPointerException exception) {
    }
    try {
        new CTagManager(new Tree<CTag>(new TreeNode<CTag>(new CTag(1, "Foo", "Bar", TagType.VIEW_TAG, new MockSqlProvider()))), null, new MockSqlProvider());
        fail();
    } catch (final NullPointerException exception) {
    }
    try {
        new CTagManager(new Tree<CTag>(new TreeNode<CTag>(new CTag(1, "Foo", "Bar", TagType.VIEW_TAG, new MockSqlProvider()))), TagType.VIEW_TAG, null);
        fail();
    } catch (final NullPointerException exception) {
    }
    final MockSqlProvider sql = new MockSqlProvider();
    new CTagManager(new Tree<CTag>(new TreeNode<CTag>(new CTag(1, "Foo", "Bar", TagType.VIEW_TAG, sql))), TagType.VIEW_TAG, sql);
}
Also used : MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) TreeNode(com.google.security.zynamics.zylib.types.trees.TreeNode) ITreeNode(com.google.security.zynamics.zylib.types.trees.ITreeNode) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) CTagManager(com.google.security.zynamics.binnavi.Tagging.CTagManager) Test(org.junit.Test)

Example 44 with CTagManager

use of com.google.security.zynamics.binnavi.Tagging.CTagManager in project binnavi by google.

the class CTagManagerTest method testTags2.

@Test
public void testTags2() throws CouldntSaveDataException, CouldntDeleteException {
    final MockSqlProvider sql = new MockSqlProvider();
    final CTagManager manager = new CTagManager(new Tree<CTag>(new TreeNode<CTag>(new CTag(1, "Foo", "Bar", TagType.VIEW_TAG, sql))), TagType.VIEW_TAG, sql);
    final MockTagManagerListener listener = new MockTagManagerListener();
    manager.addListener(listener);
    // ----------------------------------------- ADDING TAGS ---------------------------------------
    final ITreeNode<CTag> tag1 = manager.addTag(manager.getRootTag(), "Tag I");
    final ITreeNode<CTag> tag2 = manager.addTag(manager.getRootTag(), "Tag II");
    final ITreeNode<CTag> tag3 = manager.addTag(tag2, "Tag III");
    // ------------------------------------------- INSERT TAGS
    // ---------------------------------------------------
    final ITreeNode<CTag> tag4 = manager.insertTag(manager.getRootTag(), "Tag IV");
    final ITreeNode<CTag> tag5 = manager.insertTag(tag3, "Tag V");
    try {
        manager.deleteTagSubTree(null);
        fail();
    } catch (final NullPointerException exception) {
    }
    try {
        manager.deleteTagSubTree(manager.getRootTag());
        fail();
    } catch (final IllegalArgumentException exception) {
    }
    manager.deleteTagSubTree(tag5);
    // Check listener events
    assertEquals("addedTag/addedTag/addedTag/insertedTag/insertedTag/deletedTag/", listener.eventList);
    // Check tag
    assertEquals(4, DepthFirstSorter.getSortedList(manager.getRootTag()).size());
    assertEquals(tag4, tag1.getParent());
    assertFalse(manager.getRootTag().getChildren().contains(tag1));
    assertTrue(tag4.getChildren().contains(tag1));
    assertEquals(tag4, tag2.getParent());
    assertFalse(manager.getRootTag().getChildren().contains(tag2));
    assertTrue(tag4.getChildren().contains(tag2));
    assertEquals(tag2, tag3.getParent());
    assertTrue(tag2.getChildren().contains(tag3));
    assertNull(tag5.getParent());
    assertFalse(tag3.getChildren().contains(tag5));
    assertNull(CTagHelpers.findTag(manager.getRootTag(), 5));
    manager.deleteTagSubTree(tag4);
    // Check listener events
    assertEquals("addedTag/addedTag/addedTag/insertedTag/insertedTag/deletedTag/deletedSubtree/", listener.eventList);
    // Check tag
    assertEquals(0, DepthFirstSorter.getSortedList(manager.getRootTag()).size());
}
Also used : MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) TreeNode(com.google.security.zynamics.zylib.types.trees.TreeNode) ITreeNode(com.google.security.zynamics.zylib.types.trees.ITreeNode) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) CTagManager(com.google.security.zynamics.binnavi.Tagging.CTagManager) Test(org.junit.Test)

Example 45 with CTagManager

use of com.google.security.zynamics.binnavi.Tagging.CTagManager in project binnavi by google.

the class CTagManagerTest method testTags.

@Test
public void testTags() throws CouldntSaveDataException, CouldntDeleteException {
    final MockSqlProvider sql = new MockSqlProvider();
    final CTagManager manager = new CTagManager(new Tree<CTag>(new TreeNode<CTag>(new CTag(1, "Foo", "Bar", TagType.VIEW_TAG, sql))), TagType.VIEW_TAG, sql);
    final MockTagManagerListener listener = new MockTagManagerListener();
    // ----------------------------------------- ADDING TAGS ---------------------------------------
    manager.addListener(listener);
    try {
        manager.addTag(null, "Tag I");
        fail();
    } catch (final NullPointerException exception) {
    }
    assertEquals("", listener.eventList);
    try {
        manager.addTag(manager.getRootTag(), null);
        fail();
    } catch (final NullPointerException exception) {
    }
    assertEquals("", listener.eventList);
    final ITreeNode<CTag> tag1 = manager.addTag(manager.getRootTag(), "Tag I");
    // Check listener events
    assertEquals("addedTag/", listener.eventList);
    // Check tag
    assertEquals(manager.getRootTag(), tag1.getParent());
    assertTrue(manager.getRootTag().getChildren().contains(tag1));
    final ITreeNode<CTag> tag2 = manager.addTag(manager.getRootTag(), "Tag II");
    // Check listener events
    assertEquals("addedTag/addedTag/", listener.eventList);
    // Check tag
    assertEquals(manager.getRootTag(), tag1.getParent());
    assertTrue(manager.getRootTag().getChildren().contains(tag1));
    assertEquals(manager.getRootTag(), tag2.getParent());
    assertTrue(manager.getRootTag().getChildren().contains(tag2));
    final ITreeNode<CTag> tag3 = manager.addTag(tag2, "Tag III");
    // Check listener events
    assertEquals("addedTag/addedTag/addedTag/", listener.eventList);
    // Check tag
    assertEquals(manager.getRootTag(), tag1.getParent());
    assertTrue(manager.getRootTag().getChildren().contains(tag1));
    assertEquals(manager.getRootTag(), tag2.getParent());
    assertTrue(manager.getRootTag().getChildren().contains(tag2));
    assertEquals(tag2, tag3.getParent());
    assertTrue(tag2.getChildren().contains(tag3));
    try {
        manager.insertTag(null, "Foo");
        fail();
    } catch (final NullPointerException exception) {
    }
    try {
        manager.insertTag(manager.getRootTag(), null);
        fail();
    } catch (final NullPointerException exception) {
    }
    final ITreeNode<CTag> tag4 = manager.insertTag(manager.getRootTag(), "Tag IV");
    // Check listener events
    assertEquals("addedTag/addedTag/addedTag/insertedTag/", listener.eventList);
    // Check tag
    assertEquals(tag4, tag1.getParent());
    assertFalse(manager.getRootTag().getChildren().contains(tag1));
    assertTrue(tag4.getChildren().contains(tag1));
    assertEquals(tag4, tag2.getParent());
    assertFalse(manager.getRootTag().getChildren().contains(tag2));
    assertTrue(tag4.getChildren().contains(tag2));
    assertEquals(tag2, tag3.getParent());
    assertTrue(tag2.getChildren().contains(tag3));
    final ITreeNode<CTag> tag5 = manager.insertTag(tag3, "Tag V");
    // Check listener events
    assertEquals("addedTag/addedTag/addedTag/insertedTag/insertedTag/", listener.eventList);
    // Check tag
    assertEquals(tag4, tag1.getParent());
    assertFalse(manager.getRootTag().getChildren().contains(tag1));
    assertTrue(tag4.getChildren().contains(tag1));
    assertEquals(tag4, tag2.getParent());
    assertFalse(manager.getRootTag().getChildren().contains(tag2));
    assertTrue(tag4.getChildren().contains(tag2));
    assertEquals(tag2, tag3.getParent());
    assertTrue(tag2.getChildren().contains(tag3));
    assertEquals(tag3, tag5.getParent());
    assertTrue(tag3.getChildren().contains(tag5));
    try {
        manager.deleteTag(null);
        fail();
    } catch (final NullPointerException exception) {
    }
    try {
        manager.deleteTag(manager.getRootTag());
        fail();
    } catch (final IllegalArgumentException exception) {
    }
    manager.deleteTag(tag5);
    // Check listener events
    assertEquals("addedTag/addedTag/addedTag/insertedTag/insertedTag/deletedTag/", listener.eventList);
    // Check tag
    assertEquals(tag4, tag1.getParent());
    assertFalse(manager.getRootTag().getChildren().contains(tag1));
    assertTrue(tag4.getChildren().contains(tag1));
    assertEquals(tag4, tag2.getParent());
    assertFalse(manager.getRootTag().getChildren().contains(tag2));
    assertTrue(tag4.getChildren().contains(tag2));
    assertEquals(tag2, tag3.getParent());
    assertTrue(tag2.getChildren().contains(tag3));
    assertNull(tag5.getParent());
    assertFalse(tag3.getChildren().contains(tag5));
    assertNull(CTagHelpers.findTag(manager.getRootTag(), 5));
    manager.deleteTag(tag4);
    // Check listener events
    assertEquals("addedTag/addedTag/addedTag/insertedTag/insertedTag/deletedTag/deletedTag/", listener.eventList);
    // Check tag
    assertEquals(manager.getRootTag(), tag1.getParent());
    assertTrue(manager.getRootTag().getChildren().contains(tag1));
    assertEquals(manager.getRootTag(), tag2.getParent());
    assertTrue(manager.getRootTag().getChildren().contains(tag2));
    assertEquals(tag2, tag3.getParent());
    assertTrue(tag2.getChildren().contains(tag3));
    assertNull(tag4.getParent());
    assertFalse(manager.getRootTag().getChildren().contains(tag4));
    assertNull(CTagHelpers.findTag(manager.getRootTag(), 4));
}
Also used : MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) TreeNode(com.google.security.zynamics.zylib.types.trees.TreeNode) ITreeNode(com.google.security.zynamics.zylib.types.trees.ITreeNode) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) CTagManager(com.google.security.zynamics.binnavi.Tagging.CTagManager) Test(org.junit.Test)

Aggregations

CTagManager (com.google.security.zynamics.binnavi.Tagging.CTagManager)46 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)34 Test (org.junit.Test)31 ExpensiveBaseTest (com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest)23 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)17 Tree (com.google.security.zynamics.zylib.types.trees.Tree)15 MockDatabase (com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase)13 CModule (com.google.security.zynamics.binnavi.disassembly.Modules.CModule)13 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)12 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)12 Date (java.util.Date)12 TreeNode (com.google.security.zynamics.zylib.types.trees.TreeNode)10 Before (org.junit.Before)9 TagManager (com.google.security.zynamics.binnavi.API.disassembly.TagManager)8 ITreeNode (com.google.security.zynamics.zylib.types.trees.ITreeNode)8 Database (com.google.security.zynamics.binnavi.API.disassembly.Database)7 CView (com.google.security.zynamics.binnavi.disassembly.views.CView)7 Module (com.google.security.zynamics.binnavi.API.disassembly.Module)6 MockTagManager (com.google.security.zynamics.binnavi.Tagging.MockTagManager)5 MockView (com.google.security.zynamics.binnavi.disassembly.MockView)5