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
.ITmfTimestamp
;
18 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimestamp
;
19 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfCheckpoint
;
20 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfLocation
;
23 * <b><u>TmfCheckpointTest</u></b>
25 * Test suite for the TmfCheckpoint class.
27 @SuppressWarnings("nls")
28 public class TmfCheckpointTest
extends TestCase
{
30 // ------------------------------------------------------------------------
32 // ------------------------------------------------------------------------
34 ITmfTimestamp fTimestamp1
= new TmfTimestamp();
35 ITmfTimestamp fTimestamp2
= TmfTimestamp
.BIG_BANG
;
36 ITmfTimestamp fTimestamp3
= TmfTimestamp
.BIG_CRUNCH
;
41 TmfLocation
<Long
> fLocation1
= new TmfLocation
<Long
>(aLong1
);
42 TmfLocation
<Long
> fLocation2
= new TmfLocation
<Long
>(aLong2
);
43 TmfLocation
<Long
> fLocation3
= new TmfLocation
<Long
>(aLong3
);
45 TmfCheckpoint fCheckpoint1
= new TmfCheckpoint(fTimestamp1
, fLocation1
);
46 TmfCheckpoint fCheckpoint2
= new TmfCheckpoint(fTimestamp2
, fLocation2
);
47 TmfCheckpoint fCheckpoint3
= new TmfCheckpoint(fTimestamp3
, fLocation3
);
49 // ------------------------------------------------------------------------
51 // ------------------------------------------------------------------------
54 * @param name the test name
56 public TmfCheckpointTest(final String name
) {
61 protected void setUp() throws Exception
{
66 protected void tearDown() throws Exception
{
70 // ------------------------------------------------------------------------
72 // ------------------------------------------------------------------------
74 public void testTmfCheckpoint() {
75 assertEquals("TmfCheckpoint", fTimestamp1
, fCheckpoint1
.getTimestamp());
76 assertEquals("TmfCheckpoint", fLocation1
, fCheckpoint1
.getLocation());
79 public void testTmfLocationCopy() {
80 final TmfCheckpoint checkpoint
= new TmfCheckpoint(fCheckpoint1
);
82 assertEquals("TmfCheckpoint", fTimestamp1
, checkpoint
.getTimestamp());
83 assertEquals("TmfCheckpoint", fLocation1
, checkpoint
.getLocation());
86 public void testTmfLocationCopy2() throws Exception
{
88 new TmfCheckpoint(null);
91 catch (final IllegalArgumentException e
) {
94 catch (final Exception e
) {
95 fail("wrong exception");
99 // ------------------------------------------------------------------------
101 // ------------------------------------------------------------------------
103 public void testClone() {
105 TmfCheckpoint checkpoint1
= fCheckpoint1
.clone();
106 TmfCheckpoint checkpoint2
= fCheckpoint1
.clone();
107 TmfCheckpoint checkpoint3
= fCheckpoint1
.clone();
109 assertEquals("clone", checkpoint1
, fCheckpoint1
);
110 assertEquals("clone", checkpoint2
, fCheckpoint1
);
111 assertEquals("clone", checkpoint3
, fCheckpoint1
);
113 checkpoint1
= new TmfCheckpoint(fTimestamp1
, null);
114 checkpoint2
= checkpoint1
.clone();
115 assertEquals("clone", checkpoint1
, checkpoint2
);
116 assertNull(checkpoint1
.getLocation());
117 assertNull(checkpoint2
.getLocation());
119 checkpoint1
= new TmfCheckpoint(null, fLocation1
);
120 checkpoint3
= checkpoint1
.clone();
121 assertEquals("clone", checkpoint1
, checkpoint3
);
122 assertNull(checkpoint1
.getTimestamp());
123 assertNull(checkpoint3
.getTimestamp());
125 } catch (final InternalError e
) {
130 // ------------------------------------------------------------------------
132 // ------------------------------------------------------------------------
134 public void testEqualsReflexivity() throws Exception
{
135 assertTrue("equals", fCheckpoint1
.equals(fCheckpoint1
));
136 assertTrue("equals", fCheckpoint2
.equals(fCheckpoint2
));
138 assertTrue("equals", !fCheckpoint1
.equals(fCheckpoint2
));
139 assertTrue("equals", !fCheckpoint2
.equals(fCheckpoint1
));
142 public void testEqualsSymmetry() throws Exception
{
143 final TmfCheckpoint checkpoint1
= new TmfCheckpoint(fCheckpoint1
);
144 final TmfCheckpoint checkpoint2
= new TmfCheckpoint(fCheckpoint2
);
146 assertTrue("equals", checkpoint1
.equals(fCheckpoint1
));
147 assertTrue("equals", fCheckpoint1
.equals(checkpoint1
));
149 assertTrue("equals", checkpoint2
.equals(fCheckpoint2
));
150 assertTrue("equals", fCheckpoint2
.equals(checkpoint2
));
153 public void testEqualsTransivity() throws Exception
{
154 final TmfCheckpoint checkpoint1
= new TmfCheckpoint(fCheckpoint1
);
155 final TmfCheckpoint checkpoint2
= new TmfCheckpoint(checkpoint1
);
156 final TmfCheckpoint checkpoint3
= new TmfCheckpoint(checkpoint2
);
158 assertTrue("equals", checkpoint1
.equals(checkpoint2
));
159 assertTrue("equals", checkpoint2
.equals(checkpoint3
));
160 assertTrue("equals", checkpoint1
.equals(checkpoint3
));
163 public void testEqualsNull() throws Exception
{
164 assertTrue("equals", !fCheckpoint1
.equals(null));
165 assertTrue("equals", !fCheckpoint2
.equals(null));
168 // ------------------------------------------------------------------------
170 // ------------------------------------------------------------------------
172 public void testHashCode() throws Exception
{
173 final TmfCheckpoint checkpoint1
= new TmfCheckpoint(fCheckpoint1
);
174 final TmfCheckpoint checkpoint2
= new TmfCheckpoint(fCheckpoint2
);
176 assertTrue("hashCode", fCheckpoint1
.hashCode() == checkpoint1
.hashCode());
177 assertTrue("hashCode", fCheckpoint2
.hashCode() == checkpoint2
.hashCode());
179 assertTrue("hashCode", fCheckpoint1
.hashCode() != checkpoint2
.hashCode());
180 assertTrue("hashCode", fCheckpoint2
.hashCode() != checkpoint1
.hashCode());
183 // ------------------------------------------------------------------------
185 // ------------------------------------------------------------------------
187 public void testToString() {
188 final String expected1
= "TmfCheckpoint [fLocation=" + fCheckpoint1
.getLocation() +
189 ", fTimestamp=" + fCheckpoint1
.getTimestamp() + "]";
190 final String expected2
= "TmfCheckpoint [fLocation=" + fCheckpoint2
.getLocation() +
191 ", fTimestamp=" + fCheckpoint2
.getTimestamp() + "]";
192 final String expected3
= "TmfCheckpoint [fLocation=" + fCheckpoint3
.getLocation() +
193 ", fTimestamp=" + fCheckpoint3
.getTimestamp() + "]";
195 assertEquals("toString", expected1
, fCheckpoint1
.toString());
196 assertEquals("toString", expected2
, fCheckpoint2
.toString());
197 assertEquals("toString", expected3
, fCheckpoint3
.toString());
200 // ------------------------------------------------------------------------
202 // ------------------------------------------------------------------------
204 public void testCompareTo() {
205 assertEquals("compareTo", 0, fCheckpoint1
.compareTo(fCheckpoint1
));
206 assertEquals("compareTo", 1, fCheckpoint1
.compareTo(fCheckpoint2
));
207 assertEquals("compareTo", -1, fCheckpoint1
.compareTo(fCheckpoint3
));
209 assertEquals("compareTo", -1, fCheckpoint2
.compareTo(fCheckpoint1
));
210 assertEquals("compareTo", 0, fCheckpoint2
.compareTo(fCheckpoint2
));
211 assertEquals("compareTo", -1, fCheckpoint2
.compareTo(fCheckpoint3
));
213 assertEquals("compareTo", 1, fCheckpoint3
.compareTo(fCheckpoint1
));
214 assertEquals("compareTo", 1, fCheckpoint3
.compareTo(fCheckpoint2
));
215 assertEquals("compareTo", 0, fCheckpoint3
.compareTo(fCheckpoint3
));