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;
}
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);
}
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());
}
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());
}
Aggregations