package org.eclipse.linuxtools.tmf.core.tests.ctfadaptor;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
IStatus result = fixture.validate(project, path);
assertTrue(result.isOK());
}
+
+ /**
+ * Run the boolean hasEvent(final String) method test
+ */
+ @Test
+ public void testEventLookup() {
+ assertTrue(fixture.hasEvent("sched_switch"));
+ assertFalse(fixture.hasEvent("Sched_switch"));
+ String[] events = { "sched_switch", "sched_wakeup", "timer_init" };
+ assertTrue(fixture.hasAllEvents(events));
+ assertTrue(fixture.hasAtLeastOneOfEvents(events));
+ String[] names = { "inexistent", "sched_switch", "SomeThing" };
+ assertTrue(fixture.hasAtLeastOneOfEvents(names));
+ assertFalse(fixture.hasAllEvents(names));
+ }
}
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
+import org.eclipse.linuxtools.ctf.core.event.IEventDeclaration;
import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
import org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader;
import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
-import org.eclipse.linuxtools.tmf.core.trace.ITmfTraceProperties;
import org.eclipse.linuxtools.tmf.core.trace.ITmfEventParser;
import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfTraceProperties;
import org.eclipse.linuxtools.tmf.core.trace.TmfTrace;
/**
return 0;
}
+ /**
+ * Returns whether or not an event is in the metadata of the trace,
+ * therefore if it can possibly be in the trace. It does not verify whether
+ * or not the event is actually in the trace
+ *
+ * @param eventName
+ * The name of the event to check
+ * @return Whether the event is in the metadata or not
+ * @since 2.1
+ */
+ public boolean hasEvent(final String eventName) {
+ Map<Long, IEventDeclaration> events = fTrace.getEvents(0L);
+ if (events != null) {
+ for (IEventDeclaration decl : events.values()) {
+ if (decl.getName().equals(eventName)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Return whether all requested events are in the metadata
+ *
+ * @param names
+ * The array of events to check for
+ * @return Whether all events are in the metadata
+ * @since 2.1
+ */
+ public boolean hasAllEvents(String[] names) {
+ for (String name : names) {
+ if (!hasEvent(name)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Returns whether the metadata contains at least one of the requested
+ * events
+ *
+ * @param names
+ * The array of event names of check for
+ * @return Whether one of the event is present in trace metadata
+ * @since 2.1
+ */
+ public boolean hasAtLeastOneOfEvents(String[] names) {
+ for (String name : names) {
+ if (hasEvent(name)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
// -------------------------------------------
// Parser
// -------------------------------------------