Skip to content

Package: SWTGroup_PTest

SWTGroup_PTest

nameinstructionbranchcomplexitylinemethod
SWTGroup_PTest()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
createControl()
M: 0 C: 15
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
createGroup()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
createViewWithOneGroup()
M: 0 C: 12
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
createViewWithTwoGroups()
M: 0 C: 19
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
createViewWithTwoGroupsWithTwoControls()
M: 0 C: 39
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 10
100%
M: 0 C: 1
100%
createViewWithTwoHierachicalGroups()
M: 0 C: 19
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
testEffectiveReadOnlyDoesNotDisableGroup()
M: 10 C: 23
70%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 1 C: 8
89%
M: 0 C: 1
100%
testEmptyGroup()
M: 10 C: 21
68%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 1 C: 7
88%
M: 0 C: 1
100%
testOneGroupinView()
M: 0 C: 50
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 19
100%
M: 0 C: 1
100%
testReadOnlyDoesNotDisableGroup()
M: 10 C: 27
73%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 1 C: 8
89%
M: 0 C: 1
100%
testTwoGroupsHierachicalinView()
M: 0 C: 82
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 29
100%
M: 0 C: 1
100%
testTwoGroupsWithTwoControlsInView()
M: 0 C: 109
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 33
100%
M: 0 C: 1
100%
testTwoGroupsinView()
M: 0 C: 81
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 30
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2013 EclipseSource Muenchen GmbH and others.
3: *
4: * All rights reserved. This program and the accompanying materials
5: * are made available under the terms of the Eclipse Public License 2.0
6: * which accompanies this distribution, and is available at
7: * https://www.eclipse.org/legal/epl-2.0/
8: *
9: * SPDX-License-Identifier: EPL-2.0
10: *
11: * Contributors:
12: * Johannes Faltermeier
13: *
14: *******************************************************************************/
15: package org.eclipse.emf.ecp.view.group.ui.swt.test;
16:
17: import static org.junit.Assert.assertEquals;
18: import static org.junit.Assert.assertTrue;
19: import static org.junit.Assert.fail;
20:
21: import org.eclipse.emf.ecore.EcoreFactory;
22: import org.eclipse.emf.ecore.EcorePackage;
23: import org.eclipse.emf.ecp.view.spi.group.model.VGroup;
24: import org.eclipse.emf.ecp.view.spi.group.model.VGroupFactory;
25: import org.eclipse.emf.ecp.view.spi.model.VControl;
26: import org.eclipse.emf.ecp.view.spi.model.VFeaturePathDomainModelReference;
27: import org.eclipse.emf.ecp.view.spi.model.VView;
28: import org.eclipse.emf.ecp.view.spi.model.VViewFactory;
29: import org.eclipse.emf.ecp.view.spi.renderer.NoPropertyDescriptorFoundExeption;
30: import org.eclipse.emf.ecp.view.spi.renderer.NoRendererFoundException;
31: import org.eclipse.emf.ecp.view.test.common.swt.spi.DatabindingClassRunner;
32: import org.eclipse.emf.ecp.view.test.common.swt.spi.SWTViewTestHelper;
33: import org.eclipse.emfforms.spi.swt.core.EMFFormsNoRendererException;
34: import org.eclipse.swt.widgets.Composite;
35: import org.eclipse.swt.widgets.Control;
36: import org.eclipse.swt.widgets.Group;
37: import org.eclipse.swt.widgets.Shell;
38: import org.junit.Test;
39: import org.junit.runner.RunWith;
40:
41: @RunWith(DatabindingClassRunner.class)
42: public class SWTGroup_PTest {
43:
44:         private static final String GROUP_NAME = "group";
45:         private static final String GROUP_NAME2 = "group2";
46:
47:         /**
48:          * @return a View with one Group in it
49:          */
50:         private static VView createViewWithOneGroup() {
51:                 final VView view = VViewFactory.eINSTANCE.createView();
52:                 final VGroup group = createGroup();
53:                 view.getChildren().add(group);
54:                 return view;
55:         }
56:
57:         /**
58:          * @return A view with two groups as children
59:          */
60:         private static VView createViewWithTwoGroups() {
61:                 final VView view = VViewFactory.eINSTANCE.createView();
62:                 final VGroup group = createGroup();
63:                 view.getChildren().add(group);
64:                 final VGroup group2 = createGroup();
65:                 view.getChildren().add(group2);
66:                 return view;
67:         }
68:
69:         /**
70:          * @return A View with two groups, one is the subgroup of the first one
71:          */
72:         private static VView createViewWithTwoHierachicalGroups() {
73:                 final VView view = VViewFactory.eINSTANCE.createView();
74:                 final VGroup group = createGroup();
75:                 view.getChildren().add(group);
76:                 final VGroup subGroup = createGroup();
77:                 group.getChildren().add(subGroup);
78:                 return view;
79:         }
80:
81:         private static VView createViewWithTwoGroupsWithTwoControls() {
82:                 final VView view = VViewFactory.eINSTANCE.createView();
83:                 final VGroup group1 = createGroup();
84:                 view.getChildren().add(group1);
85:                 group1.getChildren().add(createControl());
86:                 group1.getChildren().add(createControl());
87:                 final VGroup group2 = createGroup();
88:                 view.getChildren().add(group2);
89:                 group2.getChildren().add(createControl());
90:                 group2.getChildren().add(createControl());
91:                 return view;
92:         }
93:
94:         /**
95:          * @return
96:          */
97:         private static VGroup createGroup() {
98:                 return VGroupFactory.eINSTANCE.createGroup();
99:         }
100:
101:         private static VControl createControl() {
102:                 final VControl control = VViewFactory.eINSTANCE.createControl();
103:                 final VFeaturePathDomainModelReference modelReference = VViewFactory.eINSTANCE
104:                         .createFeaturePathDomainModelReference();
105:                 modelReference.setDomainModelEFeature(EcorePackage.eINSTANCE.getEClassifier_InstanceClassName());
106:                 control.setDomainModelReference(modelReference);
107:                 return control;
108:         }
109:
110:         @Test
111:         public void testOneGroupinView() throws NoRendererFoundException, NoPropertyDescriptorFoundExeption,
112:                 EMFFormsNoRendererException {
113:
114:                 // setup model
115:                 final VView view = createViewWithOneGroup();
116:                 final org.eclipse.emf.ecp.view.spi.group.model.VGroup group = (org.eclipse.emf.ecp.view.spi.group.model.VGroup) view
117:                         .getChildren()
118:                         .get(0);
119:                 group.setName(GROUP_NAME);
120:
121:                 // setup ui
122:                 final Shell shell = SWTViewTestHelper.createShell();
123:
124:                 final Control control = SWTViewTestHelper.render(view, shell);
125:                 final Composite viewComposite = (Composite) shell.getChildren()[0];
126:                 final Control renderedControl = viewComposite.getChildren()[0];
127:                 assertTrue("Rendered Control is not a Group", renderedControl instanceof org.eclipse.swt.widgets.Group);
128:                 assertEquals(
129:                         "Rendered Control and control returned by renderer are not the same",
130:                         control, viewComposite);
131:                 final Group groupControl = (Group) renderedControl;
132:                 assertEquals("Rendered Group does not have correct name",
133:                         GROUP_NAME, groupControl.getText());
134:                 assertEquals("org_eclipse_emf_ecp_ui_control_group",
135:                         renderedControl.getData("org.eclipse.rap.rwt.customVariant"));
136:         }
137:
138:         @Test
139:         public void testTwoGroupsinView() throws NoRendererFoundException, NoPropertyDescriptorFoundExeption,
140:                 EMFFormsNoRendererException {
141:
142:                 // setup model
143:                 final VView view = createViewWithTwoGroups();
144:                 final org.eclipse.emf.ecp.view.spi.group.model.VGroup group = (org.eclipse.emf.ecp.view.spi.group.model.VGroup) view
145:                         .getChildren()
146:                         .get(0);
147:                 group.setName(GROUP_NAME);
148:
149:                 final org.eclipse.emf.ecp.view.spi.group.model.VGroup group2 = (org.eclipse.emf.ecp.view.spi.group.model.VGroup) view
150:                         .getChildren()
151:                         .get(1);
152:                 group2.setName(GROUP_NAME2);
153:
154:                 // setup ui
155:                 final Shell shell = SWTViewTestHelper.createShell();
156:
157:                 final Control control = SWTViewTestHelper.render(view, shell);
158:                 final Composite viewComposite = (Composite) shell.getChildren()[0];
159:                 final Control renderedControl1 = viewComposite.getChildren()[0];
160:                 final Control renderedControl2 = viewComposite.getChildren()[1];
161:                 assertTrue("Rendered Control is not a Group", renderedControl1 instanceof org.eclipse.swt.widgets.Group);
162:                 assertEquals(
163:                         "Rendered Control and control returned by renderer are not the same",
164:                         control, viewComposite);
165:                 final Group groupControl1 = (Group) renderedControl1;
166:                 assertEquals("Rendered Group does not have correct name",
167:                         GROUP_NAME, groupControl1.getText());
168:                 assertEquals("org_eclipse_emf_ecp_ui_control_group",
169:                         renderedControl1.getData("org.eclipse.rap.rwt.customVariant"));
170:
171:                 assertTrue("Rendered Control is not a Group", renderedControl2 instanceof org.eclipse.swt.widgets.Group);
172:
173:                 final Group groupControl2 = (Group) renderedControl2;
174:                 assertEquals("Rendered Group does not have correct name",
175:                         GROUP_NAME2, groupControl2.getText());
176:                 assertEquals("org_eclipse_emf_ecp_ui_control_group",
177:                         renderedControl2.getData("org.eclipse.rap.rwt.customVariant"));
178:         }
179:
180:         @Test
181:         public void testTwoGroupsHierachicalinView() throws NoRendererFoundException, NoPropertyDescriptorFoundExeption,
182:                 EMFFormsNoRendererException {
183:
184:                 final VView view = createViewWithTwoHierachicalGroups();
185:                 final org.eclipse.emf.ecp.view.spi.group.model.VGroup group = (org.eclipse.emf.ecp.view.spi.group.model.VGroup) view
186:                         .getChildren()
187:                         .get(0);
188:                 final org.eclipse.emf.ecp.view.spi.group.model.VGroup subGroup = (org.eclipse.emf.ecp.view.spi.group.model.VGroup) group
189:                         .getChildren().get(0);
190:                 group.setName(GROUP_NAME);
191:
192:                 subGroup.setName(GROUP_NAME2);
193:
194:                 // setup ui
195:                 final Shell shell = SWTViewTestHelper.createShell();
196:
197:                 final Control control = SWTViewTestHelper.render(view, shell);
198:                 final Composite viewComposite = (Composite) shell.getChildren()[0];
199:                 final Composite renderedControl1 = (Composite) viewComposite.getChildren()[0];
200:                 final Control renderedControl2 = renderedControl1.getChildren()[0];
201:                 assertTrue("Rendered Control is not a Group", renderedControl1 instanceof org.eclipse.swt.widgets.Group);
202:                 assertEquals(
203:                         "Rendered Control and control returned by renderer are not the same",
204:                         control, viewComposite);
205:                 final Group groupControl1 = (Group) renderedControl1;
206:                 assertEquals("Rendered Group does not have correct name",
207:                         GROUP_NAME, groupControl1.getText());
208:                 assertEquals("org_eclipse_emf_ecp_ui_control_group",
209:                         renderedControl1.getData("org.eclipse.rap.rwt.customVariant"));
210:
211:                 assertTrue("Rendered Control is not a Group", renderedControl2 instanceof org.eclipse.swt.widgets.Group);
212:
213:                 final Group groupControl2 = (Group) renderedControl2;
214:                 assertEquals("Rendered Group does not have correct name",
215:                         GROUP_NAME2, groupControl2.getText());
216:                 assertEquals("org_eclipse_emf_ecp_ui_control_group",
217:                         renderedControl2.getData("org.eclipse.rap.rwt.customVariant"));
218:         }
219:
220:         @Test
221:         public void testTwoGroupsWithTwoControlsInView() throws NoRendererFoundException,
222:                 NoPropertyDescriptorFoundExeption, EMFFormsNoRendererException {
223:                 final VView view = createViewWithTwoGroupsWithTwoControls();
224:                 final org.eclipse.emf.ecp.view.spi.group.model.VGroup group1 = (org.eclipse.emf.ecp.view.spi.group.model.VGroup) view
225:                         .getChildren()
226:                         .get(0);
227:                 final org.eclipse.emf.ecp.view.spi.group.model.VGroup group2 = (org.eclipse.emf.ecp.view.spi.group.model.VGroup) view
228:                         .getChildren().get(1);
229:                 group1.setName(GROUP_NAME);
230:
231:                 group2.setName(GROUP_NAME2);
232:
233:                 // setup ui
234:                 final Shell shell = SWTViewTestHelper.createShell();
235:
236:                 final Control control = SWTViewTestHelper.render(view, EcoreFactory.eINSTANCE.createEClass(), shell);
237:                 final Composite viewComposite = (Composite) shell.getChildren()[0];
238:                 final Composite renderedControl1 = (Composite) viewComposite.getChildren()[0];
239:                 final Composite renderedControl2 = (Composite) viewComposite.getChildren()[1];
240:                 assertTrue("Rendered Control is not a Group", renderedControl1 instanceof org.eclipse.swt.widgets.Group);
241:                 assertEquals(
242:                         "Rendered Control and control returned by renderer are not the same",
243:                         control, viewComposite);
244:                 final Group groupControl1 = (Group) renderedControl1;
245:                 assertEquals("Rendered Group does not have correct name",
246:                         GROUP_NAME, groupControl1.getText());
247:                 assertEquals("org_eclipse_emf_ecp_ui_control_group",
248:                         renderedControl1.getData("org.eclipse.rap.rwt.customVariant"));
249:
250:                 assertTrue(SWTViewTestHelper.checkIfThereIsATextControl(renderedControl1.getChildren()[2]));
251:                 assertTrue(SWTViewTestHelper.checkIfThereIsATextControl(renderedControl1.getChildren()[5]));
252:
253:                 assertTrue("Rendered Control is not a Group", renderedControl2 instanceof org.eclipse.swt.widgets.Group);
254:
255:                 final Group groupControl2 = (Group) renderedControl2;
256:                 assertEquals("Rendered Group does not have correct name",
257:                         GROUP_NAME2, groupControl2.getText());
258:                 assertEquals("org_eclipse_emf_ecp_ui_control_group",
259:                         renderedControl2.getData("org.eclipse.rap.rwt.customVariant"));
260:
261:                 assertTrue(SWTViewTestHelper.checkIfThereIsATextControl(renderedControl2.getChildren()[2]));
262:                 assertTrue(SWTViewTestHelper.checkIfThereIsATextControl(renderedControl2.getChildren()[5]));
263:         }
264:
265:         @Test
266:         public void testEmptyGroup() throws NoRendererFoundException, NoPropertyDescriptorFoundExeption,
267:                 EMFFormsNoRendererException {
268:
269:                 // setup model
270:                 final VView view = createViewWithOneGroup();
271:
272:                 // setup ui
273:                 final Shell shell = SWTViewTestHelper.createShell();
274:                 try {
275:                         final Composite control = (Composite) SWTViewTestHelper.render(view, shell);
276:                         final org.eclipse.swt.widgets.Group renderedControl = (Group) control.getChildren()[0];
277:                         assertEquals("", renderedControl.getText());
278:                 } catch (final IllegalArgumentException e) {
279:                         fail("Renderer throws IlleaglArgument on empty group name" + e.getStackTrace());
280:                 }
281:         }
282:
283:         @Test
284:         public void testReadOnlyDoesNotDisableGroup()
285:                 throws NoRendererFoundException, NoPropertyDescriptorFoundExeption, EMFFormsNoRendererException {
286:                 // setup model
287:                 final VView view = createViewWithOneGroup();
288:                 view.getChildren().get(0).setReadonly(true);
289:
290:                 // setup ui
291:                 final Shell shell = SWTViewTestHelper.createShell();
292:                 try {
293:                         final Composite control = (Composite) SWTViewTestHelper.render(view, shell);
294:                         final org.eclipse.swt.widgets.Group renderedControl = (Group) control.getChildren()[0];
295:                         assertTrue(renderedControl.isEnabled());
296:                 } catch (final IllegalArgumentException e) {
297:                         fail("Renderer throws IlleaglArgument on empty group name" + e.getStackTrace());
298:                 }
299:         }
300:
301:         @Test
302:         public void testEffectiveReadOnlyDoesNotDisableGroup()
303:                 throws NoRendererFoundException, NoPropertyDescriptorFoundExeption, EMFFormsNoRendererException {
304:                 // setup model
305:                 final VView view = createViewWithOneGroup();
306:                 view.setReadonly(true);
307:
308:                 // setup ui
309:                 final Shell shell = SWTViewTestHelper.createShell();
310:                 try {
311:                         final Composite control = (Composite) SWTViewTestHelper.render(view, shell);
312:                         final org.eclipse.swt.widgets.Group renderedControl = (Group) control.getChildren()[0];
313:                         assertTrue(renderedControl.isEnabled());
314:                 } catch (final IllegalArgumentException e) {
315:                         fail("Renderer throws IlleaglArgument on empty group name" + e.getStackTrace());
316:                 }
317:         }
318: }