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
.TmfContext
;
19 import org
.eclipse
.linuxtools
.tmf
.trace
.TmfLocation
;
22 * <b><u>TmfContextTest</u></b>
24 * Test suite for the TmfContext class.
26 public class TmfContextTest
extends TestCase
{
28 // ------------------------------------------------------------------------
30 // ------------------------------------------------------------------------
32 final String aString
= "some location";
33 final Long aLong
= 12345L;
34 final TmfTimestamp aTimestamp
= new TmfTimestamp();
36 final TmfLocation
<String
> fLocation1
= new TmfLocation
<String
>(aString
);
37 final TmfLocation
<Long
> fLocation2
= new TmfLocation
<Long
>(aLong
);
38 final TmfLocation
<TmfTimestamp
> fLocation3
= new TmfLocation
<TmfTimestamp
>(aTimestamp
);
40 final long fRank1
= 1;
41 final long fRank2
= 2;
42 final long fRank3
= 3;
44 final TmfContext fContext1
= new TmfContext(fLocation1
, fRank1
);
45 final TmfContext fContext2
= new TmfContext(fLocation2
, fRank2
);
46 final TmfContext fContext3
= new TmfContext(fLocation3
, fRank3
);
48 // ------------------------------------------------------------------------
50 // ------------------------------------------------------------------------
53 * @param name the test name
55 public TmfContextTest(String name
) {
60 protected void setUp() throws Exception
{
65 protected void tearDown() throws Exception
{
69 // ------------------------------------------------------------------------
71 // ------------------------------------------------------------------------
73 public void testTmfContextDefault() {
74 TmfContext context
= new TmfContext();
75 assertEquals("getLocation", null, context
.getLocation());
76 assertEquals("getRank", 0, context
.getRank());
79 public void testTmfContextNoRank() {
80 TmfContext context1
= new TmfContext(fLocation1
);
81 TmfContext context2
= new TmfContext(fLocation2
);
82 TmfContext context3
= new TmfContext(fLocation3
);
84 assertEquals("getLocation", fLocation1
, context1
.getLocation());
85 assertEquals("getLocation", fLocation2
, context2
.getLocation());
86 assertEquals("getLocation", fLocation3
, context3
.getLocation());
88 assertEquals("getRank", 0, context1
.getRank());
89 assertEquals("getRank", 0, context2
.getRank());
90 assertEquals("getRank", 0, context3
.getRank());
93 public void testTmfContext() {
94 assertEquals("getLocation", fLocation1
, fContext1
.getLocation());
95 assertEquals("getLocation", fLocation2
, fContext2
.getLocation());
96 assertEquals("getLocation", fLocation3
, fContext3
.getLocation());
98 assertEquals("getRank", fRank1
, fContext1
.getRank());
99 assertEquals("getRank", fRank2
, fContext2
.getRank());
100 assertEquals("getRank", fRank3
, fContext3
.getRank());
103 public void testTmfContextCopy() {
104 TmfContext context1
= new TmfContext(fContext1
);
105 TmfContext context2
= new TmfContext(fContext2
);
106 TmfContext context3
= new TmfContext(fContext3
);
108 assertEquals("getLocation", fLocation1
, context1
.getLocation());
109 assertEquals("getLocation", fLocation2
, context2
.getLocation());
110 assertEquals("getLocation", fLocation3
, context3
.getLocation());
112 assertEquals("getRank", fRank1
, context1
.getRank());
113 assertEquals("getRank", fRank2
, context2
.getRank());
114 assertEquals("getRank", fRank3
, context3
.getRank());
117 // ------------------------------------------------------------------------
119 // ------------------------------------------------------------------------
121 public void testEqualsReflexivity() throws Exception
{
122 assertTrue("equals", fContext1
.equals(fContext1
));
123 assertTrue("equals", fContext2
.equals(fContext2
));
125 assertTrue("equals", !fContext1
.equals(fContext2
));
126 assertTrue("equals", !fContext2
.equals(fContext1
));
129 public void testEqualsSymmetry() throws Exception
{
130 TmfContext context1
= new TmfContext(fContext1
);
131 TmfContext context2
= new TmfContext(fContext2
);
133 assertTrue("equals", context1
.equals(fContext1
));
134 assertTrue("equals", fContext1
.equals(context1
));
136 assertTrue("equals", context2
.equals(fContext2
));
137 assertTrue("equals", fContext2
.equals(context2
));
140 public void testEqualsTransivity() throws Exception
{
141 TmfContext context1
= new TmfContext(fContext1
);
142 TmfContext context2
= new TmfContext(context1
);
143 TmfContext context3
= new TmfContext(context2
);
145 assertTrue("equals", context1
.equals(context2
));
146 assertTrue("equals", context2
.equals(context3
));
147 assertTrue("equals", context1
.equals(context3
));
150 public void testEqualsNull() throws Exception
{
151 assertTrue("equals", !fContext1
.equals(null));
152 assertTrue("equals", !fContext2
.equals(null));
155 // ------------------------------------------------------------------------
157 // ------------------------------------------------------------------------
159 public void testHashCode() throws Exception
{
160 TmfContext context1
= new TmfContext(fContext1
);
161 TmfContext context2
= new TmfContext(fContext2
);
163 assertTrue("hashCode", fContext1
.hashCode() == context1
.hashCode());
164 assertTrue("hashCode", fContext2
.hashCode() == context2
.hashCode());
166 assertTrue("hashCode", fContext1
.hashCode() != context2
.hashCode());
167 assertTrue("hashCode", fContext2
.hashCode() != context1
.hashCode());
170 // ------------------------------------------------------------------------
172 // ------------------------------------------------------------------------
174 public void testToString() {
175 String expected1
= "[TmfContext(" + fLocation1
+ "," + 1 + ")]";
176 String expected2
= "[TmfContext(" + fLocation2
+ "," + 2 + ")]";
177 String expected3
= "[TmfContext(" + fLocation3
+ "," + 3 + ")]";
179 assertEquals("toString", expected1
, fContext1
.toString());
180 assertEquals("toString", expected2
, fContext2
.toString());
181 assertEquals("toString", expected3
, fContext3
.toString());
184 // ------------------------------------------------------------------------
186 // ------------------------------------------------------------------------
188 public void testClone() {
190 TmfContext context1
= fContext1
.clone();
191 TmfContext context2
= fContext2
.clone();
192 TmfContext context3
= fContext3
.clone();
194 assertEquals("clone", context1
, fContext1
);
195 assertEquals("clone", context2
, fContext2
);
196 assertEquals("clone", context3
, fContext3
);
198 catch (InternalError e
) {
203 // ------------------------------------------------------------------------
204 // setLocation, setRank, updateRank
205 // ------------------------------------------------------------------------
207 public void testSetLocation() {
208 TmfContext context1
= new TmfContext(fContext1
);
209 context1
.setLocation(fContext2
.getLocation());
211 assertEquals("getLocation", fLocation2
, context1
.getLocation());
212 assertEquals("getRank", 1, context1
.getRank());
215 public void testSetRank() {
216 TmfContext context1
= new TmfContext(fContext1
);
217 context1
.setRank(fContext2
.getRank());
219 assertEquals("getLocation", fLocation1
, context1
.getLocation());
220 assertEquals("getRank", fRank2
, context1
.getRank());
223 public void testUpdatetRank() {
224 TmfContext context1
= new TmfContext(fContext1
);
226 context1
.updateRank(0);
227 assertEquals("getRank", fRank1
, context1
.getRank());
229 context1
.updateRank(-1);
230 assertEquals("getRank", fRank1
- 1, context1
.getRank());
232 context1
.updateRank(2);
233 assertEquals("getRank", fRank1
+ 1, context1
.getRank());
This page took 0.042311 seconds and 5 git commands to generate.