[Bug309042] Improved test code coverage and other mundane issues.
authorFrancois Chouinard <fchouinard@gmail.com>
Tue, 13 Apr 2010 20:10:35 +0000 (20:10 +0000)
committerFrancois Chouinard <fchouinard@gmail.com>
Tue, 13 Apr 2010 20:10:35 +0000 (20:10 +0000)
44 files changed:
org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/tests/event/LttngTimestampTest.java
org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/timeframe/SpinnerGroup.java
org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/timeframe/TimeFrameView.java
org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/event/LttngEventContent.java
org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/trace/LTTngTextTrace.java
org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/tests/AllTmfCoreTests.java
org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/tests/TmfCoreTestPlugin.java
org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/tests/event/TmfEventContentTest.java
org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/tests/event/TmfEventFieldTest.java
org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/tests/event/TmfEventReferenceTest.java
org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/tests/event/TmfEventSourceTest.java
org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/tests/event/TmfEventTest.java
org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/tests/event/TmfEventTypeTest.java
org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/tests/event/TmfTimeRangeTest.java
org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/tests/event/TmfTimestampTest.java
org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/tests/event/TmfTraceEventTest.java
org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/tests/request/TmfCoalescedEventRequestTest.java
org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/tests/trace/TmfExperimentTest.java
org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/tests/trace/TmfMultiTraceExperimentTest.java
org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/tests/trace/TmfTraceTest.java
org.eclipse.linuxtools.tmf.tests/stubs/org/eclipse/linuxtools/tmf/component/TmfDataProviderStub.java
org.eclipse.linuxtools.tmf.tests/stubs/org/eclipse/linuxtools/tmf/component/TmfEventProviderStub.java
org.eclipse.linuxtools.tmf.tests/stubs/org/eclipse/linuxtools/tmf/component/TmfSyntheticEventProviderStub.java
org.eclipse.linuxtools.tmf.tests/stubs/org/eclipse/linuxtools/tmf/event/TmfEventContentStub.java
org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/TmfCorePlugin.java
org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/component/TmfDataProvider.java
org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfData.java
org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfEvent.java
org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfEventContent.java
org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfEventField.java
org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfEventReference.java
org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfEventSource.java
org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfEventType.java
org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfTimeRange.java
org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfTimestamp.java
org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfTraceEvent.java
org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/experiment/TmfExperiment.java
org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/experiment/TmfExperimentCheckpoint.java
org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/request/TmfDataRequest.java
org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/ITmfContext.java
org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/ITmfLocation.java
org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/TmfCheckpoint.java
org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/TmfContext.java
org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/TmfTrace.java

index 3c3f85a9da34152ee539a39b842e98cb95ab9ee7..d8e60136e720273c91b143f8faae8acb826a761c 100644 (file)
@@ -4,6 +4,7 @@ import java.io.File;
 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;
index f8e9c3d605159744272992aa952185d7a80c9545..961e945ad87ccf76e3b9b3c7afd505f3375c87ba 100644 (file)
@@ -157,7 +157,7 @@ public class SpinnerGroup {
     }
 
     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;
     }
 
