001: /*
002: * Copyright 2007 Google Inc.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005: * use this file except in compliance with the License. You may obtain a copy of
006: * the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013: * License for the specific language governing permissions and limitations under
014: * the License.
015: */
016: package com.google.gwt.user.client.ui;
017:
018: import com.google.gwt.junit.client.GWTTestCase;
019:
020: /**
021: * Tests <code>ListBox</code>. Needs many, many more tests.
022: */
023: public class StackPanelTest extends GWTTestCase {
024:
025: static class Adder implements HasWidgetsTester.WidgetAdder {
026: public void addChild(HasWidgets container, Widget child) {
027: ((StackPanel) container).add(child, "foo");
028: }
029: }
030:
031: public String getModuleName() {
032: return "com.google.gwt.user.User";
033: }
034:
035: public String curContents(StackPanel p) {
036: String accum = "";
037: int size = p.getWidgetCount();
038: for (int i = 0; i < size; i++) {
039: Label l = (Label) p.getWidget(i);
040: if (i != 0) {
041: accum += " ";
042: }
043: accum += l.getText();
044: }
045: return accum;
046: }
047:
048: public void testAttachDetachOrder() {
049: HasWidgetsTester.testAll(new StackPanel(), new Adder());
050: }
051:
052: /**
053: * Tests getSelectedStack.
054: */
055: public void testGetSelectedStack() {
056: StackPanel p = new StackPanel();
057: assertEquals(-1, p.getSelectedIndex());
058: Label a = new Label("a");
059: Label b = new Label("b");
060: Label c = new Label("c");
061: Label d = new Label("d");
062: p.add(a);
063: p.add(b, "b");
064: p.add(c);
065: p.add(d, "d");
066: assertEquals(0, p.getSelectedIndex());
067: p.showStack(2);
068: assertEquals(2, p.getSelectedIndex());
069: p.showStack(-1);
070: assertEquals(-1, p.getSelectedIndex());
071: }
072:
073: /**
074: * Tests new remove implementation for StackPanel.
075: */
076: public void testRemove() {
077: StackPanel p = new StackPanel();
078: Label a = new Label("a");
079: Label b = new Label("b");
080: Label c = new Label("c");
081: Label d = new Label("d");
082: p.add(a);
083: p.add(b, "b");
084: p.add(c);
085: p.add(d, "d");
086: assertEquals("a b c d", curContents(p));
087:
088: // Remove c
089: p.remove(c);
090: assertEquals("a b d", curContents(p));
091:
092: // Remove b.
093: p.remove(1);
094: assertEquals("a d", curContents(p));
095:
096: // Remove non-existant element
097: assertFalse(p.remove(b));
098:
099: // Remove a.
100: p.remove(a);
101: assertEquals("d", curContents(p));
102:
103: // Remove d.
104: p.remove(a);
105: assertEquals("d", curContents(p));
106: }
107: }
|