Skip to content

Package: SWTHorizontal_PTest

SWTHorizontal_PTest

nameinstructionbranchcomplexitylinemethod
SWTHorizontal_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%
createHorizontal()
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%
createHorizontalWithTwoControlsAsChildren()
M: 0 C: 14
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
createHorizontalWithTwoHorizontalAsChildrenAndControlAsSubChildren()
M: 0 C: 22
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
createHorizontalWithoutChildren()
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
init()
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%
testEffectivelyReadOnlyDoesNotDisableComposite()
M: 0 C: 31
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 9
100%
M: 0 C: 1
100%
testHorizontalWithTwoControlsAsChildren()
M: 0 C: 40
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 9
100%
M: 0 C: 1
100%
testHorizontalWithTwoHorizontalAsChildrenAndControlAsSubChildren()
M: 0 C: 89
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 16
100%
M: 0 C: 1
100%
testHorizontalWithoutChildren()
M: 0 C: 23
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
testReadOnlyDoesNotDisableComposite()
M: 0 C: 24
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 7
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: * Jonas
13: *
14: *******************************************************************************/
15: package org.eclipse.emf.ecp.view.horizontal.ui.swt.test;
16:
17: import static org.junit.Assert.assertEquals;
18: import static org.junit.Assert.assertTrue;
19:
20: import org.eclipse.emf.ecore.EClass;
21: import org.eclipse.emf.ecore.EObject;
22: import org.eclipse.emf.ecore.EcoreFactory;
23: import org.eclipse.emf.ecore.EcorePackage;
24: import org.eclipse.emf.ecp.ui.view.test.HierarchyViewModelHandle;
25: import org.eclipse.emf.ecp.view.spi.horizontal.model.VHorizontalFactory;
26: import org.eclipse.emf.ecp.view.spi.horizontal.model.VHorizontalLayout;
27: import org.eclipse.emf.ecp.view.spi.model.VControl;
28: import org.eclipse.emf.ecp.view.spi.model.VElement;
29: import org.eclipse.emf.ecp.view.spi.model.VFeaturePathDomainModelReference;
30: import org.eclipse.emf.ecp.view.spi.model.VView;
31: import org.eclipse.emf.ecp.view.spi.model.VViewFactory;
32: import org.eclipse.emf.ecp.view.spi.renderer.NoPropertyDescriptorFoundExeption;
33: import org.eclipse.emf.ecp.view.spi.renderer.NoRendererFoundException;
34: import org.eclipse.emf.ecp.view.test.common.swt.spi.DatabindingClassRunner;
35: import org.eclipse.emf.ecp.view.test.common.swt.spi.SWTViewTestHelper;
36: import org.eclipse.emfforms.spi.swt.core.EMFFormsNoRendererException;
37: import org.eclipse.swt.widgets.Composite;
38: import org.eclipse.swt.widgets.Control;
39: import org.eclipse.swt.widgets.Shell;
40: import org.junit.Before;
41: import org.junit.Test;
42: import org.junit.runner.RunWith;
43:
44: @RunWith(DatabindingClassRunner.class)
45: public class SWTHorizontal_PTest {
46:
47:         private Shell shell;
48:         private EObject domainElement;
49:
50:         private static VHorizontalLayout createHorizontal() {
51:                 return VHorizontalFactory.eINSTANCE.createHorizontalLayout();
52:         }
53:
54:         private static HierarchyViewModelHandle createHorizontalWithoutChildren() {
55:                 final VElement horizontal = createHorizontal();
56:                 return new HierarchyViewModelHandle(horizontal);
57:         }
58:
59:         private static VControl createControl() {
60:                 final VControl control = VViewFactory.eINSTANCE.createControl();
61:                 final VFeaturePathDomainModelReference domainModelReference = VViewFactory.eINSTANCE
62:                         .createFeaturePathDomainModelReference();
63:                 domainModelReference.setDomainModelEFeature(EcorePackage.eINSTANCE.getEClassifier_InstanceClassName());
64:                 control.setDomainModelReference(domainModelReference);
65:                 return control;
66:         }
67:
68:         private static HierarchyViewModelHandle createHorizontalWithTwoControlsAsChildren() {
69:                 final HierarchyViewModelHandle horizontalHandle = createHorizontalWithoutChildren();
70:                 final VControl control1 = createControl();
71:                 horizontalHandle.addFirstChildToRoot(control1);
72:                 final VControl control2 = createControl();
73:                 horizontalHandle.addSecondChildToRoot(control2);
74:                 return horizontalHandle;
75:         }
76:
77:         public static HierarchyViewModelHandle createHorizontalWithTwoHorizontalAsChildrenAndControlAsSubChildren() {
78:                 final HierarchyViewModelHandle horizontalHandle = createHorizontalWithoutChildren();
79:                 horizontalHandle.addFirstChildToRoot(createHorizontal());
80:                 horizontalHandle.addSecondChildToRoot(createHorizontal());
81:                 horizontalHandle.addFirstChildToFirstChild(createControl());
82:                 horizontalHandle.addSecondChildToFirstChild(createControl());
83:                 horizontalHandle.addFirstChildToSecondChild(createControl());
84:                 horizontalHandle.addSecondChildToSecondChild(createControl());
85:                 return horizontalHandle;
86:         }
87:
88:         @Before
89:         public void init() {
90:                 shell = SWTViewTestHelper.createShell();
91:
92:                 final EClass eClass = EcoreFactory.eINSTANCE.createEClass();
93:                 eClass.getESuperTypes().add(EcorePackage.eINSTANCE.getEClass());
94:                 eClass.setInstanceClassName("Test");
95:                 domainElement = eClass;
96:         }
97:
98:         @Test
99:         public void testHorizontalWithoutChildren() throws NoRendererFoundException,
100:                 NoPropertyDescriptorFoundExeption, EMFFormsNoRendererException {
101:                 // setup model
102:                 final HierarchyViewModelHandle handle = createHorizontalWithoutChildren();
103:                 final Control render = SWTViewTestHelper.render(handle.getRoot(), domainElement, shell);
104:                 assertTrue(render instanceof Composite);
105:                 final Composite composite = (Composite) render;
106:                 assertEquals(0, composite.getChildren().length);
107:         }
108:
109:         @Test
110:         public void testHorizontalWithTwoControlsAsChildren() throws NoRendererFoundException,
111:                 NoPropertyDescriptorFoundExeption, EMFFormsNoRendererException {
112:                 // setup model
113:                 final HierarchyViewModelHandle handle = createHorizontalWithTwoControlsAsChildren();
114:                 final Control render = SWTViewTestHelper.render(handle.getRoot(), domainElement, shell);
115:                 assertTrue(render instanceof Composite);
116:                 final Composite composite = (Composite) render;
117:                 assertEquals(2, composite.getChildren().length);
118:                 assertEquals(2, SWTViewTestHelper.getNumberofColumns(composite));
119:                 assertTrue(SWTViewTestHelper.checkIfThereIsATextControlWithLabel(composite.getChildren()[0]));
120:                 assertTrue(SWTViewTestHelper.checkIfThereIsATextControlWithLabel(composite.getChildren()[1]));
121:         }
122:
123:         @Test
124:         public void testHorizontalWithTwoHorizontalAsChildrenAndControlAsSubChildren() throws NoRendererFoundException,
125:                 NoPropertyDescriptorFoundExeption, EMFFormsNoRendererException {
126:                 // setup model
127:                 final HierarchyViewModelHandle handle = createHorizontalWithTwoHorizontalAsChildrenAndControlAsSubChildren();
128:                 final Control render = SWTViewTestHelper.render(handle.getRoot(), domainElement, shell);
129:                 assertTrue(render instanceof Composite);
130:                 final Composite composite = (Composite) render;
131:                 assertEquals(2, composite.getChildren().length);
132:                 final Composite firstHorizontal = (Composite) ((Composite) composite.getChildren()[0]).getChildren()[0];
133:                 final Composite secondHorizontal = (Composite) ((Composite) composite.getChildren()[1]).getChildren()[0];
134:
135:                 assertEquals(2, firstHorizontal.getChildren().length);
136:                 assertEquals(2, secondHorizontal.getChildren().length);
137:                 assertEquals(2, SWTViewTestHelper.getNumberofColumns(firstHorizontal));
138:                 assertEquals(2, SWTViewTestHelper.getNumberofColumns(secondHorizontal));
139:
140:                 assertTrue(SWTViewTestHelper.checkIfThereIsATextControlWithLabel(firstHorizontal.getChildren()[0]));
141:                 assertTrue(SWTViewTestHelper.checkIfThereIsATextControlWithLabel(secondHorizontal.getChildren()[0]));
142:                 assertTrue(SWTViewTestHelper.checkIfThereIsATextControlWithLabel(firstHorizontal.getChildren()[1]));
143:                 assertTrue(SWTViewTestHelper.checkIfThereIsATextControlWithLabel(secondHorizontal.getChildren()[1]));
144:         }
145:
146:         @Test
147:         public void testReadOnlyDoesNotDisableComposite() throws NoRendererFoundException,
148:                 NoPropertyDescriptorFoundExeption, EMFFormsNoRendererException {
149:                 final HierarchyViewModelHandle handle = createHorizontalWithoutChildren();
150:                 handle.getRoot().setReadonly(true);
151:                 final Control render = SWTViewTestHelper.render(handle.getRoot(), domainElement, shell);
152:                 assertTrue(render instanceof Composite);
153:                 final Composite composite = (Composite) render;
154:                 assertTrue(composite.isEnabled());
155:         }
156:
157:         @Test
158:         public void testEffectivelyReadOnlyDoesNotDisableComposite() throws NoRendererFoundException,
159:                 NoPropertyDescriptorFoundExeption, EMFFormsNoRendererException {
160:                 final VView view = VViewFactory.eINSTANCE.createView();
161:                 view.setReadonly(true);
162:                 final VHorizontalLayout horizontal = VHorizontalFactory.eINSTANCE.createHorizontalLayout();
163:                 view.getChildren().add(horizontal);
164:                 final Control render = SWTViewTestHelper.render(horizontal, domainElement, shell);
165:                 assertTrue(render instanceof Composite);
166:                 final Composite composite = (Composite) render;
167:                 assertTrue(composite.isEnabled());
168:         }
169: }