]> source.dussan.org Git - vaadin-framework.git/commitdiff
Tests for HorizontalLayout and VerticalLayout
authorArtur Signell <artur.signell@itmill.com>
Thu, 2 Dec 2010 07:55:18 +0000 (07:55 +0000)
committerArtur Signell <artur.signell@itmill.com>
Thu, 2 Dec 2010 07:55:18 +0000 (07:55 +0000)
svn changeset:16262/svn branch:6.5

tests/src/com/vaadin/tests/components/AbstractComponentContainerTest.java
tests/src/com/vaadin/tests/components/AbstractLayoutTest.java
tests/src/com/vaadin/tests/components/AbstractOrderedLayoutTest.java [new file with mode: 0644]
tests/src/com/vaadin/tests/components/orderedlayout/HorizontalLayoutTest.java [new file with mode: 0644]
tests/src/com/vaadin/tests/components/orderedlayout/VerticalLayoutTest.java [new file with mode: 0644]

index 4f0170552737323585e49aa0e12378a0d576874d..e73c5f69bd5bc556f3df709335b0558976acfe04 100644 (file)
@@ -105,11 +105,8 @@ public abstract class AbstractComponentContainerTest<T extends AbstractComponent
     private Command<T, Integer> removeComponentByIndexCommand = new Command<T, Integer>() {\r
 \r
         public void execute(T c, Integer value, Object data) {\r
-            Iterator<Component> iter = c.getComponentIterator();\r
-            for (int i = 0; i < value; i++) {\r
-                iter.next();\r
-            }\r
-            c.removeComponent(iter.next());\r
+            Component child = getComponentAtIndex(c, value);\r
+            c.removeComponent(child);\r
 \r
         }\r
     };\r
@@ -135,6 +132,24 @@ public abstract class AbstractComponentContainerTest<T extends AbstractComponent
         }\r
     };\r
 \r
+    private Command<T, Integer> setComponentHeight = new Command<T, Integer>() {\r
+\r
+        public void execute(T c, Integer value, Object data) {\r
+            Component child = getComponentAtIndex(c, value);\r
+            child.setHeight((String) data);\r
+\r
+        }\r
+    };\r
+\r
+    private Command<T, Integer> setComponentWidth = new Command<T, Integer>() {\r
+\r
+        public void execute(T c, Integer value, Object data) {\r
+            Component child = getComponentAtIndex(c, value);\r
+            child.setWidth((String) data);\r
+\r
+        }\r
+    };\r
+\r
     protected static class ComponentSize {\r
         private String width, height;\r
 \r
@@ -172,10 +187,20 @@ public abstract class AbstractComponentContainerTest<T extends AbstractComponent
 \r
         createAddComponentActions(CATEGORY_COMPONENT_CONTAINER_FEATURES);\r
         createRemoveComponentActions(CATEGORY_COMPONENT_CONTAINER_FEATURES);\r
+        createChangeComponentSizeActions(CATEGORY_COMPONENT_CONTAINER_FEATURES);\r
         createComponentAttachListener(CATEGORY_LISTENERS);\r
         createComponentDetachListener(CATEGORY_LISTENERS);\r
     }\r
 \r
