Merge branch 'master' into TmfTraceModel-new
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core.tests / src / org / eclipse / linuxtools / tmf / core / tests / trace / TmfCheckpointTest.java
CommitLineData
d18dd09b 1/*******************************************************************************
5d837f9b 2 * Copyright (c) 2009, 2010, 2012 Ericsson
d18dd09b
ASL
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
4df4581d 17import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
6c13869b
FC
18import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
19import org.eclipse.linuxtools.tmf.core.trace.TmfCheckpoint;
20import 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
28public class TmfCheckpointTest extends TestCase {
29
5d837f9b
FC
30 // ------------------------------------------------------------------------
31 // Variables
32 // ------------------------------------------------------------------------
33
34 ITmfTimestamp fTimestamp1 = new TmfTimestamp();
35 ITmfTimestamp fTimestamp2 = TmfTimestamp.BIG_BANG;
36 ITmfTimestamp fTimestamp3 = TmfTimestamp.BIG_CRUNCH;
d18dd09b 37
5d837f9b
FC
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);
d18dd09b 44
5d837f9b
FC
45 TmfCheckpoint fCheckpoint1 = new TmfCheckpoint(fTimestamp1, fLocation1);
46 TmfCheckpoint fCheckpoint2 = new TmfCheckpoint(fTimestamp2, fLocation2);
47 TmfCheckpoint fCheckpoint3 = new TmfCheckpoint(fTimestamp3, fLocation3);
d18dd09b 48
d18dd09b
ASL
49 // ------------------------------------------------------------------------
50 // Housekeeping
51 // ------------------------------------------------------------------------
52
5d837f9b
FC
53 /**
54 * @param name the test name
55 */
56 public TmfCheckpointTest(final String name) {
57 super(name);
58 }
d18dd09b 59
5d837f9b
FC
60 @Override
61 protected void setUp() throws Exception {
62 super.setUp();
63 }
d18dd09b 64
5d837f9b
FC
65 @Override
66 protected void tearDown() throws Exception {
67 super.tearDown();
68 }
d18dd09b
ASL
69
70 // ------------------------------------------------------------------------
71 // Constructors
72 // ------------------------------------------------------------------------
73
5d837f9b
FC
74 public void testTmfCheckpoint() {
75 assertEquals("TmfCheckpoint", fTimestamp1, fCheckpoint1.getTimestamp());
76 assertEquals("TmfCheckpoint", fLocation1, fCheckpoint1.getLocation());
77 }
78
79 public void testTmfLocationCopy() {
80 final 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 (final IllegalArgumentException e) {
92 // Success
93 }
94 catch (final Exception e) {
95 fail("wrong exception");
96 }
97 }
d18dd09b 98
5d837f9b
FC
99 // ------------------------------------------------------------------------
100 // clone
101 // ------------------------------------------------------------------------
d18dd09b 102
5d837f9b
FC
103 public void testClone() {
104 try {
105 TmfCheckpoint checkpoint1 = fCheckpoint1.clone();
106 TmfCheckpoint checkpoint2 = fCheckpoint1.clone();
107 TmfCheckpoint checkpoint3 = fCheckpoint1.clone();
108
109 assertEquals("clone", checkpoint1, fCheckpoint1);
110 assertEquals("clone", checkpoint2, fCheckpoint1);
111 assertEquals("clone", checkpoint3, fCheckpoint1);
112
113 checkpoint1 = new TmfCheckpoint(fTimestamp1, null);
114 checkpoint2 = checkpoint1.clone();
115 assertEquals("clone", checkpoint1, checkpoint2);
116 assertNull(checkpoint1.getLocation());
117 assertNull(checkpoint2.getLocation());
118
119 checkpoint1 = new TmfCheckpoint(null, fLocation1);
120 checkpoint3 = checkpoint1.clone();
121 assertEquals("clone", checkpoint1, checkpoint3);
122 assertNull(checkpoint1.getTimestamp());
123 assertNull(checkpoint3.getTimestamp());
124
125 } catch (final InternalError e) {
126 fail("clone()");
127 }
128 }
d18dd09b
ASL
129
130 // ------------------------------------------------------------------------
131 // equals
132 // ------------------------------------------------------------------------
133
5d837f9b
FC
134 public void testEqualsReflexivity() throws Exception {
135 assertTrue("equals", fCheckpoint1.equals(fCheckpoint1));
136 assertTrue("equals", fCheckpoint2.equals(fCheckpoint2));
137
138 assertTrue("equals", !fCheckpoint1.equals(fCheckpoint2));
139 assertTrue("equals", !fCheckpoint2.equals(fCheckpoint1));
140 }
141
142 public void testEqualsSymmetry() throws Exception {
143 final TmfCheckpoint checkpoint1 = new TmfCheckpoint(fCheckpoint1);
144 final TmfCheckpoint checkpoint2 = new TmfCheckpoint(fCheckpoint2);
145
146 assertTrue("equals", checkpoint1.equals(fCheckpoint1));
147 assertTrue("equals", fCheckpoint1.equals(checkpoint1));
148
149 assertTrue("equals", checkpoint2.equals(fCheckpoint2));
150 assertTrue("equals", fCheckpoint2.equals(checkpoint2));
151 }
152
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);
157
158 assertTrue("equals", checkpoint1.equals(checkpoint2));
159 assertTrue("equals", checkpoint2.equals(checkpoint3));
160 assertTrue("equals", checkpoint1.equals(checkpoint3));
161 }
162
163 public void testEqualsNull() throws Exception {
164 assertTrue("equals", !fCheckpoint1.equals(null));
165 assertTrue("equals", !fCheckpoint2.equals(null));
166 }
167
168 // ------------------------------------------------------------------------
169 // hashCode
170 // ------------------------------------------------------------------------
171
172 public void testHashCode() throws Exception {
173 final TmfCheckpoint checkpoint1 = new TmfCheckpoint(fCheckpoint1);
174 final TmfCheckpoint checkpoint2 = new TmfCheckpoint(fCheckpoint2);
175
176 assertTrue("hashCode", fCheckpoint1.hashCode() == checkpoint1.hashCode());
177 assertTrue("hashCode", fCheckpoint2.hashCode() == checkpoint2.hashCode());
178
179 assertTrue("hashCode", fCheckpoint1.hashCode() != checkpoint2.hashCode());
180 assertTrue("hashCode", fCheckpoint2.hashCode() != checkpoint1.hashCode());
181 }
182
d18dd09b
ASL
183 // ------------------------------------------------------------------------
184 // toString
185 // ------------------------------------------------------------------------
186
5d837f9b
FC
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() + "]";
d18dd09b 194
5d837f9b
FC
195 assertEquals("toString", expected1, fCheckpoint1.toString());
196 assertEquals("toString", expected2, fCheckpoint2.toString());
197 assertEquals("toString", expected3, fCheckpoint3.toString());
198 }
d18dd09b
ASL
199
200 // ------------------------------------------------------------------------
201 // compareTo
202 // ------------------------------------------------------------------------
203
5d837f9b
FC
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));
d18dd09b 208
5d837f9b
FC
209 assertEquals("compareTo", -1, fCheckpoint2.compareTo(fCheckpoint1));
210 assertEquals("compareTo", 0, fCheckpoint2.compareTo(fCheckpoint2));
211 assertEquals("compareTo", -1, fCheckpoint2.compareTo(fCheckpoint3));
d18dd09b 212
5d837f9b
FC
213 assertEquals("compareTo", 1, fCheckpoint3.compareTo(fCheckpoint1));
214 assertEquals("compareTo", 1, fCheckpoint3.compareTo(fCheckpoint2));
215 assertEquals("compareTo", 0, fCheckpoint3.compareTo(fCheckpoint3));
216 }
d18dd09b
ASL
217
218}
This page took 0.039291 seconds and 5 git commands to generate.