use of org.eclipse.tracecompass.internal.provisional.tmf.core.model.filter.parser.FilterCu in project tracecompass by tracecompass.
the class TmfFilterHelperTest method getRegex.
private static Predicate<Multimap<String, Object>> getRegex(ITmfFilter filter, String expected) {
String regex = TmfFilterHelper.getRegexFromFilter(filter);
assertEquals(expected, regex);
FilterCu compile = FilterCu.compile(regex);
assertNotNull(compile);
Predicate<Multimap<String, Object>> predicate = compile.generate();
return predicate;
}
use of org.eclipse.tracecompass.internal.provisional.tmf.core.model.filter.parser.FilterCu in project tracecompass by tracecompass.
the class ElementResolverFilterTest method testMatchesOperator.
@Test
public void testMatchesOperator() {
FilterCu cu = FilterCu.compile("key0 matches v.*ue");
assertNotNull(cu);
Predicate<Multimap<String, Object>> predicate = cu.generate();
assertTrue(predicate.test(ELEMENT.getMetadata()));
// Test with a second value of key0
cu = FilterCu.compile("key0 matches o.*er");
assertNotNull(cu);
predicate = cu.generate();
assertTrue(predicate.test(ELEMENT.getMetadata()));
cu = FilterCu.compile("key0 matches v.*ue$");
assertNotNull(cu);
predicate = cu.generate();
assertFalse(predicate.test(ELEMENT.getMetadata()));
cu = FilterCu.compile(" \"key 2\" matches value2");
assertNotNull(cu);
predicate = cu.generate();
assertTrue(predicate.test(ELEMENT.getMetadata()));
cu = FilterCu.compile(" \"key3\" matches 10");
assertNotNull(cu);
predicate = cu.generate();
assertTrue(predicate.test(ELEMENT.getMetadata()));
// Match a number against an hex string
cu = FilterCu.compile(" \"key3\" matches 0xa");
assertNotNull(cu);
predicate = cu.generate();
assertTrue(predicate.test(ELEMENT.getMetadata()));
}
use of org.eclipse.tracecompass.internal.provisional.tmf.core.model.filter.parser.FilterCu in project tracecompass by tracecompass.
the class ElementResolverFilterTest method testFilterWithNumber.
@Test
public void testFilterWithNumber() {
// Simple number comparison
FilterCu cu = FilterCu.compile("key3 > 9");
assertNotNull(cu);
Predicate<Multimap<String, Object>> predicate = cu.generate();
assertTrue(predicate.test(ELEMENT.getMetadata()));
assertFalse(predicate.test(ImmutableMultimap.of("key3", 8)));
// String comparison, "10" < "9a"
cu = FilterCu.compile("key3 > 9a");
assertNotNull(cu);
predicate = cu.generate();
assertFalse(predicate.test(ELEMENT.getMetadata()));
// "9b" > "9a"
assertTrue(predicate.test(ImmutableMultimap.of("key3", "9b")));
// String comparison with duration numbers
cu = FilterCu.compile("key3 > 2ms");
assertNotNull(cu);
predicate = cu.generate();
assertFalse(predicate.test(ELEMENT.getMetadata()));
// Would be smaller as a String, but larger as a Number
assertTrue(predicate.test(ImmutableMultimap.of("key3", 10000000)));
// String comparison with decimal with unit numbers
cu = FilterCu.compile("key3 > 2k");
assertNotNull(cu);
predicate = cu.generate();
assertFalse(predicate.test(ELEMENT.getMetadata()));
// Would be smaller as a String, but larger as a Number
assertTrue(predicate.test(ImmutableMultimap.of("key3", 10000000)));
// String comparison with timestamps
// For now, only the TTT format works for timestamp comparison, so we
// first update the time preferences and put it back to its original
// value at the end
Map<String, String> defaultPrefMap = TmfTimePreferences.getPreferenceMap();
IEclipsePreferences defaultPreferences = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID);
String dateFormat = defaultPrefMap.get(ITmfTimePreferencesConstants.DATIME);
try {
defaultPreferences.put(ITmfTimePreferencesConstants.DATIME, "TTT.SSS SSS SSS");
TmfTimestampFormat.updateDefaultFormats();
long timeValue = 1000000000L;
String dateString = TmfTimestampFormat.getDefaulTimeFormat().format(timeValue);
cu = FilterCu.compile("key3 == \"" + dateString + "\"");
assertNotNull(cu);
predicate = cu.generate();
assertFalse(predicate.test(ELEMENT.getMetadata()));
assertFalse(predicate.test(ImmutableMultimap.of("key3", timeValue + 3)));
assertTrue(predicate.test(ImmutableMultimap.of("key3", timeValue)));
// Use another less trivial time value
timeValue = 1539786952382956759L;
dateString = TmfTimestampFormat.getDefaulTimeFormat().format(timeValue);
cu = FilterCu.compile("key3 == \"" + dateString + "\"");
assertNotNull(cu);
predicate = cu.generate();
assertFalse(predicate.test(ELEMENT.getMetadata()));
assertFalse(predicate.test(ImmutableMultimap.of("key3", timeValue + 3)));
assertTrue(predicate.test(ImmutableMultimap.of("key3", timeValue)));
} finally {
defaultPreferences.put(ITmfTimePreferencesConstants.DATIME, dateFormat);
TmfTimestampFormat.updateDefaultFormats();
}
}
use of org.eclipse.tracecompass.internal.provisional.tmf.core.model.filter.parser.FilterCu in project tracecompass by tracecompass.
the class ElementResolverFilterTest method testLessThanOperator.
@Test
public void testLessThanOperator() {
FilterCu cu = FilterCu.compile("key3 < 11");
assertNotNull(cu);
Predicate<Multimap<String, Object>> predicate = cu.generate();
assertTrue(predicate.test(ELEMENT.getMetadata()));
cu = FilterCu.compile("key3 < 10");
assertNotNull(cu);
predicate = cu.generate();
assertFalse(predicate.test(ELEMENT.getMetadata()));
}
use of org.eclipse.tracecompass.internal.provisional.tmf.core.model.filter.parser.FilterCu in project tracecompass by tracecompass.
the class ElementResolverFilterTest method testGreaterThanOperator.
@Test
public void testGreaterThanOperator() {
FilterCu cu = FilterCu.compile("key3 > 9");
assertNotNull(cu);
Predicate<Multimap<String, Object>> predicate = cu.generate();
assertTrue(predicate.test(ELEMENT.getMetadata()));
cu = FilterCu.compile("key3 > 10");
assertNotNull(cu);
predicate = cu.generate();
assertFalse(predicate.test(ELEMENT.getMetadata()));
}
Aggregations