Fix for Update legacy lttng for TCF 1.0.0.
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core.tests / src / org / eclipse / linuxtools / tmf / core / tests / trace / TmfLocationTest.java
CommitLineData
d18dd09b
ASL
1/*******************************************************************************
2 * Copyright (c) 2009, 2010 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
6c13869b 13package org.eclipse.linuxtools.tmf.core.tests.trace;
d18dd09b
ASL
14
15import junit.framework.TestCase;
16
6c13869b
FC
17import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
18import org.eclipse.linuxtools.tmf.core.trace.TmfLocation;
d18dd09b
ASL
19
20/**
21 * <b><u>TmfLocationTest</u></b>
22 * <p>
23 * Test suite for the TmfLocation class.
24 */
3b38ea61 25@SuppressWarnings("nls")
d18dd09b
ASL
26public 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 TmfLocation<String> fLocation1;
37 TmfLocation<Long> fLocation2;
38 TmfLocation<TmfTimestamp> fLocation3;
39
40 // ------------------------------------------------------------------------
41 // Housekeeping
42 // ------------------------------------------------------------------------
43
44 /**
45 * @param name the test name
46 */
47 public TmfLocationTest(String name) {
48 super(name);
49 }
50
51 @Override
52 protected void setUp() throws Exception {
53 super.setUp();
54 fLocation1 = new TmfLocation<String>(aString);
55 fLocation2 = new TmfLocation<Long>(aLong);
56 fLocation3 = new TmfLocation<TmfTimestamp>(aTimestamp);
57 }
58
59 @Override
60 protected void tearDown() throws Exception {
61 super.tearDown();
62 }
63
64 // ------------------------------------------------------------------------
65 // Constructors
66 // ------------------------------------------------------------------------
67
68 public void testTmfLocation() {
69 assertEquals("TmfLocation", aString, fLocation1.getLocation());
70 assertEquals("TmfLocation", aLong, fLocation2.getLocation());
71 assertEquals("TmfLocation", aTimestamp, fLocation3.getLocation());
72 }
73
74 public void testTmfLocationCopy() {
75 TmfLocation<String> location1 = new TmfLocation<String>(fLocation1);
76 TmfLocation<Long> location2 = new TmfLocation<Long>(fLocation2);
77 TmfLocation<TmfTimestamp> location3 = new TmfLocation<TmfTimestamp>(fLocation3);
78
79 assertEquals("TmfLocation", aString, location1.getLocation());
80 assertEquals("TmfLocation", aLong, location2.getLocation());
81 assertEquals("TmfLocation", aTimestamp, location3.getLocation());
82 }
83
84 public void testTmfLocationCopy2() throws Exception {
85 try {
a79913eb 86 new TmfLocation<Long>((TmfLocation<Long>) null);
d18dd09b
ASL
87 fail("null copy");
88 }
89 catch (IllegalArgumentException e) {
90 // Success
91 }
92 }
93
94 // ------------------------------------------------------------------------
95 // setLocation
96 // ------------------------------------------------------------------------
97
98 public void testSetLocation() {
99 String aString2 = "some other location";
100 Long aLong2 = 1234567L;
a4115405 101 TmfTimestamp aTimestamp2 = (TmfTimestamp) TmfTimestamp.BIG_BANG;
d18dd09b
ASL
102
103 fLocation1.setLocation(aString2);
104 fLocation2.setLocation(aLong2);
105 fLocation3.setLocation(aTimestamp2);
106
107 assertEquals("TmfLocation", aString2, fLocation1.getLocation());
108 assertEquals("TmfLocation", aLong2, fLocation2.getLocation());
109 assertEquals("TmfLocation", aTimestamp2, fLocation3.getLocation());
110 }
111
112 // ------------------------------------------------------------------------
113 // toEquals
114 // ------------------------------------------------------------------------
115
116 public void testEqualsReflexivity() throws Exception {
117 assertTrue("equals", fLocation1.equals(fLocation1));
118 assertTrue("equals", fLocation2.equals(fLocation2));
119
120 assertTrue("equals", !fLocation1.equals(fLocation2));
121 assertTrue("equals", !fLocation2.equals(fLocation1));
122 }
123
124 public void testEqualsSymmetry() throws Exception {
125 TmfLocation<String> location1 = new TmfLocation<String>(aString);
126 TmfLocation<Long> location2 = new TmfLocation<Long>(aLong);
127
128 assertTrue("equals", location1.equals(fLocation1));
129 assertTrue("equals", fLocation1.equals(location1));
130
131 assertTrue("equals", location2.equals(fLocation2));
132 assertTrue("equals", fLocation2.equals(location2));
133 }
134
135 public void testEqualsTransivity() throws Exception {
136 TmfLocation<String> location1 = new TmfLocation<String>(aString);
137 TmfLocation<String> location2 = new TmfLocation<String>(aString);
138 TmfLocation<String> location3 = new TmfLocation<String>(aString);
139
140 assertTrue("equals", location1.equals(location2));
141 assertTrue("equals", location2.equals(location3));
142 assertTrue("equals", location1.equals(location3));
143 }
144
145 public void testEqualsNull() throws Exception {
146 assertTrue("equals", !fLocation1.equals(null));
147 assertTrue("equals", !fLocation1.equals(null));
148 }
149
150 // ------------------------------------------------------------------------
151 // hashCode
152 // ------------------------------------------------------------------------
153
154 public void testHashCode() throws Exception {
155 TmfLocation<String> location1 = new TmfLocation<String>(aString);
156 TmfLocation<Long> location2 = new TmfLocation<Long>(aLong);
157
158 assertTrue("hashCode", fLocation1.hashCode() == location1.hashCode());
159 assertTrue("hashCode", fLocation2.hashCode() == location2.hashCode());
160
161 assertTrue("hashCode", fLocation1.hashCode() != location2.hashCode());
162 assertTrue("hashCode", fLocation2.hashCode() != location1.hashCode());
163 }
164
165 // ------------------------------------------------------------------------
166 // toString
167 // ------------------------------------------------------------------------
168
169 public void testToString() {
170 String aString = "some location";
171 Long aLong = 12345L;
172 TmfTimestamp aTimestamp = new TmfTimestamp();
173
174 TmfLocation<String> location1 = new TmfLocation<String>(aString);
175 TmfLocation<Long> location2 = new TmfLocation<Long>(aLong);
176 TmfLocation<TmfTimestamp> location3 = new TmfLocation<TmfTimestamp>(aTimestamp);
177
178 assertEquals("TmfLocation", aString.toString(), location1.toString());
179 assertEquals("TmfLocation", aLong.toString(), location2.toString());
180 assertEquals("TmfLocation", aTimestamp.toString(), location3.toString());
181 }
182
183 // ------------------------------------------------------------------------
184 // clone
185 // ------------------------------------------------------------------------
186
187 public void testClone() {
188 try {
189 TmfLocation<String> location1 = fLocation1.clone();
190 TmfLocation<Long> location2 = fLocation2.clone();
191 TmfLocation<TmfTimestamp> location3 = fLocation3.clone();
192
193 assertEquals("TmfLocation", aString.toString(), location1.toString());
194 assertEquals("TmfLocation", aLong.toString(), location2.toString());
195 assertEquals("TmfLocation", aTimestamp.toString(), location3.toString());
196 }
197 catch (InternalError e) {
198 fail("clone()");
199 }
200 }
201
6e85c58d 202 public static class MyCloneableClass implements Cloneable, Comparable<MyCloneableClass> {
d18dd09b
ASL
203 private String fName;
204 public MyCloneableClass(String name) {
205 fName = name;
206 }
207 @Override
208 public String toString() {
209 return fName;
210 }
211 @Override
212 public MyCloneableClass clone() {
213 MyCloneableClass clone = null;
214 try {
215 clone = (MyCloneableClass) super.clone();
216 clone.fName = fName;
217 } catch (CloneNotSupportedException e) {
218 }
219 return clone;
220 }
a79913eb
FC
221 @Override
222 public int compareTo(MyCloneableClass o) {
223 return 0;
224 }
d18dd09b
ASL
225 }
226
227 public void testCloneCloneable() {
228 try {
229 MyCloneableClass myClass = new MyCloneableClass("myClass");
230 TmfLocation<MyCloneableClass> myLocation = new TmfLocation<MyCloneableClass>(myClass);
231 TmfLocation<MyCloneableClass> location4 = myLocation.clone();
232
233 assertEquals("TmfLocation", myClass.toString(), location4.toString());
234 }
235 catch (InternalError e) {
236 fail("clone()");
237 }
238 }
239
6e85c58d 240 public static class MyUnCloneableClass implements Comparable<MyUnCloneableClass> {
d18dd09b
ASL
241 private String fName;
242 public MyUnCloneableClass(String name) {
243 fName = name;
244 }
245 @Override
246 public String toString() {
247 return fName;
248 }
249 @Override
250 public Object clone() throws CloneNotSupportedException {
251 throw new CloneNotSupportedException();
252 }
a79913eb
FC
253 @Override
254 public int compareTo(MyUnCloneableClass o) {
255 return 0;
256 }
d18dd09b
ASL
257 }
258
259 public void testCloneUnCloneable() {
260 try {
261 MyUnCloneableClass myClass = new MyUnCloneableClass("myClass");
262 TmfLocation<MyUnCloneableClass> myLocation = new TmfLocation<MyUnCloneableClass>(myClass);
263 myLocation.clone();
264 fail("clone()");
265 }
266 catch (InternalError e) {
267 // Success
268 }
269 }
270
271}
This page took 0.04084 seconds and 5 git commands to generate.