lttng: More luna annotation updates
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core.tests / src / org / eclipse / linuxtools / tmf / core / tests / trace / TmfLocationTest.java
index dc47e9d8a317c86099226905154a53c53ceb8ee9..82ff2679e8e78f40c6181263ac6849e6d0ca8ec1 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2009, 2010, 2012 Ericsson
+ * Copyright (c) 2009, 2013 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
  *
  * Contributors:
  *   Francois Chouinard - Initial API and implementation
+ *   Alexandre Montplaisir - Port to JUnit4
+ *   Patrick Tasse - Add tests for TmfExperimentLocation
  *******************************************************************************/
 
 package org.eclipse.linuxtools.tmf.core.tests.trace;
 
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
 
-import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
+import org.eclipse.linuxtools.internal.tmf.core.trace.TmfExperimentLocation;
+import org.eclipse.linuxtools.internal.tmf.core.trace.TmfLocationArray;
+import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
 import org.eclipse.linuxtools.tmf.core.trace.TmfLongLocation;
 import org.eclipse.linuxtools.tmf.core.trace.TmfTimestampLocation;
+import org.junit.Before;
+import org.junit.Test;
 
 /**
  * Test suite for the TmfLocation class.
  */
-@SuppressWarnings({"nls","javadoc"})
-public class TmfLocationTest extends TestCase {
+@SuppressWarnings("javadoc")
+public class TmfLocationTest {
 
     // ------------------------------------------------------------------------
     // Variables
     // ------------------------------------------------------------------------
 
-    String aString = "some location";
-    Long aLong = 12345L;
-    TmfTimestamp aTimestamp = new TmfTimestamp();
+    private String aString = "some location";
+    private Long aLong = 12345L;
+    private TmfTimestamp aTimestamp = new TmfTimestamp();
+    private TmfLocationArray aLocationArray;
 
-    TmfStringLocation fLocation1;
-    TmfStringLocation fLocation2;
-    TmfLongLocation fLocation3;
-    TmfTimestampLocation fLocation4;
+    private TmfStringLocation fLocation1;
+    private TmfStringLocation fLocation2;
+    private TmfLongLocation fLocation3;
+    private TmfTimestampLocation fLocation4;
+    private TmfExperimentLocation fExpLocation;
 
     // ------------------------------------------------------------------------
     // Housekeeping
     // ------------------------------------------------------------------------
 
-    /**
-     * @param name
-     *            the test name
-     */
-    public TmfLocationTest(String name) {
-        super(name);
-    }
-
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
+    @Before
+    public void setUp() {
         fLocation1 = new TmfStringLocation((String) null);
         fLocation2 = new TmfStringLocation(aString);
         fLocation3 = new TmfLongLocation(aLong);
         fLocation4 = new TmfTimestampLocation(aTimestamp);
-    }
-
-    @Override
-    protected void tearDown() throws Exception {
-        super.tearDown();
+        aLocationArray = new TmfLocationArray(
+                new ITmfLocation[] { fLocation1, fLocation2, fLocation3, fLocation4 },
+                new long[] { 1, 2, 3, 4 }
+                );
+        fExpLocation = new TmfExperimentLocation(aLocationArray);
     }
 
     // ------------------------------------------------------------------------
     // Constructors
     // ------------------------------------------------------------------------
 
+    @Test
     public void testTmfLocation() {
         assertNull("TmfLocation", fLocation1.getLocationInfo());
         assertEquals("TmfLocation", aString, fLocation2.getLocationInfo());
         assertEquals("TmfLocation", aLong, fLocation3.getLocationInfo());
         assertEquals("TmfLocation", aTimestamp, fLocation4.getLocationInfo());
+        assertEquals("TmfLocation", aLocationArray, fExpLocation.getLocationInfo());
     }
 
+    @Test
     public void testTmfLocationCopy() {
         TmfStringLocation location1 = new TmfStringLocation(fLocation1);
         TmfStringLocation location2 = new TmfStringLocation(fLocation2);
         TmfLongLocation location3 = new TmfLongLocation(fLocation3);
         TmfTimestampLocation location4 = new TmfTimestampLocation(fLocation4);
+        TmfExperimentLocation expLocation = new TmfExperimentLocation(fExpLocation);
 
         assertNull("TmfLocation", location1.getLocationInfo());
         assertEquals("TmfLocation", aString, location2.getLocationInfo());
         assertEquals("TmfLocation", aLong, location3.getLocationInfo());
         assertEquals("TmfLocation", aTimestamp, location4.getLocationInfo());
+        assertEquals("TmfLocation", aLocationArray, expLocation.getLocationInfo());
     }
 
     // ------------------------------------------------------------------------
     // hashCode
     // ------------------------------------------------------------------------
 
+    @Test
     public void testHashCode() {
         TmfStringLocation location1 = new TmfStringLocation((String) null);
         TmfStringLocation location2 = new TmfStringLocation(aString);
         TmfLongLocation location3 = new TmfLongLocation(aLong);
+        TmfExperimentLocation expLocation = new TmfExperimentLocation(fExpLocation);
+        TmfLocationArray locationArray1 = new TmfLocationArray(aLocationArray, 3, fLocation4, 5);
+        TmfExperimentLocation expLocation1 = new TmfExperimentLocation(locationArray1);
+        TmfLocationArray locationArray2 = new TmfLocationArray(aLocationArray, 3, fLocation3, 4);
+        TmfExperimentLocation expLocation2 = new TmfExperimentLocation(locationArray2);
+        TmfLocationArray locationArray3 = new TmfLocationArray(
+                new ITmfLocation[] { fLocation1, fLocation2, fLocation3 },
+                new long[] { 1, 2, 3 }
+                );
+        TmfExperimentLocation expLocation3 = new TmfExperimentLocation(locationArray3);
 
         assertTrue("hashCode", fLocation1.hashCode() == location1.hashCode());
         assertTrue("hashCode", fLocation2.hashCode() == location2.hashCode());
         assertTrue("hashCode", fLocation3.hashCode() == location3.hashCode());
+        assertTrue("hashCode", fExpLocation.hashCode() == expLocation.hashCode());
 
         assertTrue("hashCode", fLocation2.hashCode() != location3.hashCode());
         assertTrue("hashCode", fLocation3.hashCode() != location2.hashCode());
+        assertTrue("hashCode", fExpLocation.hashCode() != expLocation1.hashCode());
+        assertTrue("hashCode", fExpLocation.hashCode() != expLocation2.hashCode());
+        assertTrue("hashCode", fExpLocation.hashCode() != expLocation3.hashCode());
     }
 
     // ------------------------------------------------------------------------
@@ -114,6 +136,7 @@ public class TmfLocationTest extends TestCase {
         }
     }
 
+    @Test
     public void testEqualsWrongTypes() {
         ITmfLocation location1 = new TmfStringLocation(aString);
         TmfLocation2 location2 = new TmfLocation2(aString);
@@ -122,6 +145,7 @@ public class TmfLocationTest extends TestCase {
         assertFalse("equals", location2.equals(location1));
     }
 
+    @Test
     public void testEqualsWithNulls() {
         TmfStringLocation location1 = new TmfStringLocation(aString);
         TmfStringLocation location2 = new TmfStringLocation((String) null);
@@ -130,61 +154,95 @@ public class TmfLocationTest extends TestCase {
         assertFalse("equals", location2.equals(location1));
     }
 
+    @Test
     public void testEqualsReflexivity() {
         assertTrue("equals", fLocation2.equals(fLocation2));
         assertTrue("equals", fLocation3.equals(fLocation3));
+        assertTrue("equals", fExpLocation.equals(fExpLocation));
 
         assertTrue("equals", !fLocation2.equals(fLocation3));
         assertTrue("equals", !fLocation3.equals(fLocation2));
+        TmfLocationArray locationArray1 = new TmfLocationArray(aLocationArray, 3, fLocation4, 5);
+        TmfExperimentLocation expLocation1 = new TmfExperimentLocation(locationArray1);
+        TmfLocationArray locationArray2 = new TmfLocationArray(aLocationArray, 3, fLocation3, 4);
+        TmfExperimentLocation expLocation2 = new TmfExperimentLocation(locationArray2);
+        TmfLocationArray locationArray3 = new TmfLocationArray(
+                new ITmfLocation[] { fLocation1, fLocation2, fLocation3 },
+                new long[] { 1, 2, 3 }
+                );
+        TmfExperimentLocation expLocation3 = new TmfExperimentLocation(locationArray3);
+        assertTrue("equals", !fExpLocation.equals(expLocation1));
+        assertTrue("equals", !expLocation1.equals(fExpLocation));
+        assertTrue("equals", !fExpLocation.equals(expLocation2));
+        assertTrue("equals", !expLocation2.equals(fExpLocation));
+        assertTrue("equals", !fExpLocation.equals(expLocation3));
+        assertTrue("equals", !expLocation3.equals(fExpLocation));
     }
 
+    @Test
     public void testEqualsSymmetry() {
         TmfStringLocation location2 = new TmfStringLocation(aString);
         TmfLongLocation location3 = new TmfLongLocation(aLong);
+        TmfExperimentLocation expLocation = new TmfExperimentLocation(fExpLocation);
 
         assertTrue("equals", location2.equals(fLocation2));
         assertTrue("equals", fLocation2.equals(location2));
 
         assertTrue("equals", location3.equals(fLocation3));
         assertTrue("equals", fLocation3.equals(location3));
+
+        assertTrue("equals", expLocation.equals(fExpLocation));
+        assertTrue("equals", fExpLocation.equals(expLocation));
     }
 
+    @Test
     public void testEqualsTransivity() {
         TmfStringLocation location1 = new TmfStringLocation(aString);
         TmfStringLocation location2 = new TmfStringLocation(aString);
         TmfStringLocation location3 = new TmfStringLocation(aString);
+        TmfExperimentLocation expLocation1 = new TmfExperimentLocation(aLocationArray);
+        TmfExperimentLocation expLocation2 = new TmfExperimentLocation(aLocationArray);
+        TmfExperimentLocation expLocation3 = new TmfExperimentLocation(aLocationArray);
 
         assertTrue("equals", location1.equals(location2));
         assertTrue("equals", location2.equals(location3));
         assertTrue("equals", location3.equals(location1));
+        assertTrue("equals", expLocation1.equals(expLocation2));
+        assertTrue("equals", expLocation2.equals(expLocation3));
+        assertTrue("equals", expLocation3.equals(expLocation1));
     }
 
+    @Test
     public void testEqualsNull() {
         assertTrue("equals", !fLocation2.equals(null));
         assertTrue("equals", !fLocation2.equals(null));
+        assertTrue("equals", !fExpLocation.equals(null));
     }
 
     // ------------------------------------------------------------------------
     // toString
     // ------------------------------------------------------------------------
 
-    @SuppressWarnings("hiding")
+    @Test
     public void testToString() {
-        String aString = "some location";
-        Long aLong = 12345L;
-        TmfTimestamp aTimestamp = new TmfTimestamp();
+        String str = "some location";
+        Long lng = 12345L;
+        TmfTimestamp ts = new TmfTimestamp();
 
-        TmfStringLocation location1 = new TmfStringLocation(aString);
-        TmfLongLocation location2 = new TmfLongLocation(aLong);
-        TmfTimestampLocation location3 = new TmfTimestampLocation(aTimestamp);
+        TmfStringLocation location1 = new TmfStringLocation(str);
+        TmfLongLocation location2 = new TmfLongLocation(lng);
+        TmfTimestampLocation location3 = new TmfTimestampLocation(ts);
+        TmfExperimentLocation expLocation = new TmfExperimentLocation(aLocationArray);
 
-        String expected1 = "TmfLocation [fLocation=" + aString + "]";
-        String expected2 = "TmfLocation [fLocation=" + aLong + "]";
-        String expected3 = "TmfLocation [fLocation=" + aTimestamp + "]";
+        String expected1 = "TmfStringLocation [fLocationInfo=" + str + "]";
+        String expected2 = "TmfLongLocation [fLocationInfo=" + lng + "]";
+        String expected3 = "TmfTimestampLocation [fLocationInfo=" + ts + "]";
+        String expected4 = "TmfExperimentLocation [" + aLocationArray + "]";
 
         assertEquals("toString", expected1, location1.toString());
         assertEquals("toString", expected2, location2.toString());
         assertEquals("toString", expected3, location3.toString());
+        assertEquals("toString", expected4, expLocation.toString());
     }
 
 }
This page took 0.026395 seconds and 5 git commands to generate.