From 6dd3aa13d75c22e6b0be888f9058cc98bdae2010 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Thu, 2 Dec 2010 07:55:18 +0000 Subject: [PATCH] Tests for HorizontalLayout and VerticalLayout svn changeset:16262/svn branch:6.5 --- .../AbstractComponentContainerTest.java | 65 ++++++++++++-- .../tests/components/AbstractLayoutTest.java | 63 +++++++++++++- .../components/AbstractOrderedLayoutTest.java | 85 +++++++++++++++++++ .../orderedlayout/HorizontalLayoutTest.java | 14 +++ .../orderedlayout/VerticalLayoutTest.java | 14 +++ 5 files changed, 234 insertions(+), 7 deletions(-) create mode 100644 tests/src/com/vaadin/tests/components/AbstractOrderedLayoutTest.java create mode 100644 tests/src/com/vaadin/tests/components/orderedlayout/HorizontalLayoutTest.java create mode 100644 tests/src/com/vaadin/tests/components/orderedlayout/VerticalLayoutTest.java diff --git a/tests/src/com/vaadin/tests/components/AbstractComponentContainerTest.java b/tests/src/com/vaadin/tests/components/AbstractComponentContainerTest.java index 4f01705527..e73c5f69bd 100644 --- a/tests/src/com/vaadin/tests/components/AbstractComponentContainerTest.java +++ b/tests/src/com/vaadin/tests/components/AbstractComponentContainerTest.java @@ -105,11 +105,8 @@ public abstract class AbstractComponentContainerTest removeComponentByIndexCommand = new Command() { public void execute(T c, Integer value, Object data) { - Iterator iter = c.getComponentIterator(); - for (int i = 0; i < value; i++) { - iter.next(); - } - c.removeComponent(iter.next()); + Component child = getComponentAtIndex(c, value); + c.removeComponent(child); } }; @@ -135,6 +132,24 @@ public abstract class AbstractComponentContainerTest setComponentHeight = new Command() { + + public void execute(T c, Integer value, Object data) { + Component child = getComponentAtIndex(c, value); + child.setHeight((String) data); + + } + }; + + private Command setComponentWidth = new Command() { + + public void execute(T c, Integer value, Object data) { + Component child = getComponentAtIndex(c, value); + child.setWidth((String) data); + + } + }; + protected static class ComponentSize { private String width, height; @@ -172,10 +187,20 @@ public abstract class AbstractComponentContainerTest iter = container.getComponentIterator(); + for (int i = 0; i < value; i++) { + iter.next(); + } + + return iter.next(); + } + protected Table createTable() { Table t = new Table(); t.addContainerProperty("property 1", String.class, ""); @@ -218,7 +243,7 @@ public abstract class AbstractComponentContainerTest extends AbstractComponentContainerTest { - private static final String CATEGORY_LAYOUT_FEATURES = "Layout features"; + protected static final String CATEGORY_LAYOUT_FEATURES = "Layout features"; private Command marginCommand = new Command() { public void execute(T c, MarginInfo value, Object data) { @@ -17,10 +21,32 @@ public abstract class AbstractLayoutTest extends } }; + protected Command spacingCommand = new Command() { + public void execute(T c, Boolean value, Object data) { + ((SpacingHandler) c).setSpacing(value); + } + }; + + private Command setComponentAlignment = new Command() { + + public void execute(T c, Integer value, Object alignment) { + Component child = getComponentAtIndex(c, value); + ((AlignmentHandler) c).setComponentAlignment(child, + (Alignment) alignment); + } + }; + @Override protected void createActions() { super.createActions(); createMarginsSelect(CATEGORY_LAYOUT_FEATURES); + if (SpacingHandler.class.isAssignableFrom(getTestClass())) { + createSpacingSelect(CATEGORY_LAYOUT_FEATURES); + } + if (AlignmentHandler.class.isAssignableFrom(getTestClass())) { + createChangeComponentAlignmentAction(CATEGORY_LAYOUT_FEATURES); + } + } private void createMarginsSelect(String category) { @@ -36,4 +62,39 @@ public abstract class AbstractLayoutTest extends createSelectAction("Margins", category, options, "off", marginCommand); } + + private void createSpacingSelect(String category) { + createBooleanAction("Spacing", category, false, spacingCommand); + } + + private void createChangeComponentAlignmentAction(String category) { + String alignmentCategory = "Component alignment"; + createCategory(alignmentCategory, category); + + LinkedHashMap options = new LinkedHashMap(); + options.put("Top left", Alignment.TOP_LEFT); + options.put("Top center", Alignment.TOP_CENTER); + options.put("Top right", Alignment.TOP_RIGHT); + + options.put("Middle left", Alignment.MIDDLE_LEFT); + options.put("Middle center", Alignment.MIDDLE_CENTER); + options.put("Middle right", Alignment.MIDDLE_RIGHT); + + options.put("Bottom left", Alignment.BOTTOM_LEFT); + options.put("Bottom center", Alignment.BOTTOM_CENTER); + options.put("Bottom right", Alignment.BOTTOM_RIGHT); + + for (int i = 0; i < 20; i++) { + String componentAlignmentCategory = "Component " + i + " alignment"; + createCategory(componentAlignmentCategory, alignmentCategory); + + for (String option : options.keySet()) { + createClickAction(option, componentAlignmentCategory, + setComponentAlignment, Integer.valueOf(i), + options.get(option)); + } + + } + + } } diff --git a/tests/src/com/vaadin/tests/components/AbstractOrderedLayoutTest.java b/tests/src/com/vaadin/tests/components/AbstractOrderedLayoutTest.java new file mode 100644 index 0000000000..d6cbe8590d --- /dev/null +++ b/tests/src/com/vaadin/tests/components/AbstractOrderedLayoutTest.java @@ -0,0 +1,85 @@ +package com.vaadin.tests.components; + +import java.util.LinkedHashMap; + +import com.vaadin.event.LayoutEvents.LayoutClickEvent; +import com.vaadin.event.LayoutEvents.LayoutClickListener; +import com.vaadin.ui.AbstractOrderedLayout; +import com.vaadin.ui.Component; + +public abstract class AbstractOrderedLayoutTest + extends AbstractLayoutTest implements LayoutClickListener { + + private Command layoutClickListenerCommand = new Command() { + + public void execute(T c, Boolean value, Object data) { + if (value) { + c.addListener((LayoutClickListener) AbstractOrderedLayoutTest.this); + } else { + + } + + } + }; + + private Command setComponentExpandRatio = new Command() { + + public void execute(T c, Integer value, Object ratio) { + Component child = getComponentAtIndex(c, value); + c.setExpandRatio(child, (Float) ratio); + } + }; + + @Override + protected void createActions() { + super.createActions(); + + createLayoutClickListenerAction(CATEGORY_LISTENERS); + createChangeComponentExpandRatioAction(CATEGORY_LAYOUT_FEATURES); + // Set a root style so we can see the component. Can be overridden by + // setting the style name in the UI + for (T c : getTestComponents()) { + c.setStyleName("background-lightblue"); + } + } + + private void createLayoutClickListenerAction(String category) { + createBooleanAction("Layout click listener", category, false, + layoutClickListenerCommand); + } + + private void createChangeComponentExpandRatioAction(String category) { + String expandRatioCategory = "Component expand ratio"; + createCategory(expandRatioCategory, category); + + LinkedHashMap options = new LinkedHashMap(); + options.put("0", 0f); + options.put("0.5", 0.5f); + for (float f = 1; f <= 5; f++) { + options.put(String.valueOf(f), f); + } + + for (int i = 0; i < 20; i++) { + String componentExpandRatioCategory = "Component " + i + + " expand ratio"; + createCategory(componentExpandRatioCategory, expandRatioCategory); + + for (String option : options.keySet()) { + createClickAction(option, componentExpandRatioCategory, + setComponentExpandRatio, Integer.valueOf(i), + options.get(option)); + } + + } + + } + + public void layoutClick(LayoutClickEvent event) { + log(event.getClass().getSimpleName() + ": button=" + + event.getButtonName() + ", childComponent=" + + event.getChildComponent().getClass().getSimpleName() + + ", relativeX=" + event.getRelativeX() + ", relativeY=" + + event.getRelativeY()); + + } +} diff --git a/tests/src/com/vaadin/tests/components/orderedlayout/HorizontalLayoutTest.java b/tests/src/com/vaadin/tests/components/orderedlayout/HorizontalLayoutTest.java new file mode 100644 index 0000000000..b06179efd7 --- /dev/null +++ b/tests/src/com/vaadin/tests/components/orderedlayout/HorizontalLayoutTest.java @@ -0,0 +1,14 @@ +package com.vaadin.tests.components.orderedlayout; + +import com.vaadin.tests.components.AbstractOrderedLayoutTest; +import com.vaadin.ui.HorizontalLayout; + +public class HorizontalLayoutTest extends + AbstractOrderedLayoutTest { + + @Override + protected Class getTestClass() { + return HorizontalLayout.class; + } + +} \ No newline at end of file diff --git a/tests/src/com/vaadin/tests/components/orderedlayout/VerticalLayoutTest.java b/tests/src/com/vaadin/tests/components/orderedlayout/VerticalLayoutTest.java new file mode 100644 index 0000000000..20babc8576 --- /dev/null +++ b/tests/src/com/vaadin/tests/components/orderedlayout/VerticalLayoutTest.java @@ -0,0 +1,14 @@ +package com.vaadin.tests.components.orderedlayout; + +import com.vaadin.tests.components.AbstractOrderedLayoutTest; +import com.vaadin.ui.VerticalLayout; + +public class VerticalLayoutTest extends + AbstractOrderedLayoutTest { + + @Override + protected Class getTestClass() { + return VerticalLayout.class; + } + +} -- 2.39.5