Implement simultaneously opened traces in TMF
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui.tests / src / org / eclipse / linuxtools / tmf / ui / tests / views / uml2sd / loader / TmfUml2SDSyncLoaderExpTest.java
1 /*******************************************************************************
2 * Copyright (c) 2011, 2012 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 *******************************************************************************/
12 package org.eclipse.linuxtools.tmf.ui.tests.views.uml2sd.loader;
13
14 import java.util.List;
15
16 import junit.framework.Test;
17 import junit.framework.TestCase;
18 import junit.framework.TestSuite;
19
20 import org.eclipse.linuxtools.tmf.core.signal.TmfSignalManager;
21 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.dialogs.FilterCriteria;
22 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.dialogs.FilterListDialog;
23 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDAdvancedPagingProvider;
24 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider;
25 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.loader.TmfUml2SDSyncLoader;
26
27 /**
28 * Test cases for Experiment handling.
29 *
30 * @author Bernd Hufmann
31 *
32 */
33 @SuppressWarnings("nls")
34 public class TmfUml2SDSyncLoaderExpTest extends TestCase {
35
36 // ------------------------------------------------------------------------
37 // Attributes
38 // ------------------------------------------------------------------------
39 private Uml2SDTestFacility fFacility;
40
41 // ------------------------------------------------------------------------
42 // Static methods
43 // ------------------------------------------------------------------------
44
45 /**
46 * Returns test setup used when executing test case stand-alone.
47 * @return Test setup class
48 */
49 public static Test suite() {
50 return new Uml2SDTestSetup(new TestSuite(TmfUml2SDSyncLoaderExpTest.class));
51 }
52
53 // ------------------------------------------------------------------------
54 // Constructors
55 // ------------------------------------------------------------------------
56
57 /**
58 * Constructor
59 */
60 public TmfUml2SDSyncLoaderExpTest() {
61 }
62
63 // ------------------------------------------------------------------------
64 // Operations
65 // ------------------------------------------------------------------------
66 @Override
67 public void setUp() throws Exception {
68 super.setUp();
69 fFacility = Uml2SDTestFacility.getInstance();
70 // create filter criteria (incl. save)
71 fFacility.createFilterCriteria();
72 fFacility.selectExperiment();
73 }
74
75
76 @Override
77 public void tearDown() throws Exception {
78 fFacility = null;
79 super.tearDown();
80 }
81
82
83 /**
84 * Main method with test cases.
85 */
86 public void testExperimentHandling() {
87
88 /*
89 * Test Case: 001
90 * Description: Verify setup
91 * Verified Methods: loader.getTitleString()
92 * view.getPartName()
93 * view.getFrame()
94 * Expected result: Title, view name are set properly.
95 */
96
97 assertEquals("getTitleString", "Component Interactions", fFacility.getLoader().getTitleString());
98 assertEquals("getPartName", "Sequence Diagram", fFacility.getSdView().getPartName());
99 assertNotNull("getFrame", fFacility.getSdView().getFrame());
100
101 fFacility.disposeExperiment();
102
103 fFacility.delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
104 verifyPage(0, 0, false, false, 0);
105
106 /*
107 * Test Case: 002
108 * Description: Verifies cancellation of ongoing indexing.
109 * Verified Methods: loader.experimentSelected(), loader.experimentDisposed(), loader.nextPage()
110 * Expected result: No exceptions during cancellation and nextPage() operation..
111 *
112 * Note this test is not sufficient to verify the concurrent access of the loader attributes
113 * by multiple threads. Contention might happen but it's not guaranteed.
114 */
115
116 for(int i = 0; i < 5; i++) {
117 fFacility.selectExperiment(false);
118 fFacility.delay(IUml2SDTestConstants.INITIAL_INDEX_DELAY);
119
120 try {
121 fFacility.disposeExperiment();
122 fFacility.getLoader().nextPage(); // to test out of bounce
123 // Note: To actually create an out of bound exception remove
124 // safety-checks in nextPage/moveToPage of loader class
125 } catch (Exception e){
126 // No Exception expected
127 fail("exp.select/exp.dispose");
128 }
129 }
130
131 /*
132 * Test Case: 003
133 * Description: Verifies disposed experiment.
134 * Verified Methods: loader.nextPage(),
135 * loader.pagesCount(), loader.hasNextPage(), loader.hasPrevPage(),
136 * frame.syncMessagesCount, frame.lifeLinesCount
137 * Expected result: Page values and filter are reset.
138 *
139 * Note this test is not sufficient to verify the concurrent access ofthe loader attributes
140 * by multiple threads. Contention might happen but it's not guaranteed.
141 */
142
143 verifyPage(0, 0, false, false, 0);
144
145 // verify that all enable filters are disabled after disposal
146 List<FilterCriteria> filter = FilterListDialog.getGlobalFilters();
147
148 for (FilterCriteria filterCriteria : filter) {
149 assertFalse("exp.dispose", filterCriteria.isActive());
150 }
151
152 /*
153 * Test Case: 004
154 * Description: Verifies the disposal of the loader.
155 * Verified Methods: loader.dispose(),
156 * Expected result: All providers are removed from SDView.
157 */
158 fFacility.getLoader().dispose();
159 assertTrue("loader.dispose", fFacility.getSdView().getSDPagingProvider() == null);
160 assertTrue("loader.dispose", fFacility.getSdView().getSDFindProvider() == null);
161 assertTrue("loader.dispose", fFacility.getSdView().getSDFilterProvider() == null);
162 assertTrue("loader.dispose", fFacility.getSdView().getExtendedFindProvider() == null);
163 assertTrue("loader.dispose", fFacility.getSdView().getExtendedFilterProvider() == null);
164
165 // Set again loader as signal handler, which was removed by the the dispose above
166 TmfSignalManager.register(fFacility.getLoader());
167
168 /*
169 * Test Case: 005
170 * Description: Verifies setViewer.
171 * Verified Methods: loader.setViewer
172 * Expected result: Paging, find and filter provider are set
173 */
174
175 fFacility.getLoader().setViewer(fFacility.getSdView());
176 ISDPagingProvider pagingProvider = fFacility.getSdView().getSDPagingProvider();
177 assertTrue("loader.setViewer", pagingProvider != null);
178 assertTrue("loader.setViewer", pagingProvider instanceof ISDAdvancedPagingProvider);
179 assertTrue("loader.setViewer", pagingProvider instanceof TmfUml2SDSyncLoader);
180
181 assertTrue("loader.setViewer", fFacility.getSdView().getSDFindProvider() != null);
182
183 assertTrue("loader.setViewer", fFacility.getSdView().getSDFilterProvider() != null);
184
185 // All other providers are not used.
186 assertTrue("loader.setViewer", fFacility.getSdView().getExtendedFindProvider() == null);
187 assertTrue("loader.setViewer", fFacility.getSdView().getExtendedFilterProvider() == null);
188 }
189
190 private void verifyPage(int currentPage, int numMsg, boolean hasNext, boolean hasPrev, int lifelineCount) {
191 assertEquals("currentPage", currentPage, fFacility.getLoader().currentPage());
192 assertEquals("syncMessageCount, ", numMsg, fFacility.getSdView().getFrame().syncMessageCount());
193 if (hasNext) {
194 assertTrue("hasNextpage", fFacility.getLoader().hasNextPage());
195 } else {
196 assertFalse("hasNextPage", fFacility.getLoader().hasNextPage());
197 }
198 if (hasPrev) {
199 assertTrue("hasPrevPage", fFacility.getLoader().hasPrevPage());
200 } else {
201 assertFalse("hasPrevPage", fFacility.getLoader().hasPrevPage());
202 }
203 assertEquals("lifeLinesCount", lifelineCount, fFacility.getSdView().getFrame().lifeLinesCount());
204 }
205 }
This page took 0.062093 seconds and 6 git commands to generate.