Search in sources :

Example 1 with CAndCriterium

use of com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.And.CAndCriterium in project binnavi by google.

the class JCriteriumTreeModelTest method testRemoveNode.

@Test
public void testRemoveNode() {
    final JTree tree = new JTree();
    final CCriteriumTree cCriteriumTree = new CCriteriumTree();
    final CCriteriaFactory cCriteriaFactory = new CCriteriaFactory(m_graph, null, null);
    final JCriteriumTreeModel jCriterumTreeModel = new JCriteriumTreeModel(tree, cCriteriumTree, cCriteriaFactory.getConditions());
    final CCriteriumTreeNode child = new CCriteriumTreeNode(new CColorCriterium(m_graph));
    cCriteriumTree.appendNode(cCriteriumTree.getRoot(), child);
    final CCriteriumTreeNode child2 = new CCriteriumTreeNode(new CAndCriterium());
    cCriteriumTree.insertNode(cCriteriumTree.getRoot(), child2);
    final CCriteriumTreeNode child3 = new CCriteriumTreeNode(new CColorCriterium(m_graph));
    cCriteriumTree.appendNode(child2, child3);
    cCriteriumTree.remove(child);
    assertEquals(1, ((JCriteriumTreeNode) jCriterumTreeModel.getRoot()).getChildCount());
    assertEquals(1, ((JCriteriumTreeNode) ((JCriteriumTreeNode) jCriterumTreeModel.getRoot()).getChildAt(0)).getChildCount());
    assertEquals(child2.getCriterium(), ((JCriteriumTreeNode) ((JCriteriumTreeNode) jCriterumTreeModel.getRoot()).getChildAt(0)).getCriterium());
}
Also used : JTree(javax.swing.JTree) JCriteriumTreeModel(com.google.security.zynamics.binnavi.Gui.CriteriaDialog.ExpressionTree.JCriteriumTreeModel) CColorCriterium(com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.NodeColor.CColorCriterium) CCriteriaFactory(com.google.security.zynamics.binnavi.Gui.CriteriaDialog.CCriteriaFactory) CAndCriterium(com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.And.CAndCriterium) JCriteriumTreeNode(com.google.security.zynamics.binnavi.Gui.CriteriaDialog.ExpressionTree.JCriteriumTreeNode) CCriteriumTree(com.google.security.zynamics.binnavi.Gui.CriteriaDialog.ExpressionModel.CCriteriumTree) CCriteriumTreeNode(com.google.security.zynamics.binnavi.Gui.CriteriaDialog.ExpressionModel.CCriteriumTreeNode) Test(org.junit.Test)

Example 2 with CAndCriterium

use of com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.And.CAndCriterium in project binnavi by google.

the class CExpressionTreeValidator method isValid.

/**
   * Checks whether a given tree contains a valid boolean formula.
   *
   * @param tree The tree to check.
   *
   * @return True, if the tree is valid. False, otherwise.
   */
public static boolean isValid(final JCriteriumTree tree) {
    final JCriteriumTreeNode root = (JCriteriumTreeNode) tree.getModel().getRoot();
    if (root.getChildCount() != 1) {
        return false;
    }
    final Enumeration<?> enumeration = root.breadthFirstEnumeration();
    while (enumeration.hasMoreElements()) {
        final JCriteriumTreeNode node = (JCriteriumTreeNode) enumeration.nextElement();
        final ICriterium type = node.getCriterium();
        final int count = node.getChildCount();
        if ((type instanceof CAndCriterium || type instanceof COrCriterium) && count < 2) {
            return false;
        } else if (type instanceof CNotCriterium && count != 1) {
            return false;
        }
    }
    return true;
}
Also used : ICriterium(com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.ICriterium) CAndCriterium(com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.And.CAndCriterium) CNotCriterium(com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.Not.CNotCriterium) COrCriterium(com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.Or.COrCriterium)

Example 3 with CAndCriterium

use of com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.And.CAndCriterium in project binnavi by google.

the class CCriteriumFunctionsTest method testAppendOne.

@Test
public void testAppendOne() {
    final CCriteriumTree cCriteriumTree = new CCriteriumTree();
    final CCriteriumTreeNode child = new CCriteriumTreeNode(new CColorCriterium(m_graph));
    cCriteriumTree.appendNode(cCriteriumTree.getRoot(), child);
    CCriteriumFunctions.appendCriterium(cCriteriumTree, cCriteriumTree.getRoot().getChildren().get(0), new CAndCriterium());
    assertTrue(cCriteriumTree.getRoot().getChildren().get(0).getChildren().get(0).getCriterium() instanceof CAndCriterium);
}
Also used : CColorCriterium(com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.NodeColor.CColorCriterium) CAndCriterium(com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.And.CAndCriterium) CCriteriumTree(com.google.security.zynamics.binnavi.Gui.CriteriaDialog.ExpressionModel.CCriteriumTree) CCriteriumTreeNode(com.google.security.zynamics.binnavi.Gui.CriteriaDialog.ExpressionModel.CCriteriumTreeNode) Test(org.junit.Test)

Example 4 with CAndCriterium

use of com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.And.CAndCriterium in project binnavi by google.

the class JCriteriumTreeModelTest method testInsertNode.

