Search in sources :

Example 1 with ITmfFilterTreeNode

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

the class TmfFilterHelperTest method testInputRegexMatches.

/**
 * Test a regex with matches
 */
@Test
public void testInputRegexMatches() {
    ITmfEventAspect<@NonNull Object> contentAspect = TmfBaseAspects.getContentsAspect().forField(FIELD1_NAME);
    String regex = FIELD1_NAME + " matches .*other.*";
    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(contentAspect, equalsNode.getEventAspect());
    assertEquals(".*other.*", equalsNode.getRegex());
    // Test expected behavior on events
    assertFalse(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 2 with ITmfFilterTreeNode

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

the class TmfFilterHelperTest method testInputRegexMatchesNot.

/**
 * Test a regex with a not matches
 */
@Test
public void testInputRegexMatchesNot() {
    ITmfEventAspect<@NonNull Object> contentAspect = TmfBaseAspects.getContentsAspect().forField(FIELD1_NAME);
    String regex = "!(" + FIELD1_NAME + " matches .*other.*)";
    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(contentAspect, equalsNode.getEventAspect());
    assertEquals(".*other.*", equalsNode.getRegex());
    // Test expected behavior on events
    assertTrue(filter.matches(fEvent1));
    assertTrue(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) TmfFilterMatchesNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterMatchesNode) TmfFilterRootNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterRootNode) Test(org.junit.Test)

Example 3 with ITmfFilterTreeNode

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

the class TmfFilterHelperTest method testInputRegexCompare.

/**
 * Test a regex whose parameter is not an aspect name
 */
@Test
public void testInputRegexCompare() {
    ITmfEventAspect<@NonNull Object> contentAspect = TmfBaseAspects.getContentsAspect().forField(FIELD2_NAME);
    /* Test the greater than operator */
    String regex = FIELD2_NAME + " > " + FIELD2_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 TmfFilterCompareNode);
    TmfFilterCompareNode equalsNode = (TmfFilterCompareNode) child;
    assertEquals(contentAspect, equalsNode.getEventAspect());
    assertEquals(FIELD2_VALUE1, equalsNode.getValue());
    assertEquals(1, equalsNode.getResult());
    // Test expected behavior on events
    assertFalse(filter.matches(fEvent1));
    assertFalse(filter.matches(fEvent2));
    assertTrue(filter.matches(fEvent3));
    /* Test the less than operator */
    regex = FIELD2_NAME + " < " + FIELD2_VALUE2;
    filter = getFilter(regex);
    assertTrue(filter instanceof TmfFilterRootNode);
    node = (TmfFilterRootNode) filter;
    assertEquals(1, node.getChildrenCount());
    child = node.getChild(0);
    assertTrue(child instanceof TmfFilterCompareNode);
    equalsNode = (TmfFilterCompareNode) child;
    assertEquals(contentAspect, equalsNode.getEventAspect());
    assertEquals(FIELD2_VALUE2, equalsNode.getValue());
    assertEquals(-1, equalsNode.getResult());
    // Test expected behavior on events
    assertFalse(filter.matches(fEvent1));
    assertTrue(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) TmfFilterRootNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterRootNode) TmfFilterCompareNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterCompareNode) Test(org.junit.Test)

Example 4 with ITmfFilterTreeNode

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

the class TmfFilterHelperTest method testInputRegexNoField.

/**
 * Test a regex with no parameter
 */
@Test
public void testInputRegexNoField() {
    String regex = "afield";
    ITmfFilter filter = getFilter(regex);
    assertTrue(filter instanceof TmfFilterRootNode);
    TmfFilterRootNode node = (TmfFilterRootNode) filter;
    assertEquals(1, node.getChildrenCount());
    ITmfFilterTreeNode child = node.getChild(0);
    assertTrue(child instanceof TmfFilterOrNode);
    // Verify the orNode
    TmfFilterOrNode orNode = (TmfFilterOrNode) child;
    ITmfTrace trace = STUB_TRACE;
    assertNotNull(trace);
    Iterable<@NonNull ITmfEventAspect<?>> eventAspects = trace.getEventAspects();
    // Verify that each child is a matches node and there's one per aspect
    assertEquals(Iterables.size(eventAspects), orNode.getChildrenCount());
    for (int i = 0; i < orNode.getChildrenCount(); i++) {
        assertTrue(orNode.getChild(i) instanceof TmfFilterMatchesNode);
    }
    for (ITmfEventAspect<?> aspect : eventAspects) {
        // Find a contains condition for each aspect
        ITmfFilterTreeNode[] children = orNode.getChildren();
        TmfFilterMatchesNode found = null;
        for (int i = 0; i < children.length; i++) {
            TmfFilterMatchesNode childFilter = (TmfFilterMatchesNode) children[i];
            if (aspect.equals(childFilter.getEventAspect())) {
                found = childFilter;
                break;
            }
        }
        assertNotNull("found aspect " + aspect.getName(), found);
        assertEquals(regex, found.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) ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) ITmfEventAspect(org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect) TmfFilterOrNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterOrNode) 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 5 with ITmfFilterTreeNode

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

the class TmfFilterHelperTest method testInputRegexContains.

/**
 * Test a regex with contains
 */
@Test
public void testInputRegexContains() {
    ITmfEventAspect<@NonNull String> eventTypeAspect = TmfBaseAspects.getEventTypeAspect();
    String regex = "\"" + eventTypeAspect.getName() + "\" contains 1";
    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 TmfFilterContainsNode);
    // verify the equals node
    TmfFilterContainsNode equalsNode = (TmfFilterContainsNode) child;
    assertEquals(eventTypeAspect, equalsNode.getEventAspect());
    assertEquals("1", 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) TmfFilterContainsNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterContainsNode) TmfFilterRootNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterRootNode) Test(org.junit.Test)

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