Skip to content

Package: OpenEditor_PTest

OpenEditor_PTest

nameinstructionbranchcomplexitylinemethod
OpenEditor_PTest(boolean)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
afterClass()
M: 1 C: 15
94%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 3
100%
M: 0 C: 1
100%
assertions(double, double)
M: 1 C: 52
98%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 0 C: 15
100%
M: 0 C: 1
100%
createCategorizations(VContainedElement, VContainedElement, VContainedElement, VContainedElement)
M: 0 C: 94
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 31
100%
M: 0 C: 1
100%
createControl(EStructuralFeature)
M: 0 C: 14
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
createDomainObject()
M: 0 C: 36
100%
M: 1 C: 5
83%
M: 1 C: 3
75%
M: 0 C: 12
100%
M: 0 C: 1
100%
createView()
M: 0 C: 45
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 15
100%
M: 0 C: 1
100%
data()
M: 0 C: 33
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
logic()
M: 0 C: 18
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
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: * jfaltermeier - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.view.ui.editor.test;
15:
16: import java.util.ArrayList;
17: import java.util.Collection;
18: import java.util.List;
19:
20: import org.eclipse.emf.ecore.EObject;
21: import org.eclipse.emf.ecore.EStructuralFeature;
22: import org.eclipse.emf.ecp.view.spi.categorization.model.VCategorization;
23: import org.eclipse.emf.ecp.view.spi.categorization.model.VCategorizationElement;
24: import org.eclipse.emf.ecp.view.spi.categorization.model.VCategorizationFactory;
25: import org.eclipse.emf.ecp.view.spi.categorization.model.VCategory;
26: import org.eclipse.emf.ecp.view.spi.model.VControl;
27: import org.eclipse.emf.ecp.view.spi.model.VFeaturePathDomainModelReference;
28: import org.eclipse.emf.ecp.view.spi.model.VView;
29: import org.eclipse.emf.ecp.view.spi.model.VViewFactory;
30: import org.eclipse.emf.ecp.view.test.common.spi.GCCollectable;
31: import org.eclipse.emf.emfstore.bowling.BowlingFactory;
32: import org.eclipse.emf.emfstore.bowling.BowlingPackage;
33: import org.eclipse.emf.emfstore.bowling.Player;
34: import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
35: import org.junit.AfterClass;
36: import org.junit.runner.RunWith;
37: import org.junit.runners.Parameterized;
38: import org.junit.runners.Parameterized.Parameters;
39:
40: /**
41: * Test case that renders a view, disposes it and checks whether the view
42: * is garbage collectable.
43: *
44: * @author emueller
45: * @author jfaltermeier
46: *
47: */
48: @RunWith(Parameterized.class)
49: public class OpenEditor_PTest extends ECPCommonSWTBotTest {
50:
51:         private static double memBefore;
52:         private static double memAfter;
53:
54:         private final boolean isDomainCollectable;
55:
56:         private GCCollectable viewCollectable;
57:         private GCCollectable domainCollectable;
58:
59:         public OpenEditor_PTest(boolean isDomainCollectable) {
60:                 this.isDomainCollectable = isDomainCollectable;
61:         }
62:
63:         @Parameters
64:         public static Collection<Object[]> data() {
65:                 final List<Object[]> data = new ArrayList<Object[]>();
66:•                for (int i = 0; i < 99; i++) {
67:                         data.add(new Boolean[] { false });
68:                 }
69:                 data.add(new Boolean[] { true });
70:                 return data;
71:         }
72:
73:         @AfterClass
74:         public static void afterClass() {
75:                 final double diff = Math.abs((memBefore - memAfter) / memBefore);
76:•                assertTrue(diff < 0.05);
77:         }
78:
79:         /**
80:          * {@inheritDoc}
81:          *
82:          * @see org.eclipse.emf.ecp.view.ui.editor.test.ECPCommonSWTBotTest#logic()
83:          */
84:         @Override
85:         public void logic() {
86:                 final SWTBotTree tree = bot.tree();
87:                 tree.getTreeItem("parent").getNode("foo").getNode("2").select();
88:                 bot.activeShell().setFocus();
89:         }
90:
91:         @Override
92:         public void assertions(double before, double after) {
93:                 OpenEditor_PTest.memBefore += before;
94:                 OpenEditor_PTest.memAfter += after;
95:
96:•                if (getDomainObject() != null) {
97:
98:                         assertTrue("More than four adapter left on domain model element after dispose of ECPSWTView: "
99:                                 + getDomainObject().eAdapters().size()
100:                                 + " adapters. Not all adapters can be removed, but it's maybe time to get suspicious.",
101:•                                getDomainObject()
102:                                         .eAdapters().size() < 5);
103:
104:                 }
105:
106:                 assertTrue(getSWTViewCollectable().isCollectable());
107:                 unsetSWTViewCollectable();
108:                 unsetDomainObject();
109:                 assertTrue(viewCollectable.isCollectable());
110:                 viewCollectable = null;
111:                 assertTrue(domainCollectable.isCollectable());
112:         }
113:
114:         /**
115:          * {@inheritDoc}
116:          *
117:          * @see org.eclipse.emf.ecp.view.ui.editor.test.ECPCommonSWTBotTest#createDomainObject()
118:          */
119:         @Override
120:         public EObject createDomainObject() {
121:                 Player player = (Player) getDomainObject();
122:
123:•                if (isDomainCollectable) {
124:                         // remove reference to domain object, since gc will be tested
125:                         setDomainObject(null);
126:                 }
127:
128:•                if (player == null) {
129:                         player = BowlingFactory.eINSTANCE.createPlayer();
130:                         player.setName("Test");
131:                         memBefore = 0d;
132:                         memAfter = 0d;
133:                 }
134:
135:•                if (!isDomainCollectable) {
136:                         setDomainObject(player);
137:                 }
138:
139:                 domainCollectable = new GCCollectable(player);
140:                 return player;
141:         }
142:
143:         /**
144:          * {@inheritDoc}
145:          *
146:          * @see org.eclipse.emf.ecp.view.ui.editor.test.ECPCommonSWTBotTest#createView()
147:          */
148:         @Override
149:         public VView createView() {
150:                 final VView view = VViewFactory.eINSTANCE.createView();
151:                 view.setRootEClass(BowlingPackage.eINSTANCE.getPlayer());
152:
153:                 final VControl nameControl = createControl(BowlingPackage.eINSTANCE
154:                         .getPlayer_Name());
155:                 final VControl genderControl = createControl(BowlingPackage.eINSTANCE
156:                         .getPlayer_Gender());
157:                 final VControl heightControl = createControl(BowlingPackage.eINSTANCE
158:                         .getPlayer_Height());
159:                 final VControl victoriesControl = createControl(BowlingPackage.eINSTANCE
160:                         .getPlayer_NumberOfVictories());
161:
162:                 view.getChildren().add(
163:                         createCategorizations(nameControl, genderControl, heightControl,
164:                                 victoriesControl));
165:
166:                 viewCollectable = new GCCollectable(view);
167:
168:                 return view;
169:         }
170:
171:         private VControl createControl(EStructuralFeature feature) {
172:                 final org.eclipse.emf.ecp.view.spi.model.VControl control = VViewFactory.eINSTANCE
173:                         .createControl();
174:                 final VFeaturePathDomainModelReference domainModelReference = VViewFactory.eINSTANCE
175:                         .createFeaturePathDomainModelReference();
176:                 domainModelReference.setDomainModelEFeature(feature);
177:                 control.setDomainModelReference(domainModelReference);
178:                 return control;
179:         }
180:
181:         private VCategorizationElement createCategorizations(
182:                 org.eclipse.emf.ecp.view.spi.model.VContainedElement composite1,
183:                 org.eclipse.emf.ecp.view.spi.model.VContainedElement composite2,
184:                 org.eclipse.emf.ecp.view.spi.model.VContainedElement composite3,
185:                 org.eclipse.emf.ecp.view.spi.model.VContainedElement composite4) {
186:
187:                 final VCategorizationElement categorizationElement = VCategorizationFactory.eINSTANCE
188:                         .createCategorizationElement();
189:
190:                 final VCategorization parentCategorization = VCategorizationFactory.eINSTANCE
191:                         .createCategorization();
192:                 final VCategorization fooCategorization = VCategorizationFactory.eINSTANCE
193:                         .createCategorization();
194:                 final VCategorization barCategorization = VCategorizationFactory.eINSTANCE
195:                         .createCategorization();
196:                 final VCategory category1 = VCategorizationFactory.eINSTANCE.createCategory();
197:                 final VCategory category2 = VCategorizationFactory.eINSTANCE.createCategory();
198:                 final VCategory category3 = VCategorizationFactory.eINSTANCE.createCategory();
199:                 final VCategory category4 = VCategorizationFactory.eINSTANCE.createCategory();
200:                 parentCategorization.setName("parent");
201:                 fooCategorization.setName("foo");
202:                 barCategorization.setName("bar");
203:                 category1.setName("1");
204:                 category2.setName("2");
205:                 category3.setName("3");
206:                 category4.setName("4");
207:                 category1.setComposite(composite1);
208:                 category2.setComposite(composite2);
209:                 category3.setComposite(composite3);
210:                 category4.setComposite(composite4);
211:                 fooCategorization.getCategorizations().add(category1);
212:                 fooCategorization.getCategorizations().add(category2);
213:                 barCategorization.getCategorizations().add(category3);
214:                 barCategorization.getCategorizations().add(category4);
215:                 parentCategorization.getCategorizations().add(fooCategorization);
216:                 parentCategorization.getCategorizations().add(barCategorization);
217:                 categorizationElement.getCategorizations().add(parentCategorization);
218:                 return categorizationElement;
219:         }
220:
221: }