@Test public void testSetDataEvent() { shell.setSize(100, 100); table = new Table(shell, SWT.VIRTUAL); Fixture.markInitialized(table); getRemoteObject(table).setHandler(new TableOperationHandler(table)); Listener listener = new Listener() { @Override public void handleEvent(Event event) { Item item = (Item) event.item; item.setText("Item " + event.index); } }; table.addListener(SWT.SetData, listener); table.setSize(90, 90); table.setItemCount(1000); shell.layout(); shell.open(); assertTrue(isItemVirtual(table, 500)); // ensure precondition fakeSetTopItemIndex(table, 500); Fixture.executeLifeCycleFromServerThread(); // Remove SetData listener to not accidentially resolve item with asserts table.removeListener(SWT.SetData, listener); assertFalse(isItemVirtual(table, 500)); assertFalse(isItemVirtual(table, 502)); assertTrue(isItemVirtual(table, 510)); assertEquals("Item 500", table.getItem(500).getText()); assertEquals("Item 502", table.getItem(502).getText()); }
@Test public void testRedraw() { final Table[] table = {null}; shell.setSize(100, 100); Button button = new Button(shell, SWT.PUSH); getRemoteObject(button).setHandler(new ButtonOperationHandler(button)); button.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent event) { table[0] = new Table(shell, SWT.VIRTUAL); table[0].setItemCount(500); table[0].setSize(90, 90); assertFalse(isItemVirtual(table[0], 0)); table[0].clearAll(); table[0].redraw(); } }); shell.open(); Fixture.fakeNotifyOperation(getId(button), ClientMessageConst.EVENT_SELECTION, null); Fixture.readDataAndProcessAction(display); assertFalse(isItemVirtual(table[0], 0)); }
@Test public void testRenderCellToolTipText() { Fixture.markInitialized(display); Fixture.markInitialized(table); getRemoteObject(table).setHandler(new TableOperationHandler(table)); createTableItems(table, 5); final ICellToolTipAdapter adapter = CellToolTipUtil.getAdapter(table); adapter.setCellToolTipProvider( new ICellToolTipProvider() { @Override public void getToolTipText(Item item, int columnIndex) { StringBuilder buffer = new StringBuilder(); buffer.append("["); buffer.append(WidgetUtil.getId(item)); buffer.append(","); buffer.append(columnIndex); buffer.append("]"); adapter.setCellToolTipText(buffer.toString()); } }); String itemId = WidgetUtil.getId(table.getItem(2)); fakeCellToolTipRequest(table, itemId, 0); Fixture.executeLifeCycleFromServerThread(); TestMessage message = Fixture.getProtocolMessage(); String expected = "[" + itemId + ",0]"; assertEquals(expected, message.findSetProperty(table, "cellToolTipText").asString()); }
@Before public void setUp() { Fixture.setUp(); display = new Display(); shell = new Shell(display); grid = new Grid(shell, SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL); column = new GridColumn(grid, SWT.NONE); lca = (GridColumnLCA) WidgetUtil.getLCA(column); Fixture.fakeNewRequest(); }
@Test public void testDontRenderSetDataWithoutVirtual() throws Exception { Fixture.markInitialized(display); Fixture.markInitialized(table); Fixture.preserveWidgets(); lca.renderChanges(table); TestMessage message = Fixture.getProtocolMessage(); assertNull(message.findListenOperation(table, "SetData")); }
@Test public void testRenderScrollLeftUnchanged() throws IOException { Fixture.markInitialized(display); Fixture.markInitialized(table); table.getAdapter(ITableAdapter.class).setLeftOffset(10); Fixture.preserveWidgets(); getLCA(display).render(display); TestMessage message = Fixture.getProtocolMessage(); assertNull(message.findSetOperation(table, "scrollLeft")); }
@Test public void testRenderLinesVisibleUnchanged() throws IOException { Fixture.markInitialized(display); Fixture.markInitialized(table); table.setLinesVisible(true); Fixture.preserveWidgets(); lca.renderChanges(table); TestMessage message = Fixture.getProtocolMessage(); assertNull(message.findSetOperation(table, "linesVisible")); }
@Test public void testRenderColumnCountUnchanged() throws IOException { Fixture.markInitialized(display); Fixture.markInitialized(table); new TableColumn(table, SWT.NONE); Fixture.preserveWidgets(); lca.renderChanges(table); TestMessage message = Fixture.getProtocolMessage(); assertNull(message.findSetOperation(table, "columnCount")); }
@Test public void testRenderItemCountUnchanged() throws IOException { Fixture.markInitialized(display); Fixture.markInitialized(table); table.setItemCount(10); Fixture.preserveWidgets(); lca.renderChanges(table); TestMessage message = Fixture.getProtocolMessage(); assertNull(message.findSetOperation(table, "itemCount")); }
@Test public void testDontRenderSetDataListenerTwice() throws Exception { table = new Table(shell, SWT.VIRTUAL | SWT.NO_SCROLL | SWT.MULTI); Fixture.markInitialized(display); Fixture.markInitialized(table); Fixture.preserveWidgets(); lca.renderChanges(table); TestMessage message = Fixture.getProtocolMessage(); assertNull(message.findListenOperation(table, "SetData")); }
@Test public void testRenderEnableCellToolTipUnchanged() throws IOException { Fixture.markInitialized(display); Fixture.markInitialized(table); table.setData(ICellToolTipProvider.ENABLE_CELL_TOOLTIP, Boolean.TRUE); Fixture.preserveWidgets(); lca.renderChanges(table); TestMessage message = Fixture.getProtocolMessage(); assertNull(message.findSetOperation(table, "enableCellToolTip")); }
@Test public void testRenderCustomVariantUnchanged() throws IOException { Fixture.markInitialized(display); Fixture.markInitialized(column); column.setData(RWT.CUSTOM_VARIANT, "blue"); Fixture.preserveWidgets(); lca.renderChanges(column); TestMessage message = Fixture.getProtocolMessage(); assertNull(message.findSetOperation(column, "customVariant")); }
@Test public void testRenderAlignmentUnchanged() throws IOException { Fixture.markInitialized(display); Fixture.markInitialized(column); column.setAlignment(SWT.RIGHT); Fixture.preserveWidgets(); lca.renderChanges(column); TestMessage message = Fixture.getProtocolMessage(); assertNull(message.findSetOperation(column, "alignment")); }
@Test public void testRenderMnemonicIndexUnchanged() throws IOException { Fixture.markInitialized(display); Fixture.markInitialized(group); group.setText("te&st"); Fixture.preserveWidgets(); lca.renderChanges(group); TestMessage message = Fixture.getProtocolMessage(); assertNull(message.findSetOperation(group, "mnemonicIndex")); }
@Test public void testRenderHeaderWordWrapUnchanged() throws IOException { Fixture.markInitialized(display); Fixture.markInitialized(column); column.setHeaderWordWrap(true); Fixture.preserveWidgets(); lca.renderChanges(column); TestMessage message = Fixture.getProtocolMessage(); assertNull(message.findSetOperation(column, "headerWordWrap")); }
@Test public void testRenderShowFocusedControlUnchanged() throws IOException { Fixture.markInitialized(display); Fixture.markInitialized(sc); sc.setShowFocusedControl(true); Fixture.preserveWidgets(); lca.renderChanges(sc); TestMessage message = Fixture.getProtocolMessage(); assertNull(message.findSetOperation(sc, "showFocusedControl")); }
@Test public void testRenderFontUnchanged() throws IOException { Fixture.markInitialized(display); Fixture.markInitialized(column); column.setHeaderFont(new Font(display, "Arial", 20, SWT.BOLD)); Fixture.preserveWidgets(); lca.renderChanges(column); TestMessage message = Fixture.getProtocolMessage(); assertNull(message.findSetOperation(column, "font")); }
@Test public void testRenderFooterTextUnchanged() throws IOException { Fixture.markInitialized(display); Fixture.markInitialized(column); column.setFooterText("foo"); Fixture.preserveWidgets(); lca.renderChanges(column); TestMessage message = Fixture.getProtocolMessage(); assertNull(message.findSetOperation(column, "footerText")); }
@Test public void testRenderAddSelectionListener() throws Exception { Fixture.markInitialized(display); Fixture.markInitialized(column); Fixture.preserveWidgets(); column.addListener(SWT.Selection, mock(Listener.class)); lca.renderChanges(column); TestMessage message = Fixture.getProtocolMessage(); assertEquals(JsonValue.TRUE, message.findListenProperty(column, "Selection")); }
@Test public void testRenderCheckUnchanged() throws IOException { column = new GridColumn(grid, SWT.CHECK); Fixture.markInitialized(display); Fixture.markInitialized(column); Fixture.preserveWidgets(); lca.renderChanges(column); TestMessage message = Fixture.getProtocolMessage(); assertNull(message.findSetOperation(column, "check")); }
@Test public void testRenderVisibleUnchanged() throws IOException { Fixture.markInitialized(display); Fixture.markInitialized(column); column.setVisible(false); Fixture.preserveWidgets(); lca.renderChanges(column); TestMessage message = Fixture.getProtocolMessage(); assertNull(message.findSetOperation(column, "visibility")); }
@Test public void testRenderAlwaysHideSelectionUnchanged() throws IOException { Fixture.markInitialized(display); Fixture.markInitialized(table); table.setData(Table.ALWAYS_HIDE_SELECTION, Boolean.TRUE); Fixture.preserveWidgets(); lca.renderChanges(table); TestMessage message = Fixture.getProtocolMessage(); assertNull(message.findSetOperation(table, "alwaysHideSelection")); }
@Test public void testRenderAddScrollBarsSelectionListener_Vertical() throws Exception { Fixture.markInitialized(display); Fixture.markInitialized(sc); Fixture.markInitialized(vScroll); Fixture.preserveWidgets(); vScroll.addSelectionListener(new SelectionAdapter() {}); lca.renderChanges(sc); TestMessage message = Fixture.getProtocolMessage(); assertEquals(JsonValue.TRUE, message.findListenProperty(vScroll, "Selection")); }
@Test public void testRenderContentUnchanged() throws IOException { Composite content = new Composite(sc, SWT.NONE); Fixture.markInitialized(display); Fixture.markInitialized(sc); sc.setContent(content); Fixture.preserveWidgets(); lca.renderChanges(sc); TestMessage message = Fixture.getProtocolMessage(); assertNull(message.findSetOperation(sc, "content")); }
@Test public void testReadData_ScrollBarsSelectionEvent() { sc.setContent(new Composite(sc, SWT.NONE)); SelectionListener selectionListener = mock(SelectionListener.class); hScroll.addSelectionListener(selectionListener); vScroll.addSelectionListener(selectionListener); Fixture.fakeNotifyOperation(getId(hScroll), "Selection", null); Fixture.fakeNotifyOperation(getId(vScroll), "Selection", null); Fixture.readDataAndProcessAction(sc); verify(selectionListener, times(2)).widgetSelected(any(SelectionEvent.class)); }
@Test public void testRenderFooterSpanUnchanged() throws IOException { Fixture.markInitialized(display); Fixture.markInitialized(column); createGridColumns(grid, 3, SWT.NONE); column.setData("footerSpan", Integer.valueOf(2)); Fixture.preserveWidgets(); lca.renderChanges(column); TestMessage message = Fixture.getProtocolMessage(); assertNull(message.findSetOperation(column, "footerSpan")); }
@Test public void testRenderFooterImageUnchanged() throws IOException { Fixture.markInitialized(display); Fixture.markInitialized(column); Image image = loadImage(display, Fixture.IMAGE_100x50); column.setFooterImage(image); Fixture.preserveWidgets(); lca.renderChanges(column); TestMessage message = Fixture.getProtocolMessage(); assertNull(message.findSetOperation(column, "footerImage")); }
@Test public void testRenderFocusItemUnchanged() throws IOException { createTableItems(table, 3); Fixture.markInitialized(display); Fixture.markInitialized(table); table.getAdapter(ITableAdapter.class).setFocusIndex(2); Fixture.preserveWidgets(); getLCA(display).render(display); TestMessage message = Fixture.getProtocolMessage(); assertNull(message.findSetOperation(table, "focusItem")); }
@Test public void testRenderSelectionListenerUnchanged() throws Exception { Fixture.markInitialized(display); Fixture.markInitialized(column); Fixture.preserveWidgets(); column.addListener(SWT.Selection, mock(Listener.class)); Fixture.preserveWidgets(); lca.renderChanges(column); TestMessage message = Fixture.getProtocolMessage(); assertNull(message.findListenOperation(column, "Selection")); }
@Test public void testRenderLeftUnchanged() throws IOException { Fixture.markInitialized(display); Fixture.markInitialized(column); GridColumn column2 = new GridColumn(grid, SWT.NONE, 0); column2.setWidth(50); Fixture.preserveWidgets(); lca.renderChanges(column); TestMessage message = Fixture.getProtocolMessage(); assertNull(message.findSetOperation(column, "left")); }