Search in sources :

Example 6 with ITmfFilterTreeNode

use of org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode in project tracecompass by tracecompass.

the class TmfFilterHelperTest method testInputRegexNoAspect.

/**
 * Test a regex whose parameter is not an aspect name
 */
@Test
public void testInputRegexNoAspect() {
    ITmfEventAspect<@NonNull Object> contentAspect = TmfBaseAspects.getContentsAspect().forField(FIELD1_NAME);
    String regex = FIELD1_NAME + " == \"" + FIELD1_VALUE1 + "\"";
    ITmfFilter filter = getFilter(regex);
    assertTrue(filter instanceof TmfFilterRootNode);
    TmfFilterRootNode node = (TmfFilterRootNode) filter;
    assertEquals(1, node.getChildrenCount());
    ITmfFilterTreeNode child = node.getChild(0);
    assertTrue(child instanceof TmfFilterEqualsNode);
    TmfFilterEqualsNode equalsNode = (TmfFilterEqualsNode) child;
    assertEquals(contentAspect, equalsNode.getEventAspect());
    assertEquals(FIELD1_VALUE1, equalsNode.getValue());
    // Test expected behavior on events
    assertTrue(filter.matches(fEvent1));
    assertFalse(filter.matches(fEvent2));
    assertFalse(filter.matches(fEvent3));
}
Also used : ITmfFilterTreeNode(org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode) ITmfFilter(org.eclipse.tracecompass.tmf.core.filter.ITmfFilter) TmfFilterEqualsNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterEqualsNode) TmfFilterRootNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterRootNode) Test(org.junit.Test)

Example 7 with ITmfFilterTreeNode

use of org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode in project tracecompass by tracecompass.

the class TmfFilterHelperTest method testInputRegexPresent.

/**
 * Test a regex with present
 */
@Test
public void testInputRegexPresent() {
    ITmfEventAspect<@NonNull Object> aspect = TmfBaseAspects.getContentsAspect().forField(FIELD1_NAME);
    String regex = FIELD1_NAME + " present";
    ITmfFilter filter = getFilter(regex);
    // verify the main root node
    assertTrue(filter instanceof TmfFilterRootNode);
    TmfFilterRootNode node = (TmfFilterRootNode) filter;
    assertEquals(1, node.getChildrenCount());
    ITmfFilterTreeNode child = node.getChild(0);
    assertTrue(child instanceof TmfFilterMatchesNode);
    // verify the equals node
    TmfFilterMatchesNode equalsNode = (TmfFilterMatchesNode) child;
    assertEquals(aspect, equalsNode.getEventAspect());
    assertEquals(".*", equalsNode.getRegex());
    // Test expected behavior on events
    assertTrue(filter.matches(fEvent1));
    assertFalse(filter.matches(fEvent2));
    assertTrue(filter.matches(fEvent3));
}
Also used : ITmfFilterTreeNode(org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode) ITmfFilter(org.eclipse.tracecompass.tmf.core.filter.ITmfFilter) TmfFilterMatchesNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterMatchesNode) TmfFilterRootNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterRootNode) Test(org.junit.Test)

Example 8 with ITmfFilterTreeNode

use of org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode in project tracecompass by tracecompass.

the class TmfFilterTreeNodeTestBase method testRemove.

@Test
public void testRemove() {
    ITmfFilterTreeNode child = fFilterNode.clone();
    assertEquals("addChild()", 0, fFilterNode.addChild(child));
    assertEquals("remove()", child, child.remove());
    assertEquals("hasChildren()", false, fFilterNode.hasChildren());
}
Also used : ITmfFilterTreeNode(org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode) Test(org.junit.Test)

Example 9 with ITmfFilterTreeNode

use of org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode in project tracecompass by tracecompass.

the class TmfFilterTreeNodeTestBase method testRemoveChild.

@Test
public void testRemoveChild() {
    ITmfFilterTreeNode child = fFilterNode.clone();
    assertEquals("addChild()", 0, fFilterNode.addChild(child));
    assertEquals("removeChild()", child, fFilterNode.removeChild(child));
    assertEquals("hasChildren()", false, fFilterNode.hasChildren());
}
Also used : ITmfFilterTreeNode(org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode) Test(org.junit.Test)

Example 10 with ITmfFilterTreeNode

use of org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode in project tracecompass by tracecompass.

the class FilterManager method setSavedFilters.

/**
 * Set the passed filters as the currently saved ones.
 *
 * @param filters
 *            The filters to save
 */
public static void setSavedFilters(ITmfFilterTreeNode[] filters) {
    fRoot = new TmfFilterRootNode();
    for (ITmfFilterTreeNode filter : filters) {
        fRoot.addChild(filter.clone());
    }
    try {
        TmfFilterXMLWriter writerXML = new TmfFilterXMLWriter(fRoot);
        writerXML.saveTree(SAVED_FILTERS_PATH_NAME);
    } catch (ParserConfigurationException e) {
        // $NON-NLS-1$
        Activator.logError("Error saving filter xml file: " + SAVED_FILTERS_PATH_NAME, e);
    }
}
Also used : ITmfFilterTreeNode(org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode) TmfFilterXMLWriter(org.eclipse.tracecompass.tmf.core.filter.xml.TmfFilterXMLWriter) TmfFilterRootNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterRootNode) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Aggregations

ITmfFilterTreeNode (org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode)46 TmfFilterRootNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterRootNode)18 Test (org.junit.Test)15 ITmfFilter (org.eclipse.tracecompass.tmf.core.filter.ITmfFilter)11 TmfFilterMatchesNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterMatchesNode)10 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)7 ISelection (org.eclipse.jface.viewers.ISelection)5 TmfFilterAndNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterAndNode)5 TmfFilterNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterNode)5 TmfFilterOrNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterOrNode)5 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)4 TmfFilterContainsNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterContainsNode)4 TmfFilterEqualsNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterEqualsNode)4 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)4 Action (org.eclipse.jface.action.Action)3 Point (org.eclipse.swt.graphics.Point)3 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)3 HashMap (java.util.HashMap)2 PatternSyntaxException (java.util.regex.PatternSyntaxException)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2