Commit | Line | Data |
---|---|---|
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 | 13 | package org.eclipse.linuxtools.tmf.core.tests.trace; |
d18dd09b ASL |
14 | |
15 | import junit.framework.TestCase; | |
16 | ||
4df4581d | 17 | import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp; |
6c13869b FC |
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; | |
d18dd09b ASL |
21 | |
22 | /** | |
23 | * <b><u>TmfCheckpointTest</u></b> | |
24 | * <p> | |
25 | * Test suite for the TmfCheckpoint class. | |
26 | */ | |
3b38ea61 | 27 | @SuppressWarnings("nls") |
d18dd09b ASL |
28 | public class TmfCheckpointTest extends TestCase { |
29 | ||
30 | // ------------------------------------------------------------------------ | |
31 | // Variables | |
32 | // ------------------------------------------------------------------------ | |
33 | ||
4df4581d | 34 | ITmfTimestamp fTimestamp1 = new TmfTimestamp(); |
35 | ITmfTimestamp fTimestamp2 = TmfTimestamp.BigBang; | |
36 | ITmfTimestamp fTimestamp3 = TmfTimestamp.BigCrunch; | |
d18dd09b ASL |
37 | |
38 | Long aLong1 = 12345L; | |
39 | Long aLong2 = 23456L; | |
40 | Long aLong3 = 34567L; | |
41 | TmfLocation<Long> fLocation1 = new TmfLocation<Long>(aLong1); | |
42 | TmfLocation<Long> fLocation2 = new TmfLocation<Long>(aLong2); | |
43 | TmfLocation<Long> fLocation3 = new TmfLocation<Long>(aLong3); | |
44 | ||
45 | TmfCheckpoint fCheckpoint1 = new TmfCheckpoint(fTimestamp1, fLocation1); | |
46 | TmfCheckpoint fCheckpoint2 = new TmfCheckpoint(fTimestamp2, fLocation2); | |
47 | TmfCheckpoint fCheckpoint3 = new TmfCheckpoint(fTimestamp3, fLocation3); | |
48 | ||
49 | // ------------------------------------------------------------------------ | |
50 | // Housekeeping | |
51 | // ------------------------------------------------------------------------ | |
52 | ||
53 | /** | |
54 | * @param name the test name | |
55 | */ | |
56 | public TmfCheckpointTest(String name) { | |
57 | super(name); | |
58 | } | |
59 | ||
60 | @Override | |
61 | protected void setUp() throws Exception { | |
62 | super.setUp(); | |
63 | } | |
64 | ||
65 | @Override | |
66 | protected void tearDown() throws Exception { | |
67 | super.tearDown(); | |
68 | } | |
69 | ||
70 | // ------------------------------------------------------------------------ | |
71 | // Constructors | |
72 | // ------------------------------------------------------------------------ | |
73 | ||
74 | public void testTmfCheckpoint() { | |
75 | assertEquals("TmfCheckpoint", fTimestamp1, fCheckpoint1.getTimestamp()); | |
76 | assertEquals("TmfCheckpoint", fLocation1, fCheckpoint1.getLocation()); | |
77 | } | |
78 | ||
79 | public void testTmfLocationCopy() { | |
80 | TmfCheckpoint checkpoint = new TmfCheckpoint(fCheckpoint1); | |
81 | ||
82 | assertEquals("TmfCheckpoint", fTimestamp1, checkpoint.getTimestamp()); | |
83 | assertEquals("TmfCheckpoint", fLocation1, checkpoint.getLocation()); | |
84 | } | |
85 | ||
86 | public void testTmfLocationCopy2() throws Exception { | |
87 | try { | |
88 | new TmfCheckpoint(null); | |
89 | fail("null copy"); | |
90 | } | |
91 | catch (IllegalArgumentException e) { | |
92 | // Success | |
93 | } | |
94 | } | |
95 | ||
96 | // ------------------------------------------------------------------------ | |
97 | // equals | |
98 | // ------------------------------------------------------------------------ | |
99 | ||
100 | public void testEqualsReflexivity() throws Exception { | |
101 | assertTrue("equals", fCheckpoint1.equals(fCheckpoint1)); | |
102 | assertTrue("equals", fCheckpoint2.equals(fCheckpoint2)); | |
103 | ||
104 | assertTrue("equals", !fCheckpoint1.equals(fCheckpoint2)); | |
105 | assertTrue("equals", !fCheckpoint2.equals(fCheckpoint1)); | |
106 | } | |
107 | ||
108 | public void testEqualsSymmetry() throws Exception { | |
109 | TmfCheckpoint checkpoint1 = new TmfCheckpoint(fCheckpoint1); | |
110 | TmfCheckpoint checkpoint2 = new TmfCheckpoint(fCheckpoint2); | |
111 | ||
112 | assertTrue("equals", checkpoint1.equals(fCheckpoint1)); | |
113 | assertTrue("equals", fCheckpoint1.equals(checkpoint1)); | |
114 | ||
115 | assertTrue("equals", checkpoint2.equals(fCheckpoint2)); | |
116 | assertTrue("equals", fCheckpoint2.equals(checkpoint2)); | |
117 | } | |
118 | ||
119 | public void testEqualsTransivity() throws Exception { | |
120 | TmfCheckpoint checkpoint1 = new TmfCheckpoint(fCheckpoint1); | |
121 | TmfCheckpoint checkpoint2 = new TmfCheckpoint(checkpoint1); | |
122 | TmfCheckpoint checkpoint3 = new TmfCheckpoint(checkpoint2); | |
123 | ||
124 | assertTrue("equals", checkpoint1.equals(checkpoint2)); | |
125 | assertTrue("equals", checkpoint2.equals(checkpoint3)); | |
126 | assertTrue("equals", checkpoint1.equals(checkpoint3)); | |
127 | } | |
128 | ||
129 | public void testEqualsNull() throws Exception { | |
130 | assertTrue("equals", !fCheckpoint1.equals(null)); | |
131 | assertTrue("equals", !fCheckpoint2.equals(null)); | |
132 | } | |
133 | ||
134 | // ------------------------------------------------------------------------ | |
135 | // hashCode | |
136 | // ------------------------------------------------------------------------ | |
137 | ||
138 | public void testHashCode() throws Exception { | |
139 | TmfCheckpoint checkpoint1 = new TmfCheckpoint(fCheckpoint1); | |
140 | TmfCheckpoint checkpoint2 = new TmfCheckpoint(fCheckpoint2); | |
141 | ||
142 | assertTrue("hashCode", fCheckpoint1.hashCode() == checkpoint1.hashCode()); | |
143 | assertTrue("hashCode", fCheckpoint2.hashCode() == checkpoint2.hashCode()); | |
144 | ||
145 | assertTrue("hashCode", fCheckpoint1.hashCode() != checkpoint2.hashCode()); | |
146 | assertTrue("hashCode", fCheckpoint2.hashCode() != checkpoint1.hashCode()); | |
147 | } | |
148 | ||
149 | // ------------------------------------------------------------------------ | |
150 | // toString | |
151 | // ------------------------------------------------------------------------ | |
152 | ||
153 | public void testToString() { | |
154 | String expected1 = "[TmfCheckpoint(" + fCheckpoint1.getTimestamp() + "," + | |
155 | fCheckpoint1.getLocation() + ")]"; | |
156 | String expected2 = "[TmfCheckpoint(" + fCheckpoint2.getTimestamp() + "," + | |
157 | fCheckpoint2.getLocation() + ")]"; | |
158 | String expected3 = "[TmfCheckpoint(" + fCheckpoint3.getTimestamp() + "," + | |
159 | fCheckpoint3.getLocation() + ")]"; | |
160 | ||
161 | assertEquals("toString", expected1, fCheckpoint1.toString()); | |
162 | assertEquals("toString", expected2, fCheckpoint2.toString()); | |
163 | assertEquals("toString", expected3, fCheckpoint3.toString()); | |
164 | } | |
165 | ||
166 | // ------------------------------------------------------------------------ | |
167 | // compareTo | |
168 | // ------------------------------------------------------------------------ | |
169 | ||
170 | public void testCompareTo() { | |
171 | assertEquals("compareTo", 0, fCheckpoint1.compareTo(fCheckpoint1)); | |
172 | assertEquals("compareTo", 1, fCheckpoint1.compareTo(fCheckpoint2)); | |
173 | assertEquals("compareTo", -1, fCheckpoint1.compareTo(fCheckpoint3)); | |
174 | ||
175 | assertEquals("compareTo", -1, fCheckpoint2.compareTo(fCheckpoint1)); | |
176 | assertEquals("compareTo", 0, fCheckpoint2.compareTo(fCheckpoint2)); | |
177 | assertEquals("compareTo", -1, fCheckpoint2.compareTo(fCheckpoint3)); | |
178 | ||
179 | assertEquals("compareTo", 1, fCheckpoint3.compareTo(fCheckpoint1)); | |
180 | assertEquals("compareTo", 1, fCheckpoint3.compareTo(fCheckpoint2)); | |
181 | assertEquals("compareTo", 0, fCheckpoint3.compareTo(fCheckpoint3)); | |
182 | } | |
183 | ||
184 | } |