diff options
author | Tomasz Zarna | 2011-04-18 14:19:01 +0000 |
---|---|---|
committer | Tomasz Zarna | 2011-04-18 14:19:01 +0000 |
commit | 9c96306301937943eb39ae5b59b44428f048b47e (patch) | |
tree | a7f23b20e7051ddc220e196efa7488eaa75fe110 /tests | |
parent | d4d7173fe539db4fdb3efa350a83c3e5e3e127bb (diff) | |
download | eclipse.platform.team-9c96306301937943eb39ae5b59b44428f048b47e.tar.gz eclipse.platform.team-9c96306301937943eb39ae5b59b44428f048b47e.tar.xz eclipse.platform.team-9c96306301937943eb39ae5b59b44428f048b47e.zip |
bug 342541: [History View] New Branches column: column widths need some work - a better fix + tests
Diffstat (limited to 'tests')
3 files changed, 218 insertions, 6 deletions
diff --git a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/ui/AllUITests.java b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/ui/AllUITests.java index 4703e8cdf..93d31a5d1 100644 --- a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/ui/AllUITests.java +++ b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/ui/AllUITests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2010 IBM Corporation and others. + * Copyright (c) 2000, 2011 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -35,6 +35,7 @@ public class AllUITests extends EclipseTest { suite.addTest(PatchWizardRadioButtonGroupTests.suite()); suite.addTest(CVSProjectSetImportTest.suite()); suite.addTest(CreatePatchTest.suite()); + suite.addTest(CVSHisoryTableProviderTest.suite()); return suite; } diff --git a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/ui/CVSHisoryTableProviderTest.java b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/ui/CVSHisoryTableProviderTest.java new file mode 100644 index 000000000..23b9681da --- /dev/null +++ b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/ui/CVSHisoryTableProviderTest.java @@ -0,0 +1,206 @@ +/******************************************************************************* + * Copyright (c) 2011 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.team.tests.ccvs.ui; + +import java.util.Iterator; +import java.util.List; + +import junit.framework.Test; + +import org.eclipse.jface.dialogs.DialogSettings; +import org.eclipse.jface.dialogs.IDialogSettings; +import org.eclipse.jface.layout.PixelConverter; +import org.eclipse.jface.viewers.ColumnLayoutData; +import org.eclipse.jface.viewers.ColumnPixelData; +import org.eclipse.jface.viewers.ColumnWeightData; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Item; +import org.eclipse.swt.widgets.Layout; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.team.internal.ccvs.ui.CVSHistoryTableProvider; +import org.eclipse.team.internal.ccvs.ui.CVSUIMessages; +import org.eclipse.team.tests.ccvs.core.EclipseTest; + +public class CVSHisoryTableProviderTest extends EclipseTest { + + public void testAllNegatives() throws Exception { + Display display = Display.getCurrent(); + Shell shell = new Shell(display); + Composite composite = new Composite(shell, SWT.NONE); + composite.setLayout(new FillLayout()); + + CVSHistoryTableProvider provider = new CVSHistoryTableProvider(); + // empty settings + TreeViewer treeViewer = provider.createTree(composite); + Tree tree = treeViewer.getTree(); + Layout layout = tree.getLayout(); + + // layout.getColumns(tree); + Item[] items = (Item[]) ReflectionUtils.callMethod(layout, + "getColumns", new Class[] { Composite.class }, + new Object[] { tree }); + assertEquals(6, items.length); + + // List columns = layout.columns; + List/* <ColumnLayoutData> */columns = (List) ReflectionUtils.getField( + layout, "columns"); + // same weight for all columns + int weight = ((ColumnWeightData) columns.get(0)).weight; + for (Iterator iterator = columns.iterator(); iterator.hasNext();) { + ColumnLayoutData column = (ColumnLayoutData) iterator.next(); + assertTrue(column instanceof ColumnWeightData); + ColumnWeightData c = (ColumnWeightData) column; + assertTrue(c.weight > 0); + assertEquals(weight, c.weight); + } + // layout.layout(tree, false /*ignored in TableLayout*/); + } + + public void testAllZeros() throws Exception { + Display display = Display.getCurrent(); + Shell shell = new Shell(display); + Composite composite = new Composite(shell, SWT.NONE); + composite.setLayout(new FillLayout()); + + CVSHistoryTableProvider provider = new CVSHistoryTableProvider(); + // provider.settings = createDialogSettings(...); + ReflectionUtils.setField(provider, "settings", + createDialogSettings(provider, new int[] { 0, 0, 0, 0, 0, 0 })); + TreeViewer treeViewer = provider.createTree(composite); + Tree tree = treeViewer.getTree(); + Layout layout = tree.getLayout(); + + // layout.getColumns(tree); + Item[] items = (Item[]) ReflectionUtils.callMethod(layout, + "getColumns", new Class[] { Composite.class }, + new Object[] { tree }); + assertEquals(6, items.length); + + // List columns = layout.columns; + List/* <ColumnLayoutData> */columns = (List) ReflectionUtils.getField( + layout, "columns"); + // same weight for all columns + int weight = ((ColumnWeightData) columns.get(0)).weight; + for (Iterator iterator = columns.iterator(); iterator.hasNext();) { + ColumnLayoutData column = (ColumnLayoutData) iterator.next(); + assertTrue(column instanceof ColumnWeightData); + ColumnWeightData c = (ColumnWeightData) column; + assertTrue(c.weight > 0); + assertEquals(weight, c.weight); + } + } + + public void testNewBranchColumn() throws Exception { + Display display = Display.getCurrent(); + Shell shell = new Shell(display); + Composite composite = new Composite(shell, SWT.NONE); + composite.setLayout(new FillLayout()); + + CVSHistoryTableProvider provider = new CVSHistoryTableProvider(); + // provider.settings = createDialogSettings(...); + ReflectionUtils.setField( + provider, + "settings", + createDialogSettings(provider, new int[] { 100, -1, 100, 100, + 100, 100 })); + TreeViewer treeViewer = provider.createTree(composite); + Tree tree = treeViewer.getTree(); + Layout layout = tree.getLayout(); + + // layout.getColumns(tree); + Item[] items = (Item[]) ReflectionUtils.callMethod(layout, + "getColumns", new Class[] { Composite.class }, + new Object[] { tree }); + assertEquals(6, items.length); + + // List columns = layout.columns; + List/* <ColumnLayoutData> */columns = (List) ReflectionUtils.getField( + layout, "columns"); + for (Iterator iterator = columns.iterator(); iterator.hasNext();) { + ColumnLayoutData column = (ColumnLayoutData) iterator.next(); + assertTrue(column instanceof ColumnPixelData); + ColumnPixelData c = (ColumnPixelData) column; + assertTrue(c.width > 0); + } + int branchesColumnWidth = ((ColumnPixelData) columns.get(1)).width; + int pixels = new PixelConverter(tree) + .convertWidthInCharsToPixels(CVSUIMessages.HistoryView_branches + .length() + 4); + assertEquals(pixels, branchesColumnWidth); + } + + public void testAllPositives() throws Exception { + Display display = Display.getCurrent(); + Shell shell = new Shell(display); + Composite composite = new Composite(shell, SWT.NONE); + composite.setLayout(new FillLayout()); + + CVSHistoryTableProvider provider = new CVSHistoryTableProvider(); + // provider.settings = createDialogSettings(...); + ReflectionUtils.setField( + provider, + "settings", + createDialogSettings(provider, new int[] { 100, 100, 100, 100, + 100, 100 })); + TreeViewer treeViewer = provider.createTree(composite); + Tree tree = treeViewer.getTree(); + Layout layout = tree.getLayout(); + + // layout.getColumns(tree); + Item[] items = (Item[]) ReflectionUtils.callMethod(layout, + "getColumns", new Class[] { Composite.class }, + new Object[] { tree }); + assertEquals(6, items.length); + + // List columns = layout.columns; + List/* <ColumnLayoutData> */columns = (List) ReflectionUtils.getField( + layout, "columns"); + for (Iterator iterator = columns.iterator(); iterator.hasNext();) { + ColumnLayoutData column = (ColumnLayoutData) iterator.next(); + assertTrue(column instanceof ColumnPixelData); + ColumnPixelData c = (ColumnPixelData) column; + assertEquals(100, c.width); + } + } + + private IDialogSettings createDialogSettings( + CVSHistoryTableProvider provider, int[] widths) { + String sectionName = (String) ReflectionUtils.getField(provider, + "CVS_HISTORY_TABLE_PROVIDER_SECTION"); + IDialogSettings settings = new DialogSettings(sectionName); + + assertEquals(6, widths.length); + String key = (String) ReflectionUtils.getField(provider, + "COL_REVISIONID_NAME"); + settings.put(key, widths[0]); + key = (String) ReflectionUtils.getField(provider, "COL_BRANCHES_NAME"); + settings.put(key, widths[1]); + key = (String) ReflectionUtils.getField(provider, "COL_TAGS_NAME"); + settings.put(key, widths[2]); + key = (String) ReflectionUtils.getField(provider, "COL_DATE_NAME"); + settings.put(key, widths[3]); + key = (String) ReflectionUtils.getField(provider, "COL_AUTHOR_NAME"); + settings.put(key, widths[4]); + key = (String) ReflectionUtils.getField(provider, "COL_COMMENT_NAME"); + settings.put(key, widths[5]); + + return settings; + } + + public static Test suite() { + return suite(CVSHisoryTableProviderTest.class); + } +} diff --git a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/ui/ReflectionUtils.java b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/ui/ReflectionUtils.java index 2bccdc0e4..855d6d73a 100644 --- a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/ui/ReflectionUtils.java +++ b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/ui/ReflectionUtils.java @@ -54,12 +54,9 @@ public class ReflectionUtils { return null; } - public static Object callMethod(Object object, String name, Object args[]) { + public static Object callMethod(Object object, String name, Class types[], + Object args[]) { try { - Class types[] = new Class[args.length]; - for (int i = 0; i < args.length; i++) { - types[i] = args[i].getClass(); - } Method method = null; Class clazz = object.getClass(); NoSuchMethodException ex = null; @@ -93,6 +90,14 @@ public class ReflectionUtils { return null; } + public static Object callMethod(Object object, String name, Object args[]) { + Class types[] = new Class[args.length]; + for (int i = 0; i < args.length; i++) { + types[i] = args[i].getClass(); + } + return callMethod(object, name, types, args); + } + public static Object getField(Object object, String name) { try { Field field = null; |