1 /*******************************************************************************
2 * Copyright (c) 2009, 2010, 2012 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.core
.tests
.trace
;
15 import junit
.framework
.TestCase
;
17 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimestamp
;
18 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfLocation
;
19 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfLongLocation
;
20 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfTimestampLocation
;
23 * Test suite for the TmfLocation class.
25 @SuppressWarnings({"nls","javadoc"})
26 public class TmfLocationTest
extends TestCase
{
28 // ------------------------------------------------------------------------
30 // ------------------------------------------------------------------------
32 String aString
= "some location";
34 TmfTimestamp aTimestamp
= new TmfTimestamp();
36 TmfStringLocation fLocation1
;
37 TmfStringLocation fLocation2
;
38 TmfLongLocation fLocation3
;
39 TmfTimestampLocation fLocation4
;
41 // ------------------------------------------------------------------------
43 // ------------------------------------------------------------------------
49 public TmfLocationTest(String name
) {
54 protected void setUp() throws Exception
{
56 fLocation1
= new TmfStringLocation((String
) null);
57 fLocation2
= new TmfStringLocation(aString
);
58 fLocation3
= new TmfLongLocation(aLong
);
59 fLocation4
= new TmfTimestampLocation(aTimestamp
);
63 protected void tearDown() throws Exception
{
67 // ------------------------------------------------------------------------
69 // ------------------------------------------------------------------------
71 public void testTmfLocation() {
72 assertNull("TmfLocation", fLocation1
.getLocationInfo());
73 assertEquals("TmfLocation", aString
, fLocation2
.getLocationInfo());
74 assertEquals("TmfLocation", aLong
, fLocation3
.getLocationInfo());
75 assertEquals("TmfLocation", aTimestamp
, fLocation4
.getLocationInfo());
78 public void testTmfLocationCopy() {
79 TmfStringLocation location1
= new TmfStringLocation(fLocation1
);
80 TmfStringLocation location2
= new TmfStringLocation(fLocation2
);
81 TmfLongLocation location3
= new TmfLongLocation(fLocation3
);
82 TmfTimestampLocation location4
= new TmfTimestampLocation(fLocation4
);
84 assertNull("TmfLocation", location1
.getLocationInfo());
85 assertEquals("TmfLocation", aString
, location2
.getLocationInfo());
86 assertEquals("TmfLocation", aLong
, location3
.getLocationInfo());
87 assertEquals("TmfLocation", aTimestamp
, location4
.getLocationInfo());
90 // ------------------------------------------------------------------------
92 // ------------------------------------------------------------------------
94 public void testHashCode() {
95 TmfStringLocation location1
= new TmfStringLocation((String
) null);
96 TmfStringLocation location2
= new TmfStringLocation(aString
);
97 TmfLongLocation location3
= new TmfLongLocation(aLong
);
99 assertTrue("hashCode", fLocation1
.hashCode() == location1
.hashCode());
100 assertTrue("hashCode", fLocation2
.hashCode() == location2
.hashCode());
101 assertTrue("hashCode", fLocation3
.hashCode() == location3
.hashCode());
103 assertTrue("hashCode", fLocation2
.hashCode() != location3
.hashCode());
104 assertTrue("hashCode", fLocation3
.hashCode() != location2
.hashCode());
107 // ------------------------------------------------------------------------
109 // ------------------------------------------------------------------------
111 private static class TmfLocation2
extends TmfStringLocation
{
112 public TmfLocation2(String location
) {
117 public void testEqualsWrongTypes() {
118 ITmfLocation location1
= new TmfStringLocation(aString
);
119 TmfLocation2 location2
= new TmfLocation2(aString
);
121 assertFalse("equals", location1
.equals(location2
));
122 assertFalse("equals", location2
.equals(location1
));
125 public void testEqualsWithNulls() {
126 TmfStringLocation location1
= new TmfStringLocation(aString
);
127 TmfStringLocation location2
= new TmfStringLocation((String
) null);
129 assertFalse("equals", location1
.equals(location2
));
130 assertFalse("equals", location2
.equals(location1
));
133 public void testEqualsReflexivity() {
134 assertTrue("equals", fLocation2
.equals(fLocation2
));
135 assertTrue("equals", fLocation3
.equals(fLocation3
));
137 assertTrue("equals", !fLocation2
.equals(fLocation3
));
138 assertTrue("equals", !fLocation3
.equals(fLocation2
));
141 public void testEqualsSymmetry() {
142 TmfStringLocation location2
= new TmfStringLocation(aString
);
143 TmfLongLocation location3
= new TmfLongLocation(aLong
);
145 assertTrue("equals", location2
.equals(fLocation2
));
146 assertTrue("equals", fLocation2
.equals(location2
));
148 assertTrue("equals", location3
.equals(fLocation3
));
149 assertTrue("equals", fLocation3
.equals(location3
));
152 public void testEqualsTransivity() {
153 TmfStringLocation location1
= new TmfStringLocation(aString
);
154 TmfStringLocation location2
= new TmfStringLocation(aString
);
155 TmfStringLocation location3
= new TmfStringLocation(aString
);
157 assertTrue("equals", location1
.equals(location2
));
158 assertTrue("equals", location2
.equals(location3
));
159 assertTrue("equals", location3
.equals(location1
));
162 public void testEqualsNull() {
163 assertTrue("equals", !fLocation2
.equals(null));
164 assertTrue("equals", !fLocation2
.equals(null));
167 // ------------------------------------------------------------------------
169 // ------------------------------------------------------------------------
171 @SuppressWarnings("hiding")
172 public void testToString() {
173 String aString
= "some location";
175 TmfTimestamp aTimestamp
= new TmfTimestamp();
177 TmfStringLocation location1
= new TmfStringLocation(aString
);
178 TmfLongLocation location2
= new TmfLongLocation(aLong
);
179 TmfTimestampLocation location3
= new TmfTimestampLocation(aTimestamp
);
181 String expected1
= "TmfLocation [fLocation=" + aString
+ "]";
182 String expected2
= "TmfLocation [fLocation=" + aLong
+ "]";
183 String expected3
= "TmfLocation [fLocation=" + aTimestamp
+ "]";
185 assertEquals("toString", expected1
, location1
.toString());
186 assertEquals("toString", expected2
, location2
.toString());
187 assertEquals("toString", expected3
, location3
.toString());