be67b8a3e8e4ee4011062b61f0d40829669fe59c
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.ui.tests / src / org / eclipse / tracecompass / tmf / ui / tests / views / uml2sd / loader / TmfUml2SDSyncLoaderTimeTest.java
1 /*******************************************************************************
2 * Copyright (c) 2011, 2014 Ericsson
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 * Bernd Hufmann - Initial API and implementation
11 * Alexandre Montplaisir - Port to JUnit4
12 * Patrick Tasse - Support selection range
13 *******************************************************************************/
14
15 package org.eclipse.tracecompass.tmf.ui.tests.views.uml2sd.loader;
16
17 import static org.junit.Assert.assertEquals;
18 import static org.junit.Assert.assertNotNull;
19 import static org.junit.Assert.assertTrue;
20
21 import java.util.List;
22
23 import org.eclipse.tracecompass.tmf.core.signal.TmfRangeSynchSignal;
24 import org.eclipse.tracecompass.tmf.core.signal.TmfTimeSynchSignal;
25 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
26 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
27 import org.eclipse.tracecompass.tmf.ui.views.uml2sd.core.GraphNode;
28 import org.eclipse.tracecompass.tmf.ui.views.uml2sd.loader.TmfSyncMessage;
29 import org.junit.AfterClass;
30 import org.junit.BeforeClass;
31 import org.junit.Test;
32
33 /**
34 * Test cases for time synchronization handling.
35 *
36 * @author Bernd Hufmann
37 */
38 public class TmfUml2SDSyncLoaderTimeTest {
39
40 // ------------------------------------------------------------------------
41 // Attributes
42 // ------------------------------------------------------------------------
43
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;
52
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;
61
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;
65
66 // Test case 004 expected values
67 final static private int TC_004_PAGE_VALUE = 0;
68
69 // Test case 005 expected values
70 final static private int TC_005_PAGE_VALUE = IUml2SDTestConstants.TOTAL_NUMBER_OF_PAGES - 1;
71
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;
77
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;
83
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);
89
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);
95
96 // Fields used in tests
97 private static Uml2SDTestFacility fFacility;
98 private static List<GraphNode> selection;
99 private static TmfSyncMessage msg;
100
101 // ------------------------------------------------------------------------
102 // Operations
103 // ------------------------------------------------------------------------
104
105 /**
106 * Initialization
107 */
108 @BeforeClass
109 public static void setUpClass() {
110 fFacility = Uml2SDTestFacility.getInstance();
111 fFacility.selectExperiment();
112 }
113
114 /**
115 * Cleanup
116 */
117 @AfterClass
118 public static void tearDownClass() {
119 fFacility.disposeExperiment();
120 fFacility = null;
121 }
122
123 /**
124 * Test Case: 001
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.
128 */
129 @Test
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()));
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());
146 }
147
148 /**
149 * Test Case: 002
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.
153 */
154 @Test
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()));
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());
171 }
172
173
174 /**
175 * Test Case: 003
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.
179 */
180 @Test
181 public void verifySynchToTimeNonExisting() {
182 fFacility.getLoader().firstPage();
183
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()));
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());
192 }
193
194 /**
195 * Test Case: 004
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.
199 */
200 @Test
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());
209 }
210
211 /**
212 * Test Case: 005
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.
216 */
217 @Test
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());
226 }
227
228 /**
229 * Test Case: 006
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.
233 */
234 @Test
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());
246 }
247
248 /**
249 * Test Case: 007
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.
253 */
254 @Test
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());
266 }
267
268 /**
269 * Test Case: 008
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.
273 */
274 @Test
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()));
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());
289 }
290
291 /**
292 * Test Case: 009
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.
296 */
297 @Test
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()));
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());
310 }
311 }
This page took 0.053582 seconds and 4 git commands to generate.