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 @SuppressWarnings("nls")
27 public class TmfContextTest
extends TestCase
{
29 // ------------------------------------------------------------------------
31 // ------------------------------------------------------------------------
33 final String aString
= "some location";
34 final Long aLong
= 12345L;
35 final TmfTimestamp aTimestamp
= new TmfTimestamp();
37 final TmfLocation
<String
> fLocation1
= new TmfLocation
<String
>(aString
);
38 final TmfLocation
<Long
> fLocation2
= new TmfLocation
<Long
>(aLong
);
39 final TmfLocation
<TmfTimestamp
> fLocation3
= new TmfLocation
<TmfTimestamp
>(aTimestamp
);
41 final long fRank1
= 1;
42 final long fRank2
= 2;
43 final long fRank3
= 3;
45 final TmfContext fContext1
= new TmfContext(fLocation1
, fRank1
);
46 final TmfContext fContext2
= new TmfContext(fLocation2
, fRank2
);
47 final TmfContext fContext3
= new TmfContext(fLocation3
, fRank3
);
49 // ------------------------------------------------------------------------
51 // ------------------------------------------------------------------------
54 * @param name the test name
56 public TmfContextTest(String name
) {
61 protected void setUp() throws Exception
{
66 protected void tearDown() throws Exception
{
70 // ------------------------------------------------------------------------
72 // ------------------------------------------------------------------------
74 public void testTmfContextDefault() {
75 TmfContext context
= new TmfContext();
76 assertEquals("getLocation", null, context
.getLocation());
77 assertEquals("getRank", TmfContext
.UNKNOWN_RANK
, context
.getRank());
80 public void testTmfContextNoRank() {
81 TmfContext context1
= new TmfContext(fLocation1
);
82 TmfContext context2
= new TmfContext(fLocation2
);
83 TmfContext context3
= new TmfContext(fLocation3
);
85 assertEquals("getLocation", fLocation1
, context1
.getLocation());
86 assertEquals("getLocation", fLocation2
, context2
.getLocation());
87 assertEquals("getLocation", fLocation3
, context3
.getLocation());
89 assertEquals("getRank", TmfContext
.UNKNOWN_RANK
, context1
.getRank());
90 assertEquals("getRank", TmfContext
.UNKNOWN_RANK
, context2
.getRank());
91 assertEquals("getRank", TmfContext
.UNKNOWN_RANK
, context3
.getRank());
94 public void testTmfContext() {
95 assertEquals("getLocation", fLocation1
, fContext1
.getLocation());
96 assertEquals("getLocation", fLocation2
, fContext2
.getLocation());
97 assertEquals("getLocation", fLocation3
, fContext3
.getLocation());
99 assertEquals("getRank", fRank1
, fContext1
.getRank());
100 assertEquals("getRank", fRank2
, fContext2
.getRank());
101 assertEquals("getRank", fRank3
, fContext3
.getRank());
104 public void testTmfContextCopy() {
105 TmfContext context1
= new TmfContext(fContext1
);
106 TmfContext context2
= new TmfContext(fContext2
);
107 TmfContext context3
= new TmfContext(fContext3
);
109 assertEquals("getLocation", fLocation1
, context1
.getLocation());
110 assertEquals("getLocation", fLocation2
, context2
.getLocation());
111 assertEquals("getLocation", fLocation3
, context3
.getLocation());
113 assertEquals("getRank", fRank1
, context1
.getRank());
114 assertEquals("getRank", fRank2
, context2
.getRank());
115 assertEquals("getRank", fRank3
, context3
.getRank());
118 // ------------------------------------------------------------------------
120 // ------------------------------------------------------------------------
122 public void testEqualsReflexivity() throws Exception
{
123 assertTrue("equals", fContext1
.equals(fContext1
));
124 assertTrue("equals", fContext2
.equals(fContext2
));
126 assertTrue("equals", !fContext1
.equals(fContext2
));
127 assertTrue("equals", !fContext2
.equals(fContext1
));
130 public void testEqualsSymmetry() throws Exception
{
131 TmfContext context1
= new TmfContext(fContext1
);
132 TmfContext context2
= new TmfContext(fContext2
);
134 assertTrue("equals", context1
.equals(fContext1
));
135 assertTrue("equals", fContext1
.equals(context1
));
137 assertTrue("equals", context2
.equals(fContext2
));
138 assertTrue("equals", fContext2
.equals(context2
));
141 public void testEqualsTransivity() throws Exception
{
142 TmfContext context1
= new TmfContext(fContext1
);
143 TmfContext context2
= new TmfContext(context1
);
144 TmfContext context3
= new TmfContext(context2
);
146 assertTrue("equals", context1
.equals(context2
));
147 assertTrue("equals", context2
.equals(context3
));
148 assertTrue("equals", context1
.equals(context3
));
151 public void testEqualsNull() throws Exception
{
152 assertTrue("equals", !fContext1
.equals(null));
153 assertTrue("equals", !fContext2
.equals(null));
156 // ------------------------------------------------------------------------
158 // ------------------------------------------------------------------------
160 public void testHashCode() throws Exception
{
161 TmfContext context1
= new TmfContext(fContext1
);
162 TmfContext context2
= new TmfContext(fContext2
);
164 assertTrue("hashCode", fContext1
.hashCode() == context1
.hashCode());
165 assertTrue("hashCode", fContext2
.hashCode() == context2
.hashCode());
167 assertTrue("hashCode", fContext1
.hashCode() != context2
.hashCode());
168 assertTrue("hashCode", fContext2
.hashCode() != context1
.hashCode());
171 // ------------------------------------------------------------------------
173 // ------------------------------------------------------------------------
175 public void testToString() {
176 String expected1
= "[TmfContext(" + fLocation1
+ "," + 1 + ")]";
177 String expected2
= "[TmfContext(" + fLocation2
+ "," + 2 + ")]";
178 String expected3
= "[TmfContext(" + fLocation3
+ "," + 3 + ")]";
180 assertEquals("toString", expected1
, fContext1
.toString());
181 assertEquals("toString", expected2
, fContext2
.toString());
182 assertEquals("toString", expected3
, fContext3
.toString());
185 // ------------------------------------------------------------------------
187 // ------------------------------------------------------------------------
189 public void testClone() {
191 TmfContext context1
= fContext1
.clone();
192 TmfContext context2
= fContext2
.clone();
193 TmfContext context3
= fContext3
.clone();
195 assertEquals("clone", context1
, fContext1
);
196 assertEquals("clone", context2
, fContext2
);
197 assertEquals("clone", context3
, fContext3
);
199 catch (InternalError e
) {
204 // ------------------------------------------------------------------------
205 // setLocation, setRank, updateRank
206 // ------------------------------------------------------------------------
208 public void testSetLocation() {
209 TmfContext context1
= new TmfContext(fContext1
);
210 context1
.setLocation(fContext2
.getLocation());
212 assertEquals("getLocation", fLocation2
, context1
.getLocation());
213 assertEquals("getRank", 1, context1
.getRank());
216 public void testSetRank() {
217 TmfContext context1
= new TmfContext(fContext1
);
218 context1
.setRank(fContext2
.getRank());
220 assertEquals("getLocation", fLocation1
, context1
.getLocation());
221 assertEquals("getRank", fRank2
, context1
.getRank());
224 public void testUpdatetRank() {
225 TmfContext context1
= new TmfContext(fContext1
);
227 context1
.updateRank(0);
228 assertEquals("getRank", fRank1
, context1
.getRank());
230 context1
.updateRank(-1);
231 assertEquals("getRank", fRank1
- 1, context1
.getRank());
233 context1
.updateRank(2);
234 assertEquals("getRank", fRank1
+ 1, context1
.getRank());
This page took 0.037827 seconds and 5 git commands to generate.