1 /*******************************************************************************
2 * Copyright (c) 2011, 2013 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 * Alexandre Montplaisir - Port to JUnit4
12 * Patrick Tasse - Support selection range
13 *******************************************************************************/
15 package org
.eclipse
.linuxtools
.tmf
.ui
.tests
.views
.uml2sd
.loader
;
17 import static org
.junit
.Assert
.assertEquals
;
18 import static org
.junit
.Assert
.assertNotNull
;
19 import static org
.junit
.Assert
.assertTrue
;
21 import java
.util
.List
;
23 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfRangeSynchSignal
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTimeSynchSignal
;
25 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.TmfTimeRange
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.TmfTimestamp
;
27 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.GraphNode
;
28 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.loader
.TmfSyncMessage
;
29 import org
.junit
.AfterClass
;
30 import org
.junit
.BeforeClass
;
31 import org
.junit
.Test
;
34 * Test cases for time synchronization handling.
36 * @author Bernd Hufmann
38 public class TmfUml2SDSyncLoaderTimeTest
{
40 // ------------------------------------------------------------------------
42 // ------------------------------------------------------------------------
44 // Test case 001 expected values
45 final static private Uml2SDTestTimestamp TC_001_TIME_VALUE
= new Uml2SDTestTimestamp(9788642228395L);
46 final static private String TC_001_MESSAGE_NAME
= "START_GAME_REPLY";
47 final static private int TC_001_PAGE_VALUE
= 0;
48 final static private int TC_001_START_OCCURRANCE
= 6;
49 final static private int TC_001_END_OCCURRANCE
= TC_001_START_OCCURRANCE
;
50 final static private String TC_001_START_LIFELINE
= IUml2SDTestConstants
.MASTER_PLAYER_NAME
;
51 final static private String TC_001_END_LIFELINE
= IUml2SDTestConstants
.FIRST_PLAYER_NAME
;
53 // Test case 002 expected values
54 final static private Uml2SDTestTimestamp TC_002_TIME_VALUE
= new Uml2SDTestTimestamp(9789689830722L);
55 final static private String TC_002_MESSAGE_NAME
= "PAUSE_GAME_REQUEST";
56 final static private int TC_002_PAGE_VALUE
= 2;
57 final static private int TC_002_START_OCCURRANCE
= 7;
58 final static private int TC_002_END_OCCURRANCE
= TC_002_START_OCCURRANCE
;
59 final static private String TC_002_START_LIFELINE
= IUml2SDTestConstants
.FIRST_PLAYER_NAME
;
60 final static private String TC_002_END_LIFELINE
= IUml2SDTestConstants
.MASTER_PLAYER_NAME
;
62 // Test case 003 expected values
63 final static private Uml2SDTestTimestamp TC_003_TIME_VALUE
= new Uml2SDTestTimestamp(9790750000000L);
64 final static private int TC_003_PAGE_VALUE
= 4;
66 // Test case 004 expected values
67 final static private int TC_004_PAGE_VALUE
= 0;
69 // Test case 005 expected values
70 final static private int TC_005_PAGE_VALUE
= IUml2SDTestConstants
.TOTAL_NUMBER_OF_PAGES
- 1;
72 // Test case 006 expected values
73 final static private Uml2SDTestTimestamp TC_006_TIME_VALUE
= new Uml2SDTestTimestamp(9792420661655L);
74 final static private int TC_006_PAGE_VALUE
= 4;
75 final static private int TC_006_START_OCCURRANCE
= IUml2SDTestConstants
.MAX_MESSEAGES_PER_PAGE
;
76 final static private int TC_006_END_OCCURRANCE
= TC_006_START_OCCURRANCE
;
78 // Test case 007 expected values
79 final static private Uml2SDTestTimestamp TC_007_TIME_VALUE
= new Uml2SDTestTimestamp(9792420756010L);
80 final static private int TC_007_PAGE_VALUE
= 5;
81 final static private int TC_007_START_OCCURRANCE
= 1;
82 final static private int TC_007_END_OCCURRANCE
= TC_007_START_OCCURRANCE
;
84 // Test case 008 expected values
85 final static private Uml2SDTestTimestamp TC_008_TIME_VALUE
= new Uml2SDTestTimestamp(9788642228395L);
86 final static private int TC_008_PAGE_VALUE
= 0;
87 final static private Uml2SDTestTimestamp TC_008_START_TIME_VALUE
= new Uml2SDTestTimestamp(9788642228395L);
88 final static private Uml2SDTestTimestamp TC_008_END_TIME_VALUE
= new Uml2SDTestTimestamp(9789164833324L);
90 // Test case 009 expected values
91 final static private Uml2SDTestTimestamp TC_009_TIME_VALUE
= new Uml2SDTestTimestamp(9789689220871L);
92 final static private int TC_009_PAGE_VALUE
= 1;
93 final static private Uml2SDTestTimestamp TC_009_START_TIME_VALUE
= TC_009_TIME_VALUE
;
94 final static private Uml2SDTestTimestamp TC_009_END_TIME_VALUE
= new Uml2SDTestTimestamp(9789773881426L);
96 // Fields used in tests
97 private static Uml2SDTestFacility fFacility
;
98 private static List
<GraphNode
> selection
;
99 private static TmfSyncMessage msg
;
101 // ------------------------------------------------------------------------
103 // ------------------------------------------------------------------------
109 public static void setUpClass() {
110 fFacility
= Uml2SDTestFacility
.getInstance();
111 fFacility
.selectExperiment();
118 public static void tearDownClass() {
119 fFacility
.disposeExperiment();
125 * Description: Verify synchToTime (exact time in page), selection of message in page
126 * Verified Methods: loader.syncToTime(), loader.moveToMessage(), loader.moveToMessageInPage()
127 * Expected result: Correct message is selected.
130 public void verifySynchToTimeInPage() {
131 fFacility
.getTrace().broadcast(new TmfTimeSynchSignal(this, TC_001_TIME_VALUE
));
132 fFacility
.getLoader().waitForCompletion();
133 fFacility
.delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
134 assertEquals("synchToTime", TC_001_PAGE_VALUE
, fFacility
.getLoader().currentPage());
135 selection
= fFacility
.getSdView().getSDWidget().getSelection();
136 assertNotNull(selection
);
137 assertEquals("synchToTime", 1, selection
.size());
138 assertTrue(selection
.get(0) instanceof TmfSyncMessage
);
139 msg
= (TmfSyncMessage
) selection
.get(0);
140 assertEquals("synchToTime", TC_001_MESSAGE_NAME
, msg
.getName());
141 assertEquals("synchToTime", 0, TC_001_TIME_VALUE
.compareTo(msg
.getStartTime(), false));
142 assertEquals("synchToTime", TC_001_START_OCCURRANCE
, msg
.getStartOccurrence());
143 assertEquals("synchToTime", TC_001_END_OCCURRANCE
, msg
.getEndOccurrence());
144 assertEquals("synchToTime", TC_001_START_LIFELINE
, msg
.getStartLifeline().getName());
145 assertEquals("synchToTime", TC_001_END_LIFELINE
, msg
.getEndLifeline().getName());
150 * Description: Verify synchToTime (exact time outside of page), selection of message in page
151 * Verified Methods: loader.syncToTime(), loader.moveToMessage(), loader.moveToPage()
152 * Expected result: Correct message is selected.
155 public void verifySynchToTimeOutsidePage() {
156 fFacility
.getTrace().broadcast(new TmfTimeSynchSignal(this, TC_002_TIME_VALUE
));
157 fFacility
.getLoader().waitForCompletion();
158 fFacility
.delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
159 assertEquals("synchToTime", TC_002_PAGE_VALUE
, fFacility
.getLoader().currentPage());
160 selection
= fFacility
.getSdView().getSDWidget().getSelection();
161 assertNotNull("synchToTime", selection
);
162 assertEquals("synchToTime", 1, selection
.size());
163 assertTrue("synchToTime", selection
.get(0) instanceof TmfSyncMessage
);
164 msg
= (TmfSyncMessage
) selection
.get(0);
165 assertEquals("synchToTime", TC_002_MESSAGE_NAME
, msg
.getName());
166 assertEquals(0, TC_002_TIME_VALUE
.compareTo(msg
.getStartTime(), false));
167 assertEquals("synchToTime", TC_002_START_OCCURRANCE
, msg
.getStartOccurrence());
168 assertEquals("synchToTime", TC_002_END_OCCURRANCE
, msg
.getEndOccurrence());
169 assertEquals(TC_002_START_LIFELINE
, msg
.getStartLifeline().getName());
170 assertEquals(TC_002_END_LIFELINE
, msg
.getEndLifeline().getName());
176 * Description: Verify synchToTime (timestamp doesn't exist in trace), no selection of message in page
177 * Verified Methods: loader.syncToTime(), loader.moveToMessage(), loader.moveToPage()
178 * Expected result: Move to correct page, currentTime is updated so that focus on the currentTime, but no selection.
181 public void verifySynchToTimeNonExisting() {
182 fFacility
.getLoader().firstPage();
184 fFacility
.getTrace().broadcast(new TmfTimeSynchSignal(this, TC_003_TIME_VALUE
));
185 fFacility
.getLoader().waitForCompletion();
186 fFacility
.delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
187 assertEquals("synchToTime", 0, TC_003_TIME_VALUE
.compareTo(fFacility
.getLoader().getCurrentTime(), false));
188 assertEquals("synchToTime", TC_003_PAGE_VALUE
, fFacility
.getLoader().currentPage());
189 selection
= fFacility
.getSdView().getSDWidget().getSelection();
190 assertNotNull("synchToTime", selection
);
191 assertEquals("synchToTime", 0, selection
.size());
196 * Description: Verify synchToTime (timestamp < experiment time range start)
197 * Verified Methods: loader.syncToTime(), loader.moveToMessage(), loader.moveToPage()
198 * Expected result: Move to first page, focus on the beginning of the page, but no selection.
201 public void verifySynchToTimeBeforeExpStart() {
202 fFacility
.getTrace().broadcast(new TmfTimeSynchSignal(this, TmfTimestamp
.BIG_BANG
));
203 fFacility
.getLoader().waitForCompletion();
204 fFacility
.delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
205 assertEquals("synchToTime", TC_004_PAGE_VALUE
, fFacility
.getLoader().currentPage());
206 selection
= fFacility
.getSdView().getSDWidget().getSelection();
207 assertNotNull("synchToTime", selection
);
208 assertEquals("synchToTime", 0, selection
.size());
213 * Description: Verify synchToTime (timestamp > experiment time range end)
214 * Verified Methods: loader.syncToTime(), loader.moveToMessage(), loader.moveToPage()
215 * Expected result: Move to last page, focus on the end of the page, but no selection.
218 public void verifySynchToTimeAfterExpEnd() {
219 fFacility
.getTrace().broadcast(new TmfTimeSynchSignal(this, TmfTimestamp
.BIG_CRUNCH
));
220 fFacility
.getLoader().waitForCompletion();
221 fFacility
.delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
222 assertEquals("synchToTime", TC_005_PAGE_VALUE
, fFacility
.getLoader().currentPage());
223 selection
= fFacility
.getSdView().getSDWidget().getSelection();
224 assertNotNull(selection
);
225 assertEquals("synchToTime", 0, selection
.size());
230 * Description: Verify synchToTime (timestamp of last message in page)
231 * Verified Methods: loader.syncToTime(), loader.moveToMessage(), loader.moveToPage(), loader.moveToMessageInPage()
232 * Expected result: Move to correct page, selection of last message in page.
235 public void verifySynchToTimeEqualsLast() {
236 fFacility
.getTrace().broadcast(new TmfTimeSynchSignal(this, TC_006_TIME_VALUE
));
237 fFacility
.getLoader().waitForCompletion();
238 fFacility
.delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
239 assertEquals("synchToTime", TC_006_PAGE_VALUE
, fFacility
.getLoader().currentPage());
240 selection
= fFacility
.getSdView().getSDWidget().getSelection();
241 assertNotNull("synchToTime", selection
);
242 assertEquals("synchToTime", 1, selection
.size());
243 msg
= (TmfSyncMessage
) selection
.get(0);
244 assertEquals("synchToTime", TC_006_START_OCCURRANCE
, msg
.getStartOccurrence());
245 assertEquals("synchToTime", TC_006_END_OCCURRANCE
, msg
.getEndOccurrence());
250 * Description: Verify synchToTime (timestamp of first message in page)
251 * Verified Methods: loader.syncToTime(), loader.moveToMessage(), loader.moveToPage()
252 * Expected result: Move to correct page, selection of last message in page.
255 public void verifySynchToTimeFirst() {
256 fFacility
.getTrace().broadcast(new TmfTimeSynchSignal(this, TC_007_TIME_VALUE
));
257 fFacility
.getLoader().waitForCompletion();
258 fFacility
.delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
259 assertEquals("synchToTime", TC_007_PAGE_VALUE
, fFacility
.getLoader().currentPage());
260 selection
= fFacility
.getSdView().getSDWidget().getSelection();
261 assertNotNull("synchToTime", selection
);
262 msg
= (TmfSyncMessage
) selection
.get(0);
263 assertEquals("synchToTime", 1, selection
.size());
264 assertEquals("synchToTime", TC_007_START_OCCURRANCE
, msg
.getStartOccurrence());
265 assertEquals("synchToTime", TC_007_END_OCCURRANCE
, msg
.getEndOccurrence());
270 * Description: Verify time range signal (start, end time and current time are in same page)
271 * Verified Methods: loader.synchToTimeRange(), loader.moveToMessage(), loader.moveToMessageInPage()
272 * Expected result: Move to correct page(=page of start time of range), set focus on start time of range, but no selection of message.
275 public void verifyTimeRangeSamePage() {
276 // 9788.642228395 (page 0) -> 9789.164833324 (page 0) with selected time 9788.642228395 (page 0)
277 fFacility
.getLoader().firstPage();
278 TmfTimeRange range
= new TmfTimeRange(TC_008_START_TIME_VALUE
, TC_008_END_TIME_VALUE
);
279 fFacility
.getLoader().waitForCompletion();
280 fFacility
.delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
281 fFacility
.getTrace().broadcast(new TmfRangeSynchSignal(this, range
));
282 assertEquals("synchToTimeRange", TC_008_PAGE_VALUE
, fFacility
.getLoader().currentPage());
283 assertNotNull("synchToTimeRange", fFacility
.getLoader().getCurrentTime());
284 assertEquals("synchToTimeRange", 0, TC_008_TIME_VALUE
.compareTo(fFacility
.getLoader().getCurrentTime(), false));
285 selection
= fFacility
.getSdView().getSDWidget().getSelection();
286 // We actually don't want something to be selected!!!
287 assertNotNull("synchToTimeRange", selection
);
288 assertEquals("synchToTimeRange", 0, selection
.size());
293 * Description: Verify time range signal (start and end time are across 2 pages)
294 * Verified Methods: loader.synchToTimeRange(), loader.moveToMessage(), loader.moveToPage()
295 * Expected result: Move to correct page (=page of start time of range), set focus on start time of range, but no selection of message.
298 public void verifyTimeRangeDifferentPages() {
299 TmfTimeRange range
= new TmfTimeRange(TC_009_START_TIME_VALUE
, TC_009_END_TIME_VALUE
);
300 fFacility
.getTrace().broadcast(new TmfRangeSynchSignal(this, range
));
301 fFacility
.getLoader().waitForCompletion();
302 fFacility
.delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
303 assertEquals("synchToTimeRange", TC_009_PAGE_VALUE
, fFacility
.getLoader().currentPage());
304 assertNotNull("synchToTimeRange", fFacility
.getLoader().getCurrentTime());
305 assertEquals("synchToTimeRange", 0, TC_009_TIME_VALUE
.compareTo(fFacility
.getLoader().getCurrentTime(), false));
306 selection
= fFacility
.getSdView().getSDWidget().getSelection();
307 // We actually don't want something to be selected!!!
308 assertNotNull("synchToTimeRange", selection
);
309 assertEquals("synchToTimeRange", 0, selection
.size());