]> source.dussan.org Git - vaadin-framework.git/commitdiff
Deep component tree test
authorMatti Tahvonen <matti.tahvonen@itmill.com>
Fri, 13 Mar 2009 09:13:56 +0000 (09:13 +0000)
committerMatti Tahvonen <matti.tahvonen@itmill.com>
Fri, 13 Mar 2009 09:13:56 +0000 (09:13 +0000)
svn changeset:7074/svn branch:6.0

src/com/itmill/toolkit/tests/layouts/DeepComponentTrees.java [new file with mode: 0644]

diff --git a/src/com/itmill/toolkit/tests/layouts/DeepComponentTrees.java b/src/com/itmill/toolkit/tests/layouts/DeepComponentTrees.java
new file mode 100644 (file)
index 0000000..de83665
--- /dev/null
@@ -0,0 +1,114 @@
+package com.itmill.toolkit.tests.layouts;\r
+\r
+import com.itmill.toolkit.data.Property.ValueChangeEvent;\r
+import com.itmill.toolkit.tests.components.TestBase;\r
+import com.itmill.toolkit.ui.Button;\r
+import com.itmill.toolkit.ui.ComboBox;\r
+import com.itmill.toolkit.ui.GridLayout;\r
+import com.itmill.toolkit.ui.HorizontalLayout;\r
+import com.itmill.toolkit.ui.Label;\r
+import com.itmill.toolkit.ui.Layout;\r
+import com.itmill.toolkit.ui.Panel;\r
+import com.itmill.toolkit.ui.VerticalLayout;\r
+import com.itmill.toolkit.ui.Button.ClickEvent;\r
+\r
+public class DeepComponentTrees extends TestBase {\r
+\r
+    private Panel root;\r
+\r
+    @Override\r
+    protected String getDescription() {\r
+        return "Toolkit should not choke on deep component trees. 15 levels should be minimum to survive.";\r
+    }\r
+\r
+    @Override\r
+    protected Integer getTicketNumber() {\r
+        return null;\r
+    }\r
+\r
+    private int i = 0;\r
+    private Class<?> currentValue = VerticalLayout.class;\r
+\r
+    @Override\r
+    protected void setup() {\r
+        Layout main = getLayout();\r
+        main.setSizeUndefined();\r
+        getMainWindow().getLayout().setHeight(null);\r
+\r
+        Label l = new Label(\r
+                "This is a nice game to guess how many Layouts your FF2 (or any other browser) can deal with. Due to the worldwide attempt to decrease energy consumption, playing this game is only allowed above 60° longitude betwheen August and May (as excess energy consumed by you CPU is used to heat your room). It is considered wise to save all your work before starting the game.");\r
+\r
+        root = new Panel("Test box");\r
+        root.setWidth("600px");\r
+        root.setHeight("200px");\r
+        final Button b = new Button("Go try your luck with " + i + " layouts!");\r
+        b.addListener(new Button.ClickListener() {\r
+\r
+            public void buttonClick(ClickEvent event) {\r
+                FF2KILLER(i++);\r
+                b.setCaption("Go try your luck with " + i + " layouts!");\r
+            }\r
+\r
+        });\r
+\r
+        final ComboBox s = new ComboBox("Restart game with select:");\r
+        s.setNullSelectionAllowed(false);\r
+        s.addItem("-- Choose value --");\r
+        s.setValue("-- Choose value --");\r
+        s.addItem(VerticalLayout.class);\r
+        s.addItem(HorizontalLayout.class);\r
+        s.addItem(GridLayout.class);\r
+        s.addListener(new ComboBox.ValueChangeListener() {\r
+\r
+            public void valueChange(ValueChangeEvent event) {\r
+                Object value = s.getValue();\r
+                if (!value.equals("-- Choose value --")) {\r
+                    currentValue = (Class<?>) value;\r
+                    i = 0;\r
+                    s.setValue("-- Choose value --");\r
+                    b.setCaption("Go try your luck with " + i + " layouts!");\r
+                }\r
+\r
+            }\r
+        });\r
+        s.setImmediate(true);\r
+\r
+        main.addComponent(l);\r
+        main.addComponent(b);\r
+        main.addComponent(s);\r
+        main.addComponent(root);\r
+\r
+    }\r
+\r
+    private void FF2KILLER(int layouts) {\r
+        Layout layout = getTestLayout();\r
+        Layout r = layout;\r
+        for (int i = 0; i < layouts; i++) {\r
+            Layout lo = getTestLayout();\r
+            layout.addComponent(lo);\r
+            layout = lo;\r
+        }\r
+        layout.addComponent(new Label(\r
+                "FF did it! Toolkit, Mozilla and you win! Dare to try again?"));\r
+        root.setLayout(r);\r
+    }\r
+\r
+    Layout getTestLayout() {\r
+        Layout l = new VerticalLayout();\r
+        if (currentValue == GridLayout.class) {\r
+            l = new GridLayout(1, 1);\r
+        } else {\r
+            try {\r
+                l = (Layout) currentValue.newInstance();\r
+            } catch (InstantiationException e) {\r
+                // TODO Auto-generated catch block\r
+                e.printStackTrace();\r
+            } catch (IllegalAccessException e) {\r
+                // TODO Auto-generated catch block\r
+                e.printStackTrace();\r
+            }\r
+        }\r
+        return l;\r
+    }\r
+\r
+}\r