index 62950724dd4beb77ebb4391745c6f141c3e3bb7d..92979192e03fb263d14702b656df490267c9d26b 100644 (file)
@@ -166,7 +166,8 @@ public class TimeFrameView extends TmfView {
 
         // 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);
@@ -223,8 +224,9 @@ public class TimeFrameView extends TmfView {
     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;
@@ -275,7 +277,7 @@ public class TimeFrameView extends TmfView {
 
         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);
@@ -299,7 +301,7 @@ public class TimeFrameView extends TmfView {
         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);
     }
index 813814ee75271c3cd4851c9cf0a20b995e893960..8530ca17573aeddbe8021f4be9fc3bee3ad97057 100644 (file)
@@ -16,6 +16,7 @@ import java.util.HashMap;
 
 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>
@@ -161,7 +162,11 @@ public class LttngEventContent extends TmfEventContent {
                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 ) {
@@ -184,7 +189,11 @@ public class LttngEventContent extends TmfEventContent {
     @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);
index 5b09ffbdc2f98e8fd239f44bf2d2076cec43e2e3..ec7898b897b066af5e9542d885a0c10d6477ae6b 100644 (file)
@@ -25,6 +25,7 @@ import org.eclipse.linuxtools.lttng.event.LttngEventSource;
 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;
@@ -492,7 +493,11 @@ class TextLttngEventContent extends LttngEventContent {
     @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);
index 5a36462a963e6fecf1f05cdbe89035c0353a620d..080270457bc55b725aeeb8efea04f2980e406ce0 100644 (file)
@@ -27,6 +27,8 @@ public class AllTmfCoreTests {
        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);
 
index 340da826be195eb625d43ef6653bd05357bf72f0..3c607976630db8ee16f5f1a10b8ef7f18c48e9c1 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * 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
@@ -13,6 +13,7 @@
 package org.eclipse.linuxtools.tmf.tests;
 
 import org.eclipse.core.runtime.Plugin;
+import org.osgi.framework.BundleContext;
 
 /**
  * <b><u>TmfTestPlugin</u></b>
@@ -21,36 +22,59 @@ import org.eclipse.core.runtime.Plugin;
  */
 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);
+       }
+
 }
index f534586d1ac0acf3eb031f1096d086a2b688d7bc..39102259034b887f36f5f37febb8028da7afb34a 100644 (file)
@@ -27,10 +27,14 @@ import junit.framework.TestCase;
 /**
  * <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;
@@ -39,13 +43,20 @@ public class TmfEventContentTest extends TestCase {
        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);
@@ -55,11 +66,13 @@ public class TmfEventContentTest extends TestCase {
                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
@@ -72,53 +85,108 @@ public class TmfEventContentTest extends TestCase {
                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");
                } 
@@ -126,7 +194,7 @@ public class TmfEventContentTest extends TestCase {
 
        public void testGetFieldFromIdFailed() {
                try {
-                       fBasicContent.getField("Dummy");
+                       fBasicContent0.getField("Dummy");
                        fail("Found an inexisting field...");
                } catch (TmfNoSuchFieldException e) {
                        // Success
@@ -134,13 +202,18 @@ public class TmfEventContentTest extends TestCase {
        }
 
        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(); 
@@ -171,9 +244,10 @@ public class TmfEventContentTest extends TestCase {
        }
 
        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);
@@ -189,14 +263,4 @@ public class TmfEventContentTest extends TestCase {
                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());
-       }
-
 }
index f2d5362eaafb53c4ecc1edf1a1a3f50d014747a6..2d3f8c1b367e458061d0f9d0542275faf5e0f687 100644 (file)
@@ -12,6 +12,8 @@
 
 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;
@@ -21,24 +23,34 @@ import org.eclipse.linuxtools.tmf.event.TmfEventType;
 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();
@@ -48,6 +60,11 @@ public class TmfEventFieldTest extends TestCase {
                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
@@ -60,15 +77,24 @@ public class TmfEventFieldTest extends TestCase {
                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() {
@@ -79,28 +105,86 @@ public class TmfEventFieldTest extends TestCase {
                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() + ")]";
index 0f6d755006eaa2ce99010fb93448ebcde3bff456..e029e3322e037ada4c0fd1efa68878e80d454214 100644 (file)
 
 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);
        }
@@ -43,9 +56,9 @@ public class TmfEventReferenceTest extends TestCase {
                super.tearDown();
        }
 
-       // ========================================================================
+    // ------------------------------------------------------------------------
        // Constructors
-       // ========================================================================
+    // ------------------------------------------------------------------------
 
        public void testTmfEventReferenceDefault() {
                TmfEventReference reference = new TmfEventReference();
@@ -53,40 +66,77 @@ public class TmfEventReferenceTest extends TestCase {
        }
 
        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());
        }
 
index b06137f462ea5fbdc8ea1f59a339536eab1026b2..3cc39ae51eff0da77c8b443f878ede99aa3508e8 100644 (file)
 
 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);
        }
@@ -43,9 +56,9 @@ public class TmfEventSourceTest extends TestCase {
                super.tearDown();
        }
 
-       // ========================================================================
+       // ------------------------------------------------------------------------
        // Constructors
-       // ========================================================================
+       // ------------------------------------------------------------------------
 
        public void testTmfEventSourceDefault() {
                TmfEventSource source = new TmfEventSource();
@@ -53,41 +66,78 @@ public class TmfEventSourceTest extends TestCase {
        }
 
        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());
        }
 
 }
index ee6abecc83b3ee7d75d5a8e4a0a2e1e2c5b5afd0..6198588e43bd3e7ab78aa12692c25c8b2a952e99 100644 (file)
@@ -12,6 +12,8 @@
 
 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;
@@ -19,15 +21,17 @@ import org.eclipse.linuxtools.tmf.event.TmfEventSource;
 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";
@@ -45,10 +49,13 @@ public class TmfEventTest extends TestCase {
        private final TmfEventContent fContent1;
        private final TmfEventContent fContent2;
        
-       // ========================================================================
+       // ------------------------------------------------------------------------
        // Housekeeping
-       // ========================================================================
+       // ------------------------------------------------------------------------
 
+       /**
+        * @param name the test name
+        */
        public TmfEventTest(String name) {
                super(name);
 
@@ -71,9 +78,9 @@ public class TmfEventTest extends TestCase {
                super.tearDown();
        }
 
-       // ========================================================================
+       // ------------------------------------------------------------------------
        // Constructors
-       // ========================================================================
+       // ------------------------------------------------------------------------
 
        public void testTmfEvent() {
                assertEquals("getTimestamp",         fTimestamp1, fEvent1.getTimestamp());
@@ -93,6 +100,32 @@ public class TmfEventTest extends TestCase {
                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());
@@ -103,36 +136,90 @@ public class TmfEventTest extends TestCase {
                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());
+       }
 
 }
