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
.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
.TmfCheckpoint
;
19 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfLocation
;
22 * <b><u>TmfCheckpointTest</u></b>
24 * Test suite for the TmfCheckpoint class.
26 @SuppressWarnings("nls")
27 public class TmfCheckpointTest
extends TestCase
{
29 // ------------------------------------------------------------------------
31 // ------------------------------------------------------------------------
33 TmfTimestamp fTimestamp1
= new TmfTimestamp();
34 TmfTimestamp fTimestamp2
= TmfTimestamp
.BigBang
;
35 TmfTimestamp fTimestamp3
= TmfTimestamp
.BigCrunch
;
40 TmfLocation
<Long
> fLocation1
= new TmfLocation
<Long
>(aLong1
);
41 TmfLocation
<Long
> fLocation2
= new TmfLocation
<Long
>(aLong2
);
42 TmfLocation
<Long
> fLocation3
= new TmfLocation
<Long
>(aLong3
);
44 TmfCheckpoint fCheckpoint1
= new TmfCheckpoint(fTimestamp1
, fLocation1
);
45 TmfCheckpoint fCheckpoint2
= new TmfCheckpoint(fTimestamp2
, fLocation2
);
46 TmfCheckpoint fCheckpoint3
= new TmfCheckpoint(fTimestamp3
, fLocation3
);
48 // ------------------------------------------------------------------------
50 // ------------------------------------------------------------------------
53 * @param name the test name
55 public TmfCheckpointTest(String name
) {
60 protected void setUp() throws Exception
{
65 protected void tearDown() throws Exception
{
69 // ------------------------------------------------------------------------
71 // ------------------------------------------------------------------------
73 public void testTmfCheckpoint() {
74 assertEquals("TmfCheckpoint", fTimestamp1
, fCheckpoint1
.getTimestamp());
75 assertEquals("TmfCheckpoint", fLocation1
, fCheckpoint1
.getLocation());
78 public void testTmfLocationCopy() {
79 TmfCheckpoint checkpoint
= new TmfCheckpoint(fCheckpoint1
);
81 assertEquals("TmfCheckpoint", fTimestamp1
, checkpoint
.getTimestamp());
82 assertEquals("TmfCheckpoint", fLocation1
, checkpoint
.getLocation());
85 public void testTmfLocationCopy2() throws Exception
{
87 new TmfCheckpoint(null);
90 catch (IllegalArgumentException e
) {
95 // ------------------------------------------------------------------------
97 // ------------------------------------------------------------------------
99 public void testEqualsReflexivity() throws Exception
{
100 assertTrue("equals", fCheckpoint1
.equals(fCheckpoint1
));
101 assertTrue("equals", fCheckpoint2
.equals(fCheckpoint2
));
103 assertTrue("equals", !fCheckpoint1
.equals(fCheckpoint2
));
104 assertTrue("equals", !fCheckpoint2
.equals(fCheckpoint1
));
107 public void testEqualsSymmetry() throws Exception
{
108 TmfCheckpoint checkpoint1
= new TmfCheckpoint(fCheckpoint1
);
109 TmfCheckpoint checkpoint2
= new TmfCheckpoint(fCheckpoint2
);
111 assertTrue("equals", checkpoint1
.equals(fCheckpoint1
));
112 assertTrue("equals", fCheckpoint1
.equals(checkpoint1
));
114 assertTrue("equals", checkpoint2
.equals(fCheckpoint2
));
115 assertTrue("equals", fCheckpoint2
.equals(checkpoint2
));
118 public void testEqualsTransivity() throws Exception
{
119 TmfCheckpoint checkpoint1
= new TmfCheckpoint(fCheckpoint1
);
120 TmfCheckpoint checkpoint2
= new TmfCheckpoint(checkpoint1
);
121 TmfCheckpoint checkpoint3
= new TmfCheckpoint(checkpoint2
);
123 assertTrue("equals", checkpoint1
.equals(checkpoint2
));
124 assertTrue("equals", checkpoint2
.equals(checkpoint3
));
125 assertTrue("equals", checkpoint1
.equals(checkpoint3
));
128 public void testEqualsNull() throws Exception
{
129 assertTrue("equals", !fCheckpoint1
.equals(null));
130 assertTrue("equals", !fCheckpoint2
.equals(null));
133 // ------------------------------------------------------------------------
135 // ------------------------------------------------------------------------
137 public void testHashCode() throws Exception
{
138 TmfCheckpoint checkpoint1
= new TmfCheckpoint(fCheckpoint1
);
139 TmfCheckpoint checkpoint2
= new TmfCheckpoint(fCheckpoint2
);
141 assertTrue("hashCode", fCheckpoint1
.hashCode() == checkpoint1
.hashCode());
142 assertTrue("hashCode", fCheckpoint2
.hashCode() == checkpoint2
.hashCode());
144 assertTrue("hashCode", fCheckpoint1
.hashCode() != checkpoint2
.hashCode());
145 assertTrue("hashCode", fCheckpoint2
.hashCode() != checkpoint1
.hashCode());
148 // ------------------------------------------------------------------------
150 // ------------------------------------------------------------------------
152 public void testToString() {
153 String expected1
= "[TmfCheckpoint(" + fCheckpoint1
.getTimestamp() + "," +
154 fCheckpoint1
.getLocation() + ")]";
155 String expected2
= "[TmfCheckpoint(" + fCheckpoint2
.getTimestamp() + "," +
156 fCheckpoint2
.getLocation() + ")]";
157 String expected3
= "[TmfCheckpoint(" + fCheckpoint3
.getTimestamp() + "," +
158 fCheckpoint3
.getLocation() + ")]";
160 assertEquals("toString", expected1
, fCheckpoint1
.toString());
161 assertEquals("toString", expected2
, fCheckpoint2
.toString());
162 assertEquals("toString", expected3
, fCheckpoint3
.toString());
165 // ------------------------------------------------------------------------
167 // ------------------------------------------------------------------------
169 public void testCompareTo() {
170 assertEquals("compareTo", 0, fCheckpoint1
.compareTo(fCheckpoint1
));
171 assertEquals("compareTo", 1, fCheckpoint1
.compareTo(fCheckpoint2
));
172 assertEquals("compareTo", -1, fCheckpoint1
.compareTo(fCheckpoint3
));
174 assertEquals("compareTo", -1, fCheckpoint2
.compareTo(fCheckpoint1
));
175 assertEquals("compareTo", 0, fCheckpoint2
.compareTo(fCheckpoint2
));
176 assertEquals("compareTo", -1, fCheckpoint2
.compareTo(fCheckpoint3
));
178 assertEquals("compareTo", 1, fCheckpoint3
.compareTo(fCheckpoint1
));
179 assertEquals("compareTo", 1, fCheckpoint3
.compareTo(fCheckpoint2
));
180 assertEquals("compareTo", 0, fCheckpoint3
.compareTo(fCheckpoint3
));