+    protected Component getComponentAtIndex(T container, int value) {\r
+        Iterator<Component> iter = container.getComponentIterator();\r
+        for (int i = 0; i < value; i++) {\r
+            iter.next();\r
+        }\r
+\r
+        return iter.next();\r
+    }\r
+\r
     protected Table createTable() {\r
         Table t = new Table();\r
         t.addContainerProperty("property 1", String.class, "");\r
@@ -218,7 +243,7 @@ public abstract class AbstractComponentContainerTest<T extends AbstractComponent
         createCategory(byIndexCategory, subCategory);\r
         createClickAction("Remove all components", subCategory,\r
                 removeAllComponentsCommand, null);\r
-        for (int i = 0; i < 10; i++) {\r
+        for (int i = 0; i < 20; i++) {\r
             createClickAction("Remove component " + i, byIndexCategory,\r
                     removeComponentByIndexCommand, Integer.valueOf(i));\r
         }\r
@@ -264,6 +289,34 @@ public abstract class AbstractComponentContainerTest<T extends AbstractComponent
 \r
     }\r
 \r
+    private void createChangeComponentSizeActions(String category) {\r
+        String widthCategory = "Change component width";\r
+        createCategory(widthCategory, category);\r
+        String heightCategory = "Change component height";\r
+        createCategory(heightCategory, category);\r
+\r
+        String[] options = new String[] { "100px", "200px", "50%", "100%" };\r
+        for (int i = 0; i < 20; i++) {\r
+            String componentWidthCategory = "Component " + i + " width";\r
+            String componentHeightCategory = "Component " + i + " height";\r
+            createCategory(componentWidthCategory, widthCategory);\r
+            createCategory(componentHeightCategory, heightCategory);\r
+\r
+            createClickAction("auto", componentHeightCategory,\r
+                    setComponentHeight, Integer.valueOf(i), null);\r
+            createClickAction("auto", componentWidthCategory,\r
+                    setComponentWidth, Integer.valueOf(i), null);\r
+            for (String option : options) {\r
+                createClickAction(option, componentHeightCategory,\r
+                        setComponentHeight, Integer.valueOf(i), option);\r
+                createClickAction(option, componentWidthCategory,\r
+                        setComponentWidth, Integer.valueOf(i), option);\r
+            }\r
+\r
+        }\r
+\r
+    }\r
+\r
     public void componentDetachedFromContainer(ComponentDetachEvent event) {\r
         log(event.getClass().getSimpleName() + ": "\r
                 + event.getDetachedComponent().getClass().getSimpleName()\r
index 7dc481d38766b282eeebab2935a55955d28981ac..f6b979c6982d7e2268c720c57175ee41c0099e4e 100644 (file)
@@ -3,12 +3,16 @@ package com.vaadin.tests.components;
 import java.util.LinkedHashMap;\r
 \r
 import com.vaadin.ui.AbstractLayout;\r
+import com.vaadin.ui.Alignment;\r
+import com.vaadin.ui.Component;\r
+import com.vaadin.ui.Layout.AlignmentHandler;\r
 import com.vaadin.ui.Layout.MarginInfo;\r
+import com.vaadin.ui.Layout.SpacingHandler;\r
 \r
 public abstract class AbstractLayoutTest<T extends AbstractLayout> extends\r
         AbstractComponentContainerTest<T> {\r
 \r
-    private static final String CATEGORY_LAYOUT_FEATURES = "Layout features";\r
+    protected static final String CATEGORY_LAYOUT_FEATURES = "Layout features";\r
     private Command<T, MarginInfo> marginCommand = new Command<T, MarginInfo>() {\r
 \r
         public void execute(T c, MarginInfo value, Object data) {\r
@@ -17,10 +21,32 @@ public abstract class AbstractLayoutTest<T extends AbstractLayout> extends
         }\r
     };\r
 \r
+    protected Command<T, Boolean> spacingCommand = new Command<T, Boolean>() {\r
+        public void execute(T c, Boolean value, Object data) {\r
+            ((SpacingHandler) c).setSpacing(value);\r
+        }\r
+    };\r
+\r
+    private Command<T, Integer> setComponentAlignment = new Command<T, Integer>() {\r
+\r
+        public void execute(T c, Integer value, Object alignment) {\r
+            Component child = getComponentAtIndex(c, value);\r
+            ((AlignmentHandler) c).setComponentAlignment(child,\r
+                    (Alignment) alignment);\r
+        }\r
+    };\r
+\r
     @Override\r
     protected void createActions() {\r
         super.createActions();\r
         createMarginsSelect(CATEGORY_LAYOUT_FEATURES);\r
+        if (SpacingHandler.class.isAssignableFrom(getTestClass())) {\r
+            createSpacingSelect(CATEGORY_LAYOUT_FEATURES);\r
+        }\r
+        if (AlignmentHandler.class.isAssignableFrom(getTestClass())) {\r
+            createChangeComponentAlignmentAction(CATEGORY_LAYOUT_FEATURES);\r
+        }\r
+\r
     }\r
 \r
     private void createMarginsSelect(String category) {\r
@@ -36,4 +62,39 @@ public abstract class AbstractLayoutTest<T extends AbstractLayout> extends
 \r
         createSelectAction("Margins", category, options, "off", marginCommand);\r
     }\r
+\r
+    private void createSpacingSelect(String category) {\r
+        createBooleanAction("Spacing", category, false, spacingCommand);\r
+    }\r
+\r
+    private void createChangeComponentAlignmentAction(String category) {\r
+        String alignmentCategory = "Component alignment";\r
+        createCategory(alignmentCategory, category);\r
+\r
+        LinkedHashMap<String, Alignment> options = new LinkedHashMap<String, Alignment>();\r
+        options.put("Top left", Alignment.TOP_LEFT);\r
+        options.put("Top center", Alignment.TOP_CENTER);\r
+        options.put("Top right", Alignment.TOP_RIGHT);\r
+\r
+        options.put("Middle left", Alignment.MIDDLE_LEFT);\r
+        options.put("Middle center", Alignment.MIDDLE_CENTER);\r
+        options.put("Middle right", Alignment.MIDDLE_RIGHT);\r
+\r
+        options.put("Bottom left", Alignment.BOTTOM_LEFT);\r
+        options.put("Bottom center", Alignment.BOTTOM_CENTER);\r
+        options.put("Bottom right", Alignment.BOTTOM_RIGHT);\r
+\r
+        for (int i = 0; i < 20; i++) {\r
+            String componentAlignmentCategory = "Component " + i + " alignment";\r
+            createCategory(componentAlignmentCategory, alignmentCategory);\r
+\r
+            for (String option : options.keySet()) {\r
+                createClickAction(option, componentAlignmentCategory,\r
+                        setComponentAlignment, Integer.valueOf(i),\r
+                        options.get(option));\r
+            }\r
+\r
+        }\r
+\r
+    }\r
 }\r
diff --git a/tests/src/com/vaadin/tests/components/AbstractOrderedLayoutTest.java b/tests/src/com/vaadin/tests/components/AbstractOrderedLayoutTest.java
new file mode 100644 (file)
index 0000000..d6cbe85
--- /dev/null
@@ -0,0 +1,85 @@
+package com.vaadin.tests.components;\r
+\r
+import java.util.LinkedHashMap;\r
+\r
+import com.vaadin.event.LayoutEvents.LayoutClickEvent;\r
+import com.vaadin.event.LayoutEvents.LayoutClickListener;\r
+import com.vaadin.ui.AbstractOrderedLayout;\r
+import com.vaadin.ui.Component;\r
+\r
+public abstract class AbstractOrderedLayoutTest<T extends AbstractOrderedLayout>\r
+        extends AbstractLayoutTest<T> implements LayoutClickListener {\r
+\r
+    private Command<T, Boolean> layoutClickListenerCommand = new Command<T, Boolean>() {\r
+\r
+        public void execute(T c, Boolean value, Object data) {\r
+            if (value) {\r
+                c.addListener((LayoutClickListener) AbstractOrderedLayoutTest.this);\r
+            } else {\r
+\r
+            }\r
+\r
+        }\r
+    };\r
+\r
+    private Command<T, Integer> setComponentExpandRatio = new Command<T, Integer>() {\r
+\r
+        public void execute(T c, Integer value, Object ratio) {\r
+            Component child = getComponentAtIndex(c, value);\r
+            c.setExpandRatio(child, (Float) ratio);\r
+        }\r
+    };\r
+\r
+    @Override\r
+    protected void createActions() {\r
+        super.createActions();\r
+\r
+        createLayoutClickListenerAction(CATEGORY_LISTENERS);\r
+        createChangeComponentExpandRatioAction(CATEGORY_LAYOUT_FEATURES);\r
+        // Set a root style so we can see the component. Can be overridden by\r
+        // setting the style name in the UI\r
+        for (T c : getTestComponents()) {\r
+            c.setStyleName("background-lightblue");\r
+        }\r
+    }\r
+\r
+    private void createLayoutClickListenerAction(String category) {\r
+        createBooleanAction("Layout click listener", category, false,\r
+                layoutClickListenerCommand);\r
+    }\r
+\r
+    private void createChangeComponentExpandRatioAction(String category) {\r
+        String expandRatioCategory = "Component expand ratio";\r
+        createCategory(expandRatioCategory, category);\r
+\r
+        LinkedHashMap<String, Float> options = new LinkedHashMap<String, Float>();\r
+        options.put("0", 0f);\r
+        options.put("0.5", 0.5f);\r
+        for (float f = 1; f <= 5; f++) {\r
+            options.put(String.valueOf(f), f);\r
+        }\r
+\r
+        for (int i = 0; i < 20; i++) {\r
+            String componentExpandRatioCategory = "Component " + i\r
+                    + " expand ratio";\r
+            createCategory(componentExpandRatioCategory, expandRatioCategory);\r
+\r
+            for (String option : options.keySet()) {\r
+                createClickAction(option, componentExpandRatioCategory,\r
+                        setComponentExpandRatio, Integer.valueOf(i),\r
+                        options.get(option));\r
+            }\r
+\r
+        }\r
+\r
+    }\r
+\r
+    public void layoutClick(LayoutClickEvent event) {\r
+        log(event.getClass().getSimpleName() + ": button="\r
+                + event.getButtonName() + ", childComponent="\r
+                + event.getChildComponent().getClass().getSimpleName()\r
+                + ", relativeX=" + event.getRelativeX() + ", relativeY="\r
+                + event.getRelativeY());\r
+\r
+    }\r
+}\r
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 (file)
index 0000000..b06179e
--- /dev/null
@@ -0,0 +1,14 @@
+package com.vaadin.tests.components.orderedlayout;\r
+\r
+import com.vaadin.tests.components.AbstractOrderedLayoutTest;\r
+import com.vaadin.ui.HorizontalLayout;\r
+\r
+public class HorizontalLayoutTest extends\r
+        AbstractOrderedLayoutTest<HorizontalLayout> {\r
+\r
+    @Override\r
+    protected Class<HorizontalLayout> getTestClass() {\r
+        return HorizontalLayout.class;\r
+    }\r
+\r
+}
\ 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 (file)
index 0000000..20babc8
--- /dev/null
@@ -0,0 +1,14 @@
+package com.vaadin.tests.components.orderedlayout;\r
+\r
+import com.vaadin.tests.components.AbstractOrderedLayoutTest;\r
+import com.vaadin.ui.VerticalLayout;\r
+\r
+public class VerticalLayoutTest extends\r
+        AbstractOrderedLayoutTest<VerticalLayout> {\r
+\r
+    @Override\r
+    protected Class<VerticalLayout> getTestClass() {\r
+        return VerticalLayout.class;\r
+    }\r
+\r
+}\r