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.user.client.DOM;
019: import com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter;
020:
021: /**
022: * TODO: document me.
023: */
024: public class FlexTableTest extends HTMLTableTestBase {
025:
026: public HTMLTable getTable(int row, int column) {
027: return new FlexTable();
028: }
029:
030: public void testWidgetPos() {
031: FlexTable t = new FlexTable();
032: HTML widget_3_0 = new HTML("3,0");
033: HTML widget_3_1 = new HTML("3,1");
034: HTML widget_1_2 = new HTML("1,2");
035:
036: t.setWidget(0, 0, widget_3_1);
037: t.insertRow(0);
038: t.insertCell(1, 0);
039: t.setWidget(1, 0, widget_3_0);
040: t.insertRow(0);
041: t.setWidget(0, 0, widget_1_2);
042: t.insertCells(0, 0, 2);
043: t.insertRow(0);
044: int hit = 0;
045: for (int row = 0; row < 4; row++) {
046: int colBounds = t.getCellCount(row);
047: for (int col = 0; col < colBounds; col++) {
048: Widget widget = t.getWidget(row, col);
049: if (row == 3 && col == 0) {
050: ++hit;
051: assertEquals(widget_3_0, widget);
052: } else if (row == 3 && col == 1) {
053: ++hit;
054: assertEquals(widget_3_1, widget);
055: } else if (row == 1 && col == 2) {
056: ++hit;
057: assertEquals(widget_1_2, widget);
058: } else {
059: if (widget != null) {
060: System.err.println("row: " + row + ", col: "
061: + col + ", widget: "
062: + DOM.toString(widget.getElement()));
063: }
064: assertNull(widget);
065: }
066: }
067: }
068: assertEquals(3, hit);
069:
070: // Move widget.
071: t.setWidget(3, 2, widget_1_2);
072: assertEquals(widget_1_2, t.getWidget(3, 2));
073: assertNull(t.getWidget(1, 2));
074:
075: // Remove by widget.
076: t.remove(widget_3_0);
077: assertNull(t.getWidget(3, 0));
078: assertEquals(widget_3_1, t.getWidget(3, 1));
079:
080: // Remove by cell.
081: t.removeCell(3, 1);
082: assertEquals(widget_1_2, t.getWidget(3, 1));
083: }
084:
085: public void testInertFirst() {
086: FlexTable t = new FlexTable();
087: t.insertRow(0);
088: t.setWidget(0, 3, new HTML("hello"));
089:
090: t.insertRow(1);
091: t.setWidget(1, 0, new HTML("goodbye"));
092: }
093:
094: public void testBounds() {
095: HTMLTable t = getTable(3, 3);
096: try {
097: t.setText(-1, 0, "hello");
098: fail("IndexOutOfBoundsException should have been thrown");
099: } catch (IndexOutOfBoundsException e) {
100: assertEquals(
101: "Cannot create a row with a negative index: -1", e
102: .getMessage());
103: }
104: try {
105: t.setText(0, -1, "hello");
106: fail("IndexOutOfBoundsException should have been thrown");
107: } catch (IndexOutOfBoundsException e) {
108: assertEquals(
109: "Cannot create a column with a negative index: -1",
110: e.getMessage());
111: }
112: try {
113: t.clearCell(3, 3);
114: fail("IndexOutOfBoundsException should have been thrown");
115: } catch (IndexOutOfBoundsException e) {
116: assertEquals("Row index: 3, Row size: 1", e.getMessage());
117: }
118:
119: try {
120: t.getText(0, 5);
121: fail("IndexOutOfBoundsException should have been thrown");
122: } catch (Exception e) {
123: // Expected
124: }
125: }
126:
127: public void testNullWidget() {
128: FlexTable ft = new FlexTable();
129: ft.setText(0, 0, "hello");
130: assertNull(ft.getWidget(0, 0));
131: ft.setWidget(0, 1, null);
132: assertNull(ft.getWidget(0, 1));
133: ft.clear();
134: }
135:
136: public void secondarySetHeightTest() {
137: FlexTable ft = new FlexTable();
138: FlexCellFormatter cellFormatter = (FlexCellFormatter) ft
139: .getCellFormatter();
140: cellFormatter.setHeight(3, 1, "300px");
141: cellFormatter.setColSpan(3, 1, 2);
142: }
143:
144: }
|