Merge branch 'master' into lttng-kepler
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core.tests / src / org / eclipse / linuxtools / tmf / core / tests / trace / TmfLocationTest.java
1 /*******************************************************************************
2 * Copyright (c) 2009, 2010, 2012 Ericsson
3 *
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
8 *
9 * Contributors:
10 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.tmf.core.tests.trace;
14
15 import junit.framework.TestCase;
16
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;
21
22 /**
23 * Test suite for the TmfLocation class.
24 */
25 @SuppressWarnings({"nls","javadoc"})
26 public class TmfLocationTest extends TestCase {
27
28 // ------------------------------------------------------------------------
29 // Variables
30 // ------------------------------------------------------------------------
31
32 String aString = "some location";
33 Long aLong = 12345L;
34 TmfTimestamp aTimestamp = new TmfTimestamp();
35
36 TmfStringLocation fLocation1;
37 TmfStringLocation fLocation2;
38 TmfLongLocation fLocation3;
39 TmfTimestampLocation fLocation4;
40
41 // ------------------------------------------------------------------------
42 // Housekeeping
43 // ------------------------------------------------------------------------
44
45 /**
46 * @param name
47 * the test name
48 */
49 public TmfLocationTest(String name) {
50 super(name);
51 }
52
53 @Override
54 protected void setUp() throws Exception {
55 super.setUp();
56 fLocation1 = new TmfStringLocation((String) null);
57 fLocation2 = new TmfStringLocation(aString);
58 fLocation3 = new TmfLongLocation(aLong);
59 fLocation4 = new TmfTimestampLocation(aTimestamp);
60 }
61
62 @Override
63 protected void tearDown() throws Exception {
64 super.tearDown();
65 }
66
67 // ------------------------------------------------------------------------
68 // Constructors
69 // ------------------------------------------------------------------------
70
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());
76 }
77
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);
83
84 assertNull("TmfLocation", location1.getLocationInfo());
85 assertEquals("TmfLocation", aString, location2.getLocationInfo());
86 assertEquals("TmfLocation", aLong, location3.getLocationInfo());
87 assertEquals("TmfLocation", aTimestamp, location4.getLocationInfo());
88 }
89
90 // ------------------------------------------------------------------------
91 // hashCode
92 // ------------------------------------------------------------------------
93
94 public void testHashCode() {
95 TmfStringLocation location1 = new TmfStringLocation((String) null);
96 TmfStringLocation location2 = new TmfStringLocation(aString);
97 TmfLongLocation location3 = new TmfLongLocation(aLong);
98
99 assertTrue("hashCode", fLocation1.hashCode() == location1.hashCode());
100 assertTrue("hashCode", fLocation2.hashCode() == location2.hashCode());
101 assertTrue("hashCode", fLocation3.hashCode() == location3.hashCode());
102
103 assertTrue("hashCode", fLocation2.hashCode() != location3.hashCode());
104 assertTrue("hashCode", fLocation3.hashCode() != location2.hashCode());
105 }
106
107 // ------------------------------------------------------------------------
108 // toEquals
109 // ------------------------------------------------------------------------
110
111 private static class TmfLocation2 extends TmfStringLocation {
112 public TmfLocation2(String location) {
113 super(location);
114 }
115 }
116
117 public void testEqualsWrongTypes() {
118 ITmfLocation location1 = new TmfStringLocation(aString);
119 TmfLocation2 location2 = new TmfLocation2(aString);
120
121 assertFalse("equals", location1.equals(location2));
122 assertFalse("equals", location2.equals(location1));
123 }
124
125 public void testEqualsWithNulls() {
126 TmfStringLocation location1 = new TmfStringLocation(aString);
127 TmfStringLocation location2 = new TmfStringLocation((String) null);
128
129 assertFalse("equals", location1.equals(location2));
130 assertFalse("equals", location2.equals(location1));
131 }
132
133 public void testEqualsReflexivity() {
134 assertTrue("equals", fLocation2.equals(fLocation2));
135 assertTrue("equals", fLocation3.equals(fLocation3));
136
137 assertTrue("equals", !fLocation2.equals(fLocation3));
138 assertTrue("equals", !fLocation3.equals(fLocation2));
139 }
140
141 public void testEqualsSymmetry() {
142 TmfStringLocation location2 = new TmfStringLocation(aString);
143 TmfLongLocation location3 = new TmfLongLocation(aLong);
144
145 assertTrue("equals", location2.equals(fLocation2));
146 assertTrue("equals", fLocation2.equals(location2));
147
148 assertTrue("equals", location3.equals(fLocation3));
149 assertTrue("equals", fLocation3.equals(location3));
150 }
151
152 public void testEqualsTransivity() {
153 TmfStringLocation location1 = new TmfStringLocation(aString);
154 TmfStringLocation location2 = new TmfStringLocation(aString);
155 TmfStringLocation location3 = new TmfStringLocation(aString);
156
157 assertTrue("equals", location1.equals(location2));
158 assertTrue("equals", location2.equals(location3));
159 assertTrue("equals", location3.equals(location1));
160 }
161
162 public void testEqualsNull() {
163 assertTrue("equals", !fLocation2.equals(null));
164 assertTrue("equals", !fLocation2.equals(null));
165 }
166
167 // ------------------------------------------------------------------------
168 // toString
169 // ------------------------------------------------------------------------
170
171 @SuppressWarnings("hiding")
172 public void testToString() {
173 String aString = "some location";
174 Long aLong = 12345L;
175 TmfTimestamp aTimestamp = new TmfTimestamp();
176
177 TmfStringLocation location1 = new TmfStringLocation(aString);
178 TmfLongLocation location2 = new TmfLongLocation(aLong);
179 TmfTimestampLocation location3 = new TmfTimestampLocation(aTimestamp);
180
181 String expected1 = "TmfLocation [fLocation=" + aString + "]";
182 String expected2 = "TmfLocation [fLocation=" + aLong + "]";
183 String expected3 = "TmfLocation [fLocation=" + aTimestamp + "]";
184
185 assertEquals("toString", expected1, location1.toString());
186 assertEquals("toString", expected2, location2.toString());
187 assertEquals("toString", expected3, location3.toString());
188 }
189
190 }
This page took 0.035212 seconds and 6 git commands to generate.