ctf: Rename internal CTFStrings to MetadataStrings
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui.tests / src / org / eclipse / linuxtools / tmf / ui / tests / views / uml2sd / loader / TmfUml2SDSyncLoaderTimeTest.java
1 /*******************************************************************************
2 * Copyright (c) 2011-2013 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 *******************************************************************************/
13
14 package org.eclipse.linuxtools.tmf.ui.tests.views.uml2sd.loader;
15
16 import static org.junit.Assert.assertEquals;
17 import static org.junit.Assert.assertNotNull;
18 import static org.junit.Assert.assertTrue;
19
20 import java.util.List;
21
22 import org.eclipse.linuxtools.tmf.core.signal.TmfRangeSynchSignal;
23 import org.eclipse.linuxtools.tmf.core.signal.TmfTimeSynchSignal;
24 import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
25 import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
26 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode;
27 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.loader.TmfSyncMessage;
28 import org.junit.AfterClass;
29 import org.junit.BeforeClass;
30 import org.junit.Test;
31
32 /**
33 * Test cases for time synchronization handling.
34 *
35 * @author Bernd Hufmann
36 */
37 public class TmfUml2SDSyncLoaderTimeTest {
38
39 // ------------------------------------------------------------------------
40 // Attributes
41 // ------------------------------------------------------------------------
42
43 // Test case 001 expected values
44 final static private Uml2SDTestTimestamp TC_001_TIME_VALUE = new Uml2SDTestTimestamp(9788642228395L);
45 final static private String TC_001_MESSAGE_NAME = "START_GAME_REPLY";
46 final static private int TC_001_PAGE_VALUE = 0;
47 final static private int TC_001_START_OCCURRANCE = 6;
48 final static private int TC_001_END_OCCURRANCE = TC_001_START_OCCURRANCE;
49 final static private String TC_001_START_LIFELINE = IUml2SDTestConstants.MASTER_PLAYER_NAME;
50 final static private String TC_001_END_LIFELINE = IUml2SDTestConstants.FIRST_PLAYER_NAME;
51
52 // Test case 002 expected values
53 final static private Uml2SDTestTimestamp TC_002_TIME_VALUE = new Uml2SDTestTimestamp(9789689830722L);
54 final static private String TC_002_MESSAGE_NAME = "PAUSE_GAME_REQUEST";
55 final static private int TC_002_PAGE_VALUE = 2;
56 final static private int TC_002_START_OCCURRANCE = 7;
57 final static private int TC_002_END_OCCURRANCE = TC_002_START_OCCURRANCE;
58 final static private String TC_002_START_LIFELINE = IUml2SDTestConstants.FIRST_PLAYER_NAME;
59 final static private String TC_002_END_LIFELINE = IUml2SDTestConstants.MASTER_PLAYER_NAME;
60
61 // Test case 003 expected values
62 final static private Uml2SDTestTimestamp TC_003_TIME_VALUE = new Uml2SDTestTimestamp(9790750000000L);
63 final static private int TC_003_PAGE_VALUE = 4;
64
65 // Test case 004 expected values
66 final static private int TC_004_PAGE_VALUE = 0;
67
68 // Test case 005 expected values
69 final static private int TC_005_PAGE_VALUE = IUml2SDTestConstants.TOTAL_NUMBER_OF_PAGES - 1;
70
71 // Test case 006 expected values
72 final static private Uml2SDTestTimestamp TC_006_TIME_VALUE = new Uml2SDTestTimestamp(9792420661655L);
73 final static private int TC_006_PAGE_VALUE = 4;
74 final static private int TC_006_START_OCCURRANCE = IUml2SDTestConstants.MAX_MESSEAGES_PER_PAGE;
75 final static private int TC_006_END_OCCURRANCE = TC_006_START_OCCURRANCE;
76
77 // Test case 007 expected values
78 final static private Uml2SDTestTimestamp TC_007_TIME_VALUE = new Uml2SDTestTimestamp(9792420756010L);
79 final static private int TC_007_PAGE_VALUE = 5;
80 final static private int TC_007_START_OCCURRANCE = 1;
81 final static private int TC_007_END_OCCURRANCE = TC_007_START_OCCURRANCE;
82
83 // Test case 008 expected values
84 final static private Uml2SDTestTimestamp TC_008_TIME_VALUE = new Uml2SDTestTimestamp(9788642228395L);
85 final static private int TC_008_PAGE_VALUE = 0;
86 final static private Uml2SDTestTimestamp TC_008_START_TIME_VALUE = new Uml2SDTestTimestamp(9788642228395L);
87 final static private Uml2SDTestTimestamp TC_008_END_TIME_VALUE = new Uml2SDTestTimestamp(9789164833324L);
88
89 // Test case 009 expected values
90 final static private Uml2SDTestTimestamp TC_009_TIME_VALUE = new Uml2SDTestTimestamp(9789689220871L);
91 final static private int TC_009_PAGE_VALUE = 1;
92 final static private Uml2SDTestTimestamp TC_009_START_TIME_VALUE = TC_009_TIME_VALUE;
93 final static private Uml2SDTestTimestamp TC_009_END_TIME_VALUE = new Uml2SDTestTimestamp(9789773881426L);
94
95 // Fields used in tests
96 private static Uml2SDTestFacility fFacility;
97 private static List<GraphNode> selection;
98 private static TmfSyncMessage msg;
99
100 // ------------------------------------------------------------------------
101 // Operations
102 // ------------------------------------------------------------------------
103
104 /**
105 * Initialization
106 */
107 @BeforeClass
108 public static void setUpClass() {
109 fFacility = Uml2SDTestFacility.getInstance();
110 fFacility.selectExperiment();
111 }
112
113 /**
114 * Cleanup
115 */
116 @AfterClass
117 public static void tearDownClass() {
118 fFacility.disposeExperiment();
119 fFacility = null;
120 }
121
122 /**
123 * Test Case: 001
124 * Description: Verify synchToTime (exact time in page), selection of message in page
125 * Verified Methods: loader.syncToTime(), loader.moveToMessage(), loader.moveToMessageInPage()
126 * Expected result: Correct message is selected.
127 */
128 @Test
129 public void verifySynchToTimeInPage() {
130 fFacility.getTrace().broadcast(new TmfTimeSynchSignal(this, TC_001_TIME_VALUE));
131 fFacility.getLoader().waitForCompletion();
132 fFacility.delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
133 assertEquals("synchToTime", TC_001_PAGE_VALUE, fFacility.getLoader().currentPage());
134 selection = fFacility.getSdView().getSDWidget().getSelection();
135 assertNotNull(selection);
136 assertEquals("synchToTime", 1, selection.size());
137 assertTrue(selection.get(0) instanceof TmfSyncMessage);
138 msg = (TmfSyncMessage) selection.get(0);
139 assertEquals("synchToTime", TC_001_MESSAGE_NAME, msg.getName());
140 assertEquals("synchToTime", 0, TC_001_TIME_VALUE.compareTo(msg.getStartTime(), false));
141 assertEquals("synchToTime", TC_001_START_OCCURRANCE, msg.getStartOccurrence());
142 assertEquals("synchToTime", TC_001_END_OCCURRANCE, msg.getEndOccurrence());
143 assertEquals("synchToTime", TC_001_START_LIFELINE, msg.getStartLifeline().getName());
144 assertEquals("synchToTime", TC_001_END_LIFELINE, msg.getEndLifeline().getName());
145 }
146
147 /**
148 * Test Case: 002
149 * Description: Verify synchToTime (exact time outside of page), selection of message in page
150 * Verified Methods: loader.syncToTime(), loader.moveToMessage(), loader.moveToPage()
151 * Expected result: Correct message is selected.
152 */
153 @Test
154 public void verifySynchToTimeOutsidePage() {
155 fFacility.getTrace().broadcast(new TmfTimeSynchSignal(this, TC_002_TIME_VALUE));
156 fFacility.getLoader().waitForCompletion();
157 fFacility.delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
158 assertEquals("synchToTime", TC_002_PAGE_VALUE, fFacility.getLoader().currentPage());
159 selection = fFacility.getSdView().getSDWidget().getSelection();
160 assertNotNull("synchToTime", selection);
161 assertEquals("synchToTime", 1, selection.size());
162 assertTrue("synchToTime", selection.get(0) instanceof TmfSyncMessage);
163 msg = (TmfSyncMessage) selection.get(0);
164 assertEquals("synchToTime", TC_002_MESSAGE_NAME, msg.getName());
165 assertEquals(0, TC_002_TIME_VALUE.compareTo(msg.getStartTime(), false));
166 assertEquals("synchToTime", TC_002_START_OCCURRANCE, msg.getStartOccurrence());
167 assertEquals("synchToTime", TC_002_END_OCCURRANCE, msg.getEndOccurrence());
168 assertEquals(TC_002_START_LIFELINE, msg.getStartLifeline().getName());
169 assertEquals(TC_002_END_LIFELINE, msg.getEndLifeline().getName());
170 }
171
172
173 /**
174 * Test Case: 003
175 * Description: Verify synchToTime (timestamp doesn't exist in trace), no selection of message in page
176 * Verified Methods: loader.syncToTime(), loader.moveToMessage(), loader.moveToPage()
177 * Expected result: Move to correct page, currentTime is updated so that focus on the currentTime, but no selection.
178 */
179 @Test
180 public void verifySynchToTimeNonExisting() {
181 fFacility.getLoader().firstPage();
182
183 fFacility.getTrace().broadcast(new TmfTimeSynchSignal(this, TC_003_TIME_VALUE));
184 fFacility.getLoader().waitForCompletion();
185 fFacility.delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
186 assertEquals("synchToTime", 0, TC_003_TIME_VALUE.compareTo(fFacility.getLoader().getCurrentTime(), false));
187 assertEquals("synchToTime", TC_003_PAGE_VALUE, fFacility.getLoader().currentPage());
188 selection = fFacility.getSdView().getSDWidget().getSelection();
189 assertNotNull("synchToTime", selection);
190 assertEquals("synchToTime", 0, selection.size());
191 }
192
193 /**
194 * Test Case: 004
195 * Description: Verify synchToTime (timestamp < experiment time range start)
196 * Verified Methods: loader.syncToTime(), loader.moveToMessage(), loader.moveToPage()
197 * Expected result: Move to first page, focus on the beginning of the page, but no selection.
198 */
199 @Test
200 public void verifySynchToTimeBeforeExpStart() {
201 fFacility.getTrace().broadcast(new TmfTimeSynchSignal(this, TmfTimestamp.BIG_BANG));
202 fFacility.getLoader().waitForCompletion();
203 fFacility.delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
204 assertEquals("synchToTime", TC_004_PAGE_VALUE, fFacility.getLoader().currentPage());
205 selection = fFacility.getSdView().getSDWidget().getSelection();
206 assertNotNull("synchToTime", selection);
207 assertEquals("synchToTime", 0, selection.size());
208 }
209
210 /**
211 * Test Case: 005
212 * Description: Verify synchToTime (timestamp > experiment time range end)
213 * Verified Methods: loader.syncToTime(), loader.moveToMessage(), loader.moveToPage()
214 * Expected result: Move to last page, focus on the end of the page, but no selection.
215 */
216 @Test
217 public void verifySynchToTimeAfterExpEnd() {
218 fFacility.getTrace().broadcast(new TmfTimeSynchSignal(this, TmfTimestamp.BIG_CRUNCH));
219 fFacility.getLoader().waitForCompletion();
220 fFacility.delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
221 assertEquals("synchToTime", TC_005_PAGE_VALUE, fFacility.getLoader().currentPage());
222 selection = fFacility.getSdView().getSDWidget().getSelection();
223 assertNotNull(selection);
224 assertEquals("synchToTime", 0, selection.size());
225 }
226
227 /**
228 * Test Case: 006
229 * Description: Verify synchToTime (timestamp of last message in page)
230 * Verified Methods: loader.syncToTime(), loader.moveToMessage(), loader.moveToPage(), loader.moveToMessageInPage()
231 * Expected result: Move to correct page, selection of last message in page.
232 */
233 @Test
234 public void verifySynchToTimeEqualsLast() {
235 fFacility.getTrace().broadcast(new TmfTimeSynchSignal(this, TC_006_TIME_VALUE));
236 fFacility.getLoader().waitForCompletion();
237 fFacility.delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
238 assertEquals("synchToTime", TC_006_PAGE_VALUE, fFacility.getLoader().currentPage());
239 selection = fFacility.getSdView().getSDWidget().getSelection();
240 assertNotNull("synchToTime", selection);
241 assertEquals("synchToTime", 1, selection.size());
242 msg = (TmfSyncMessage) selection.get(0);
243 assertEquals("synchToTime", TC_006_START_OCCURRANCE, msg.getStartOccurrence());
244 assertEquals("synchToTime", TC_006_END_OCCURRANCE, msg.getEndOccurrence());
245 }
246
247 /**
248 * Test Case: 007
249 * Description: Verify synchToTime (timestamp of first message in page)
250 * Verified Methods: loader.syncToTime(), loader.moveToMessage(), loader.moveToPage()
251 * Expected result: Move to correct page, selection of last message in page.
252 */
253 @Test
254 public void verifySynchToTimeFirst() {
255 fFacility.getTrace().broadcast(new TmfTimeSynchSignal(this, TC_007_TIME_VALUE));
256 fFacility.getLoader().waitForCompletion();
257 fFacility.delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
258 assertEquals("synchToTime", TC_007_PAGE_VALUE, fFacility.getLoader().currentPage());
259 selection = fFacility.getSdView().getSDWidget().getSelection();
260 assertNotNull("synchToTime", selection);
261 msg = (TmfSyncMessage) selection.get(0);
262 assertEquals("synchToTime", 1, selection.size());
263 assertEquals("synchToTime", TC_007_START_OCCURRANCE, msg.getStartOccurrence());
264 assertEquals("synchToTime", TC_007_END_OCCURRANCE, msg.getEndOccurrence());
265 }
266
267 /**
268 * Test Case: 008
269 * Description: Verify time range signal (start, end time and current time are in same page)
270 * Verified Methods: loader.synchToTimeRange(), loader.moveToMessage(), loader.moveToMessageInPage()
271 * Expected result: Move to correct page(=page of start time of range), set focus on start time of range, but no selection of message.
272 */
273 @Test
274 public void verifyTimeRangeSamePage() {
275 // 9788.642228395 (page 0) -> 9789.164833324 (page 0) with selected time 9788.642228395 (page 0)
276 fFacility.getLoader().firstPage();
277 TmfTimeRange range = new TmfTimeRange(TC_008_START_TIME_VALUE, TC_008_END_TIME_VALUE);
278 fFacility.getLoader().waitForCompletion();
279 fFacility.delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
280 fFacility.getTrace().broadcast(new TmfRangeSynchSignal(this, range, TC_008_TIME_VALUE));
281 assertEquals("synchToTimeRange", TC_008_PAGE_VALUE, fFacility.getLoader().currentPage());
282 assertNotNull("synchToTimeRange", fFacility.getLoader().getCurrentTime());
283 assertEquals("synchToTimeRange", 0, TC_008_TIME_VALUE.compareTo(fFacility.getLoader().getCurrentTime(), false));
284 selection = fFacility.getSdView().getSDWidget().getSelection();
285 // We actually don't want something to be selected!!!
286 assertNotNull("synchToTimeRange", selection);
287 assertEquals("synchToTimeRange", 0, selection.size());
288 }
289
290 /**
291 * Test Case: 009
292 * Description: Verify time range signal (start and end time are across 2 pages)
293 * Verified Methods: loader.synchToTimeRange(), loader.moveToMessage(), loader.moveToPage()
294 * Expected result: Move to correct page (=page of start time of range), set focus on start time of range, but no selection of message.
295 */
296 @Test
297 public void verifyTimeRangeDifferentPages() {
298 TmfTimeRange range = new TmfTimeRange(TC_009_START_TIME_VALUE, TC_009_END_TIME_VALUE);
299 fFacility.getTrace().broadcast(new TmfRangeSynchSignal(this, range, TC_009_TIME_VALUE));
300 fFacility.getLoader().waitForCompletion();
301 fFacility.delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
302 assertEquals("synchToTimeRange", TC_009_PAGE_VALUE, fFacility.getLoader().currentPage());
303 assertNotNull("synchToTimeRange", fFacility.getLoader().getCurrentTime());
304 assertEquals("synchToTimeRange", 0, TC_009_TIME_VALUE.compareTo(fFacility.getLoader().getCurrentTime(), false));
305 selection = fFacility.getSdView().getSDWidget().getSelection();
306 // We actually don't want something to be selected!!!
307 assertNotNull("synchToTimeRange", selection);
308 assertEquals("synchToTimeRange", 0, selection.size());
309 }
310 }
This page took 0.038831 seconds and 5 git commands to generate.