01: /*
02: * Copyright 2007 Google Inc.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License. You may obtain a copy of
06: * the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13: * License for the specific language governing permissions and limitations under
14: * the License.
15: */
16: package com.google.gwt.user.client.ui;
17:
18: import com.google.gwt.junit.client.GWTTestCase;
19:
20: import java.util.Iterator;
21:
22: /**
23: * A test for {@link HorizontalPanel}.
24: */
25: public class HorizontalPanelTest extends GWTTestCase {
26:
27: public String getModuleName() {
28: return "com.google.gwt.user.User";
29: }
30:
31: public void testAttachDetachOrder() {
32: HasWidgetsTester.testAll(new HorizontalPanel());
33: }
34:
35: public void testInsertMultipleTimes() {
36: HorizontalPanel p = new HorizontalPanel();
37:
38: TextBox tb = new TextBox();
39: p.add(tb);
40: p.add(tb);
41: p.add(tb);
42:
43: assertEquals(1, p.getWidgetCount());
44: assertEquals(0, p.getWidgetIndex(tb));
45: Iterator i = p.iterator();
46: assertTrue(i.hasNext());
47: assertTrue(tb.equals(i.next()));
48: assertFalse(i.hasNext());
49:
50: Label l = new Label();
51: p.add(l);
52: p.add(l);
53: p.add(l);
54: assertEquals(2, p.getWidgetCount());
55: assertEquals(0, p.getWidgetIndex(tb));
56: assertEquals(1, p.getWidgetIndex(l));
57:
58: p.insert(l, 0);
59: assertEquals(2, p.getWidgetCount());
60: assertEquals(0, p.getWidgetIndex(l));
61: assertEquals(1, p.getWidgetIndex(tb));
62:
63: p.insert(l, 1);
64: assertEquals(2, p.getWidgetCount());
65: assertEquals(0, p.getWidgetIndex(l));
66: assertEquals(1, p.getWidgetIndex(tb));
67:
68: p.insert(l, 2);
69: assertEquals(2, p.getWidgetCount());
70: assertEquals(0, p.getWidgetIndex(tb));
71: assertEquals(1, p.getWidgetIndex(l));
72: }
73: }
|