1 /*******************************************************************************
2 * Copyright (c) 2009, 2010 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
.tests
.trace
;
15 import junit
.framework
.TestCase
;
17 import org
.eclipse
.linuxtools
.tmf
.event
.TmfTimestamp
;
18 import org
.eclipse
.linuxtools
.tmf
.trace
.TmfLocation
;
21 * <b><u>TmfLocationTest</u></b>
23 * Test suite for the TmfLocation class.
25 public class TmfLocationTest
extends TestCase
{
27 // ------------------------------------------------------------------------
29 // ------------------------------------------------------------------------
31 String aString
= "some location";
33 TmfTimestamp aTimestamp
= new TmfTimestamp();
35 TmfLocation
<String
> fLocation1
;
36 TmfLocation
<Long
> fLocation2
;
37 TmfLocation
<TmfTimestamp
> fLocation3
;
39 // ------------------------------------------------------------------------
41 // ------------------------------------------------------------------------
44 * @param name the test name
46 public TmfLocationTest(String name
) {
51 protected void setUp() throws Exception
{
53 fLocation1
= new TmfLocation
<String
>(aString
);
54 fLocation2
= new TmfLocation
<Long
>(aLong
);
55 fLocation3
= new TmfLocation
<TmfTimestamp
>(aTimestamp
);
59 protected void tearDown() throws Exception
{
63 // ------------------------------------------------------------------------
65 // ------------------------------------------------------------------------
67 public void testTmfLocation() {
68 assertEquals("TmfLocation", aString
, fLocation1
.getLocation());
69 assertEquals("TmfLocation", aLong
, fLocation2
.getLocation());
70 assertEquals("TmfLocation", aTimestamp
, fLocation3
.getLocation());
73 public void testTmfLocationCopy() {
74 TmfLocation
<String
> location1
= new TmfLocation
<String
>(fLocation1
);
75 TmfLocation
<Long
> location2
= new TmfLocation
<Long
>(fLocation2
);
76 TmfLocation
<TmfTimestamp
> location3
= new TmfLocation
<TmfTimestamp
>(fLocation3
);
78 assertEquals("TmfLocation", aString
, location1
.getLocation());
79 assertEquals("TmfLocation", aLong
, location2
.getLocation());
80 assertEquals("TmfLocation", aTimestamp
, location3
.getLocation());
83 public void testTmfLocationCopy2() throws Exception
{
85 new TmfLocation
<Object
>(null);
88 catch (IllegalArgumentException e
) {
93 // ------------------------------------------------------------------------
95 // ------------------------------------------------------------------------
97 public void testSetLocation() {
98 String aString2
= "some other location";
99 Long aLong2
= 1234567L;
100 TmfTimestamp aTimestamp2
= TmfTimestamp
.BigBang
;
102 fLocation1
.setLocation(aString2
);
103 fLocation2
.setLocation(aLong2
);
104 fLocation3
.setLocation(aTimestamp2
);
106 assertEquals("TmfLocation", aString2
, fLocation1
.getLocation());
107 assertEquals("TmfLocation", aLong2
, fLocation2
.getLocation());
108 assertEquals("TmfLocation", aTimestamp2
, fLocation3
.getLocation());
111 // ------------------------------------------------------------------------
113 // ------------------------------------------------------------------------
115 public void testEqualsReflexivity() throws Exception
{
116 assertTrue("equals", fLocation1
.equals(fLocation1
));
117 assertTrue("equals", fLocation2
.equals(fLocation2
));
119 assertTrue("equals", !fLocation1
.equals(fLocation2
));
120 assertTrue("equals", !fLocation2
.equals(fLocation1
));
123 public void testEqualsSymmetry() throws Exception
{
124 TmfLocation
<String
> location1
= new TmfLocation
<String
>(aString
);
125 TmfLocation
<Long
> location2
= new TmfLocation
<Long
>(aLong
);
127 assertTrue("equals", location1
.equals(fLocation1
));
128 assertTrue("equals", fLocation1
.equals(location1
));
130 assertTrue("equals", location2
.equals(fLocation2
));
131 assertTrue("equals", fLocation2
.equals(location2
));
134 public void testEqualsTransivity() throws Exception
{
135 TmfLocation
<String
> location1
= new TmfLocation
<String
>(aString
);
136 TmfLocation
<String
> location2
= new TmfLocation
<String
>(aString
);
137 TmfLocation
<String
> location3
= new TmfLocation
<String
>(aString
);
139 assertTrue("equals", location1
.equals(location2
));
140 assertTrue("equals", location2
.equals(location3
));
141 assertTrue("equals", location1
.equals(location3
));
144 public void testEqualsNull() throws Exception
{
145 assertTrue("equals", !fLocation1
.equals(null));
146 assertTrue("equals", !fLocation1
.equals(null));
149 // ------------------------------------------------------------------------
151 // ------------------------------------------------------------------------
153 public void testHashCode() throws Exception
{
154 TmfLocation
<String
> location1
= new TmfLocation
<String
>(aString
);
155 TmfLocation
<Long
> location2
= new TmfLocation
<Long
>(aLong
);
157 assertTrue("hashCode", fLocation1
.hashCode() == location1
.hashCode());
158 assertTrue("hashCode", fLocation2
.hashCode() == location2
.hashCode());
160 assertTrue("hashCode", fLocation1
.hashCode() != location2
.hashCode());
161 assertTrue("hashCode", fLocation2
.hashCode() != location1
.hashCode());
164 // ------------------------------------------------------------------------
166 // ------------------------------------------------------------------------
168 public void testToString() {
169 String aString
= "some location";
171 TmfTimestamp aTimestamp
= new TmfTimestamp();
173 TmfLocation
<String
> location1
= new TmfLocation
<String
>(aString
);
174 TmfLocation
<Long
> location2
= new TmfLocation
<Long
>(aLong
);
175 TmfLocation
<TmfTimestamp
> location3
= new TmfLocation
<TmfTimestamp
>(aTimestamp
);
177 assertEquals("TmfLocation", aString
.toString(), location1
.toString());
178 assertEquals("TmfLocation", aLong
.toString(), location2
.toString());
179 assertEquals("TmfLocation", aTimestamp
.toString(), location3
.toString());
182 // ------------------------------------------------------------------------
184 // ------------------------------------------------------------------------
186 public void testClone() {
188 TmfLocation
<String
> location1
= fLocation1
.clone();
189 TmfLocation
<Long
> location2
= fLocation2
.clone();
190 TmfLocation
<TmfTimestamp
> location3
= fLocation3
.clone();
192 assertEquals("TmfLocation", aString
.toString(), location1
.toString());
193 assertEquals("TmfLocation", aLong
.toString(), location2
.toString());
194 assertEquals("TmfLocation", aTimestamp
.toString(), location3
.toString());
196 catch (InternalError e
) {
201 public class MyCloneableClass
implements Cloneable
{
202 private String fName
;
203 public MyCloneableClass(String name
) {
207 public String
toString() {
211 public MyCloneableClass
clone() {
212 MyCloneableClass clone
= null;
214 clone
= (MyCloneableClass
) super.clone();
216 } catch (CloneNotSupportedException e
) {
222 public void testCloneCloneable() {
224 MyCloneableClass myClass
= new MyCloneableClass("myClass");
225 TmfLocation
<MyCloneableClass
> myLocation
= new TmfLocation
<MyCloneableClass
>(myClass
);
226 TmfLocation
<MyCloneableClass
> location4
= myLocation
.clone();
228 assertEquals("TmfLocation", myClass
.toString(), location4
.toString());
230 catch (InternalError e
) {
235 public class MyUnCloneableClass
{
236 private String fName
;
237 public MyUnCloneableClass(String name
) {
241 public String
toString() {
245 public Object
clone() throws CloneNotSupportedException
{
246 throw new CloneNotSupportedException();
250 public void testCloneUnCloneable() {
252 MyUnCloneableClass myClass
= new MyUnCloneableClass("myClass");
253 TmfLocation
<MyUnCloneableClass
> myLocation
= new TmfLocation
<MyUnCloneableClass
>(myClass
);
257 catch (InternalError e
) {