import java.net.URL;
import junit.framework.TestCase;
+
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Path;
import org.eclipse.linuxtools.lttng.event.LttngTimestamp;
}
public TmfTimestamp getSpan() {
- TmfTimestamp span = new TmfTimestamp(startTime.getAdjustment(endTime), NS_SCALING_FACTOR, 0);
+ TmfTimestamp span = new TmfTimestamp(startTime.getAdjustment(endTime, NS_SCALING_FACTOR), NS_SCALING_FACTOR, 0);
return span;
}
// Compute the new time range
TmfTimeRange subrange = new TmfTimeRange(startTime, endTime);
- TmfTimestamp interval = new TmfTimestamp(startTime.getAdjustment(endTime), startTime.getScale(), 0);
+ byte scale = startTime.getScale();
+ TmfTimestamp interval = new TmfTimestamp(startTime.getAdjustment(endTime, scale), scale, 0);
// Update the spinner groups
fStartGroup.setContent(fTraceTimeRange, startTime);
private void updateSlider(TmfTimeRange range, TmfTimestamp timestamp) {
// Determine the new relative position
- long total = range.getStartTime().getAdjustment(range.getEndTime());
- long relative = range.getStartTime().getAdjustment(timestamp);
+ byte scale = range.getEndTime().getScale();
+ long total = range.getStartTime().getAdjustment(range.getEndTime(), scale);
+ long relative = range.getStartTime().getAdjustment(timestamp, scale);
// Set the slider value
final long position = (total > 0) ? (relative * SLIDER_RANGE / total) : 0;
fCurrentTime = fTraceStartTime;
- TmfTimestamp delta = new TmfTimestamp(fTraceStartTime.getAdjustment(fTraceEndTime), fScale, 0);
+ TmfTimestamp delta = new TmfTimestamp(fTraceStartTime.getAdjustment(fTraceEndTime, fScale), fScale, 0);
fTraceSpan = new TmfTimeRange(new TmfTimestamp(0, fScale, 0), delta);
// fRangeGroup.setContent(fTraceSpan, delta);
TmfTimestamp start = new TmfTimestamp(1, (byte) -1, 0);
fEndGroup.setContent(fTraceTimeRange, fTraceEndTime);
fCurrentGroup.setContent(fTraceTimeRange, fCurrentGroup.getCurrentTime());
- TmfTimestamp delta = new TmfTimestamp(fTraceStartTime.getAdjustment(fTraceEndTime), fScale, 0);
+ TmfTimestamp delta = new TmfTimestamp(fTraceStartTime.getAdjustment(fTraceEndTime, fScale), fScale, 0);
fTraceSpan = new TmfTimeRange(new TmfTimestamp(0, fScale, 0), delta);
fRangeGroup.setContent(fTraceSpan, delta);
}
import org.eclipse.linuxtools.lttng.jni.JniEvent;
import org.eclipse.linuxtools.tmf.event.TmfEventContent;
+import org.eclipse.linuxtools.tmf.event.TmfNoSuchFieldException;
/**
* <b><u>LttngEventContent</u></b><p>
LttngEventType tmpType = (LttngEventType)fParentEvent.getType();
for ( int pos=0; pos<tmpType.getNbFields(); pos++ ) {
- String name = tmpType.getLabel(pos);
+ String name = null;
+ try {
+ name = tmpType.getLabel(pos);
+ } catch (TmfNoSuchFieldException e) {
+ }
JniEvent tmpEvent = ((LttngEvent)getEvent()).convertEventTmfToJni();
if ( tmpEvent != null ) {
@Override
public LttngEventField getField(int position) {
LttngEventField returnedField = null;
- String label = fParentEvent.getType().getLabel(position);
+ String label = null;
+ try {
+ label = fParentEvent.getType().getLabel(position);
+ } catch (TmfNoSuchFieldException e) {
+ }
if ( label != null ) {
returnedField = this.getField(label);
import org.eclipse.linuxtools.lttng.event.LttngEventType;
import org.eclipse.linuxtools.lttng.event.LttngTimestamp;
import org.eclipse.linuxtools.lttng.jni.JniEvent;
+import org.eclipse.linuxtools.tmf.event.TmfNoSuchFieldException;
import org.eclipse.linuxtools.tmf.event.TmfTimeRange;
import org.eclipse.linuxtools.tmf.request.TmfDataRequest;
import org.eclipse.linuxtools.tmf.trace.ITmfContext;
@Override
public LttngEventField getField(int position) {
LttngEventField returnedField = null;
- String label = fParentEvent.getType().getLabel(position);
+ String label = null;
+ try {
+ label = fParentEvent.getType().getLabel(position);
+ } catch (TmfNoSuchFieldException e) {
+ }
if ( label != null ) {
returnedField = this.getField(label);
public static Test suite() {
TestSuite suite = new TestSuite(AllTmfCoreTests.class.getName());
//$JUnit-BEGIN$
+ suite.addTestSuite(TmfCorePluginTest.class);
+
suite.addTestSuite(TmfEventProviderTest.class);
suite.addTestSuite(TmfProviderManagerTest.class);
/*******************************************************************************
- * Copyright (c) 2009 Ericsson
+ * Copyright (c) 2009, 2010 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
package org.eclipse.linuxtools.tmf.tests;
import org.eclipse.core.runtime.Plugin;
+import org.osgi.framework.BundleContext;
/**
* <b><u>TmfTestPlugin</u></b>
*/
public class TmfCoreTestPlugin extends Plugin {
- // ========================================================================
+ // ------------------------------------------------------------------------
// Attributes
- // ========================================================================
+ // ------------------------------------------------------------------------
// The plug-in ID
public static final String PLUGIN_ID = "org.eclipse.linuxtools.tmf.tests";
// The shared instance
- private static TmfCoreTestPlugin plugin;
+ private static TmfCoreTestPlugin fPlugin;
- // ========================================================================
+ // ------------------------------------------------------------------------
// Constructors
- // ========================================================================
+ // ------------------------------------------------------------------------
/**
* The constructor
*/
public TmfCoreTestPlugin() {
- plugin = this;
+ setDefault(this);
}
- // ========================================================================
+ // ------------------------------------------------------------------------
// Accessors
- // ========================================================================
+ // ------------------------------------------------------------------------
/**
* @return the shared instance
*/
- public static TmfCoreTestPlugin getPlugin() {
- return plugin;
+ public static TmfCoreTestPlugin getDefault() {
+ return fPlugin;
}
+ /**
+ * @param plugin the shared instance
+ */
+ private static void setDefault(TmfCoreTestPlugin plugin) {
+ fPlugin = plugin;
+ }
+
+ // ------------------------------------------------------------------------
+ // Operations
+ // ------------------------------------------------------------------------
+
+ @Override
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ setDefault(this);
+ }
+
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ setDefault(null);
+ super.stop(context);
+ }
+
}
/**
* <b><u>TmfEventContentTest</u></b>
* <p>
- * TODO: Implement me. Please.
+ * Test suite for the TmfEventContent class.
*/
public class TmfEventContentTest extends TestCase {
+ // ------------------------------------------------------------------------
+ // Variables
+ // ------------------------------------------------------------------------
+
private final TmfTimestamp fTimestamp;
private final TmfEventSource fEventSource;
private final TmfEventType fEventType;
private final TmfEvent fEvent;
private final TmfEvent fEventStub;
- private final Object fRawContent = new String("Some content");
+ private final Object fRawContent0 = new String("Some content");
+ private final Object fRawContent1 = new String("Some other content");
- private final TmfEventContent fBasicContent;
+ private final TmfEventContent fBasicContent0;
+ private final TmfEventContent fBasicContent1;
+ private final TmfEventContent fBasicContent2;
private final TmfEventContentStub fStubContent;
+ // ------------------------------------------------------------------------
+ // Housekeeping
+ // ------------------------------------------------------------------------
+
/**
- * @param name
+ * @param name the test name
*/
public TmfEventContentTest(String name) {
super(name);
fEventTypeStub = new TmfEventTypeStub();
fReference = new TmfEventReference();
- fEvent = new TmfEvent(fTimestamp, fEventSource, fEventType, fReference);
- fBasicContent = new TmfEventContent(fEvent, fRawContent);
+ fEvent = new TmfEvent(fTimestamp, fEventSource, fEventType, fReference);
+ fBasicContent0 = new TmfEventContent(fEvent, fRawContent0);
+ fBasicContent1 = new TmfEventContent(fEvent, fRawContent0);
+ fBasicContent2 = new TmfEventContent(fEvent, fRawContent0);
fEventStub = new TmfEvent(fTimestamp, fEventSource, fEventTypeStub, fReference);
- fStubContent = new TmfEventContentStub(fEventStub, fRawContent);
+ fStubContent = new TmfEventContentStub(fEventStub, fRawContent1);
}
@Override
super.tearDown();
}
- // ========================================================================
+ // ------------------------------------------------------------------------
// Constructors
- // ========================================================================
+ // ------------------------------------------------------------------------
public void testTmfEventContent() {
- assertSame("getLabels", fEvent, fBasicContent.getEvent());
- assertSame("getType", fEventType, fBasicContent.getType());
- assertSame("getContent", fRawContent, fBasicContent.getContent());
+ assertSame("getLabels", fEvent, fBasicContent0.getEvent());
+ assertEquals("getType", fEventType, fBasicContent0.getType());
+ assertEquals("getContent", fRawContent0, fBasicContent0.getContent());
}
public void testTmfEventContentCopy() {
- TmfEventContent content = new TmfEventContent(fBasicContent);
- assertSame("getLabels", fEvent, content.getEvent());
- assertSame("getType", fEventType, content.getType());
- assertSame("getContent", fRawContent, content.getContent());
+ TmfEventContent content = new TmfEventContent(fBasicContent0);
+ assertSame("getLabels", fEvent, content.getEvent());
+ assertEquals("getType", fEventType, content.getType());
+ assertEquals("getContent", fRawContent0, content.getContent());
+ }
+
+ public void testTmfEventContentCopy2() {
+ try {
+ new TmfEventContent(null);
+ fail("null copy");
+ }
+ catch (IllegalArgumentException e) {
+ // Success
+ }
+ }
+
+ // ------------------------------------------------------------------------
+ // equals
+ // ------------------------------------------------------------------------
+
+ public void testEqualsReflexivity() throws Exception {
+ @SuppressWarnings("unused")
+ Object[] fields1 = fBasicContent0.getFields();
+ @SuppressWarnings("unused")
+ Object[] fields2 = fStubContent.getFields();
+
+ assertTrue("equals", fBasicContent0.equals(fBasicContent0));
+ assertTrue("equals", fStubContent.equals(fStubContent));
+
+ assertTrue("equals", !fBasicContent0.equals(fStubContent));
+ assertTrue("equals", !fStubContent.equals(fBasicContent0));
+ }
+
+ public void testEqualsSymmetry() throws Exception {
+ assertTrue("equals", fBasicContent0.equals(fBasicContent2));
+ assertTrue("equals", fBasicContent2.equals(fBasicContent0));
+
+ assertTrue("equals", !fBasicContent0.equals(fStubContent));
+ assertTrue("equals", !fStubContent.equals(fBasicContent0));
+ }
+
+ public void testEqualsTransivity() throws Exception {
+ assertTrue("equals", fBasicContent0.equals(fBasicContent1));
+ assertTrue("equals", fBasicContent1.equals(fBasicContent2));
+ assertTrue("equals", fBasicContent0.equals(fBasicContent2));
}
+
+ public void testEqualsConsistency() throws Exception {
+ assertTrue("equals", fBasicContent0.equals(fBasicContent0));
+ assertTrue("equals", fBasicContent0.equals(fBasicContent0));
- public void testCloneShallowCopy() {
- TmfEventContent content = fBasicContent.clone();
- assertSame("getLabels", fEvent, content.getEvent());
- assertSame("getType", fEventType, content.getType());
- assertSame("getContent", fRawContent, content.getContent());
+ assertTrue("equals", fStubContent.equals(fStubContent));
+ assertTrue("equals", fStubContent.equals(fStubContent));
}
+
+ public void testEqualsNull() throws Exception {
+ assertTrue("equals", !fBasicContent0.equals(null));
+ assertTrue("equals", !fStubContent.equals(null));
+ }
+
+ // ------------------------------------------------------------------------
+ // toString
+ // ------------------------------------------------------------------------
- public void testCloneDeepCopy() {
- TmfEventContent content = fStubContent.clone();
- assertSame ("getEvent", fEventStub, content.getEvent());
- assertSame ("getType", fEventTypeStub, content.getType());
- assertNotSame("getContent", fRawContent, content.getContent());
- assertEquals ("getContent", fRawContent, content.getContent());
+ public void testToString() {
+ String expected = "[TmfEventContent(" + fRawContent0 + ")]";
+ TmfEventContent content = new TmfEventContent(fEvent, fRawContent0);
+ assertEquals("toString", expected, content.toString());
}
- // ========================================================================
+ public void testToString2() {
+ String expected = "[TmfEventContent(1,-10,true,some string,[TmfTimestamp(1,2,3)])]";
+ TmfEventContentStub content = new TmfEventContentStub(fEvent, fRawContent0);
+ assertEquals("toString", expected, content.toString());
+ }
+
+ // ------------------------------------------------------------------------
// Basic content parsing
- // ========================================================================
+ // ------------------------------------------------------------------------
public void testGetFields() {
- Object[] fields = fBasicContent.getFields();
+ Object[] fields = fBasicContent0.getFields();
assertEquals("getFields", 1, fields.length);
- assertEquals("getFields", fRawContent, fields[0].toString());
+ assertEquals("getFields", fRawContent0, fields[0].toString());
}
public void testGetFieldFromId() {
Object field;
try {
- field = fBasicContent.getField("Content");
- assertEquals("getField", fRawContent, field.toString());
+ field = fBasicContent0.getField("Content");
+ assertEquals("getField", fRawContent0, field.toString());
} catch (TmfNoSuchFieldException e) {
fail("Field not found");
}
public void testGetFieldFromIdFailed() {
try {
- fBasicContent.getField("Dummy");
+ fBasicContent0.getField("Dummy");
fail("Found an inexisting field...");
} catch (TmfNoSuchFieldException e) {
// Success
}
public void testGetFieldFromPos() {
- Object field = fBasicContent.getField(0);
- assertEquals("getField", fRawContent, field.toString());
+ Object field = fBasicContent0.getField(0);
+ assertEquals("getField", fRawContent0, field.toString());
+ }
+
+ public void testGetFieldFromPosFailed() {
+ Object field = fBasicContent0.getField(10);
+ assertEquals("getField", null, field);
}
- // ========================================================================
+ // ------------------------------------------------------------------------
// Standard content parsing
- // ========================================================================
+ // ------------------------------------------------------------------------
public void testGetFields2() {
Object[] fields = fStubContent.getFields();
}
public void testGetFieldFromPos2() {
- TmfEventContentStub content = new TmfEventContentStub(fEvent, fRawContent);
+ TmfEventContentStub content = new TmfEventContentStub(fEvent, fRawContent0);
- Object field = content.getField(0);
+ Object field;
+ field = content.getField(0);
assertEquals("getField", new Integer(1), field);
field = content.getField(1);
assertEquals("getField", new TmfTimestamp(1, (byte) 2, 3), field);
}
- // ========================================================================
- // Operators
- // ========================================================================
-
- public void testToString() {
- String expected = "[TmfEventContent(" + fRawContent + ",)]";
- TmfEventContent content = new TmfEventContent(fEvent, fRawContent);
- assertEquals("toString", expected, content.toString());
- }
-
}
package org.eclipse.linuxtools.tmf.tests.event;
+import junit.framework.TestCase;
+
import org.eclipse.linuxtools.tmf.event.TmfEvent;
import org.eclipse.linuxtools.tmf.event.TmfEventContent;
import org.eclipse.linuxtools.tmf.event.TmfEventField;
import org.eclipse.linuxtools.tmf.event.TmfEventTypeStub;
import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
-import junit.framework.TestCase;
-
/**
* <b><u>TmfEventFieldTest</u></b>
* <p>
- * TODO: Implement me. Please.
+ * Test suite for the TmfEventField class.
*/
public class TmfEventFieldTest extends TestCase {
+ // ------------------------------------------------------------------------
+ // Variables
+ // ------------------------------------------------------------------------
+
private final TmfEventContent fContent;
private final String fFieldId = "Field";
private final Object fValue1 = new String("Value");
private final Object fValue2 = new Integer(10);
- // ========================================================================
+ private TmfEventField fField0;
+ private TmfEventField fField1;
+ private TmfEventField fField2;
+ private TmfEventField fField3;
+
+ // ------------------------------------------------------------------------
// Housekeeping
- // ========================================================================
+ // ------------------------------------------------------------------------
+ /**
+ * @param name the test name
+ */
public TmfEventFieldTest(String name) {
super(name);
TmfTimestamp fTimestamp = new TmfTimestamp();
TmfEvent fEvent = new TmfEvent(fTimestamp, fEventSource, fEventType, fReference);
fContent = new TmfEventContent(fEvent, "Some content");
+
+ fField0 = new TmfEventField(fContent, fFieldId, fValue1);
+ fField1 = new TmfEventField(fContent, fFieldId, fValue1);
+ fField2 = new TmfEventField(fContent, fFieldId, fValue1);
+ fField3 = new TmfEventField(fContent, fFieldId, fValue2);
}
@Override
super.tearDown();
}
- // ========================================================================
+ // ------------------------------------------------------------------------
// Constructors
- // ========================================================================
+ // ------------------------------------------------------------------------
public void testTmfEventField() {
- TmfEventField field = new TmfEventField(fContent, fFieldId, fValue1);
- assertSame("getParent", fContent, field.getParent());
- assertSame("getId", fFieldId, field.getId());
- assertSame("getValue", fValue1, field.getValue());
+ assertSame("getParent", fContent, fField0.getParent());
+ assertSame("getId", fFieldId, fField0.getId());
+ assertSame("getValue", fValue1, fField0.getValue());
+ }
+
+ public void testTmfEventFieldBadArg() {
+ try {
+ new TmfEventField(fContent, null, fValue1);
+ fail("null copy");
+ }
+ catch (IllegalArgumentException e) {
+ // Success
+ }
}
public void testTmfEventFieldCopy() {
assertSame("getValue", fValue1, field.getValue());
}
- public void testCloneShallowCopy() {
+ public void testTmfEventFieldCopy2() {
+ try {
+ new TmfEventField(null);
+ fail("null copy");
+ }
+ catch (IllegalArgumentException e) {
+ // Success
+ }
+ }
+
+ // ------------------------------------------------------------------------
+ // Modifiers
+ // ------------------------------------------------------------------------
+
+ private class MyField extends TmfEventField {
+ public MyField(TmfEventContent parent, String id, Object value) {
+ super(parent, id, value);
+ }
+ public MyField(TmfEventField field) {
+ super(field);
+ }
+ @Override
+ public void setValue(Object value) {
+ super.setValue(value);
+ }
+ }
+
+ public void testSetValue() {
TmfEventField original = new TmfEventField(fContent, fFieldId, fValue1);
- TmfEventField field = original.clone();
- assertSame("getParent", fContent, field.getParent());
- assertSame("getId", fFieldId, field.getId());
- assertSame("getValue", fValue1, field.getValue());
+ TmfEventField field = new TmfEventField(original);
+
+ MyField myField = new MyField(field);
+ assertSame("getValue", fValue1, myField.getValue());
+
+ myField.setValue(fValue2);
+ assertSame("getValue", fValue2, myField.getValue());
+ }
+
+ // ------------------------------------------------------------------------
+ // equals
+ // ------------------------------------------------------------------------
+
+ public void testEqualsReflexivity() throws Exception {
+ assertTrue("equals", fField0.equals(fField0));
+ assertTrue("equals", fField3.equals(fField3));
+
+ assertTrue("equals", !fField0.equals(fField3));
+ assertTrue("equals", !fField3.equals(fField0));
+ }
+
+ public void testEqualsSymmetry() throws Exception {
+ assertTrue("equals", fField0.equals(fField1));
+ assertTrue("equals", fField1.equals(fField0));
+
+ assertTrue("equals", !fField0.equals(fField3));
+ assertTrue("equals", !fField3.equals(fField0));
+ }
+
+ public void testEqualsTransivity() throws Exception {
+ assertTrue("equals", fField0.equals(fField1));
+ assertTrue("equals", fField1.equals(fField2));
+ assertTrue("equals", fField0.equals(fField2));
}
+
+ public void testEqualsConsistency() throws Exception {
+ assertTrue("equals", fField0.equals(fField0));
+ assertTrue("equals", fField0.equals(fField0));
-// public void testCloneDeepCopy() {
-// TmfEventField original = new TmfEventField(fContent, fFieldId, fValue1);
-// TmfEventField field = original.clone();
-// assertNotSame("getParent", fContent, field.getParent());
-// assertNotSame("getId", fFieldId, field.getId());
-// assertNotSame("getValue", fValue1, field.getValue());
-// assertEquals ("getParent", fContent, field.getParent());
-// assertEquals ("getId", fFieldId, field.getId());
-// assertEquals ("getValue", fValue1, field.getValue());
-// }
-
- // ========================================================================
- // Operators
- // ========================================================================
+ assertTrue("equals", fField3.equals(fField3));
+ assertTrue("equals", fField3.equals(fField3));
+ }
+
+ public void testEqualsNull() throws Exception {
+ assertTrue("equals", !fField0.equals(null));
+ assertTrue("equals", !fField3.equals(null));
+ }
+
+ // ------------------------------------------------------------------------
+ // toString
+ // ------------------------------------------------------------------------
public void testToString() {
String expected1 = "[TmfEventField(" + fFieldId + ":" + fValue1.toString() + ")]";
package org.eclipse.linuxtools.tmf.tests.event;
-import org.eclipse.linuxtools.tmf.event.TmfEventReference;
-
import junit.framework.TestCase;
+import org.eclipse.linuxtools.tmf.event.TmfEventReference;
+
/**
* <b><u>TmfEventReferenceTest</u></b>
* <p>
- * TODO: Implement me. Please.
+ * Test suite for the TmfEventReference class.
*/
public class TmfEventReferenceTest extends TestCase {
- private final Object fReference = new String("Some reference");
+ // ------------------------------------------------------------------------
+ // Variables
+ // ------------------------------------------------------------------------
- // ========================================================================
+ private final Object reference0 = new String("Some reference");
+ private final Object reference2 = new String("Some other reference");
+
+ private TmfEventReference fReference0 = new TmfEventReference(reference0);
+ private TmfEventReference fReference1 = new TmfEventReference(reference0);
+ private TmfEventReference fReference2 = new TmfEventReference(reference0);
+ private TmfEventReference fReference3 = new TmfEventReference(reference2);
+
+ // ------------------------------------------------------------------------
// Housekeeping
- // ========================================================================
+ // ------------------------------------------------------------------------
+ /**
+ * @param name the test name
+ */
public TmfEventReferenceTest(String name) {
super(name);
}
super.tearDown();
}
- // ========================================================================
+ // ------------------------------------------------------------------------
// Constructors
- // ========================================================================
+ // ------------------------------------------------------------------------
public void testTmfEventReferenceDefault() {
TmfEventReference reference = new TmfEventReference();
}
public void testTmfEventReference() {
- TmfEventReference reference = new TmfEventReference(fReference);
- assertSame("getReference", fReference, reference.getReference());
+ TmfEventReference reference = new TmfEventReference(reference0);
+ assertSame("getReference", reference0, reference.getReference());
}
public void testTmfEventReferenceCopy() {
- TmfEventReference original = new TmfEventReference(fReference);
+ TmfEventReference original = new TmfEventReference(reference0);
TmfEventReference reference = new TmfEventReference(original);
- assertSame("getReference", fReference, reference.getReference());
+ assertSame("getReference", reference0, reference.getReference());
+ }
+
+ public void testTmfEventReferenceCopy2() {
+ try {
+ @SuppressWarnings("unused")
+ TmfEventReference reference = new TmfEventReference(null);
+ fail("null copy");
+ }
+ catch (IllegalArgumentException e) {
+ // Success
+ }
}
- public void testCloneShallowCopy() {
- TmfEventReference original = new TmfEventReference(fReference);
- TmfEventReference reference = original.clone();
- assertSame("getReference", fReference, reference.getReference());
+ // ------------------------------------------------------------------------
+ // equals
+ // ------------------------------------------------------------------------
+
+ public void testEqualsReflexivity() throws Exception {
+ assertTrue("equals", fReference0.equals(fReference0));
+ assertTrue("equals", fReference3.equals(fReference3));
+
+ assertTrue("equals", !fReference0.equals(fReference3));
+ assertTrue("equals", !fReference3.equals(fReference0));
}
+
+ public void testEqualsSymmetry() throws Exception {
+ assertTrue("equals", fReference0.equals(fReference1));
+ assertTrue("equals", fReference1.equals(fReference0));
-// public void testCloneDeepCopy() {
-// TmfEventReference original = new TmfEventReference(fReference);
-// TmfEventReference reference = original.clone();
-// assertNotSame("getReference", fReference, reference.getReference());
-// assertEquals ("getReference", fReference, reference.getReference());
-// }
+ assertTrue("equals", !fReference0.equals(fReference3));
+ assertTrue("equals", !fReference3.equals(fReference0));
+ }
+
+ public void testEqualsTransivity() throws Exception {
+ assertTrue("equals", fReference0.equals(fReference1));
+ assertTrue("equals", fReference1.equals(fReference2));
+ assertTrue("equals", fReference0.equals(fReference2));
+ }
+
+ public void testEqualsConsistency() throws Exception {
+ assertTrue("equals", fReference0.equals(fReference0));
+ assertTrue("equals", fReference0.equals(fReference0));
- // ========================================================================
- // Operators
- // ========================================================================
+ assertTrue("equals", fReference3.equals(fReference3));
+ assertTrue("equals", fReference3.equals(fReference3));
+ }
+
+ public void testEqualsNull() throws Exception {
+ assertTrue("equals", !fReference0.equals(null));
+ assertTrue("equals", !fReference3.equals(null));
+ }
+
+ // ------------------------------------------------------------------------
+ // toString
+ // ------------------------------------------------------------------------
public void testToString() {
String expected1 = "[TmfEventReference(" + "null" + ")]";
TmfEventReference reference1 = new TmfEventReference();
assertEquals("toString", expected1, reference1.toString());
- String expected2 = "[TmfEventReference(" + fReference.toString() + ")]";
- TmfEventReference reference2 = new TmfEventReference(fReference);
+ String expected2 = "[TmfEventReference(" + reference0.toString() + ")]";
+ TmfEventReference reference2 = new TmfEventReference(reference0);
assertEquals("toString", expected2, reference2.toString());
}
package org.eclipse.linuxtools.tmf.tests.event;
-import org.eclipse.linuxtools.tmf.event.TmfEventSource;
-
import junit.framework.TestCase;
+import org.eclipse.linuxtools.tmf.event.TmfEventSource;
+
/**
* <b><u>TmfEventSourceTest</u></b>
* <p>
- * TODO: Implement me. Please.
+ * Test suite for the TmfEventSource class.
*/
public class TmfEventSourceTest extends TestCase {
- private final Object fSource = new String("Some source");
+ // ------------------------------------------------------------------------
+ // Variables
+ // ------------------------------------------------------------------------
- // ========================================================================
+ private final Object source1 = new String("Some source");
+ private final Object source2 = new String("Some other source");
+
+ private final TmfEventSource fSource0 = new TmfEventSource(source1);
+ private final TmfEventSource fSource1 = new TmfEventSource(source1);
+ private final TmfEventSource fSource2 = new TmfEventSource(source1);
+ private final TmfEventSource fSource3 = new TmfEventSource(source2);
+
+ // ------------------------------------------------------------------------
// Housekeeping
- // ========================================================================
+ // ------------------------------------------------------------------------
+ /**
+ * @param name the test name
+ */
public TmfEventSourceTest(String name) {
super(name);
}
super.tearDown();
}
- // ========================================================================
+ // ------------------------------------------------------------------------
// Constructors
- // ========================================================================
+ // ------------------------------------------------------------------------
public void testTmfEventSourceDefault() {
TmfEventSource source = new TmfEventSource();
}
public void testTmfEventSource() {
- TmfEventSource source = new TmfEventSource(fSource);
- assertSame("getSourceId", fSource, source.getSourceId());
+ TmfEventSource source = new TmfEventSource(source1);
+ assertSame("getSourceId", source1, source.getSourceId());
}
public void testTmfEventSourceCopy() {
- TmfEventSource original = new TmfEventSource(fSource);
+ TmfEventSource original = new TmfEventSource(source1);
TmfEventSource source = new TmfEventSource(original);
- assertSame("getSourceId", fSource, source.getSourceId());
+ assertSame("getSourceId", source1, source.getSourceId());
}
- public void testCloneShallowCopy() {
- TmfEventSource original = new TmfEventSource(fSource);
- TmfEventSource source = original.clone();
- assertSame("getSourceId", fSource, source.getSourceId());
+ public void testTmfEventSourceCopy2() {
+ try {
+ @SuppressWarnings("unused")
+ TmfEventSource source = new TmfEventSource(null);
+ fail("null copy");
+ }
+ catch (IllegalArgumentException e) {
+ // Success
+ }
}
-// public void testCloneDeepCopy() {
-// TmfEventSource original = new TmfEventSource(fSource);
-// TmfEventSource source = original.clone();
-// assertNotSame("getSourceId", fSource, source.getSourceId());
-// assertEquals ("getSourceId", fSource, source.getSourceId());
-// }
+ // ------------------------------------------------------------------------
+ // equals
+ // ------------------------------------------------------------------------
+
+ public void testEqualsReflexivity() throws Exception {
+ assertTrue("equals", fSource0.equals(fSource0));
+ assertTrue("equals", fSource3.equals(fSource3));
- // ========================================================================
- // Operators
- // ========================================================================
+ assertTrue("equals", !fSource0.equals(fSource3));
+ assertTrue("equals", !fSource3.equals(fSource0));
+ }
+
+ public void testEqualsSymmetry() throws Exception {
+ assertTrue("equals", fSource0.equals(fSource2));
+ assertTrue("equals", fSource2.equals(fSource0));
+
+ assertTrue("equals", !fSource0.equals(fSource3));
+ assertTrue("equals", !fSource3.equals(fSource0));
+ }
+
+ public void testEqualsTransivity() throws Exception {
+ assertTrue("equals", fSource0.equals(fSource1));
+ assertTrue("equals", fSource1.equals(fSource2));
+ assertTrue("equals", fSource0.equals(fSource2));
+ }
+
+ public void testEqualsConsistency() throws Exception {
+ assertTrue("equals", fSource0.equals(fSource0));
+ assertTrue("equals", fSource0.equals(fSource0));
+
+ assertTrue("equals", fSource3.equals(fSource3));
+ assertTrue("equals", fSource3.equals(fSource3));
+ }
+
+ public void testEqualsNull() throws Exception {
+ assertTrue("equals", !fSource0.equals(null));
+ assertTrue("equals", !fSource3.equals(null));
+ }
+
+ // ------------------------------------------------------------------------
+ // toString
+ // ------------------------------------------------------------------------
public void testToString() {
String expected1 = "[TmfEventSource(" + "null" + ")]";
- TmfEventSource source1 = new TmfEventSource();
- assertEquals("toString", expected1, source1.toString());
+ TmfEventSource nullSource = new TmfEventSource();
+ assertEquals("toString", expected1, nullSource.toString());
- String expected2 = "[TmfEventSource(" + fSource.toString() + ")]";
- TmfEventSource source2 = new TmfEventSource(fSource);
- assertEquals("toString", expected2, source2.toString());
+ String expected2 = "[TmfEventSource(" + source1.toString() + ")]";
+ TmfEventSource source = new TmfEventSource(source1);
+ assertEquals("toString", expected2, source.toString());
}
}
package org.eclipse.linuxtools.tmf.tests.event;
+import junit.framework.TestCase;
+
import org.eclipse.linuxtools.tmf.event.TmfEvent;
import org.eclipse.linuxtools.tmf.event.TmfEventContent;
import org.eclipse.linuxtools.tmf.event.TmfEventReference;
import org.eclipse.linuxtools.tmf.event.TmfEventType;
import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
-import junit.framework.TestCase;
-
/**
* <b><u>TmfEventTest</u></b>
* <p>
- * TODO: Implement me. Please.
+ * Test suite for the TmfEvent class.
*/
public class TmfEventTest extends TestCase {
+ // ------------------------------------------------------------------------
+ // Variables
+ // ------------------------------------------------------------------------
+
private final String fTypeId = "Some type";
private final String fLabel0 = "label1";
private final String fLabel1 = "label2";
private final TmfEventContent fContent1;
private final TmfEventContent fContent2;
- // ========================================================================
+ // ------------------------------------------------------------------------
// Housekeeping
- // ========================================================================
+ // ------------------------------------------------------------------------
+ /**
+ * @param name the test name
+ */
public TmfEventTest(String name) {
super(name);
super.tearDown();
}
- // ========================================================================
+ // ------------------------------------------------------------------------
// Constructors
- // ========================================================================
+ // ------------------------------------------------------------------------
public void testTmfEvent() {
assertEquals("getTimestamp", fTimestamp1, fEvent1.getTimestamp());
assertEquals("getReference", fReference, fEvent2.getReference());
}
+ public void testTmfEventBadArgs() {
+ try { // Bad timestamp
+ new TmfEvent(null, fSource, fType, fReference);
+ fail("null copy");
+ }
+ catch (IllegalArgumentException e) {
+ // Success
+ }
+
+ try { // Bad source
+ new TmfEvent(fTimestamp1, null, fType, fReference);
+ fail("null copy");
+ }
+ catch (IllegalArgumentException e) {
+ // Success
+ }
+
+ try { // Bad type
+ new TmfEvent(fTimestamp1, fSource, null, fReference);
+ fail("null copy");
+ }
+ catch (IllegalArgumentException e) {
+ // Success
+ }
+ }
+
public void testTmfEventCopy() {
TmfEvent event = new TmfEvent(fEvent1);
assertEquals("getTimestamp", fTimestamp1, event.getTimestamp());
assertEquals("getReference", fReference, event.getReference());
}
-// public void testTmfEventCloneShallowCopy() {
-// TmfEvent event = fEvent1.clone();
-// assertEquals("getTimestamp", fTimestamp1, event.getTimestamp());
-// assertEquals("getOriginalTimestamp", fTimestamp1, event.getOriginalTimestamp());
-// assertEquals("getSource", fSource, event.getSource());
-// assertEquals("getType", fType, event.getType());
-// assertEquals("getContent", fContent1, event.getContent());
-// assertEquals("getReference", fReference, event.getReference());
-// }
-
-// public void testTmfEventCloneDeepCopy() {
-// TmfEvent event = fEvent1.clone();
-// assertEquals("getTimestamp", fTimestamp1, event.getTimestamp());
-// assertEquals("getOriginalTimestamp", fTimestamp1, event.getOriginalTimestamp());
-// assertEquals("getSource", fSource, event.getSource());
-// assertEquals("getType", fType, event.getType());
-// assertEquals("getContent", fContent1, event.getContent());
-// assertEquals("getReference", fReference, event.getReference());
-// }
-
- // ========================================================================
- // Operators
- // ========================================================================
-
-// public void testToString() {
-// String expected1 = "[TmfEventType:" + TmfEventType.DEFAULT_TYPE_ID + "]";
-// assertEquals("toString", expected1, fEvent1.toString());
-//
-// String expected2 = "[TmfEventType:" + fTypeId + "]";
-// assertEquals("toString", expected2, fEvent2.toString());
-// }
+ public void testEventCopy2() throws Exception {
+ try {
+ new TmfEvent(null);
+ fail("null copy");
+ }
+ catch (IllegalArgumentException e) {
+ // Success
+ }
+ }
+
+ // ------------------------------------------------------------------------
+ // equals
+ // ------------------------------------------------------------------------
+
+ public void testEqualsReflexivity() throws Exception {
+ assertTrue("equals", fEvent1.equals(fEvent1));
+ assertTrue("equals", fEvent2.equals(fEvent2));
+
+ assertTrue("equals", !fEvent1.equals(fEvent2));
+ assertTrue("equals", !fEvent2.equals(fEvent1));
+ }
+
+ public void testEqualsSymmetry() throws Exception {
+ TmfEvent event1 = new TmfEvent(fEvent1);
+ TmfEvent event2 = new TmfEvent(fEvent2);
+
+ assertTrue("equals", event1.equals(fEvent1));
+ assertTrue("equals", fEvent1.equals(event1));
+
+ assertTrue("equals", event2.equals(fEvent2));
+ assertTrue("equals", fEvent2.equals(event2));
+ }
+
+ public void testEqualsTransivity() throws Exception {
+ TmfEvent event1 = new TmfEvent(fEvent1);
+ TmfEvent event2 = new TmfEvent(fEvent1);
+ TmfEvent event3 = new TmfEvent(fEvent1);
+
+ assertTrue("equals", event1.equals(event2));
+ assertTrue("equals", event2.equals(event3));
+ assertTrue("equals", event1.equals(event3));
+ }
+
+ public void testEqualsConsistency() throws Exception {
+ TmfEvent event1 = new TmfEvent(fEvent1);
+ TmfEvent event2 = new TmfEvent(fEvent2);
+
+ assertTrue("equals", event1.equals(fEvent1));
+ assertTrue("equals", event1.equals(fEvent1));
+
+ assertTrue("equals", event2.equals(fEvent2));
+ assertTrue("equals", event2.equals(fEvent2));
+ }
+
+ public void testEqualsNull() throws Exception {
+ assertTrue("equals", !fEvent1.equals(null));
+ assertTrue("equals", !fEvent2.equals(null));
+ }
+
+ // ------------------------------------------------------------------------
+ // toString
+ // ------------------------------------------------------------------------
+
+ public void testToString() {
+ String expected1 = "[TmfEvent(" + fTimestamp1 + "," + fSource + "," + fType + "," + fContent1 + ")]";
+ assertEquals("toString", expected1, fEvent1.toString());
+
+ String expected2 = "[TmfEvent(" + fTimestamp2 + "," + fSource + "," + fType + "," + fContent2 + ")]";
+ assertEquals("toString", expected2, fEvent2.toString());
+ }
+
+ // ------------------------------------------------------------------------
+ // setContent
+ // ------------------------------------------------------------------------
+
+ public void testSetContent() {
+ TmfEvent event = new TmfEvent(fEvent1);
+ assertEquals("setContent", fContent1, event.getContent());
+
+ event.setContent(fContent2);
+ assertEquals("setContent", fContent2, event.getContent());
+
+ event.setContent(fContent1);
+ assertEquals("setContent", fContent1, event.getContent());
+ }
}
package org.eclipse.linuxtools.tmf.tests.event;
+import junit.framework.TestCase;
+
import org.eclipse.linuxtools.tmf.event.TmfEventType;
import org.eclipse.linuxtools.tmf.event.TmfNoSuchFieldException;
-import junit.framework.TestCase;
-
/**
* <b><u>TmfEventTypeTest</u></b>
* <p>
*/
public class TmfEventTypeTest extends TestCase {
- private final String fTypeId = "Some type";
- private final String fLabel0 = "label1";
- private final String fLabel1 = "label2";
- private final String[] fLabels = new String[] { fLabel0, fLabel1 };
+ // ------------------------------------------------------------------------
+ // Variables
+ // ------------------------------------------------------------------------
+
+ private final String fTypeId = "Some type";
+ private final String fTypeId2 = "Some other type";
+ private final String fLabel0 = "label1";
+ private final String fLabel1 = "label2";
+ private final String[] fLabels = new String[] { fLabel0, fLabel1 };
+ private final String[] fLabels2 = new String[] { fLabel1, fLabel0 };
- // ========================================================================
+ private final TmfEventType fType0 = new TmfEventType(fTypeId, fLabels);
+ private final TmfEventType fType1 = new TmfEventType(fTypeId, fLabels);
+ private final TmfEventType fType2 = new TmfEventType(fTypeId, fLabels);
+ private final TmfEventType fType3 = new TmfEventType(fTypeId2, fLabels2);
+
+ // ------------------------------------------------------------------------
// Housekeeping
- // ========================================================================
+ // ------------------------------------------------------------------------
+ /**
+ * @param name the test name
+ */
public TmfEventTypeTest(String name) {
super(name);
}
super.tearDown();
}
- // ========================================================================
+ // ------------------------------------------------------------------------
// Constructors
- // ========================================================================
+ // ------------------------------------------------------------------------
public void testTmfEventTypeDefault() {
TmfEventType type = new TmfEventType();
} catch (TmfNoSuchFieldException e) {
// Success
}
+
+ try {
+ type.getLabel(10);
+ fail("getLabel: inexistant field");
+ } catch (TmfNoSuchFieldException e) {
+ // Success
+ }
+ }
+
+ public void testTmfEventType2() {
+ try {
+ @SuppressWarnings("unused")
+ TmfEventType type = new TmfEventType(fTypeId, null);
+ fail("TmfEventType: bad constructor");
+ } catch (IllegalArgumentException e) {
+ // Success
+ }
+ }
+
+ public void testTmfEventType3() {
+ try {
+ @SuppressWarnings("unused")
+ TmfEventType type = new TmfEventType(null, fLabels);
+ fail("TmfEventType: bad constructor");
+ } catch (IllegalArgumentException e) {
+ // Success
+ }
}
public void testTmfEventTypeCopy() {
assertEquals("getLabels", fLabels, type.getLabels());
}
- public void testCloneShallowCopy() {
- TmfEventType original = new TmfEventType(fTypeId, fLabels);
- TmfEventType type = original.clone();
- assertEquals("getTypeId", fTypeId, type.getTypeId());
- assertEquals("getNbFields", fLabels.length, type.getNbFields());
- assertEquals("getLabels", fLabels, type.getLabels());
+ public void testTmfEventSourceCopy2() {
+ try {
+ @SuppressWarnings("unused")
+ TmfEventType type = new TmfEventType(null);
+ fail("null copy");
+ }
+ catch (IllegalArgumentException e) {
+ // Success
+ }
}
-// public void testCloneDeepCopy() {
-// fail("Not yet implemented");
-// }
+ // ------------------------------------------------------------------------
+ // equals
+ // ------------------------------------------------------------------------
+
+ public void testEqualsReflexivity() throws Exception {
+ assertTrue("equals", fType0.equals(fType0));
+ assertTrue("equals", fType3.equals(fType3));
- // ========================================================================
- // Operators
- // ========================================================================
+ assertTrue("equals", !fType0.equals(fType3));
+ assertTrue("equals", !fType3.equals(fType0));
+ }
+
+ public void testEqualsSymmetry() throws Exception {
+ assertTrue("equals", fType0.equals(fType1));
+ assertTrue("equals", fType1.equals(fType0));
+
+ assertTrue("equals", !fType0.equals(fType3));
+ assertTrue("equals", !fType3.equals(fType0));
+ }
+
+ public void testEqualsTransivity() throws Exception {
+ assertTrue("equals", fType0.equals(fType1));
+ assertTrue("equals", fType1.equals(fType2));
+ assertTrue("equals", fType0.equals(fType2));
+ }
+
+ public void testEqualsConsistency() throws Exception {
+ assertTrue("equals", fType0.equals(fType0));
+ assertTrue("equals", fType0.equals(fType0));
+
+ assertTrue("equals", fType3.equals(fType3));
+ assertTrue("equals", fType3.equals(fType3));
+ }
+
+ public void testEqualsNull() throws Exception {
+ assertTrue("equals", !fType0.equals(null));
+ assertTrue("equals", !fType3.equals(null));
+ }
+
+ // ------------------------------------------------------------------------
+ // toString
+ // ------------------------------------------------------------------------
public void testToString() {
String expected1 = "[TmfEventType:" + TmfEventType.DEFAULT_TYPE_ID + "]";
/*******************************************************************************
- * Copyright (c) 2009 Ericsson
+ * Copyright (c) 2009, 2010 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
/**
* <b><u>TmfTimeRangeTest</u></b>
* <p>
- * TODO: Implement me. Please.
+ * Test suite for the TmfTimeRange class.
*/
public class TmfTimeRangeTest extends TestCase {
- // ========================================================================
+
+ // ------------------------------------------------------------------------
// Housekeeping
- // ========================================================================
+ // ------------------------------------------------------------------------
public TmfTimeRangeTest(String name) {
super(name);
super.tearDown();
}
- // ========================================================================
+ // ------------------------------------------------------------------------
// Constructors
- // ========================================================================
+ // ------------------------------------------------------------------------
public void testConstructor() throws Exception {
TmfTimestamp ts1 = new TmfTimestamp(12345);
TmfTimestamp ts2 = new TmfTimestamp(12350);
TmfTimeRange range = new TmfTimeRange(ts1, ts2);
assertEquals("startTime", ts1, range.getStartTime());
- assertEquals("endTime", ts2, range.getEndTime());
+ assertEquals("endTime", ts2, range.getEndTime());
+ }
+
+ public void testBadConstructor() throws Exception {
+ try {
+ new TmfTimeRange(TmfTimestamp.BigBang, null);
+ fail("null copy");
+ }
+ catch (IllegalArgumentException e) {
+ // Success
+ }
+
+ try {
+ new TmfTimeRange(null, TmfTimestamp.BigCrunch);
+ fail("null copy");
+ }
+ catch (IllegalArgumentException e) {
+ // Success
+ }
}
public void testOpenRange1() throws Exception {
TmfTimestamp ts2 = new TmfTimestamp(12350);
TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, ts2);
assertEquals("startTime", TmfTimestamp.BigBang, range.getStartTime());
- assertEquals("endTime", ts2, range.getEndTime());
+ assertEquals("endTime", ts2, range.getEndTime());
}
public void testOpenRange2() throws Exception {
TmfTimestamp ts1 = new TmfTimestamp(12345);
TmfTimeRange range = new TmfTimeRange(ts1, TmfTimestamp.BigCrunch);
assertEquals("startTime", ts1, range.getStartTime());
- assertEquals("endTime", TmfTimestamp.BigCrunch, range.getEndTime());
+ assertEquals("endTime", TmfTimestamp.BigCrunch, range.getEndTime());
}
public void testOpenRange3() throws Exception {
TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch);
- assertEquals("startTime", TmfTimestamp.BigBang, range.getStartTime());
- assertEquals("endTime", TmfTimestamp.BigCrunch, range.getEndTime());
+ assertEquals("startTime", TmfTimestamp.BigBang, range.getStartTime());
+ assertEquals("endTime", TmfTimestamp.BigCrunch, range.getEndTime());
}
- // ========================================================================
- // contains
- // ========================================================================
+ public void testCopyConstructor() throws Exception {
+ TmfTimestamp ts1 = new TmfTimestamp(12345);
+ TmfTimestamp ts2 = new TmfTimestamp(12350);
+ TmfTimeRange range0 = new TmfTimeRange(ts1, ts2);
+ TmfTimeRange range1 = new TmfTimeRange(range0);
- public void testContains() throws Exception {
+ assertEquals("startTime", ts1, range1.getStartTime());
+ assertEquals("endTime", ts2, range1.getEndTime());
+
+ TmfTimeRange range2 = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch);
+ TmfTimeRange range3 = new TmfTimeRange(range2);
+ assertEquals("startTime", TmfTimestamp.BigBang, range3.getStartTime());
+ assertEquals("endTime", TmfTimestamp.BigCrunch, range3.getEndTime());
+ }
+
+ public void testCopyConstructor2() throws Exception {
+ try {
+ new TmfTimeRange(null);
+ fail("null copy");
+ }
+ catch (IllegalArgumentException e) {
+ // Success
+ }
+ }
+
+ // ------------------------------------------------------------------------
+ // equals
+ // ------------------------------------------------------------------------
+
+ public void testEqualsReflexivity() throws Exception {
TmfTimestamp ts1 = new TmfTimestamp(12345);
TmfTimestamp ts2 = new TmfTimestamp(12350);
- TmfTimeRange range = new TmfTimeRange(ts1, ts2);
+ TmfTimeRange range1 = new TmfTimeRange(ts1, ts2);
+ TmfTimeRange range2 = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch);
- assertTrue("contains (lower bound)", range.contains(new TmfTimestamp(12345)));
- assertTrue("contains (higher bound)", range.contains(new TmfTimestamp(12350)));
- assertTrue("contains (within bounds)", range.contains(new TmfTimestamp(12346)));
+ assertTrue("equals", range1.equals(range1));
+ assertTrue("equals", range2.equals(range2));
- assertFalse("contains (low value)", range.contains(new TmfTimestamp(12340)));
- assertFalse("contains (high value)", range.contains(new TmfTimestamp(12351)));
+ assertTrue("equals", !range1.equals(range2));
+ assertTrue("equals", !range2.equals(range1));
+ }
+
+ public void testEqualsSymmetry() throws Exception {
+ TmfTimestamp ts1 = new TmfTimestamp(12345);
+ TmfTimestamp ts2 = new TmfTimestamp(12350);
+ TmfTimeRange range1a = new TmfTimeRange(ts1, ts2);
+ TmfTimeRange range1b = new TmfTimeRange(ts1, ts2);
+
+ TmfTimeRange range2a = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch);
+ TmfTimeRange range2b = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch);
+
+ assertTrue("equals", range1a.equals(range1b));
+ assertTrue("equals", range1b.equals(range1a));
+
+ assertTrue("equals", range2a.equals(range2b));
+ assertTrue("equals", range2b.equals(range2a));
+ }
+
+ public void testEqualsTransivity() throws Exception {
+ TmfTimestamp ts1 = new TmfTimestamp(12345);
+ TmfTimestamp ts2 = new TmfTimestamp(12350);
+ TmfTimeRange range1a = new TmfTimeRange(ts1, ts2);
+ TmfTimeRange range1b = new TmfTimeRange(ts1, ts2);
+ TmfTimeRange range1c = new TmfTimeRange(ts1, ts2);
+
+ assertTrue("equals", range1a.equals(range1b));
+ assertTrue("equals", range1b.equals(range1c));
+ assertTrue("equals", range1a.equals(range1c));
}
+
+ public void testEqualsConsistency() throws Exception {
+ TmfTimestamp ts1 = new TmfTimestamp(12345);
+ TmfTimestamp ts2 = new TmfTimestamp(12350);
+ TmfTimeRange range1a = new TmfTimeRange(ts1, ts2);
+ TmfTimeRange range1b = new TmfTimeRange(ts1, ts2);
- // ========================================================================
+ assertTrue("equals", range1a.equals(range1a));
+ assertTrue("equals", range1a.equals(range1a));
+
+ assertTrue("equals", range1b.equals(range1b));
+ assertTrue("equals", range1b.equals(range1b));
+ }
+
+ public void testEqualsNull() throws Exception {
+ TmfTimestamp ts1 = new TmfTimestamp(12345);
+ TmfTimestamp ts2 = new TmfTimestamp(12350);
+ TmfTimeRange range1 = new TmfTimeRange(ts1, ts2);
+
+ assertTrue("equals", !range1.equals(null));
+ }
+
+ // ------------------------------------------------------------------------
// toString
- // ========================================================================
+ // ------------------------------------------------------------------------
public void testToString() throws Exception {
TmfTimestamp ts1 = new TmfTimestamp(12345);
TmfTimestamp ts2 = new TmfTimestamp(12350);
TmfTimeRange range = new TmfTimeRange(ts1, ts2);
- String expected = "[TmfTimeRange(" + ts1.toString() + ":" + ts2.toString() + ")]";
+ String expected = "[TmfTimeRange(" + ts1 + ":" + ts2 + ")]";
assertEquals("toString", expected, range.toString());
}
+ // ------------------------------------------------------------------------
+ // contains
+ // ------------------------------------------------------------------------
+
+ public void testContains() throws Exception {
+ TmfTimestamp ts1 = new TmfTimestamp(12345);
+ TmfTimestamp ts2 = new TmfTimestamp(12350);
+ TmfTimeRange range = new TmfTimeRange(ts1, ts2);
+
+ assertTrue("contains (lower bound)", range.contains(new TmfTimestamp(12345)));
+ assertTrue("contains (higher bound)", range.contains(new TmfTimestamp(12350)));
+ assertTrue("contains (within bounds)", range.contains(new TmfTimestamp(12346)));
+
+ assertFalse("contains (low value)", range.contains(new TmfTimestamp(12340)));
+ assertFalse("contains (high value)", range.contains(new TmfTimestamp(12351)));
+ }
+
}
package org.eclipse.linuxtools.tmf.tests.event;
-import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
-
import junit.framework.TestCase;
+import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
+
/**
* <b><u>TmfTimestampTest</u></b>
* <p>
- * TODO: Implement me. Please.
+ * Test suite for the TmfTimestamp class.
*/
public class TmfTimestampTest extends TestCase {
- // ========================================================================
- // Housekeeping
- // ========================================================================
+ // ------------------------------------------------------------------------
+ // Variables
+ // ------------------------------------------------------------------------
+
+ private final TmfTimestamp ts0 = new TmfTimestamp();
+ private final TmfTimestamp ts1 = new TmfTimestamp(12345);
+ private final TmfTimestamp ts2 = new TmfTimestamp(12345, (byte) -1);
+ private final TmfTimestamp ts3 = new TmfTimestamp(12345, (byte) 2, 5);
+
+ private final TmfTimestamp ts0copy = new TmfTimestamp();
+ private final TmfTimestamp ts1copy = new TmfTimestamp(12345);
+
+ private final TmfTimestamp ts0copy2 = new TmfTimestamp();
+ private final TmfTimestamp ts1copy2 = new TmfTimestamp(12345);
+
+ private final TmfTimestamp bigBang = new TmfTimestamp(TmfTimestamp.BigBang);
+ private final TmfTimestamp bigCrunch = new TmfTimestamp(TmfTimestamp.BigCrunch);
+ // ------------------------------------------------------------------------
+ // Housekeping
+ // ------------------------------------------------------------------------
+
+ /**
+ * @param name the test name
+ */
public TmfTimestampTest(String name) {
super(name);
}
super.tearDown();
}
- // ========================================================================
+ // ------------------------------------------------------------------------
// Constructors
- // ========================================================================
+ // ------------------------------------------------------------------------
public void testDefaultConstructor() throws Exception {
- TmfTimestamp ts = new TmfTimestamp();
- assertEquals("getValue", 0, ts.getValue());
- assertEquals("getscale", 0, ts.getScale());
- assertEquals("getPrecision", 0, ts.getPrecision());
+ assertEquals("getValue", 0, ts0.getValue());
+ assertEquals("getscale", 0, ts0.getScale());
+ assertEquals("getPrecision", 0, ts0.getPrecision());
}
public void testSimpleConstructor() throws Exception {
- TmfTimestamp ts = new TmfTimestamp(12345);
- assertEquals("getValue", 12345, ts.getValue());
- assertEquals("getscale", 0, ts.getScale());
- assertEquals("getPrecision", 0, ts.getPrecision());
+ assertEquals("getValue", 12345, ts1.getValue());
+ assertEquals("getscale", 0, ts1.getScale());
+ assertEquals("getPrecision", 0, ts1.getPrecision());
}
public void testSimpleConstructor2() throws Exception {
- TmfTimestamp ts = new TmfTimestamp(12345, (byte) -1);
- assertEquals("getValue", 12345, ts.getValue());
- assertEquals("getscale", -1, ts.getScale());
- assertEquals("getPrecision", 0, ts.getPrecision());
+ assertEquals("getValue", 12345, ts2.getValue());
+ assertEquals("getscale", -1, ts2.getScale());
+ assertEquals("getPrecision", 0, ts2.getPrecision());
}
public void testFullConstructor() throws Exception {
- TmfTimestamp ts = new TmfTimestamp(12345, (byte) 2, 5);
- assertEquals("getValue", 12345, ts.getValue());
- assertEquals("getscale", 2, ts.getScale());
- assertEquals("getPrecision", 5, ts.getPrecision());
+ assertEquals("getValue", 12345, ts3.getValue());
+ assertEquals("getscale", 2, ts3.getScale());
+ assertEquals("getPrecision", 5, ts3.getPrecision());
}
public void testCopyConstructor() throws Exception {
assertEquals("getPrecision", 5, ts.getPrecision());
}
- // ========================================================================
- // BigBang, BigCrunch
- // ========================================================================
+ public void testCopyConstructor2() throws Exception {
+ try {
+ @SuppressWarnings("unused")
+ TmfTimestamp timestamp = new TmfTimestamp(null);
+ fail("null copy");
+ }
+ catch (IllegalArgumentException e) {
+ // Success
+ }
+ }
public void testCopyConstructorBigBang() throws Exception {
- TmfTimestamp ts = new TmfTimestamp(TmfTimestamp.BigBang);
- assertEquals("getValue", TmfTimestamp.BigBang.getValue(), ts.getValue());
- assertEquals("getscale", TmfTimestamp.BigBang.getScale(), ts.getScale());
- assertEquals("getPrecision", TmfTimestamp.BigBang.getPrecision(), ts.getPrecision());
+ assertEquals("getValue", TmfTimestamp.BigBang.getValue(), bigBang.getValue());
+ assertEquals("getscale", TmfTimestamp.BigBang.getScale(), bigBang.getScale());
+ assertEquals("getPrecision", TmfTimestamp.BigBang.getPrecision(), bigBang.getPrecision());
}
public void testCopyConstructorBigCrunch() throws Exception {
- TmfTimestamp ts = new TmfTimestamp(TmfTimestamp.BigCrunch);
- assertEquals("getValue", TmfTimestamp.BigCrunch.getValue(), ts.getValue());
- assertEquals("getscale", TmfTimestamp.BigCrunch.getScale(), ts.getScale());
- assertEquals("getPrecision", TmfTimestamp.BigCrunch.getPrecision(), ts.getPrecision());
+ assertEquals("getValue", TmfTimestamp.BigCrunch.getValue(), bigCrunch.getValue());
+ assertEquals("getscale", TmfTimestamp.BigCrunch.getScale(), bigCrunch.getScale());
+ assertEquals("getPrecision", TmfTimestamp.BigCrunch.getPrecision(), bigCrunch.getPrecision());
+ }
+
+ // ------------------------------------------------------------------------
+ // equals
+ // ------------------------------------------------------------------------
+
+ public void testEqualsReflexivity() throws Exception {
+ assertTrue("equals", ts0.equals(ts0));
+ assertTrue("equals", ts1.equals(ts1));
+
+ assertTrue("equals", !ts0.equals(ts1));
+ assertTrue("equals", !ts1.equals(ts0));
}
+
+ public void testEqualsSymmetry() throws Exception {
+ assertTrue("equals", ts0.equals(ts0copy));
+ assertTrue("equals", ts0copy.equals(ts0));
- // ========================================================================
+ assertTrue("equals", ts1.equals(ts1copy));
+ assertTrue("equals", ts1copy.equals(ts1));
+ }
+
+ public void testEqualsTransivity() throws Exception {
+ assertTrue("equals", ts0.equals(ts0copy));
+ assertTrue("equals", ts0copy.equals(ts0copy2));
+ assertTrue("equals", ts0.equals(ts0copy2));
+
+ assertTrue("equals", ts1.equals(ts1copy));
+ assertTrue("equals", ts1copy.equals(ts1copy2));
+ assertTrue("equals", ts1.equals(ts1copy2));
+ }
+
+ public void testEqualsConsistency() throws Exception {
+ assertTrue("equals", ts0.equals(ts0copy));
+ assertTrue("equals", ts0.equals(ts0copy));
+
+ assertTrue("equals", ts1.equals(ts1copy));
+ assertTrue("equals", ts1.equals(ts1copy));
+ }
+
+ public void testEqualsNull() throws Exception {
+ assertTrue("equals", !ts0.equals(null));
+ assertTrue("equals", !ts1.equals(null));
+ }
+
+ // ------------------------------------------------------------------------
// toString
- // ========================================================================
+ // ------------------------------------------------------------------------
public void testToString() throws Exception {
- TmfTimestamp ts1 = new TmfTimestamp();
- TmfTimestamp ts2 = new TmfTimestamp(1234, (byte) 2);
- TmfTimestamp ts3 = new TmfTimestamp(1234, (byte) 2, 1);
- TmfTimestamp ts4 = new TmfTimestamp(-1234, (byte) -1, 4);
-
- assertEquals("toString", "[TmfTimestamp(0,0,0)]", ts1.toString());
- assertEquals("toString", "[TmfTimestamp(1234,2,0)]", ts2.toString());
- assertEquals("toString", "[TmfTimestamp(1234,2,1)]", ts3.toString());
- assertEquals("toString", "[TmfTimestamp(-1234,-1,4)]", ts4.toString());
+ assertEquals("toString", "[TmfTimestamp(0,0,0)]", ts0.toString());
+ assertEquals("toString", "[TmfTimestamp(12345,0,0)]", ts1.toString());
+ assertEquals("toString", "[TmfTimestamp(12345,-1,0)]", ts2.toString());
+ assertEquals("toString", "[TmfTimestamp(12345,2,5)]", ts3.toString());
}
-
- // ========================================================================
+
+ // ------------------------------------------------------------------------
// synchronize
- // ========================================================================
+ // ------------------------------------------------------------------------
public void testSynchronizeOffset() throws Exception {
- TmfTimestamp ts0 = new TmfTimestamp(1234, (byte) 0, 1);
- TmfTimestamp ts = new TmfTimestamp();
- ts = ts0.synchronize(0, (byte) 0);
- assertEquals("getValue", 1234, ts.getValue());
- assertEquals("getscale", 0, ts.getScale());
- assertEquals("getPrecision", 1, ts.getPrecision());
+ TmfTimestamp ts = ts0.synchronize(0, (byte) 0);
+ assertEquals("getValue", 0, ts.getValue());
+ assertEquals("getscale", 0, ts.getScale());
+ assertEquals("getPrecision", 0, ts.getPrecision());
+
+ ts = ts0.synchronize(12345, (byte) 0);
+ assertEquals("getValue", 12345, ts.getValue());
+ assertEquals("getscale", 0, ts.getScale());
+ assertEquals("getPrecision", 0, ts.getPrecision());
ts = ts0.synchronize(10, (byte) 0);
- assertEquals("getValue", 1244, ts.getValue());
- assertEquals("getscale", 0, ts.getScale());
- assertEquals("getPrecision", 1, ts.getPrecision());
+ assertEquals("getValue", 10, ts.getValue());
+ assertEquals("getscale", 0, ts.getScale());
+ assertEquals("getPrecision", 0, ts.getPrecision());
ts = ts0.synchronize(-10, (byte) 0);
- assertEquals("getValue", 1224, ts.getValue());
- assertEquals("getscale", 0, ts.getScale());
- assertEquals("getPrecision", 1, ts.getPrecision());
+ assertEquals("getValue", -10, ts.getValue());
+ assertEquals("getscale", 0, ts.getScale());
+ assertEquals("getPrecision", 0, ts.getPrecision());
}
public void testSynchronizeScale() throws Exception {
- TmfTimestamp ts0 = new TmfTimestamp(1234, (byte) 0, 12);
- TmfTimestamp ts = new TmfTimestamp();
- ts = ts0.synchronize(0, (byte) 0);
- assertEquals("getValue", 1234, ts.getValue());
- assertEquals("getscale", 0, ts.getScale());
- assertEquals("getPrecision", 12, ts.getPrecision());
+ TmfTimestamp ts = ts0.synchronize(0, (byte) 10);
+ assertEquals("getValue", 0, ts.getValue());
+ assertEquals("getscale", 10, ts.getScale());
+ assertEquals("getPrecision", 0, ts.getPrecision());
- ts = ts0.synchronize(0, (byte) 1);
- assertEquals("getValue", 123, ts.getValue());
- assertEquals("getscale", 1, ts.getScale());
- assertEquals("getPrecision", 1, ts.getPrecision());
+ ts = ts0.synchronize(0, (byte) -10);
+ assertEquals("getValue", 0, ts.getValue());
+ assertEquals("getscale", -10, ts.getScale());
+ assertEquals("getPrecision", 0, ts.getPrecision());
+ }
- ts = ts0.synchronize(0, (byte) 2);
- assertEquals("getValue", 12, ts.getValue());
- assertEquals("getscale", 2, ts.getScale());
+ public void testSynchronizeOffsetAndScale() throws Exception {
+ byte SCALE = 12;
+
+ TmfTimestamp ts = ts0.synchronize(0, SCALE);
+ assertEquals("getValue", 0, ts.getValue());
+ assertEquals("getscale", SCALE, ts.getScale());
assertEquals("getPrecision", 0, ts.getPrecision());
- ts = ts0.synchronize(0, (byte) 4);
- assertEquals("getValue", 0, ts.getValue());
- assertEquals("getscale", 4, ts.getScale());
+ ts = ts0.synchronize(12345, SCALE);
+ assertEquals("getValue", 12345, ts.getValue());
+ assertEquals("getscale", SCALE, ts.getScale());
assertEquals("getPrecision", 0, ts.getPrecision());
- ts = ts0.synchronize(0, (byte) -2);
- assertEquals("getValue", 123400, ts.getValue());
- assertEquals("getscale", -2, ts.getScale());
- assertEquals("getPrecision", 1200, ts.getPrecision());
- }
+ ts = ts0.synchronize(10, SCALE);
+ assertEquals("getValue", 10, ts.getValue());
+ assertEquals("getscale", SCALE, ts.getScale());
+ assertEquals("getPrecision", 0, ts.getPrecision());
- public void testSynchronizeOffsetAndScale() throws Exception {
- TmfTimestamp ts0 = new TmfTimestamp(1234, (byte) 0, 12);
- TmfTimestamp ts = new TmfTimestamp();
-
- ts = ts0.synchronize(10, (byte) 1);
- assertEquals("getValue", 133, ts.getValue());
- assertEquals("getscale", 1, ts.getScale());
- assertEquals("getPrecision", 1, ts.getPrecision());
-
- ts = ts0.synchronize(-10, (byte) -1);
- assertEquals("getValue", 12330, ts.getValue());
- assertEquals("getscale", -1, ts.getScale());
- assertEquals("getPrecision", 120, ts.getPrecision());
+ ts = ts0.synchronize(-10, SCALE);
+ assertEquals("getValue", -10, ts.getValue());
+ assertEquals("getscale", SCALE, ts.getScale());
+ assertEquals("getPrecision", 0, ts.getPrecision());
}
- // ========================================================================
+ // ------------------------------------------------------------------------
// getAdjustment
- // ========================================================================
+ // ------------------------------------------------------------------------
public void testGetAdjustmentSameScale() throws Exception {
- TmfTimestamp ts0 = new TmfTimestamp(12345, (byte) -2);
- TmfTimestamp ts = new TmfTimestamp(10000, (byte) -2);
+ long delta = ts0.getAdjustment(ts0 , ts0.getScale());
+ assertEquals("delta", 0, delta);
- long delta = ts.getAdjustment(ts0);
- assertEquals("delta", 2345, delta);
- }
+ delta = ts1.getAdjustment(ts1, ts1.getScale());
+ assertEquals("delta", 0, delta);
- public void testGetAdjustmentDifferentScale() throws Exception {
- TmfTimestamp ts0 = new TmfTimestamp(12345, (byte) -2);
- TmfTimestamp ts = new TmfTimestamp(1, (byte) 2);
+ delta = ts0.getAdjustment(ts1, ts1.getScale());
+ assertEquals("delta", 12345, delta);
- long delta = ts.getAdjustment(ts0);
- assertEquals("delta", 2345, delta);
+ delta = ts1.getAdjustment(ts0, ts0.getScale());
+ assertEquals("delta", -12345, delta);
+ }
- delta = ts0.getAdjustment(ts);
- assertEquals("delta", 0, delta);
+ public void testGetAdjustmentDifferentScales() throws Exception {
+ long delta = ts0.getAdjustment(ts2, ts2.getScale());
+ assertEquals("delta", 12345, delta);
+
+ delta = ts2.getAdjustment(ts0, ts0.getScale());
+ assertEquals("delta", -1234, delta);
}
- // ========================================================================
+ // ------------------------------------------------------------------------
// CompareTo
- // ========================================================================
+ // ------------------------------------------------------------------------
public void testCompareToSameScale() throws Exception {
- TmfTimestamp ts1 = new TmfTimestamp(900, (byte) 0, 50);
+ TmfTimestamp ts1 = new TmfTimestamp(900, (byte) 0, 50);
TmfTimestamp ts2 = new TmfTimestamp(1000, (byte) 0, 50);
TmfTimestamp ts3 = new TmfTimestamp(1100, (byte) 0, 50);
TmfTimestamp ts4 = new TmfTimestamp(1000, (byte) 0, 75);
assertTrue(ts1.compareTo(ts1, false) == 0);
- assertTrue(ts1.compareTo(ts2, false) < 0);
- assertTrue(ts1.compareTo(ts3, false) < 0);
- assertTrue(ts1.compareTo(ts4, false) < 0);
+ assertTrue("CompareTo", ts1.compareTo(ts2, false) < 0);
+ assertTrue("CompareTo", ts1.compareTo(ts3, false) < 0);
+ assertTrue("CompareTo", ts1.compareTo(ts4, false) < 0);
- assertTrue(ts2.compareTo(ts1, false) > 0);
- assertTrue(ts2.compareTo(ts3, false) < 0);
- assertTrue(ts2.compareTo(ts4, false) == 0);
+ assertTrue("CompareTo", ts2.compareTo(ts1, false) > 0);
+ assertTrue("CompareTo", ts2.compareTo(ts3, false) < 0);
+ assertTrue("CompareTo", ts2.compareTo(ts4, false) == 0);
- assertTrue(ts3.compareTo(ts1, false) > 0);
- assertTrue(ts3.compareTo(ts2, false) > 0);
- assertTrue(ts3.compareTo(ts4, false) > 0);
+ assertTrue("CompareTo", ts3.compareTo(ts1, false) > 0);
+ assertTrue("CompareTo", ts3.compareTo(ts2, false) > 0);
+ assertTrue("CompareTo", ts3.compareTo(ts4, false) > 0);
}
public void testCompareToDifferentScale() throws Exception {
TmfTimestamp ts1 = new TmfTimestamp(9000, (byte) -1, 50);
TmfTimestamp ts2 = new TmfTimestamp(1000, (byte) 0, 50);
- TmfTimestamp ts3 = new TmfTimestamp(110, (byte) 1, 50);
- TmfTimestamp ts4 = new TmfTimestamp(1, (byte) 3, 75);
+ TmfTimestamp ts3 = new TmfTimestamp(110, (byte) 1, 50);
+ TmfTimestamp ts4 = new TmfTimestamp(1, (byte) 3, 75);
- assertTrue(ts1.compareTo(ts1, false) == 0);
+ assertTrue("CompareTo", ts1.compareTo(ts1, false) == 0);
- assertTrue(ts1.compareTo(ts2, false) < 0);
- assertTrue(ts1.compareTo(ts3, false) < 0);
- assertTrue(ts1.compareTo(ts4, false) < 0);
+ assertTrue("CompareTo", ts1.compareTo(ts2, false) < 0);
+ assertTrue("CompareTo", ts1.compareTo(ts3, false) < 0);
+ assertTrue("CompareTo", ts1.compareTo(ts4, false) < 0);
- assertTrue(ts2.compareTo(ts1, false) > 0);
- assertTrue(ts2.compareTo(ts3, false) < 0);
- assertTrue(ts2.compareTo(ts4, false) == 0);
+ assertTrue("CompareTo", ts2.compareTo(ts1, false) > 0);
+ assertTrue("CompareTo", ts2.compareTo(ts3, false) < 0);
+ assertTrue("CompareTo", ts2.compareTo(ts4, false) == 0);
- assertTrue(ts3.compareTo(ts1, false) > 0);
- assertTrue(ts3.compareTo(ts2, false) > 0);
- assertTrue(ts3.compareTo(ts4, false) > 0);
+ assertTrue("CompareTo", ts3.compareTo(ts1, false) > 0);
+ assertTrue("CompareTo", ts3.compareTo(ts2, false) > 0);
+ assertTrue("CompareTo", ts3.compareTo(ts4, false) > 0);
}
public void testCompareToWithinPrecision() throws Exception {
- TmfTimestamp ts1 = new TmfTimestamp(900, (byte) 0, 50);
+ TmfTimestamp ts1 = new TmfTimestamp(900, (byte) 0, 50);
TmfTimestamp ts2 = new TmfTimestamp(1000, (byte) 0, 50);
TmfTimestamp ts3 = new TmfTimestamp(1100, (byte) 0, 50);
TmfTimestamp ts4 = new TmfTimestamp(1000, (byte) 0, 75);
- assertTrue(ts1.compareTo(ts1, true) == 0);
+ assertTrue("CompareTo", ts1.compareTo(ts1, true) == 0);
- assertTrue(ts1.compareTo(ts2, true) == 0);
- assertTrue(ts1.compareTo(ts3, true) < 0);
- assertTrue(ts1.compareTo(ts4, true) == 0);
+ assertTrue("CompareTo", ts1.compareTo(ts2, true) == 0);
+ assertTrue("CompareTo", ts1.compareTo(ts3, true) < 0);
+ assertTrue("CompareTo", ts1.compareTo(ts4, true) == 0);
- assertTrue(ts2.compareTo(ts1, true) == 0);
- assertTrue(ts2.compareTo(ts3, true) == 0);
- assertTrue(ts2.compareTo(ts4, true) == 0);
+ assertTrue("CompareTo", ts2.compareTo(ts1, true) == 0);
+ assertTrue("CompareTo", ts2.compareTo(ts3, true) == 0);
+ assertTrue("CompareTo", ts2.compareTo(ts4, true) == 0);
- assertTrue(ts3.compareTo(ts1, true) > 0);
- assertTrue(ts3.compareTo(ts2, true) == 0);
- assertTrue(ts3.compareTo(ts4, true) == 0);
+ assertTrue("CompareTo", ts3.compareTo(ts1, true) > 0);
+ assertTrue("CompareTo", ts3.compareTo(ts2, true) == 0);
+ assertTrue("CompareTo", ts3.compareTo(ts4, true) == 0);
}
public void testCompareToLargeScale() throws Exception {
- TmfTimestamp ts1 = new TmfTimestamp(-1, (byte) 100);
+ TmfTimestamp ts1 = new TmfTimestamp(-1, (byte) 100);
TmfTimestamp ts2 = new TmfTimestamp(-1000, (byte) -100);
- TmfTimestamp ts3 = new TmfTimestamp(1, (byte) 100);
- TmfTimestamp ts4 = new TmfTimestamp(1000, (byte) -100);
+ TmfTimestamp ts3 = new TmfTimestamp(1, (byte) 100);
+ TmfTimestamp ts4 = new TmfTimestamp(1000, (byte) -100);
- assertTrue(ts1.compareTo(ts2, false) < 0);
- assertTrue(ts1.compareTo(ts3, false) < 0);
- assertTrue(ts1.compareTo(ts4, false) < 0);
+ assertTrue("CompareTo", ts1.compareTo(ts2, false) < 0);
+ assertTrue("CompareTo", ts1.compareTo(ts3, false) < 0);
+ assertTrue("CompareTo", ts1.compareTo(ts4, false) < 0);
- assertTrue(ts2.compareTo(ts1, false) > 0);
- assertTrue(ts2.compareTo(ts3, false) < 0);
- assertTrue(ts2.compareTo(ts4, false) < 0);
+ assertTrue("CompareTo", ts2.compareTo(ts1, false) > 0);
+ assertTrue("CompareTo", ts2.compareTo(ts3, false) < 0);
+ assertTrue("CompareTo", ts2.compareTo(ts4, false) < 0);
- assertTrue(ts3.compareTo(ts1, false) > 0);
- assertTrue(ts3.compareTo(ts2, false) > 0);
- assertTrue(ts3.compareTo(ts4, false) > 0);
+ assertTrue("CompareTo", ts3.compareTo(ts1, false) > 0);
+ assertTrue("CompareTo", ts3.compareTo(ts2, false) > 0);
+ assertTrue("CompareTo", ts3.compareTo(ts4, false) > 0);
- assertTrue(ts4.compareTo(ts1, false) > 0);
- assertTrue(ts4.compareTo(ts2, false) > 0);
- assertTrue(ts4.compareTo(ts3, false) < 0);
+ assertTrue("CompareTo", ts4.compareTo(ts1, false) > 0);
+ assertTrue("CompareTo", ts4.compareTo(ts2, false) > 0);
+ assertTrue("CompareTo", ts4.compareTo(ts3, false) < 0);
}
- public void testCompareToBigGuys() throws Exception {
+ public void testCompareToBigRanges() throws Exception {
+ TmfTimestamp ts0a = new TmfTimestamp(0, Byte.MAX_VALUE);
+ TmfTimestamp ts0b = new TmfTimestamp(0, Byte.MIN_VALUE);
TmfTimestamp ts1 = new TmfTimestamp(-1, Byte.MAX_VALUE);
TmfTimestamp ts2 = new TmfTimestamp(-1, Byte.MIN_VALUE);
TmfTimestamp ts3 = new TmfTimestamp(1, Byte.MAX_VALUE);
TmfTimestamp ts4 = new TmfTimestamp(1, Byte.MIN_VALUE);
- assertTrue(ts1.compareTo(TmfTimestamp.BigBang, false) > 0);
- assertTrue(ts1.compareTo(TmfTimestamp.BigCrunch, false) < 0);
+ assertTrue("CompareTo", ts0a.compareTo(TmfTimestamp.BigBang, false) > 0);
+ assertTrue("CompareTo", ts0a.compareTo(TmfTimestamp.BigCrunch, false) < 0);
+
+ assertTrue("CompareTo", ts0b.compareTo(TmfTimestamp.BigBang, false) > 0);
+ assertTrue("CompareTo", ts0b.compareTo(TmfTimestamp.BigCrunch, false) < 0);
+
+ assertTrue("CompareTo", ts0a.compareTo(ts0b, false) == 0);
+ assertTrue("CompareTo", ts0b.compareTo(ts0a, false) == 0);
+
+ assertTrue("CompareTo", ts0a.compareTo(TmfTimestamp.BigBang, false) > 0);
+ assertTrue("CompareTo", ts0a.compareTo(TmfTimestamp.BigCrunch, false) < 0);
+
+ assertTrue("CompareTo", ts1.compareTo(TmfTimestamp.BigBang, false) > 0);
+ assertTrue("CompareTo", ts1.compareTo(TmfTimestamp.BigCrunch, false) < 0);
- assertTrue(ts2.compareTo(TmfTimestamp.BigBang, false) > 0);
- assertTrue(ts2.compareTo(TmfTimestamp.BigCrunch, false) < 0);
+ assertTrue("CompareTo", ts2.compareTo(TmfTimestamp.BigBang, false) > 0);
+ assertTrue("CompareTo", ts2.compareTo(TmfTimestamp.BigCrunch, false) < 0);
- assertTrue(ts3.compareTo(TmfTimestamp.BigBang, false) > 0);
- assertTrue(ts3.compareTo(TmfTimestamp.BigCrunch, false) < 0);
+ assertTrue("CompareTo", ts3.compareTo(TmfTimestamp.BigBang, false) > 0);
+ assertTrue("CompareTo", ts3.compareTo(TmfTimestamp.BigCrunch, false) < 0);
- assertTrue(ts4.compareTo(TmfTimestamp.BigBang, false) > 0);
- assertTrue(ts4.compareTo(TmfTimestamp.BigCrunch, false) < 0);
+ assertTrue("CompareTo", ts4.compareTo(TmfTimestamp.BigBang, false) > 0);
+ assertTrue("CompareTo", ts4.compareTo(TmfTimestamp.BigCrunch, false) < 0);
}
}
/**
* <b><u>TmfTraceEventTest</u></b>
* <p>
- * TODO: Implement me. Please.
+ * Test suite for the TmfTraceEvent class.
*/
public class TmfTraceEventTest extends TestCase {
+ // ------------------------------------------------------------------------
+ // Variables
+ // ------------------------------------------------------------------------
+
private final String fTypeId = "Some type";
private final String fLabel0 = "label1";
private final String fLabel1 = "label2";
private final String fFile = "filename";
private final int fLine = 10;
- // ========================================================================
+ // ------------------------------------------------------------------------
// Housekeeping
- // ========================================================================
+ // ------------------------------------------------------------------------
+ /**
+ * @param name the test name
+ */
public TmfTraceEventTest(String name) {
super(name);
super.tearDown();
}
- // ========================================================================
+ // ------------------------------------------------------------------------
// Constructors
- // ========================================================================
+ // ------------------------------------------------------------------------
public void testTmfTraceEvent() throws Exception {
assertEquals("getTimestamp", fTimestamp1, fEvent1.getTimestamp());
assertEquals("getLineNumber", fLine, event.getLineNumber());
}
+ // ------------------------------------------------------------------------
+ // equals
+ // ------------------------------------------------------------------------
+
+ // ------------------------------------------------------------------------
+ // toString
+ // ------------------------------------------------------------------------
+
}
private TmfTraceStub setupTrace(String path) {
if (fTrace == null) {
try {
- URL location = FileLocator.find(TmfCoreTestPlugin.getPlugin().getBundle(), new Path(path), null);
+ URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(path), null);
File test = new File(FileLocator.toFileURL(location).toURI());
- TmfTraceStub trace = new TmfTraceStub(test.getPath(), 500, true);
- fTrace = trace;
+ fTrace = new TmfTraceStub(test.getPath(), 500, true);
+ fTrace.register();
} catch (URISyntaxException e) {
e.printStackTrace();
} catch (IOException e) {
if (fTraces == null) {
fTraces = new ITmfTrace[1];
try {
- URL location = FileLocator.find(TmfCoreTestPlugin.getPlugin().getBundle(), new Path(path), null);
+ URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(path), null);
File test = new File(FileLocator.toFileURL(location).toURI());
TmfTraceStub trace = new TmfTraceStub(test.getPath(), true);
fTraces[0] = trace;
if (fTrace == null) {
fTrace = new ITmfTrace[2];
try {
- URL location = FileLocator.find(TmfCoreTestPlugin.getPlugin().getBundle(), new Path(path1), null);
+ URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(path1), null);
File test = new File(FileLocator.toFileURL(location).toURI());
TmfTraceStub trace1 = new TmfTraceStub(test.getPath(), true);
fTrace[0] = trace1;
- location = FileLocator.find(TmfCoreTestPlugin.getPlugin().getBundle(), new Path(path2), null);
+ location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(path2), null);
test = new File(FileLocator.toFileURL(location).toURI());
TmfTraceStub trace2 = new TmfTraceStub(test.getPath(), true);
fTrace[1] = trace2;
private TmfTraceStub setupTrace(String path) {
if (fTrace == null) {
try {
- URL location = FileLocator.find(TmfCoreTestPlugin.getPlugin().getBundle(), new Path(path), null);
+ URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(path), null);
File test = new File(FileLocator.toFileURL(location).toURI());
- TmfTraceStub trace = new TmfTraceStub(test.getPath(), 500, true);
- fTrace = trace;
+ fTrace = new TmfTraceStub(test.getPath(), 500, true);
} catch (URISyntaxException e) {
e.printStackTrace();
} catch (IOException e) {
public void testTmfTraceDefault() throws Exception {
TmfTraceStub trace = null;
try {
- URL location = FileLocator.find(TmfCoreTestPlugin.getPlugin().getBundle(), new Path(DIRECTORY + File.separator + TEST_STREAM), null);
+ URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(DIRECTORY + File.separator + TEST_STREAM), null);
File test = new File(FileLocator.toFileURL(location).toURI());
trace = new TmfTraceStub(test.getPath(), true);
} catch (URISyntaxException e) {
public TmfDataProviderStub(String path) throws IOException {
super("TmfDataProviderStub", TmfData.class);
- URL location = FileLocator.find(TmfCoreTestPlugin.getPlugin().getBundle(), new Path(path), null);
+ URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(path), null);
try {
File test = new File(FileLocator.toFileURL(location).toURI());
fTrace = new TmfTraceStub(test.getPath(), true);
public TmfEventProviderStub(String path) throws IOException {
super(TmfEvent.class);
- URL location = FileLocator.find(TmfCoreTestPlugin.getPlugin().getBundle(), new Path(path), null);
+ URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(path), null);
try {
File test = new File(FileLocator.toFileURL(location).toURI());
fTrace = new TmfTraceStub(test.getPath(), true);
super(TmfSyntheticEventStub.class);
}
+ @Override
+ public void register() {
+ super.register();
+ }
+
@Override
public void deregister() {
super.deregister();
return content;
}
- @Override
- public String toString() {
- Object[] fields = getFields();
- String result = "[TmfEventContentStub(";
- for (int i = 0; i < fields.length; i++) {
- result += fields[i].toString() + ",";
- }
- result += ")]";
-
- return result;
- }
+// @Override
+// public String toString() {
+// Object[] fields = getFields();
+// StringBuilder result = new StringBuilder("[TmfEventContent(");
+// for (int i = 0; i < fields.length; i++) {
+// if (i > 0) result.append(",");
+// result.append(fields[i]);
+// }
+// result.append(")]");
+// return result.toString();
+// }
}
/*******************************************************************************
- * Copyright (c) 2009 Ericsson
+ * Copyright (c) 2009, 2010 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
package org.eclipse.linuxtools.tmf;
import org.eclipse.core.runtime.Plugin;
+import org.osgi.framework.BundleContext;
/**
* <b><u>TmfCorePlugin</u></b>
* <p>
- * The activator class controls the plug-in life cycle
+ * The activator class controls the plug-in life cycle. No more than one such
+ * plug-in can exist at any time.
*/
public class TmfCorePlugin extends Plugin {
public static final String PLUGIN_ID = "org.eclipse.linuxtools.tmf";
// The shared instance
- private static TmfCorePlugin plugin;
+ private static TmfCorePlugin fPlugin;
// ------------------------------------------------------------------------
// Constructors
* The constructor
*/
public TmfCorePlugin() {
- plugin = this;
+ setDefault(this);
}
// ------------------------------------------------------------------------
* @return the shared instance
*/
public static TmfCorePlugin getDefault() {
- return plugin;
+ return fPlugin;
}
+ /**
+ * @param plugin the shared instance
+ */
+ private static void setDefault(TmfCorePlugin plugin) {
+ fPlugin = plugin;
+ }
+
+ // ------------------------------------------------------------------------
+ // Operations
+ // ------------------------------------------------------------------------
+
+ @Override
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ setDefault(this);
+ }
+
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ setDefault(null);
+ super.stop(context);
+ }
+
}
@TmfSignalHandler
public void startSynch(TmfStartSynchSignal signal) {
- synchronized(fSynchDepth) {
+ synchronized(this) {
fSynchDepth++;
}
}
@TmfSignalHandler
public void endSynch(TmfEndSynchSignal signal) {
- synchronized(fSynchDepth) {
+ synchronized(this) {
fSynchDepth--;
if (fSynchDepth == 0) {
fireRequests();
* <p>
* This is just an empty base class for the data meant to navigate in the
* framework.
- * <p>
- * TODO: Implement me. Please.
*/
public abstract class TmfData {
* otherwise identical events.
*
* Notice that for performance reasons TmfEvent is NOT immutable. If a copy
- * of the event is needed, use clone().
+ * of the event is needed, use the copy constructor.
*/
-public class TmfEvent extends TmfData implements Cloneable {
+public class TmfEvent extends TmfData {
- // ========================================================================
+ // ------------------------------------------------------------------------
// Attributes
- // ========================================================================
+ // ------------------------------------------------------------------------
protected TmfTimestamp fEffectiveTimestamp;
protected TmfTimestamp fOriginalTimestamp;
// using setContent()
protected TmfEventContent fContent;
- // ========================================================================
+ // ------------------------------------------------------------------------
// Constructors
- // ========================================================================
+ // ------------------------------------------------------------------------
/**
- * @param originalTS
- * @param effectiveTS
- * @param source
- * @param type
- * @param reference
+ * @param originalTS the original timestamp
+ * @param effectiveTS the effective timestamp
+ * @param source the event source (generator)
+ * @param type the event type
+ * @param reference a free-form reference field
*/
public TmfEvent(TmfTimestamp originalTS, TmfTimestamp effectiveTS,
TmfEventSource source, TmfEventType type, TmfEventReference reference)
{
+ if (source == null || type == null || effectiveTS == null) {
+ throw new IllegalArgumentException();
+ }
fOriginalTimestamp = originalTS;
fEffectiveTimestamp = effectiveTS;
fSource = source;
}
/**
- * @param timestamp
- * @param source
- * @param type
- * @param reference
+ * @param timestamp the effective timestamp
+ * @param source the event source (generator)
+ * @param type the event type
+ * @param reference a free-form reference field
*/
public TmfEvent(TmfTimestamp timestamp, TmfEventSource source,
TmfEventType type, TmfEventReference reference)
}
/**
- * Copy constructor (shallow)
+ * Copy constructor
*
- * @param other
+ * @param other the original event
*/
public TmfEvent(TmfEvent other) {
- assert(other != null);
- fOriginalTimestamp = other.fOriginalTimestamp;
- fEffectiveTimestamp = other.fEffectiveTimestamp;
- fSource = other.fSource;
- fType = other.fType;
- fContent = other.fContent;
- fReference = other.fReference;
+ if (other == null)
+ throw new IllegalArgumentException();
+ fOriginalTimestamp = new TmfTimestamp(other.fOriginalTimestamp);
+ fEffectiveTimestamp = new TmfTimestamp(other.fEffectiveTimestamp);
+ fSource = new TmfEventSource(other.fSource);
+ fType = new TmfEventType(other.fType);
+ fContent = new TmfEventContent(other.fContent);
+ fReference = new TmfEventReference(other.fReference);
}
@SuppressWarnings("unused")
private TmfEvent() {
+ throw new AssertionError();
}
- // ========================================================================
+ // ------------------------------------------------------------------------
// Accessors
- // ========================================================================
+ // ------------------------------------------------------------------------
/**
- * @return
+ * @return the effective event timestamp
*/
public TmfTimestamp getTimestamp() {
return fEffectiveTimestamp;
}
/**
- * @return
+ * @return the original event timestamp
*/
public TmfTimestamp getOriginalTimestamp() {
return fOriginalTimestamp;
}
/**
- * @return
+ * @return the event source
*/
public TmfEventSource getSource() {
return fSource;
}
/**
- * @return
+ * @return the event type
*/
public TmfEventType getType() {
return fType;
}
/**
- * @return
- */
- public void setContent(TmfEventContent content) {
- fContent = content;
- }
-
- /**
- * @return
+ * @return the event content
*/
public TmfEventContent getContent() {
return fContent;
}
/**
- * @return
+ * @return the event reference
*/
public TmfEventReference getReference() {
return fReference;
}
- // ========================================================================
- // Operators
- // ========================================================================
+ /**
+ * @param content the new event content
+ */
+ public void setContent(TmfEventContent content) {
+ fContent = content;
+ }
+
+ // ------------------------------------------------------------------------
+ // Object
+ // ------------------------------------------------------------------------
@Override
- public TmfEvent clone() {
- TmfEvent event = new TmfEvent(
- fOriginalTimestamp.clone(),
- fEffectiveTimestamp.clone(),
- fSource.clone(),
- fType.clone(),
- fReference.clone());
- TmfEventContent content = fContent.clone();
- event.setContent(content);
- return event;
- }
+ public int hashCode() {
+ int result = 17;
+ result = 37 * result + fSource.hashCode();
+ result = 37 * result + fType.hashCode();
+ result = 37 * result + fEffectiveTimestamp.hashCode();
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (!(other instanceof TmfEvent))
+ return false;
+ TmfEvent o = (TmfEvent) other;
+ return fEffectiveTimestamp.equals(o.fEffectiveTimestamp) &&
+ fSource.equals(o.fSource) &&
+ fType.equals(o.fType) &&
+ fContent.equals(o.fContent);
+ }
- // TODO: Design a proper format...
@Override
public String toString() {
- return fEffectiveTimestamp.toString();
+ return "[TmfEvent(" + fEffectiveTimestamp + "," + fSource + "," + fType + "," + fContent + ")]";
}
+
}
* <p>
* The event content.
*/
-public class TmfEventContent implements Cloneable {
+public class TmfEventContent {
- // ========================================================================
+ // ------------------------------------------------------------------------
// Attributes
- // ========================================================================
+ // ------------------------------------------------------------------------
- protected TmfEvent fParentEvent = null;
- protected Object fRawContent = null;
- protected Object[] fFields = null;
+ protected TmfEvent fParentEvent;
+ protected Object fRawContent;
+ protected Object[] fFields;
- // ========================================================================
+ // ------------------------------------------------------------------------
// Constructors
- // ========================================================================
+ // ------------------------------------------------------------------------
/**
- * @param parent
- * @param content
+ * @param parent the parent event (owner)
+ * @param content the raw content
*/
public TmfEventContent(TmfEvent parent, Object content) {
fParentEvent = parent;
}
/**
- * @param other
+ * @param other the original event content
*/
public TmfEventContent(TmfEventContent other) {
- assert(other != null);
+ if (other == null)
+ throw new IllegalArgumentException();
fParentEvent = other.fParentEvent;
fRawContent = other.fRawContent;
fFields = other.fFields;
@SuppressWarnings("unused")
private TmfEventContent() {
+ throw new AssertionError();
}
- // ========================================================================
+ // ------------------------------------------------------------------------
// Accessors
- // ========================================================================
+ // ------------------------------------------------------------------------
/**
* @return the parent (containing) event
}
/**
- * @param id
- * @return
+ * @param id the field id
+ * @return the corresponding field
+ * @throws TmfNoSuchFieldException
*/
public Object getField(String id) throws TmfNoSuchFieldException {
if (fFields == null) {
}
/**
- * @param n
- * @return
+ * @param n the field index as per TmfEventType.getLabels()
+ * @return the corresponding field (null if non-existing)
*/
public Object getField(int n) {
if (fFields == null) {
}
if (n >= 0 && n < fFields.length)
return fFields[n];
+
return null;
}
- // ========================================================================
+ // ------------------------------------------------------------------------
// Operators
- // ========================================================================
+ // ------------------------------------------------------------------------
/**
- * Should be overridden (all fields are null by default)
+ * Parse the content into fields. By default, a single field (the raw
+ * content) is returned.
+ * Should be overridden.
*/
protected void parseContent() {
fFields = new Object[1];
fFields[0] = fRawContent;
}
- /**
- * Clone: shallow copy by default; override for deep copy.
- */
- @Override
- public TmfEventContent clone() {
- return new TmfEventContent(this);
+ // ------------------------------------------------------------------------
+ // Object
+ // ------------------------------------------------------------------------
+
+ @Override
+ public int hashCode() {
+ int result = 17;
+ result = 37 * result + ((fParentEvent != null) ? fParentEvent.hashCode() : 0);
+ result = 37 * result + ((fRawContent != null) ? fRawContent.hashCode() : 0);
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (!(other instanceof TmfEventContent))
+ return false;
+ TmfEventContent o = (TmfEventContent) other;
+ return fRawContent.equals(o.fRawContent);
}
@Override
public String toString() {
Object[] fields = getFields();
- String result = "[TmfEventContent(";
+ StringBuilder result = new StringBuilder("[TmfEventContent(");
for (int i = 0; i < fields.length; i++) {
- result += fields[i].toString() + ",";
+ if (i > 0) result.append(",");
+ result.append(fields[i]);
}
- result += ")]";
-
- return result;
+ result.append(")]");
+ return result.toString();
}
}
*
* TODO: Add support for field hierarchy.
*/
-public class TmfEventField implements Cloneable {
+public class TmfEventField {
- // ========================================================================
+ // ------------------------------------------------------------------------
// Attributes
- // ========================================================================
+ // ------------------------------------------------------------------------
private final TmfEventContent fParent;
private final String fFieldId;
private Object fValue;
- // ========================================================================
+ // ------------------------------------------------------------------------
// Constructors
- // ========================================================================
+ // ------------------------------------------------------------------------
+
+ @SuppressWarnings("unused")
+ private TmfEventField() {
+ throw new AssertionError();
+ }
/**
* @param parent
* @param value
*/
public TmfEventField(TmfEventContent parent, String id, Object value) {
+ if (id == null) {
+ throw new IllegalArgumentException();
+ }
fParent = parent;
fFieldId = id;
fValue = value;
* @param other
*/
public TmfEventField(TmfEventField other) {
- assert(other != null);
+ if (other == null)
+ throw new IllegalArgumentException();
fParent = other.fParent;
fFieldId = other.fFieldId;
fValue = other.fValue;
}
- @SuppressWarnings("unused")
- private TmfEventField() {
- fParent = null;
- fFieldId = null;
- fValue = null;
- }
-
- // ========================================================================
+ // ------------------------------------------------------------------------
// Accessors
- // ========================================================================
+ // ------------------------------------------------------------------------
/**
* @return
}
/**
- * @param value
+ * @param value new field value
*/
protected void setValue(Object value) {
fValue = value;
}
- // ========================================================================
- // Operators
- // ========================================================================
+ // ------------------------------------------------------------------------
+ // Object
+ // ------------------------------------------------------------------------
- /**
- * Clone: shallow copy by default; override for deep copy.
- */
@Override
- public TmfEventField clone() {
- return new TmfEventField(this);
+ public int hashCode() {
+ return fFieldId.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (!(other instanceof TmfEventField))
+ return false;
+ TmfEventField o = (TmfEventField) other;
+ return fParent.equals(o.fParent) && fFieldId.equals(o.fFieldId) && fValue.equals(o.fValue);
}
@Override
* <p>
* An application-defined event reference.
*/
-public class TmfEventReference implements Cloneable {
+public class TmfEventReference {
- // ========================================================================
+ // ------------------------------------------------------------------------
// Attributes
- // ========================================================================
+ // ------------------------------------------------------------------------
protected Object fReference;
- // ========================================================================
+ // ------------------------------------------------------------------------
// Constructors
- // ========================================================================
+ // ------------------------------------------------------------------------
/**
- *
+ * The default constructor
*/
public TmfEventReference() {
- this(null);
+ fReference = null;
}
/**
- * @param reference
+ * @param reference the event reference
*/
public TmfEventReference(Object reference) {
fReference = reference;
}
/**
- * @param other
+ * Copy constructor
+ * @param other the original event reference
*/
public TmfEventReference(TmfEventReference other) {
- this((other != null) ? other.fReference : null);
+ if (other == null)
+ throw new IllegalArgumentException();
+ TmfEventReference o = (TmfEventReference) other;
+ fReference = o.fReference;
}
- // ========================================================================
+ // ------------------------------------------------------------------------
// Accessors
- // ========================================================================
+ // ------------------------------------------------------------------------
/**
- * @return
+ * @return the event reference
*/
public Object getReference() {
return fReference;
}
- // ========================================================================
- // Operators
- // ========================================================================
+ // ------------------------------------------------------------------------
+ // Object
+ // ------------------------------------------------------------------------
- @Override
- public TmfEventReference clone() {
- return new TmfEventReference(this);
+ @Override
+ public int hashCode() {
+ return (fReference != null) ? fReference.hashCode() : 0;
}
- @Override
+ @Override
public String toString() {
return "[TmfEventReference(" + ((fReference != null) ? fReference.toString() : "null") + ")]";
}
+ @Override
+ public boolean equals(Object other) {
+ if (!(other instanceof TmfEventReference))
+ return false;
+ TmfEventReference o = (TmfEventReference) other;
+ return fReference.equals(o.fReference);
+ }
+
}
* <p>
* The event source.
*/
-public class TmfEventSource implements Cloneable {
+public class TmfEventSource {
- // ========================================================================
+ // ------------------------------------------------------------------------
// Attributes
- // ========================================================================
+ // ------------------------------------------------------------------------
protected Object fSourceId;
- // ========================================================================
+ // ------------------------------------------------------------------------
// Constructors
- // ========================================================================
+ // ------------------------------------------------------------------------
/**
- *
+ * The default constructor
*/
public TmfEventSource() {
- this(null);
+ fSourceId = null;
}
/**
}
/**
+ * Copy constructor
* @param other
*/
public TmfEventSource(TmfEventSource other) {
- this((other != null) ? other.fSourceId : null);
+ if (other == null)
+ throw new IllegalArgumentException();
+ TmfEventSource o = (TmfEventSource) other;
+ fSourceId = o.fSourceId;
}
- // ========================================================================
+ // ------------------------------------------------------------------------
// Accessors
- // ========================================================================
+ // ------------------------------------------------------------------------
/**
* @return
return fSourceId;
}
- // ========================================================================
- // Operators
- // ========================================================================
+ // ------------------------------------------------------------------------
+ // Object
+ // ------------------------------------------------------------------------
@Override
- public TmfEventSource clone() {
- return new TmfEventSource(this);
- }
+ public int hashCode() {
+ return (fSourceId != null) ? fSourceId.hashCode() : 0;
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (!(other instanceof TmfEventSource))
+ return false;
+ TmfEventSource o = (TmfEventSource) other;
+ return fSourceId.equals(o.fSourceId);
+ }
@Override
public String toString() {
/*******************************************************************************
- * Copyright (c) 2009 Ericsson
+ * Copyright (c) 2009, 2010 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
* <p>
* The event type.
*/
-public class TmfEventType implements Cloneable {
+public class TmfEventType {
- // ========================================================================
+ // ------------------------------------------------------------------------
// Constants
- // ========================================================================
+ // ------------------------------------------------------------------------
public static final String DEFAULT_TYPE_ID = "TMF Default Type";
public static final String[] DEFAULT_LABELS = new String[] { "Content" };
- // ========================================================================
+ // ------------------------------------------------------------------------
// Attributes
- // ========================================================================
+ // ------------------------------------------------------------------------
private final String fTypeId;
private final String[] fFieldLabels;
private final int fNbFields;
private final Map<String, Integer> fFieldMap;
- // ========================================================================
+ // ------------------------------------------------------------------------
// Constructors
- // ========================================================================
+ // ------------------------------------------------------------------------
/**
- *
+ * Default constructor
*/
public TmfEventType() {
this(DEFAULT_TYPE_ID, DEFAULT_LABELS);
* @param format
*/
public TmfEventType(String typeId, String[] labels) {
- assert(typeId != null);
- assert(labels != null);
+ if (typeId == null || labels == null)
+ throw new IllegalArgumentException();
fTypeId = typeId;
fFieldLabels = labels;
fNbFields = fFieldLabels.length;
}
/**
+ * Copy constructor
* @param other
*/
public TmfEventType(TmfEventType other) {
- assert(other != null);
+ if (other == null)
+ throw new IllegalArgumentException();
fTypeId = other.fTypeId;
fFieldLabels = other.fFieldLabels;
fNbFields = other.fNbFields;
fFieldMap = other.fFieldMap;
}
- // ========================================================================
+ // ------------------------------------------------------------------------
// Accessors
- // ========================================================================
+ // ------------------------------------------------------------------------
/**
* @return
/**
* @return
*/
- public String getLabel(int i) {
+ public String getLabel(int i) throws TmfNoSuchFieldException {
if (i >= 0 && i < fNbFields)
return fFieldLabels[i];
- return null;
+ throw new TmfNoSuchFieldException("Bad index (" + i + ")");
}
- // ========================================================================
- // Operators
- // ========================================================================
+ // ------------------------------------------------------------------------
+ // Object
+ // ------------------------------------------------------------------------
- @Override
- public TmfEventType clone() {
- return new TmfEventType(this);
+ @Override
+ public int hashCode() {
+ return fTypeId.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (!(other instanceof TmfEventType))
+ return false;
+ TmfEventType o = (TmfEventType) other;
+ return fTypeId.equals(o.fTypeId);
}
@Override
*/
public class TmfTimeRange {
- // ========================================================================
+ // ------------------------------------------------------------------------
// Constants
- // ========================================================================
+ // ------------------------------------------------------------------------
- public static TmfTimeRange Eternity = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch);
+ public static final TmfTimeRange Eternity = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch);
- // ========================================================================
+ // ------------------------------------------------------------------------
// Attributes
- // ========================================================================
+ // ------------------------------------------------------------------------
private final TmfTimestamp fStartTime;
private final TmfTimestamp fEndTime;
- // ========================================================================
+ // ------------------------------------------------------------------------
// Constructors
- // ========================================================================
+ // ------------------------------------------------------------------------
- /**
- *
- */
@SuppressWarnings("unused")
private TmfTimeRange() {
- fStartTime = null;
- fEndTime = null;
+ throw new AssertionError();
}
/**
* @param endTime
*/
public TmfTimeRange(TmfTimestamp startTime, TmfTimestamp endTime) {
- fStartTime = startTime;
- fEndTime = endTime;
+ if (startTime == null || endTime == null) {
+ throw new IllegalArgumentException();
+ }
+ fStartTime = new TmfTimestamp(startTime);
+ fEndTime = new TmfTimestamp(endTime);
}
/**
+ * Copy constructor
* @param other
*/
public TmfTimeRange(TmfTimeRange other) {
- assert(other != null);
- fStartTime = other.fStartTime;
- fEndTime = other.fEndTime;
- }
-
- @Override
- public boolean equals(Object other) {
- if (other instanceof TmfTimeRange) {
- TmfTimeRange range = (TmfTimeRange) other;
- return range.fStartTime.equals(fStartTime) &&
- range.fEndTime.equals(fEndTime);
+ if (other == null) {
+ throw new IllegalArgumentException();
}
- return false;
- }
+ fStartTime = new TmfTimestamp(other.fStartTime);
+ fEndTime = new TmfTimestamp(other.fEndTime);
+ }
- // ========================================================================
+ // ------------------------------------------------------------------------
// Accessors
- // ========================================================================
+ // ------------------------------------------------------------------------
/**
* @return The time range start time
*/
public TmfTimestamp getStartTime() {
- return fStartTime;
+ return new TmfTimestamp(fStartTime);
}
/**
* @return The time range end time
*/
public TmfTimestamp getEndTime() {
- return fEndTime;
+ return new TmfTimestamp(fEndTime);
}
- // ========================================================================
+ // ------------------------------------------------------------------------
// Predicates
- // ========================================================================
+ // ------------------------------------------------------------------------
/**
* Check if the timestamp is within the time range
* @return
*/
public boolean contains(TmfTimestamp ts) {
- boolean result = (fStartTime.compareTo(ts, true) <= 0) && (fEndTime.compareTo(ts, true) >= 0);
- return result;
+ return (fStartTime.compareTo(ts, true) <= 0) && (fEndTime.compareTo(ts, true) >= 0);
}
- /* (non-Javadoc)
- * @see java.lang.Object#toString()
- */
+ // ------------------------------------------------------------------------
+ // Object
+ // ------------------------------------------------------------------------
+
+ @Override
+ public int hashCode() {
+ int result = 17;
+ result = 37 * result + fStartTime.hashCode();
+ result = 37 * result + fEndTime.hashCode();
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (!(other instanceof TmfTimeRange))
+ return false;
+ TmfTimeRange range = (TmfTimeRange) other;
+ return range.fStartTime.equals(fStartTime) && range.fEndTime.equals(fEndTime);
+ }
+
@Override
public String toString() {
- return "[TmfTimeRange(" + fStartTime.toString() + ":" + fEndTime.toString() + ")]";
+ return "[TmfTimeRange(" + fStartTime + ":" + fEndTime + ")]";
}
}
/*******************************************************************************
- * Copyright (c) 2009 Ericsson
+ * Copyright (c) 2009, 2010 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
package org.eclipse.linuxtools.tmf.event;
-
/**
* <b><u>TmfTimestamp</u></b>
* <p>
* <p>
* It provides a generic timestamp implementation in its most basic form:
* <ul>
- * <li>an unstructured integer value
- * <li>a time scale corresponding to the magnitude of the value wrt some
- * application-specific base unit (e.g. the second)
- * <li>a precision to indicate the error on the value (useful for comparing
+ * <li>timestamp = [value] * 10**[scale] +/- [precision]
+ * </ul>
+ * Where:
+ * <ul>
+ * <li>[value] is an unstructured integer value
+ * <li>[scale] is the magnitude of the value wrt some application-specific
+ * base unit (e.g. the second)
+ * <li>[precision] indicates the error on the value (useful for comparing
* timestamps in different scales). Default: 0.
* </ul>
+ * In short:
+ * <ul>
+ * </ul>
* To allow synchronization of timestamps from different reference clocks,
- * there is a possibility to "adjust" the timestamp both by changing its scale
- * (traces of different scale) and by adding an offset to its value (clock
- * drift between traces).
+ * there is a possibility to "adjust" the timestamp by changing its scale
+ * (traces of different time scale) and/or by adding an offset to its value
+ * (clock drift between traces).
* <p>
* Notice that the adjusted timestamp value could be negative e.g. for events
* that occurred before t0 wrt the reference clock.
- * <p>
- * Finally, notice that timestamps are immutable.
*/
-public class TmfTimestamp implements Cloneable {
+public class TmfTimestamp {
- // ========================================================================
+ // ------------------------------------------------------------------------
// Attributes
- // ========================================================================
+ // ------------------------------------------------------------------------
- protected long fValue; // The timestamp value
+ protected long fValue; // The timestamp raw value
protected byte fScale; // The time scale
protected long fPrecision; // The value precision (tolerance)
- // ========================================================================
+ // ------------------------------------------------------------------------
// Constants
- // ========================================================================
+ // ------------------------------------------------------------------------
// The beginning and end of time
public static final TmfTimestamp BigBang = new TmfTimestamp(Long.MIN_VALUE, Byte.MAX_VALUE, 0);
public static final TmfTimestamp BigCrunch = new TmfTimestamp(Long.MAX_VALUE, Byte.MAX_VALUE, 0);
public static final TmfTimestamp Zero = new TmfTimestamp(0, (byte) 0, 0);
- // ========================================================================
+ // ------------------------------------------------------------------------
// Constructors
- // ========================================================================
+ // ------------------------------------------------------------------------
/**
* Default constructor
* @param other
*/
public TmfTimestamp(TmfTimestamp other) {
- assert(other != null);
+ if (other == null)
+ throw new IllegalArgumentException();
fValue = other.fValue;
fScale = other.fScale;
fPrecision = other.fPrecision;
}
- // ========================================================================
+ // ------------------------------------------------------------------------
// Accessors
- // ========================================================================
+ // ------------------------------------------------------------------------
/**
* @return the timestamp value
return fPrecision;
}
- // ========================================================================
+ // ------------------------------------------------------------------------
// Operators
- // ========================================================================
+ // ------------------------------------------------------------------------
/**
* Return a shifted and scaled timestamp.
* meaning beyond that scale difference and it's not even worth the trouble
* to switch to BigDecimal arithmetics.
*
- * @param offset
- * - the shift value (in the same scale as newScale)
- * @param newScale
- * - the new scale
- * @return The synchronized timestamp
+ * @param offset the shift value (in the same scale as newScale)
+ * @param newScale the new timestamp scale
+ * @return the synchronized timestamp in the new scale
+ * @throws ArithmeticException
*/
+ public TmfTimestamp synchronize(long offset, byte newScale) throws ArithmeticException {
- /*
- * A java <code>long</code> has a maximum of 19 significant digits.
- * (-9,223,372,036,854,775,808 .. +9,223,372,036,854,775,807)
- *
- * It is therefore useless to try to synchronize 2 timestamps whose
- * difference in scale exceeds that value.
- */
- private static int MAX_SCALING = 19;
+ /*
+ * A java <code>long</code> has a maximum of 19 significant digits.
+ * (-9,223,372,036,854,775,808 .. +9,223,372,036,854,775,807)
+ *
+ * It is therefore useless to try to synchronize 2 timestamps whose
+ * difference in scale exceeds that value.
+ */
+ int MAX_SCALING = 19;
- public TmfTimestamp synchronize(long offset, byte newScale) throws ArithmeticException {
- long newValue = fValue;
+ long newValue = fValue;
long newPrecision = fPrecision;
// Determine the scaling factor
* Compute the adjustment, in the reference scale, needed to synchronize
* this timestamp with a reference timestamp.
*
- * @param reference
- * - the reference timestamp to synchronize with
+ * @param reference the reference timestamp to synchronize with
+ * @param scale the scale of the adjustment
* @return the adjustment term in the reference time scale
- * @throws TmfNumericalException
+ * @throws ArithmeticException
*/
- public long getAdjustment(TmfTimestamp reference) throws ArithmeticException {
- TmfTimestamp ts = synchronize(0, reference.fScale);
- return reference.fValue - ts.fValue;
+ public long getAdjustment(TmfTimestamp reference, byte scale) throws ArithmeticException {
+ TmfTimestamp ts1 = synchronize(0, scale);
+ TmfTimestamp ts2 = reference.synchronize(0, scale);
+ return ts2.fValue - ts1.fValue;
}
/**
* Compare with another timestamp
*
- * @param other
- * - the other timestamp
- * @param withinPrecision
- * - indicates if precision is to be take into consideration
- * @return -1: this timestamp is lower
+ * @param other the other timestamp
+ * @param withinPrecision indicates if precision is to be take into consideration
+ * @return -1: this timestamp is lower (i.e. anterior)
* 0: timestamps are equal (within precision if requested)
- * 1: this timestamp is higher
- * @throws TmfNumericalException
+ * 1: this timestamp is higher (i.e. posterior)
*/
public int compareTo(final TmfTimestamp other, boolean withinPrecision) {
return 1;
return 0;
}
- return (fValue == other.fValue) ? 0 : (fValue < other.fValue) ? -1
- : 1;
+ return (fValue == other.fValue) ? 0 : (fValue < other.fValue) ? -1 : 1;
}
// If values have different time scales, adjust to the finest one and
}
}
- @Override
- public TmfTimestamp clone() {
- return new TmfTimestamp(this);
- }
+ // ------------------------------------------------------------------------
+ // Object
+ // ------------------------------------------------------------------------
@Override
+ public int hashCode() {
+ int result = 17;
+ result = 37 * result + (int) (fValue ^ (fValue >>> 32));
+ result = 37 * result + fScale;
+ result = 37 * result + (int) (fPrecision ^ (fPrecision >>> 32));
+ return result;
+ }
+
+ @Override
public boolean equals(Object other) {
- if (other instanceof TmfTimestamp)
- return compareTo((TmfTimestamp) other, false) == 0;
- return super.equals(other);
+ if (!(other instanceof TmfTimestamp))
+ return false;
+ TmfTimestamp o = (TmfTimestamp) other;
+ return compareTo(o, false) == 0;
}
@Override
* <p>
* TODO: Concept is still a bit vague and should be aligned with the CDT
* source lookup service.
+ * TODO: Consider composition instead of extension
*/
public class TmfTraceEvent extends TmfEvent {
- // ========================================================================
+ // ------------------------------------------------------------------------
// Attributes
- // ========================================================================
+ // ------------------------------------------------------------------------
private final String fSourcePath;
private final String fFileName;
private final int fLineNumber;
- // ========================================================================
+ // ------------------------------------------------------------------------
// Constructors
- // ========================================================================
+ // ------------------------------------------------------------------------
/**
* @param originalTS
fLineNumber = other.fLineNumber;
}
- // ========================================================================
+ // ------------------------------------------------------------------------
// Accessors
- // ========================================================================
+ // ------------------------------------------------------------------------
/**
* @return
return fLineNumber;
}
- // ========================================================================
- // Operators
- // ========================================================================
+ // ------------------------------------------------------------------------
+ // Object
+ // ------------------------------------------------------------------------
- // TODO: Deep copy
@Override
- public TmfTraceEvent clone() {
- return new TmfTraceEvent(this);
+ public int hashCode() {
+ int result = super.hashCode();
+ result = 37 * result + ((fSourcePath != null) ? fSourcePath.hashCode() : 0);
+ result = 37 * result + ((fFileName != null) ? fFileName.hashCode() : 0);
+ result = 37 * result + fLineNumber;
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (!(other instanceof TmfTraceEvent)) {
+ return false;
+ }
+// TmfTraceEvent o = (TmfTraceEvent) other;
+ return false;
}
// TODO: Proper format
@Override
public String toString() {
- return null;
+ return "[TmfTraceEvent(" + fSourcePath + "," + fFileName + "," + fLineNumber + ")]";
}
}
// ------------------------------------------------------------------------
// The currently selected experiment
- private static TmfExperiment<?> fCurrentExperiment;
+ private static TmfExperiment<?> fCurrentExperiment = null;
// The experiment ID
private String fExperimentId;
public void deregister() {
fTraces = null;
fCheckpoints.clear();
- fCurrentExperiment= null;
+ setCurrentExperiment(null);
super.deregister();
}
+ private static void setCurrentExperiment(TmfExperiment<?> experiment) {
+ fCurrentExperiment = experiment;
+ }
+
// ------------------------------------------------------------------------
- // ITmfTrace accessors
+ // ITmfTrace
// ------------------------------------------------------------------------
public String getPath() {
}
TmfExperimentContext context = seekLocation(location);
- context.setRank(index * fIndexPageSize);
+ context.setRank((long) index * fIndexPageSize);
// And locate the event
TmfExperimentContext nextEventContext = new TmfExperimentContext(context);
}
TmfExperimentContext context = seekLocation(location);
- long pos = index * fIndexPageSize;
+ long pos = (long) index * fIndexPageSize;
context.setRank(pos);
// And locate the event
*/
public void indexExperiment(boolean waitForCompletion) {
- synchronized(fIndexing) {
+ synchronized(this) {
if (fIndexed || fIndexing) {
// An indexing job is already running but a new request came
// in (probably due to a change in the trace set). The index
@TmfSignalHandler
public void experimentSelected(TmfExperimentSelectedSignal<T> signal) {
- fCurrentExperiment = signal.getExperiment();
+ setCurrentExperiment(signal.getExperiment());
// if (signal.getExperiment() == this) {
// indexExperiment(true);
// }
return fContexts;
}
+ // ------------------------------------------------------------------------
+ // Object
+ // ------------------------------------------------------------------------
+
+ @Override
+ public int hashCode() {
+ int result = 37;
+ result = 17 * result + fTimestamp.hashCode();
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (!(other instanceof TmfExperimentCheckpoint)) {
+ return false;
+ }
+ TmfExperimentCheckpoint o = (TmfExperimentCheckpoint) other;
+ return fTimestamp.equals(o.fTimestamp);
+ }
+
// ------------------------------------------------------------------------
// Comparable
// ------------------------------------------------------------------------
fNbRead = 0;
}
- @Override
- public boolean equals(Object other) {
- if (other instanceof TmfDataRequest<?>) {
- TmfDataRequest<?> request = (TmfDataRequest<?>) other;
- return (request.fDataType == fDataType) &&
- (request.fIndex == fIndex) &&
- (request.fNbRequested == fNbRequested);
- }
- return false;
- }
-
-// @Override
-// public int hashCode() {
-// int hash = 0;
-// return hash;
-// }
-
// ------------------------------------------------------------------------
// Accessors
// ------------------------------------------------------------------------
}
}
+ // ------------------------------------------------------------------------
+ // Object
+ // ------------------------------------------------------------------------
+
+ @Override
+ public int hashCode() {
+ return fRequestId;
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (other instanceof TmfDataRequest<?>) {
+ TmfDataRequest<?> request = (TmfDataRequest<?>) other;
+ return (request.fDataType == fDataType) &&
+ (request.fIndex == fIndex) &&
+ (request.fNbRequested == fNbRequested);
+ }
+ return false;
+ }
+
}
* <p>
* This is a place-holder for the context objects.
*/
-public interface ITmfContext extends Cloneable {
+public interface ITmfContext {
public void setLocation(ITmfLocation<?> location);
public ITmfLocation<?> getLocation();
* <p>
* This is a place-holder for the location objects.
*/
-public interface ITmfLocation<L> extends Cloneable {
+public interface ITmfLocation<L> extends Cloneable{
public void setLocation(L location);
package org.eclipse.linuxtools.tmf.trace;
import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
+import org.eclipse.linuxtools.tmf.experiment.TmfExperimentCheckpoint;
/**
* <b><u>TmfCheckpoint</u></b>
return fLocation;
}
+ // ------------------------------------------------------------------------
+ // Object
+ // ------------------------------------------------------------------------
+
+ @Override
+ public int hashCode() {
+ int result = 37;
+ result = 17 * result + fTimestamp.hashCode();
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (!(other instanceof TmfCheckpoint)) {
+ return false;
+ }
+ TmfCheckpoint o = (TmfCheckpoint) other;
+ return fTimestamp.equals(o.fTimestamp);
+ }
+
// ------------------------------------------------------------------------
// Comparable
// ------------------------------------------------------------------------
* <p>
* Used to handle conflicting, concurrent accesses to the trace.
*/
-public class TmfContext implements ITmfContext {
+public class TmfContext implements ITmfContext, Cloneable {
private ITmfLocation<?> fLocation;
private long fRank;
private IndexingJob job;
// Indicates that an indexing job is already running
- private Boolean fIndexing = false;
+ private Object fIndexingLock = new Object();
+ private boolean fIndexing = false;
private Boolean fIndexed = false;
public void indexTrace(boolean waitForCompletion) {
- synchronized (fIndexing) {
+ synchronized (fIndexingLock) {
if (fIndexed || fIndexing) {
return;
}