Skip to content

Package: TableControlSWTRendererPerformance_PTest

TableControlSWTRendererPerformance_PTest

nameinstructionbranchcomplexitylinemethod
TableControlSWTRendererPerformance_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%
after()
M: 0 C: 14
100%
M: 2 C: 2
50%
M: 2 C: 1
33%
M: 0 C: 4
100%
M: 0 C: 1
100%
createDMR(EAttribute, EReference[])
M: 0 C: 14
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
generateInput(int)
M: 0 C: 55
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 12
100%
M: 0 C: 1
100%
init()
M: 0 C: 58
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 11
100%
M: 0 C: 1
100%
lambda$0(VTableControl, EClass)
M: 12 C: 50
81%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 2 C: 13
87%
M: 0 C: 1
100%
lambda$1(EClass)
M: 0 C: 2
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
lambda$2(EClass)
M: 0 C: 2
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
tableSorting_autoSortOnEdit()
M: 0 C: 28
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
test(Consumer)
M: 0 C: 35
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 8
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2019 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: * Lucas Koehler - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.view.spi.table.swt;
15:
16: import static org.junit.Assert.assertEquals;
17: import static org.junit.Assert.fail;
18:
19: import java.util.Arrays;
20: import java.util.Random;
21: import java.util.function.Consumer;
22:
23: import org.eclipse.emf.common.command.BasicCommandStack;
24: import org.eclipse.emf.common.notify.AdapterFactory;
25: import org.eclipse.emf.common.util.URI;
26: import org.eclipse.emf.ecore.EAttribute;
27: import org.eclipse.emf.ecore.EClass;
28: import org.eclipse.emf.ecore.EReference;
29: import org.eclipse.emf.ecore.EcoreFactory;
30: import org.eclipse.emf.ecore.EcorePackage;
31: import org.eclipse.emf.ecore.resource.Resource;
32: import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
33: import org.eclipse.emf.ecp.test.common.PerformanceClock;
34: import org.eclipse.emf.ecp.view.spi.model.VFeaturePathDomainModelReference;
35: import org.eclipse.emf.ecp.view.spi.model.VViewFactory;
36: import org.eclipse.emf.ecp.view.spi.renderer.NoPropertyDescriptorFoundExeption;
37: import org.eclipse.emf.ecp.view.spi.renderer.NoRendererFoundException;
38: import org.eclipse.emf.ecp.view.spi.table.model.VTableControl;
39: import org.eclipse.emf.ecp.view.spi.table.model.VTableDomainModelReference;
40: import org.eclipse.emf.ecp.view.table.test.common.TableTestUtil;
41: import org.eclipse.emf.ecp.view.test.common.swt.spi.DatabindingClassRunner;
42: import org.eclipse.emf.ecp.view.test.common.swt.spi.SWTTestUtil;
43: import org.eclipse.emf.ecp.view.test.common.swt.spi.SWTViewTestHelper;
44: import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
45: import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
46: import org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory;
47: import org.eclipse.emfforms.spi.swt.core.EMFFormsNoRendererException;
48: import org.eclipse.swt.SWT;
49: import org.eclipse.swt.widgets.Control;
50: import org.eclipse.swt.widgets.Shell;
51: import org.eclipse.swt.widgets.Table;
52: import org.junit.After;
53: import org.junit.Before;
54: import org.junit.Test;
55: import org.junit.runner.RunWith;
56:
57: /**
58: * Performance tests for the {@link TableControlSWTRenderer}.
59: *
60: * @author Lucas Koehler
61: *
62: */
63: @RunWith(DatabindingClassRunner.class)
64: public class TableControlSWTRendererPerformance_PTest {
65:
66:         private static final int SMALL_SCALE = 50;
67:         private static final int LARGE_SCALE = 2000;
68:         // sorting takes O(n*log n)
69:         private static final int ITERATIONS = 8;
70:         private static final double WORST_CASE_MULTIPLIER = 20.0;
71:
72:         private Shell shell;
73:         private ComposedAdapterFactory adapterFactory;
74:         private Resource smallResource;
75:         private Resource largeResource;
76:
77:         @Before
78:         public void init() {
79:                 shell = SWTViewTestHelper.createShell();
80:
81:                 // Add domain element to resource with editing domain
82:                 final ResourceSetImpl rs = new ResourceSetImpl();
83:                 adapterFactory = new ComposedAdapterFactory(new AdapterFactory[] {
84:                         new ReflectiveItemProviderAdapterFactory(),
85:                         new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE) });
86:                 final AdapterFactoryEditingDomain editingDomain = new AdapterFactoryEditingDomain(
87:                         adapterFactory, new BasicCommandStack(), rs);
88:                 rs.eAdapters().add(new AdapterFactoryEditingDomain.EditingDomainProvider(editingDomain));
89:                 smallResource = rs.createResource(URI.createURI("VIRTUAL_SMALL"));
90:                 largeResource = rs.createResource(URI.createURI("VIRTUAL_BIG"));
91:         }
92:
93:         @After
94:         public void after() {
95:                 adapterFactory.dispose();
96:•                if (shell != null && !shell.isDisposed()) {
97:                         shell.dispose();
98:                 }
99:         }
100:
101:         @Test
102:         public void tableSorting_autoSortOnEdit()
103:                 throws EMFFormsNoRendererException, NoRendererFoundException, NoPropertyDescriptorFoundExeption {
104:
105:                 // table control
106:                 final VTableControl tableControl = TableTestUtil.createTableControl();
107:                 final VTableDomainModelReference tableDMR = (VTableDomainModelReference) tableControl.getDomainModelReference();
108:                 tableDMR.setDomainModelEFeature(EcorePackage.eINSTANCE.getEClass_EAttributes());
109:                 tableDMR.getColumnDomainModelReferences().add(createDMR(EcorePackage.eINSTANCE.getENamedElement_Name()));
110:
111:                 // render
112:                 shell.open();
113:
114:                 test(domain -> {
115:                         Control control = null;
116:                         try {
117:                                 control = SWTViewTestHelper.render(tableControl, domain, shell);
118:                         } catch (NoRendererFoundException | NoPropertyDescriptorFoundExeption | EMFFormsNoRendererException ex) {
119:                                 fail("An exception occurred while rendering the table: " + ex.getMessage());
120:                         }
121:•                        if (control == null) {
122:                                 fail("No control was rendered");
123:                         }
124:                         final Table table = SWTTestUtil.findControl(control, 0, Table.class);
125:
126:                         // column 0 is validation column
127:                         // select column 1 (name) and ascending sorting
128:                         SWTTestUtil.selectWidget(table.getColumns()[1]);
129:                         SWTTestUtil.waitForUIThread();
130:                         assertEquals(SWT.DOWN, table.getSortDirection()); // SWT.DOWN := ascending sorting
131:
132:                         final EAttribute start = (EAttribute) table.getItem(0).getData();
133:                         start.setName("zzz");
134:
135:                         final EAttribute middle = (EAttribute) table.getItem(table.getItemCount() / 2).getData();
136:                         middle.setName("aaa");
137:                 });
138:         }
139:
140:         private void test(Consumer<EClass> experiment) {
141:                 final EClass smallInput = generateInput(SMALL_SCALE);
142:                 smallResource.getContents().clear();
143:                 smallResource.getContents().add(smallInput);
144:                 final EClass largeInput = generateInput(LARGE_SCALE);
145:                 largeResource.getContents().clear();
146:                 largeResource.getContents().add(largeInput);
147:                 PerformanceClock.test(ITERATIONS, WORST_CASE_MULTIPLIER, () -> smallInput, () -> largeInput, experiment);
148:         }
149:
150:         private static EClass generateInput(int childCount) {
151:                 final EClass eClass = EcoreFactory.eINSTANCE.createEClass();
152:                 final Random random = new Random(System.nanoTime());
153:                 final int nameLength = 10;
154:•                for (int i = 0; i < childCount; i++) {
155:                         final char[] result = new char[nameLength];
156:•                        for (int j = 0; j < nameLength; j++) {
157:                                 result[j] = (char) (random.nextInt('z' - 'A') + 'A');
158:                         }
159:                         final EAttribute attribute = EcoreFactory.eINSTANCE.createEAttribute();
160:                         attribute.setEType(EcorePackage.Literals.ESTRING);
161:                         attribute.setName(new String(result));
162:                         eClass.getEStructuralFeatures().add(attribute);
163:                 }
164:                 return eClass;
165:         }
166:
167:         private static VFeaturePathDomainModelReference createDMR(EAttribute attribute, EReference... refs) {
168:                 final VFeaturePathDomainModelReference dmr = VViewFactory.eINSTANCE.createFeaturePathDomainModelReference();
169:                 dmr.setDomainModelEFeature(attribute);
170:                 dmr.getDomainModelEReferencePath().addAll(Arrays.asList(refs));
171:                 return dmr;
172:         }
173: }