tmf: Enable the ctfadaptor and statistics unit tests
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui.tests / src / org / eclipse / linuxtools / tmf / ui / tests / views / uml2sd / loader / TmfUml2SDSyncLoaderPagesTest.java
CommitLineData
73005152 1/*******************************************************************************
df0b8ff4 2 * Copyright (c) 2011, 2012 Ericsson
64636df8 3 *
73005152
BH
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
64636df8 8 *
73005152
BH
9 * Contributors:
10 * Bernd Hufmann - Initial API and implementation
11 *******************************************************************************/
df0b8ff4 12package org.eclipse.linuxtools.tmf.ui.tests.views.uml2sd.loader;
73005152 13
4f5d9f9b 14import junit.framework.Test;
73005152 15import junit.framework.TestCase;
4f5d9f9b 16import junit.framework.TestSuite;
73005152 17
64636df8
BH
18/**
19 * Test cases for pages handling.
20 *
21 * @author Bernd Hufmann
22 *
23 */
73005152
BH
24public class TmfUml2SDSyncLoaderPagesTest extends TestCase {
25
26 // ------------------------------------------------------------------------
27 // Attributes
28 // ------------------------------------------------------------------------
29 private Uml2SDTestFacility fFacility;
30
4f5d9f9b
BH
31 // ------------------------------------------------------------------------
32 // Static methods
64636df8 33 // ------------------------------------------------------------------------
4f5d9f9b
BH
34
35 /**
36 * Returns test setup used when executing test case stand-alone.
64636df8 37 * @return Test setup class
4f5d9f9b
BH
38 */
39 public static Test suite() {
40 return new Uml2SDTestSetup(new TestSuite(TmfUml2SDSyncLoaderPagesTest.class));
41 }
42
73005152
BH
43 // ------------------------------------------------------------------------
44 // Constructors
45 // ------------------------------------------------------------------------
64636df8
BH
46 /**
47 * Constructor
48 */
73005152
BH
49 public TmfUml2SDSyncLoaderPagesTest() {
50 }
51
52 // ------------------------------------------------------------------------
53 // Operations
54 // ------------------------------------------------------------------------
55 @Override
56 public void setUp() throws Exception {
57 super.setUp();
58 fFacility = Uml2SDTestFacility.getInstance();
73005152
BH
59 fFacility.selectExperiment();
60 }
61
62
63 @Override
64 public void tearDown() throws Exception {
65 fFacility.disposeExperiment();
73005152
BH
66 fFacility = null;
67 super.tearDown();
68 }
69
64636df8
BH
70 /**
71 * Main method with test cases.
72 */
73005152 73 public void testPageHandling() {
64636df8 74
73005152
BH
75 verifyPagesCount();
76 verifyNextPage();
77 verifyPrevPage();
78 verifyFirstPage();
79 verifyLastPage();
80 verifyPageNumberChanged();
81
82 }
64636df8 83
73005152 84 private void verifyPagesCount() {
64636df8 85
73005152
BH
86 /*
87 * Test Case: 001
88 * Description: Test number of pages.
89 * Verified Methods: loader.pagesCount().
90 * Expected result: ITestConstants.TOTAL_NUMBER_OF_PAGES of pages
91 */
92 assertEquals(IUml2SDTestConstants.TOTAL_NUMBER_OF_PAGES, fFacility.getLoader().pagesCount());
93 }
64636df8 94
73005152
BH
95 private void verifyNextPage() {
96 // assuming we are at the first page
97
98 /*
99 * Test Case: 002
100 * Description: Tests next page feature.
64636df8
BH
101 * Verified Methods: loader.nextPage(), loader.fillCurrentPage(), loader.pagesCount(),
102 * loader.hasNextPage(), loader.hasPrevPage(),
103 * frame.syncMessagesCount, frame.lifeLinesCount
73005152
BH
104 * Expected result: Expected values are return.
105 */
64636df8 106
73005152
BH
107 for(int i = 0; i < IUml2SDTestConstants.TOTAL_NUMBER_OF_PAGES-2; i++) {
108 fFacility.nextPage();
109
110 if (i+1 == IUml2SDTestConstants.PAGE_OF_ALL_LIFELINES) {
111 verifyPage(i+1, IUml2SDTestConstants.MAX_MESSEAGES_PER_PAGE, true, true, IUml2SDTestConstants.NUM_OF_ALL_LIFELINES);
112 }
113 else {
114 verifyPage(i+1, IUml2SDTestConstants.MAX_MESSEAGES_PER_PAGE, true, true);
115 }
116 }
64636df8 117
73005152
BH
118 // Last Page
119 fFacility.nextPage();
120 verifyPage(IUml2SDTestConstants.TOTAL_NUMBER_OF_PAGES - 1, IUml2SDTestConstants.NUM_MESSAGES_OF_LAST_PAGE, false, true);
121
122 // Check for index out of bounce
123 try {
124 fFacility.getLoader().nextPage();
125 } catch (Exception e) {
126 fail();
127 }
64636df8 128
73005152
BH
129 fFacility.firstPage();
130 }
131
132
133 private void verifyPrevPage() {
134 // assuming we are at the first page
135
136 /*
137 * Test Case: 003
138 * Description: Test previous page feature.
64636df8 139 * Verified Methods: loader.prevPage(), loader.fillCurrentPage(), loader.pagesCount(),
73005152 140 * loader.hasNextPage(), loader.hasPrevPage(),
64636df8 141 * frame.syncMessagesCount, frame.lifeLinesCount
73005152
BH
142 * Expected result: Expected values are return.
143 */
144
145 // Last Page
146 fFacility.lastPage();
147 assertEquals(IUml2SDTestConstants.TOTAL_NUMBER_OF_PAGES - 1, fFacility.getLoader().currentPage());
148 assertEquals(IUml2SDTestConstants.NUM_MESSAGES_OF_LAST_PAGE, fFacility.getSdView().getFrame().syncMessageCount());
149 assertFalse(fFacility.getLoader().hasNextPage());
150 assertTrue(fFacility.getLoader().hasPrevPage());
151 assertEquals(2, fFacility.getSdView().getFrame().lifeLinesCount());
152
153 for(int i = IUml2SDTestConstants.TOTAL_NUMBER_OF_PAGES-2; i > 0; i--) {
154 fFacility.prevPage();
64636df8 155 if (i == IUml2SDTestConstants.PAGE_OF_ALL_LIFELINES) {
73005152 156 verifyPage(i, IUml2SDTestConstants.MAX_MESSEAGES_PER_PAGE, true, true, IUml2SDTestConstants.NUM_OF_ALL_LIFELINES);
64636df8 157 } else {
73005152 158 verifyPage(i, IUml2SDTestConstants.MAX_MESSEAGES_PER_PAGE, true, true);
64636df8 159 }
73005152
BH
160 }
161
162 fFacility.prevPage();
163 verifyPage(0, IUml2SDTestConstants.MAX_MESSEAGES_PER_PAGE, true, false);
164
165 // Check for index out of bounce
166 try {
167 fFacility.getLoader().prevPage();
168 } catch (Exception e) {
169 fail();
170 }
171 }
172
173 private void verifyFirstPage() {
174 fFacility.lastPage();
175 /*
176 * Test Case: 004
177 * Description: Test first page feature.
64636df8 178 * Verified Methods: loader.firstPage(), loader.fillCurrentPage(), loader.pagesCount(),
73005152 179 * loader.hasNextPage(), loader.hasPrevPage(),
64636df8 180 * frame.syncMessagesCount, frame.lifeLinesCount
73005152
BH
181 * Expected result: Expected values are return.
182 */
64636df8 183
73005152
BH
184 // First Page
185 fFacility.firstPage();
186 verifyPage(0, IUml2SDTestConstants.MAX_MESSEAGES_PER_PAGE, true, false);
187 }
188
189
190 private void verifyLastPage() {
191 /*
192 * Test Case: 005
193 * Description: Test last page feature.
194 * Verified Methods: loader.lastPage(), loader.pagesCount(), loader.hasNextPage(), loader.hasPrevPage()
64636df8 195 * frame.syncMessagesCount, frame.lifeLinesCount
73005152
BH
196 * Expected result: Expected values are return.
197 */
198 fFacility.lastPage();
199 verifyPage(IUml2SDTestConstants.TOTAL_NUMBER_OF_PAGES - 1, IUml2SDTestConstants.NUM_MESSAGES_OF_LAST_PAGE, false, true);
200 fFacility.firstPage();
201 }
202
203 private void verifyPageNumberChanged() {
64636df8 204
73005152
BH
205 /*
206 * Test Case: 006
207 * Description: Test move to any page feature.
64636df8 208 * Verified Methods: loader.pageNumberChanged(), loader.fillCurrentPage(), loader.pagesCount(),
73005152 209 * loader.hasNextPage(), loader.hasPrevPage(),
64636df8 210 * frame.syncMessagesCount, frame.lifeLinesCount
73005152
BH
211 * Expected result: Expected values are return.
212 */
213
214 // any page
215 fFacility.setPage(IUml2SDTestConstants.PAGE_OF_ALL_LIFELINES);
216 verifyPage(IUml2SDTestConstants.PAGE_OF_ALL_LIFELINES, IUml2SDTestConstants.MAX_MESSEAGES_PER_PAGE, true, true, IUml2SDTestConstants.NUM_OF_ALL_LIFELINES);
217 fFacility.firstPage();
218 }
219
220 private void verifyPage(int currentPage, int numMsg, boolean hasNext, boolean hasPrev) {
221 verifyPage(currentPage, numMsg, hasNext, hasPrev, IUml2SDTestConstants.DEFAULT_NUM_LIFELINES);
222 }
223
224 @SuppressWarnings("nls")
225 private void verifyPage(int currentPage, int numMsg, boolean hasNext, boolean hasPrev, int lifelineCount) {
226 assertEquals("currentPage", currentPage, fFacility.getLoader().currentPage());
227 assertEquals("syncMessageCount, ", numMsg, fFacility.getSdView().getFrame().syncMessageCount());
228 if (hasNext) {
229 assertTrue("hasNextpage", fFacility.getLoader().hasNextPage());
230 } else {
231 assertFalse("hasNextPage", fFacility.getLoader().hasNextPage());
232 }
233 if (hasPrev) {
234 assertTrue("hasPrevPage", fFacility.getLoader().hasPrevPage());
235 } else {
236 assertFalse("hasPrevPage", fFacility.getLoader().hasPrevPage());
237 }
238 assertEquals("lifeLinesCount", lifelineCount, fFacility.getSdView().getFrame().lifeLinesCount());
239 }
240}
This page took 0.043331 seconds and 5 git commands to generate.