1 /*******************************************************************************
2 * Copyright (c) 2011 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 * Bernd Hufmann - Initial API and implementation
11 *******************************************************************************/
12 package org
.eclipse
.linuxtools
.tmf
.ui
.tests
.views
.uml2sd
.impl
;
14 import java
.util
.List
;
16 import junit
.framework
.TestCase
;
18 import org
.eclipse
.linuxtools
.tmf
.event
.TmfTimeRange
;
19 import org
.eclipse
.linuxtools
.tmf
.event
.TmfTimestamp
;
20 import org
.eclipse
.linuxtools
.tmf
.signal
.TmfRangeSynchSignal
;
21 import org
.eclipse
.linuxtools
.tmf
.signal
.TmfTimeSynchSignal
;
22 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.GraphNode
;
23 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.impl
.TmfSyncMessage
;
25 public class TmfUml2SDSyncLoaderTimeTest
extends TestCase
{
27 // ------------------------------------------------------------------------
29 // ------------------------------------------------------------------------
30 // Test case 001 expected values
31 final static private Uml2SDTestTimestamp TC_001_TIME_VALUE
= new Uml2SDTestTimestamp(9788642228395L);
32 final static private String TC_001_MESSAGE_NAME
= "START_GAME_REPLY"; //$NON-NLS-1$
33 final static private int TC_001_PAGE_VALUE
= 0;
34 final static private int TC_001_START_OCCURRANCE
= 6;
35 final static private int TC_001_END_OCCURRANCE
= TC_001_START_OCCURRANCE
;
36 final static private String TC_001_START_LIFELINE
= IUml2SDTestConstants
.MASTER_PLAYER_NAME
;
37 final static private String TC_001_END_LIFELINE
= IUml2SDTestConstants
.FIRST_PLAYER_NAME
;
39 // Test case 002 expected values
40 final static private Uml2SDTestTimestamp TC_002_TIME_VALUE
= new Uml2SDTestTimestamp(9789689830722L);
41 final static private String TC_002_MESSAGE_NAME
= "PAUSE_GAME_REQUEST"; //$NON-NLS-1$
42 final static private int TC_002_PAGE_VALUE
= 2;
43 final static private int TC_002_START_OCCURRANCE
= 7;
44 final static private int TC_002_END_OCCURRANCE
= TC_002_START_OCCURRANCE
;
45 final static private String TC_002_START_LIFELINE
= IUml2SDTestConstants
.FIRST_PLAYER_NAME
;
46 final static private String TC_002_END_LIFELINE
= IUml2SDTestConstants
.MASTER_PLAYER_NAME
;
48 // Test case 003 expected values
49 final static private Uml2SDTestTimestamp TC_003_TIME_VALUE
= new Uml2SDTestTimestamp(9790750000000L);
50 final static private int TC_003_PAGE_VALUE
= 4;
52 // Test case 004 expected values
53 final static private int TC_004_PAGE_VALUE
= 0;
55 // Test case 005 expected values
56 final static private int TC_005_PAGE_VALUE
= IUml2SDTestConstants
.TOTAL_NUMBER_OF_PAGES
- 1;
58 // Test case 006 expected values
59 final static private Uml2SDTestTimestamp TC_006_TIME_VALUE
= new Uml2SDTestTimestamp(9792420661655L);
60 final static private int TC_006_PAGE_VALUE
= 4;
61 final static private int TC_006_START_OCCURRANCE
= IUml2SDTestConstants
.MAX_MESSEAGES_PER_PAGE
;
62 final static private int TC_006_END_OCCURRANCE
= TC_006_START_OCCURRANCE
;
64 // Test case 007 expected values
65 final static private Uml2SDTestTimestamp TC_007_TIME_VALUE
= new Uml2SDTestTimestamp(9792420756010L);
66 final static private int TC_007_PAGE_VALUE
= 5;
67 final static private int TC_007_START_OCCURRANCE
= 1;
68 final static private int TC_007_END_OCCURRANCE
= TC_007_START_OCCURRANCE
;
70 // Test case 008 expected values
71 final static private Uml2SDTestTimestamp TC_008_TIME_VALUE
= new Uml2SDTestTimestamp(9788642228395L);
72 final static private int TC_008_PAGE_VALUE
= 0;
73 final static private Uml2SDTestTimestamp TC_008_START_TIME_VALUE
= new Uml2SDTestTimestamp(9788642228395L);
74 final static private Uml2SDTestTimestamp TC_008_END_TIME_VALUE
= new Uml2SDTestTimestamp(9789164833324L);
76 // Test case 009 expected values
77 final static private Uml2SDTestTimestamp TC_009_TIME_VALUE
= new Uml2SDTestTimestamp(9789689220871L);
78 final static private int TC_009_PAGE_VALUE
= 1;
79 final static private Uml2SDTestTimestamp TC_009_START_TIME_VALUE
= TC_009_TIME_VALUE
;
80 final static private Uml2SDTestTimestamp TC_009_END_TIME_VALUE
= new Uml2SDTestTimestamp(9789773881426L);
82 private Uml2SDTestFacility fFacility
;
84 // ------------------------------------------------------------------------
86 // ------------------------------------------------------------------------
87 public TmfUml2SDSyncLoaderTimeTest() {
90 // ------------------------------------------------------------------------
92 // ------------------------------------------------------------------------
94 public void setUp() throws Exception
{
96 fFacility
= Uml2SDTestFacility
.getInstance();
97 fFacility
.init(false);
98 fFacility
.selectExperiment();
103 public void tearDown() throws Exception
{
104 fFacility
.disposeExperiment();
110 @SuppressWarnings("nls")
111 public void testTimeHandling() {
114 * Description: Verify synchToTime (exact time in page), selection of message in page
115 * Verified Methods: loader.syncToTime(), loader.moveToMessage(), loader.moveToMessageInPage()
116 * Expected result: Correct message is selected.
118 fFacility
.getTrace().broadcast(new TmfTimeSynchSignal(this, TC_001_TIME_VALUE
));
119 fFacility
.getLoader().waitForCompletion();
120 fFacility
.delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
121 assertEquals("synchToTime", TC_001_PAGE_VALUE
, fFacility
.getLoader().currentPage());
122 List
<GraphNode
> selection
= fFacility
.getSdView().getSDWidget().getSelection();
123 assertNotNull(selection
);
124 assertEquals("synchToTime", 1, selection
.size());
125 assertTrue(selection
.get(0) instanceof TmfSyncMessage
);
126 TmfSyncMessage msg
= (TmfSyncMessage
) selection
.get(0);
127 assertEquals("synchToTime", TC_001_MESSAGE_NAME
, msg
.getName());
128 assertEquals("synchToTime", 0, TC_001_TIME_VALUE
.compareTo(msg
.getStartTime(), false));
129 assertEquals("synchToTime", TC_001_START_OCCURRANCE
, msg
.getStartOccurrence());
130 assertEquals("synchToTime", TC_001_END_OCCURRANCE
, msg
.getEndOccurrence());
131 assertEquals("synchToTime", TC_001_START_LIFELINE
, msg
.getStartLifeline().getName());
132 assertEquals("synchToTime", TC_001_END_LIFELINE
, msg
.getEndLifeline().getName());
136 * Description: Verify synchToTime (exact time outside of page), selection of message in page
137 * Verified Methods: loader.syncToTime(), loader.moveToMessage(), loader.moveToPage()
138 * Expected result: Correct message is selected.
140 fFacility
.getTrace().broadcast(new TmfTimeSynchSignal(this, TC_002_TIME_VALUE
));
141 fFacility
.getLoader().waitForCompletion();
142 fFacility
.delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
143 assertEquals("synchToTime", TC_002_PAGE_VALUE
, fFacility
.getLoader().currentPage());
144 selection
= fFacility
.getSdView().getSDWidget().getSelection();
145 assertNotNull("synchToTime", selection
);
146 assertEquals("synchToTime", 1, selection
.size());
147 assertTrue("synchToTime", selection
.get(0) instanceof TmfSyncMessage
);
148 msg
= (TmfSyncMessage
) selection
.get(0);
149 assertEquals("synchToTime", TC_002_MESSAGE_NAME
, msg
.getName());
150 assertEquals(0, TC_002_TIME_VALUE
.compareTo(msg
.getStartTime(), false));
151 assertEquals("synchToTime", TC_002_START_OCCURRANCE
, msg
.getStartOccurrence());
152 assertEquals("synchToTime", TC_002_END_OCCURRANCE
, msg
.getEndOccurrence());
153 assertEquals(TC_002_START_LIFELINE
, msg
.getStartLifeline().getName());
154 assertEquals(TC_002_END_LIFELINE
, msg
.getEndLifeline().getName());
159 * Description: Verify synchToTime (timestamp doesn't exist in trace), no selection of message in page
160 * Verified Methods: loader.syncToTime(), loader.moveToMessage(), loader.moveToPage()
161 * Expected result: Move to correct page, currentTime is updated so that focus on the currentTime, but no selection.
163 fFacility
.getLoader().firstPage();
165 fFacility
.getTrace().broadcast(new TmfTimeSynchSignal(this, TC_003_TIME_VALUE
));
166 fFacility
.getLoader().waitForCompletion();
167 fFacility
.delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
168 assertEquals("synchToTime", 0, TC_003_TIME_VALUE
.compareTo(fFacility
.getLoader().getCurrentTime(), false));
169 assertEquals("synchToTime", TC_003_PAGE_VALUE
, fFacility
.getLoader().currentPage());
170 selection
= fFacility
.getSdView().getSDWidget().getSelection();
171 assertNotNull("synchToTime", selection
);
172 assertEquals("synchToTime", 0, selection
.size());
176 * Description: Verify synchToTime (timestamp < experiment time range start)
177 * Verified Methods: loader.syncToTime(), loader.moveToMessage(), loader.moveToPage()
178 * Expected result: Move to first page, focus on the beginning of the page, but no selection.
180 fFacility
.getTrace().broadcast(new TmfTimeSynchSignal(this, TmfTimestamp
.BigBang
));
181 fFacility
.getLoader().waitForCompletion();
182 fFacility
.delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
183 assertEquals("synchToTime", TC_004_PAGE_VALUE
, fFacility
.getLoader().currentPage());
184 selection
= fFacility
.getSdView().getSDWidget().getSelection();
185 assertNotNull("synchToTime", selection
);
186 assertEquals("synchToTime", 0, selection
.size());
190 * Description: Verify synchToTime (timestamp > experiment time range end)
191 * Verified Methods: loader.syncToTime(), loader.moveToMessage(), loader.moveToPage()
192 * Expected result: Move to last page, focus on the end of the page, but no selection.
194 fFacility
.getTrace().broadcast(new TmfTimeSynchSignal(this, TmfTimestamp
.BigCrunch
));
195 fFacility
.getLoader().waitForCompletion();
196 fFacility
.delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
197 assertEquals("synchToTime", TC_005_PAGE_VALUE
, fFacility
.getLoader().currentPage());
198 selection
= fFacility
.getSdView().getSDWidget().getSelection();
199 assertNotNull(selection
);
200 assertEquals("synchToTime", 0, selection
.size());
204 * Description: Verify synchToTime (timestamp of last message in page)
205 * Verified Methods: loader.syncToTime(), loader.moveToMessage(), loader.moveToPage(), loader.moveToMessageInPage()
206 * Expected result: Move to correct page, selection of last message in page.
208 fFacility
.getTrace().broadcast(new TmfTimeSynchSignal(this, TC_006_TIME_VALUE
));
209 fFacility
.getLoader().waitForCompletion();
210 fFacility
.delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
211 assertEquals("synchToTime", TC_006_PAGE_VALUE
, fFacility
.getLoader().currentPage());
212 selection
= fFacility
.getSdView().getSDWidget().getSelection();
213 assertNotNull("synchToTime", selection
);
214 assertEquals("synchToTime", 1, selection
.size());
215 msg
= (TmfSyncMessage
) selection
.get(0);
216 assertEquals("synchToTime", TC_006_START_OCCURRANCE
, msg
.getStartOccurrence());
217 assertEquals("synchToTime", TC_006_END_OCCURRANCE
, msg
.getEndOccurrence());
221 * Description: Verify synchToTime (timestamp of first message in page)
222 * Verified Methods: loader.syncToTime(), loader.moveToMessage(), loader.moveToPage()
223 * Expected result: Move to correct page, selection of last message in page.
225 fFacility
.getTrace().broadcast(new TmfTimeSynchSignal(this, TC_007_TIME_VALUE
));
226 fFacility
.getLoader().waitForCompletion();
227 fFacility
.delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
228 assertEquals("synchToTime", TC_007_PAGE_VALUE
, fFacility
.getLoader().currentPage());
229 selection
= fFacility
.getSdView().getSDWidget().getSelection();
230 assertNotNull("synchToTime", selection
);
231 msg
= (TmfSyncMessage
) selection
.get(0);
232 assertEquals("synchToTime", 1, selection
.size());
233 assertEquals("synchToTime", TC_007_START_OCCURRANCE
, msg
.getStartOccurrence());
234 assertEquals("synchToTime", TC_007_END_OCCURRANCE
, msg
.getEndOccurrence());
238 * Description: Verify time range signal (start, end time and current time are in same page)
239 * Verified Methods: loader.synchToTimeRange(), loader.moveToMessage(), loader.moveToMessageInPage()
240 * Expected result: Move to correct page(=page of start time of range), set focus on start time of range, but no selection of message.
242 // 9788.642228395 (page 0) -> 9789.164833324 (page 0) with selected time 9788.642228395 (page 0)
243 fFacility
.getLoader().firstPage();
244 TmfTimeRange range
= new TmfTimeRange(TC_008_START_TIME_VALUE
, TC_008_END_TIME_VALUE
);
245 fFacility
.getLoader().waitForCompletion();
246 fFacility
.delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
247 fFacility
.getTrace().broadcast(new TmfRangeSynchSignal(this, range
, TC_008_TIME_VALUE
));
248 assertEquals("synchToTimeRange", TC_008_PAGE_VALUE
, fFacility
.getLoader().currentPage());
249 assertNotNull("synchToTimeRange", fFacility
.getLoader().getCurrentTime());
250 assertEquals("synchToTimeRange", 0, TC_008_TIME_VALUE
.compareTo(fFacility
.getLoader().getCurrentTime(), false));
251 selection
= fFacility
.getSdView().getSDWidget().getSelection();
252 // We actually don't want something to be selected!!!
253 assertNotNull("synchToTimeRange", selection
);
254 assertEquals("synchToTimeRange", 0, selection
.size());
258 * Description: Verify time range signal (start and end time are across 2 pages)
259 * Verified Methods: loader.synchToTimeRange(), loader.moveToMessage(), loader.moveToPage()
260 * Expected result: Move to correct page (=page of start time of range), set focus on start time of range, but no selection of message.
262 range
= new TmfTimeRange(TC_009_START_TIME_VALUE
, TC_009_END_TIME_VALUE
);
263 fFacility
.getTrace().broadcast(new TmfRangeSynchSignal(this, range
, TC_009_TIME_VALUE
));
264 fFacility
.getLoader().waitForCompletion();
265 fFacility
.delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
266 assertEquals("synchToTimeRange", TC_009_PAGE_VALUE
, fFacility
.getLoader().currentPage());
267 assertNotNull("synchToTimeRange", fFacility
.getLoader().getCurrentTime());
268 assertEquals("synchToTimeRange", 0, TC_009_TIME_VALUE
.compareTo(fFacility
.getLoader().getCurrentTime(), false));
269 selection
= fFacility
.getSdView().getSDWidget().getSelection();
270 // We actually don't want something to be selected!!!
271 assertNotNull("synchToTimeRange", selection
);
272 assertEquals("synchToTimeRange", 0, selection
.size());