Search in sources :

Example 1 with TmfFilterMatchesNode

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

the class TmfFilterHelperTest method testInputFilterMatches.

/**
 * Test conversion of matches filters to regex
 */
@Test
public void testInputFilterMatches() {
    ITmfEventAspect<@NonNull Object> aspect = TmfBaseAspects.getContentsAspect().forField(FIELD1_NAME);
    /* Test a simple match */
    String expected = "\"" + FIELD1_NAME + "\" " + IFilterStrings.MATCHES + " \".*other.*\"";
    TmfFilterMatchesNode matchesFilter = new TmfFilterMatchesNode(null);
    matchesFilter.setEventAspect(aspect);
    matchesFilter.setRegex(".*other.*");
    Predicate<Multimap<String, Object>> predicate = getRegex(matchesFilter, expected);
    assertFalse(predicate.test(fObjectMap1));
    assertFalse(predicate.test(fObjectMap2));
    assertTrue(predicate.test(fObjectMap3));
    /* Test the negation */
    matchesFilter.setNot(true);
    predicate = getRegex(matchesFilter, notRegex(expected));
    assertTrue(predicate.test(fObjectMap1));
    assertTrue(predicate.test(fObjectMap2));
    assertFalse(predicate.test(fObjectMap3));
    /* Test a wildcard regex, should match with the presence of the field */
    expected = "\"" + FIELD1_NAME + "\" " + IFilterStrings.PRESENT;
    matchesFilter.setRegex(".*");
    matchesFilter.setNot(false);
    predicate = getRegex(matchesFilter, expected);
    assertTrue(predicate.test(fObjectMap1));
    assertFalse(predicate.test(fObjectMap2));
    assertTrue(predicate.test(fObjectMap3));
    /* Test the negation of present */
    matchesFilter.setNot(true);
    predicate = getRegex(matchesFilter, notRegex(expected));
    assertFalse(predicate.test(fObjectMap1));
    assertTrue(predicate.test(fObjectMap2));
    assertFalse(predicate.test(fObjectMap3));
}
Also used : Multimap(com.google.common.collect.Multimap) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) TmfFilterMatchesNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterMatchesNode) Test(org.junit.Test)

Example 2 with TmfFilterMatchesNode

use of org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterMatchesNode 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 3 with TmfFilterMatchesNode

use of org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterMatchesNode 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 4 with TmfFilterMatchesNode

use of org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterMatchesNode 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 TmfFilterMatchesNode

use of org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterMatchesNode 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)

Aggregations

TmfFilterMatchesNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterMatchesNode)19 ITmfFilterTreeNode (org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode)10 TmfFilterRootNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterRootNode)10 Test (org.junit.Test)9 ITmfFilter (org.eclipse.tracecompass.tmf.core.filter.ITmfFilter)6 TmfFilterAndNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterAndNode)6 TmfFilterOrNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterOrNode)6 TmfFilterCompareNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterCompareNode)5 TmfFilterContainsNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterContainsNode)5 TmfFilterEqualsNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterEqualsNode)5 TmfFilterNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterNode)5 TmfFilterTraceTypeNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterTraceTypeNode)4 ImmutableMultimap (com.google.common.collect.ImmutableMultimap)3 Multimap (com.google.common.collect.Multimap)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 Nullable (org.eclipse.jdt.annotation.Nullable)2 ITmfEventAspect (org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect)2 ITmfFilterWithNot (org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterWithNot)2 ITmfFilterWithValue (org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterWithValue)2 TmfFilterAspectNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterAspectNode)2