Search in sources :

Example 1 with COrCriterium

use of com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.Or.COrCriterium 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 2 with COrCriterium

use of com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.Or.COrCriterium in project binnavi by google.

the class CCriteriumFunctionsTest method testInsertCriterium.

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

Example 3 with COrCriterium

use of com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.Or.COrCriterium in project binnavi by google.

the class CCriteriumFunctionsTest method testRemoveAll.

@Test
public void testRemoveAll() {
    final CCriteriumTree cCriteriumTree = new CCriteriumTree();
    final CCriteriumTreeNode child = new CCriteriumTreeNode(new CColorCriterium(m_graph));
    cCriteriumTree.appendNode(cCriteriumTree.getRoot(), child);
    final CCriteriumTreeNode child2 = new CCriteriumTreeNode(new COrCriterium());
    cCriteriumTree.appendNode(child, child2);
    CCriteriumFunctions.removeAll(cCriteriumTree);
    assertEquals(0, cCriteriumTree.getRoot().getChildren().size());
}
Also used : CColorCriterium(com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.NodeColor.CColorCriterium) CCriteriumTree(com.google.security.zynamics.binnavi.Gui.CriteriaDialog.ExpressionModel.CCriteriumTree) CCriteriumTreeNode(com.google.security.zynamics.binnavi.Gui.CriteriaDialog.ExpressionModel.CCriteriumTreeNode) COrCriterium(com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.Or.COrCriterium) Test(org.junit.Test)

Example 4 with COrCriterium

use of com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.Or.COrCriterium in project binnavi by google.

the class CCriteriumFunctionsTest method testRemove.

@Test
public void testRemove() {
    final CCriteriumTree cCriteriumTree = new CCriteriumTree();
    final CCriteriumTreeNode child = new CCriteriumTreeNode(new CColorCriterium(m_graph));
    cCriteriumTree.appendNode(cCriteriumTree.getRoot(), child);
    final CCriteriumTreeNode child2 = new CCriteriumTreeNode(new COrCriterium());
    cCriteriumTree.appendNode(child, child2);
    CCriteriumFunctions.remove(cCriteriumTree, child);
    assertEquals(0, cCriteriumTree.getRoot().getChildren().size());
}
Also used : CColorCriterium(com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.NodeColor.CColorCriterium) CCriteriumTree(com.google.security.zynamics.binnavi.Gui.CriteriaDialog.ExpressionModel.CCriteriumTree) CCriteriumTreeNode(com.google.security.zynamics.binnavi.Gui.CriteriaDialog.ExpressionModel.CCriteriumTreeNode) COrCriterium(com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.Or.COrCriterium) Test(org.junit.Test)

Aggregations

COrCriterium (com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.Or.COrCriterium)4 CColorCriterium (com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.NodeColor.CColorCriterium)3 CCriteriumTree (com.google.security.zynamics.binnavi.Gui.CriteriaDialog.ExpressionModel.CCriteriumTree)3 CCriteriumTreeNode (com.google.security.zynamics.binnavi.Gui.CriteriaDialog.ExpressionModel.CCriteriumTreeNode)3 Test (org.junit.Test)3 CAndCriterium (com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.And.CAndCriterium)1 ICriterium (com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.ICriterium)1 CNotCriterium (com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.Not.CNotCriterium)1