index 1c46c7dc72b3e33ee3e83ae7f8c223c8aecee726..b11460eb172efc6a0b9f71b7cab9f57c42c069cf 100644 (file)
 
 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>
@@ -24,15 +24,29 @@ import junit.framework.TestCase;
  */
 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);
        }
@@ -47,9 +61,9 @@ public class TmfEventTypeTest extends TestCase {
                super.tearDown();
        }
 
-       // ========================================================================
+    // ------------------------------------------------------------------------
        // Constructors
-       // ========================================================================
+    // ------------------------------------------------------------------------
 
        public void testTmfEventTypeDefault() {
                TmfEventType type = new TmfEventType();
@@ -84,6 +98,33 @@ public class TmfEventTypeTest extends TestCase {
                } 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() {
@@ -94,21 +135,59 @@ public class TmfEventTypeTest extends TestCase {
                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 + "]";
index 19d3ba9a723f61d05d4c91a0ae5e99064b17ab81..38e8b1aff0ba1597eb519bf549b7fa671ab41665 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * 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
@@ -20,13 +20,14 @@ import junit.framework.TestCase;
 /**
  * <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);
@@ -42,66 +43,175 @@ public class TmfTimeRangeTest extends TestCase {
                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)));
+       }
+
 }
index a0773ca92654f2b5c7bd586ed7d5a08b3a996c2f..1e7c4de2a7063a620ca0a89b84f43386c251f86c 100644 (file)
 
 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);
        }
@@ -41,36 +62,32 @@ public class TmfTimestampTest extends TestCase {
                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 {
@@ -81,239 +98,294 @@ public class TmfTimestampTest extends TestCase {
                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);
        }
 
 }
index 9f2bc8b3c984e0a2ef3960ac2f7ad43cf9299e2e..989f7bf518b6fdeee47e75831fdca8cb1d080adf 100644 (file)
@@ -24,10 +24,14 @@ import junit.framework.TestCase;
 /**
  * <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";
@@ -49,10 +53,13 @@ public class TmfTraceEventTest extends TestCase {
        private final String fFile = "filename";
        private final int    fLine = 10;
 
-       // ========================================================================
+    // ------------------------------------------------------------------------
        // Housekeeping
-       // ========================================================================
+    // ------------------------------------------------------------------------
 
+       /**
+        * @param name the test name
+        */
        public TmfTraceEventTest(String name) {
                super(name);
 
@@ -75,9 +82,9 @@ public class TmfTraceEventTest extends TestCase {
                super.tearDown();
        }
 
-       // ========================================================================
+    // ------------------------------------------------------------------------
        // Constructors
-       // ========================================================================
+    // ------------------------------------------------------------------------
 
     public void testTmfTraceEvent() throws Exception {
                assertEquals("getTimestamp",         fTimestamp1, fEvent1.getTimestamp());
@@ -116,5 +123,13 @@ public class TmfTraceEventTest extends TestCase {
                assertEquals("getLineNumber",        fLine,       event.getLineNumber());
     }
 
+    // ------------------------------------------------------------------------
+       // equals
+    // ------------------------------------------------------------------------
+
+    // ------------------------------------------------------------------------
+       // toString
+    // ------------------------------------------------------------------------
+
 }
 
index 06aa1ea8c892b54904a57f31a514a3b54ea729e3..43fc8b2b74fcaf21489663407e33086b7fd9d54a 100644 (file)
@@ -54,10 +54,10 @@ public class TmfCoalescedEventRequestTest extends TestCase {
     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) {
index a51ca958b2b19fe1a925023dcb9fd77dddd16065..e9a2711c0f8bd0eaff42f3ec593e3927410e6028 100644 (file)
@@ -60,7 +60,7 @@ public class TmfExperimentTest extends TestCase {
        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;
index 65f582206fbb78482869b07384b1b9ddcd59ee0e..bb355c0609f94a2930fd860d7d92e9f79b892a43 100644 (file)
@@ -59,11 +59,11 @@ public class TmfMultiTraceExperimentTest extends TestCase {
        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;
index 8054828de0c6baefc1e92473da3f94e91bf2b651..d9600f700f9bcf22fcc66a5d05a80b67eced2b8e 100644 (file)
@@ -54,10 +54,9 @@ public class TmfTraceTest extends TestCase {
     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) {
@@ -89,7 +88,7 @@ public class TmfTraceTest extends TestCase {
     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) {
index 4ad1dde4ba01527c86710b4819c58fa4d3ddfbc7..6f8f68ee46d30352169dda3bd5977588ea02e796 100644 (file)
@@ -41,7 +41,7 @@ public class TmfDataProviderStub extends TmfDataProvider<TmfData> {
 
     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);
index 1e3b080f55c67f3a80e3201c7176511811474163..ddf092acbfead8b67b9ecc3366eed123ef1d9838 100644 (file)
@@ -41,7 +41,7 @@ public class TmfEventProviderStub extends TmfEventProvider<TmfEvent> {
 
     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);
index ad7e38edde34cd120adf6391201fc84c9ace961e..4e811268d0215667434ad57e25168dba3e2e216e 100644 (file)
@@ -34,6 +34,11 @@ public class TmfSyntheticEventProviderStub extends TmfEventProvider<TmfSynthetic
                super(TmfSyntheticEventStub.class);
        }
 
+    @Override
+    public void register() {
+       super.register();
+    }
+    
     @Override
     public void deregister() {
        super.deregister();
index b56485bbc64c056776b24aa0efac3e9675edb01b..91dc38af1c2345e601ffccaed9a9aec3a5ffcb69 100644 (file)
@@ -45,15 +45,15 @@ public class TmfEventContentStub extends TmfEventContent {
                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();
+//    }
 }
index dbed10b9b490a2245494bed4a37fddb92aad16d6..5b207aaaf277cfe4d5109763bb827055885e77dd 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * 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 {
 
@@ -29,7 +31,7 @@ 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
@@ -39,7 +41,7 @@ public class TmfCorePlugin extends Plugin {
         * The constructor
         */
        public TmfCorePlugin() {
-               plugin = this;
+               setDefault(this);
        }
 
        // ------------------------------------------------------------------------
@@ -50,7 +52,30 @@ public class TmfCorePlugin extends Plugin {
      * @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);
+       }
+
 }
index 37ce86700ad46abe7da1f6240e23ce1c876613a8..745f5b45ae5e7254fc71bb45ed247b5ff73d0120 100644 (file)
@@ -263,14 +263,14 @@ public abstract class TmfDataProvider<T extends TmfData> extends TmfComponent im
 
        @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();
index b63d9bdeafbadfc1e5bbd454f32c9ef8bf83ea77..000cec2f6737f6b9c10c60f1c0c812c5e2f81ecb 100644 (file)
@@ -17,8 +17,6 @@ package org.eclipse.linuxtools.tmf.event;
  * <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 {
 
index 934d42e642540764cb33ddc30e3a1dd88a050bbe..695826292729e34aa0148a8558e741b57bee043d 100644 (file)
@@ -27,13 +27,13 @@ package org.eclipse.linuxtools.tmf.event;
  * 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;
@@ -45,20 +45,23 @@ public class TmfEvent extends TmfData implements Cloneable {
        // 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;
@@ -67,10 +70,10 @@ public class TmfEvent extends TmfData implements Cloneable {
        }
 
        /**
-        * @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)
@@ -79,97 +82,106 @@ public class TmfEvent extends TmfData implements Cloneable {
        }
 
        /**
-        * 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 + ")]";
        }
+
 }
index 1a97c6cb524bc77c133685dc195a50c0b5665b5e..662ad85fb894e8233e6270eed8bd92cd31a576c8 100644 (file)
@@ -18,23 +18,23 @@ package org.eclipse.linuxtools.tmf.event;
  * <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;
@@ -42,10 +42,11 @@ public class TmfEventContent implements Cloneable {
        }
 
     /**
-     * @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;
@@ -53,11 +54,12 @@ public class TmfEventContent implements Cloneable {
 
     @SuppressWarnings("unused")
        private TmfEventContent() {
+               throw new AssertionError();
     }
 
-    // ========================================================================
+    // ------------------------------------------------------------------------
     // Accessors
-    // ========================================================================
+    // ------------------------------------------------------------------------
 
        /**
         * @return the parent (containing) event
@@ -93,8 +95,9 @@ public class TmfEventContent implements Cloneable {
        }
 
        /**
-        * @param id
-        * @return
+        * @param id the field id
+        * @return the corresponding field
+        * @throws TmfNoSuchFieldException
         */
        public Object getField(String id) throws TmfNoSuchFieldException {
                if (fFields == null) {
@@ -104,8 +107,8 @@ public class TmfEventContent implements Cloneable {
        }
 
        /**
-        * @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) {
@@ -113,39 +116,54 @@ public class TmfEventContent implements Cloneable {
                }
                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();
     }
 
 }
index 9cbd789af3e0e965feb53fd63139ac52db0ec245..65354750210cc259b3acf01702389912bb6840f6 100644 (file)
@@ -19,19 +19,24 @@ package org.eclipse.linuxtools.tmf.event;
  * 
  * 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
@@ -39,6 +44,9 @@ public class TmfEventField implements Cloneable {
      * @param value
      */
     public TmfEventField(TmfEventContent parent, String id, Object value) {
+       if (id == null) {
+               throw new IllegalArgumentException();
+       }
        fParent  = parent;
        fFieldId = id;
         fValue   = value;
@@ -48,22 +56,16 @@ public class TmfEventField implements Cloneable {
      * @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
@@ -87,22 +89,27 @@ public class TmfEventField implements Cloneable {
     }
 
     /**
-     * @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
index 40a2debec8688e51fa89c0b1ed21f217595be464..39b319e4dcf321cd504df74f3f8a68fcc96a2b64 100644 (file)
@@ -17,62 +17,74 @@ package org.eclipse.linuxtools.tmf.event;
  * <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);
+    }
+
 }
index 4d6cb2437b72e0eb92ab40deeb0685bee4996d73..3a351fbc4f0d6656a7fb2f239702a65da76935ca 100644 (file)
@@ -17,23 +17,23 @@ package org.eclipse.linuxtools.tmf.event;
  * <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;
     }
 
        /**
@@ -44,15 +44,19 @@ public class TmfEventSource implements Cloneable {
        }
 
        /**
+        * 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
@@ -61,14 +65,22 @@ public class TmfEventSource implements Cloneable {
                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() {
index 467910c76a908f611bca994e83c8098ede0fd33b..fa998eca2d61b8ce9b56144595cd83708b5e3049 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * 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
@@ -20,30 +20,30 @@ import java.util.Map;
  * <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);
@@ -54,8 +54,8 @@ public class TmfEventType implements Cloneable {
         * @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;
@@ -66,19 +66,21 @@ public class TmfEventType implements Cloneable {
        }
 
        /**
+        * 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
@@ -114,19 +116,27 @@ public class TmfEventType implements Cloneable {
        /**
         * @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
index 9c634bae027b82594f58efceaf6268ef82c42cfc..014bd828e661b4cf822d626fb9ba8d23dec20200 100644 (file)
@@ -19,30 +19,26 @@ package org.eclipse.linuxtools.tmf.event;
  */
 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();
        }
 
        /**
@@ -50,50 +46,46 @@ public class TmfTimeRange {
         * @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
@@ -102,16 +94,32 @@ public class TmfTimeRange {
         * @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 + ")]";
        }
 
 }
index 9172a5eeb959f2c689c86548751d654f28054475..3463a6917daf076eb91ce21e3691fe82e953aaa5 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * 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
@@ -12,7 +12,6 @@
 
 package org.eclipse.linuxtools.tmf.event;
 
-
 /**
  * <b><u>TmfTimestamp</u></b>
  * <p>
@@ -20,44 +19,49 @@ package org.eclipse.linuxtools.tmf.event;
  * <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
@@ -102,15 +106,16 @@ public class TmfTimestamp implements Cloneable {
      * @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
@@ -133,9 +138,9 @@ public class TmfTimestamp implements Cloneable {
         return fPrecision;
     }
 
-    // ========================================================================
+       // ------------------------------------------------------------------------
     // Operators
-    // ========================================================================
+       // ------------------------------------------------------------------------
 
     /**
      * Return a shifted and scaled timestamp.
@@ -145,24 +150,23 @@ public class TmfTimestamp implements Cloneable {
      * 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
@@ -193,27 +197,25 @@ public class TmfTimestamp implements Cloneable {
      * 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) {
 
@@ -226,8 +228,7 @@ public class TmfTimestamp implements Cloneable {
                     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
@@ -254,16 +255,25 @@ public class TmfTimestamp implements Cloneable {
         }
     }
 
-       @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
index f030752f892a2008831bf818328051dda8bf07da..feb8e3857fa4a163fc83569e33531984cf8fa9b5 100644 (file)
@@ -21,20 +21,21 @@ package org.eclipse.linuxtools.tmf.event;
  * <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
@@ -85,9 +86,9 @@ public class TmfTraceEvent extends TmfEvent {
                fLineNumber = other.fLineNumber;
        }
 
-    // ========================================================================
+    // ------------------------------------------------------------------------
     // Accessors
-    // ========================================================================
+    // ------------------------------------------------------------------------
 
     /**
      * @return
@@ -110,20 +111,32 @@ public class TmfTraceEvent extends TmfEvent {
         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 + ")]";
     }
 
 }
index 07ace5a356e96447d659cd06d8f406e74903a078..1e5ef008d7313417be86befd325010a6a411ed46 100644 (file)
@@ -48,7 +48,7 @@ public class TmfExperiment<T extends TmfEvent> extends TmfEventProvider<T> imple
     // ------------------------------------------------------------------------
 
        // The currently selected experiment
-    private static TmfExperiment<?> fCurrentExperiment;
+    private static TmfExperiment<?> fCurrentExperiment = null;
 
        // The experiment ID
     private String fExperimentId;
@@ -117,12 +117,16 @@ public class TmfExperiment<T extends TmfEvent> extends TmfEventProvider<T> imple
        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() {
@@ -323,7 +327,7 @@ public class TmfExperiment<T extends TmfEvent> extends TmfEventProvider<T> imple
         }
 
         TmfExperimentContext context = seekLocation(location);
-        context.setRank(index * fIndexPageSize);
+        context.setRank((long) index * fIndexPageSize);
 
         // And locate the event
         TmfExperimentContext nextEventContext = new TmfExperimentContext(context);
@@ -359,7 +363,7 @@ public class TmfExperiment<T extends TmfEvent> extends TmfEventProvider<T> imple
         }
 
         TmfExperimentContext context = seekLocation(location);
-        long pos = index * fIndexPageSize;
+        long pos = (long) index * fIndexPageSize;
         context.setRank(pos);
 
         // And locate the event
@@ -501,7 +505,7 @@ public class TmfExperiment<T extends TmfEvent> extends TmfEventProvider<T> imple
         */
        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
@@ -614,7 +618,7 @@ public class TmfExperiment<T extends TmfEvent> extends TmfEventProvider<T> imple
 
     @TmfSignalHandler
     public void experimentSelected(TmfExperimentSelectedSignal<T> signal) {
-               fCurrentExperiment = signal.getExperiment();
+               setCurrentExperiment(signal.getExperiment());
 //     if (signal.getExperiment() == this) {
 //             indexExperiment(true);
 //     }
index 926bb7398705ba938e33f0e7d2e9609f2d10c4cc..f93ccb4f19e86d71a2eb586305b9fc38fb1bba69 100644 (file)
@@ -60,6 +60,26 @@ public class TmfExperimentCheckpoint implements Comparable<TmfExperimentCheckpoi
         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
     // ------------------------------------------------------------------------
index a96dc6367b28b5f11662b5cd9d5ec65b0cc1b2a5..fbf69f860b9b2c98addb00b66158a7915c13bb43 100644 (file)
@@ -138,23 +138,6 @@ public abstract class TmfDataRequest<T extends TmfData> implements ITmfDataReque
        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
     // ------------------------------------------------------------------------
@@ -339,4 +322,24 @@ public abstract class TmfDataRequest<T extends TmfData> implements ITmfDataReque
         }
     }
 
+    // ------------------------------------------------------------------------
+    // 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;
+    }
+
 }
index 880f8c6e9f69f7c2f83a022af9e2dada3add86fa..cd2f67595c654a627d43b939b6dbe51ef0c30942 100644 (file)
@@ -17,7 +17,7 @@ package org.eclipse.linuxtools.tmf.trace;
  * <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();
index 20b20caf5e400be810c05df4bbf4591f513ba319..e7ed3cc9972d86e3dc94f13458fc69c84497deaf 100644 (file)
@@ -17,7 +17,7 @@ package org.eclipse.linuxtools.tmf.trace;
  * <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);
 
index f37cb28d57f2b4fc710a178918e0e222c52e3413..4ae6870ddd5f448cb9d98c57583b9b22a26f8c94 100644 (file)
@@ -13,6 +13,7 @@
 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>
@@ -59,6 +60,26 @@ public class TmfCheckpoint implements Comparable<TmfCheckpoint> {
         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
     // ------------------------------------------------------------------------
index d495182b474cda620ce45f779bb89d23d59b5975..86c587c3551e6550f1749704e3ac392bfb7e0186 100644 (file)
@@ -22,7 +22,7 @@ package org.eclipse.linuxtools.tmf.trace;
  * <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;
index c3799c9888f38c9662a8e42e9d4331ad419ad837..378dca1b7a4c7127943ca38756cbbf23e4cbdfa0 100644 (file)
@@ -350,11 +350,12 @@ public abstract class TmfTrace<T extends TmfEvent> extends TmfEventProvider<T> i
        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;
                }
This page took 0.092032 seconds and 5 git commands to generate.