@Test
public void testInsertNode() {
    final JTree tree = new JTree();
    final CCriteriumTree cCriteriumTree = new CCriteriumTree();
    final CCriteriaFactory cCriteriaFactory = new CCriteriaFactory(m_graph, null, null);
    final JCriteriumTreeModel jCriterumTreeModel = new JCriteriumTreeModel(tree, cCriteriumTree, cCriteriaFactory.getConditions());
    final CCriteriumTreeNode child = new CCriteriumTreeNode(new CColorCriterium(m_graph));
    cCriteriumTree.appendNode(cCriteriumTree.getRoot(), child);
    final CCriteriumTreeNode child2 = new CCriteriumTreeNode(new CAndCriterium());
    cCriteriumTree.insertNode(cCriteriumTree.getRoot(), child2);
    assertEquals(1, ((JCriteriumTreeNode) jCriterumTreeModel.getRoot()).getChildCount());
    assertEquals(child2.getCriterium(), ((JCriteriumTreeNode) ((JCriteriumTreeNode) jCriterumTreeModel.getRoot()).getChildAt(0)).getCriterium());
    assertEquals(child.getCriterium(), ((JCriteriumTreeNode) ((JCriteriumTreeNode) ((JCriteriumTreeNode) jCriterumTreeModel.getRoot()).getChildAt(0)).getChildAt(0)).getCriterium());
}
Also used : JTree(javax.swing.JTree) JCriteriumTreeModel(com.google.security.zynamics.binnavi.Gui.CriteriaDialog.ExpressionTree.JCriteriumTreeModel) CColorCriterium(com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.NodeColor.CColorCriterium) CCriteriaFactory(com.google.security.zynamics.binnavi.Gui.CriteriaDialog.CCriteriaFactory) CAndCriterium(com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.And.CAndCriterium) JCriteriumTreeNode(com.google.security.zynamics.binnavi.Gui.CriteriaDialog.ExpressionTree.JCriteriumTreeNode) CCriteriumTree(com.google.security.zynamics.binnavi.Gui.CriteriaDialog.ExpressionModel.CCriteriumTree) CCriteriumTreeNode(com.google.security.zynamics.binnavi.Gui.CriteriaDialog.ExpressionModel.CCriteriumTreeNode) Test(org.junit.Test)

Example 5 with CAndCriterium

use of com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.And.CAndCriterium in project binnavi by google.

the class JCriteriumTreeModelTest method testRemoveAll.

@Test
public void testRemoveAll() {
    final JTree tree = new JTree();
    final CCriteriumTree cCriteriumTree = new CCriteriumTree();
    final CCriteriaFactory cCriteriaFactory = new CCriteriaFactory(m_graph, null, null);
    final JCriteriumTreeModel jCriterumTreeModel = new JCriteriumTreeModel(tree, cCriteriumTree, cCriteriaFactory.getConditions());
    final CCriteriumTreeNode child = new CCriteriumTreeNode(new CColorCriterium(m_graph));
    cCriteriumTree.appendNode(cCriteriumTree.getRoot(), child);
    final CCriteriumTreeNode child2 = new CCriteriumTreeNode(new CAndCriterium());
    cCriteriumTree.insertNode(cCriteriumTree.getRoot(), child2);
    final CCriteriumTreeNode child3 = new CCriteriumTreeNode(new CColorCriterium(m_graph));
    cCriteriumTree.appendNode(child2, child3);
    cCriteriumTree.clear();
    assertEquals(0, ((JCriteriumTreeNode) jCriterumTreeModel.getRoot()).getChildCount());
}
Also used : JTree(javax.swing.JTree) JCriteriumTreeModel(com.google.security.zynamics.binnavi.Gui.CriteriaDialog.ExpressionTree.JCriteriumTreeModel) CColorCriterium(com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.NodeColor.CColorCriterium) CCriteriaFactory(com.google.security.zynamics.binnavi.Gui.CriteriaDialog.CCriteriaFactory) CAndCriterium(com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.And.CAndCriterium) CCriteriumTree(com.google.security.zynamics.binnavi.Gui.CriteriaDialog.ExpressionModel.CCriteriumTree) CCriteriumTreeNode(com.google.security.zynamics.binnavi.Gui.CriteriaDialog.ExpressionModel.CCriteriumTreeNode) Test(org.junit.Test)

Aggregations

CAndCriterium (com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.And.CAndCriterium)5 CColorCriterium (com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.NodeColor.CColorCriterium)4 CCriteriumTree (com.google.security.zynamics.binnavi.Gui.CriteriaDialog.ExpressionModel.CCriteriumTree)4 CCriteriumTreeNode (com.google.security.zynamics.binnavi.Gui.CriteriaDialog.ExpressionModel.CCriteriumTreeNode)4 Test (org.junit.Test)4 CCriteriaFactory (com.google.security.zynamics.binnavi.Gui.CriteriaDialog.CCriteriaFactory)3 JCriteriumTreeModel (com.google.security.zynamics.binnavi.Gui.CriteriaDialog.ExpressionTree.JCriteriumTreeModel)3 JTree (javax.swing.JTree)3 JCriteriumTreeNode (com.google.security.zynamics.binnavi.Gui.CriteriaDialog.ExpressionTree.JCriteriumTreeNode)2 ICriterium (com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.ICriterium)1 CNotCriterium (com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.Not.CNotCriterium)1 COrCriterium (com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.Or.COrCriterium)1