| /******************************************************************************* |
| * Copyright (c) 2002-2006 Innoopract Informationssysteme GmbH. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Innoopract Informationssysteme GmbH - initial API and implementation |
| ******************************************************************************/ |
| |
| package org.eclipse.swt.widgets; |
| |
| import junit.framework.TestCase; |
| import org.eclipse.swt.SWT; |
| import com.w4t.Fixture; |
| |
| |
| public class Widget_Test extends TestCase { |
| |
| protected void setUp() throws Exception { |
| Fixture.setUp(); |
| } |
| |
| protected void tearDown() throws Exception { |
| Fixture.tearDown(); |
| } |
| |
| public void testData() { |
| Display display = new Display(); |
| Shell shell = new Shell( display, SWT.NONE ); |
| Widget widget = new Text( shell, SWT.NONE ); |
| |
| // Test initial state |
| assertEquals( null, widget.getData() ); |
| |
| Object singleData = new Object(); |
| // Set/get some single data |
| widget.setData( singleData ); |
| assertSame( singleData, widget.getData() ); |
| |
| // Set/get some keyed data, ensure that single datat remains unchanged |
| Object keyedData = new Object(); |
| widget.setData( "key", keyedData ); |
| widget.setData( "null-key", null ); |
| assertSame( singleData, widget.getData() ); |
| assertSame( keyedData, widget.getData( "key" ) ); |
| assertSame( null, widget.getData( "null-key" ) ); |
| |
| // Test keyed data with illegal arguments |
| try { |
| widget.setData( null, new Object() ); |
| fail( "Must not allow to set data with null key" ); |
| } catch( NullPointerException e ) { |
| // expected |
| } |
| try { |
| widget.getData( null ); |
| fail( "Must not allow to get data for null key" ); |
| } catch( NullPointerException e ) { |
| // expected |
| } |
| } |
| |
| public void testCheckBits() { |
| int style = SWT.VERTICAL | SWT.HORIZONTAL; |
| int result = Widget.checkBits( style, |
| SWT.VERTICAL, |
| SWT.HORIZONTAL, |
| 0, |
| 0, |
| 0, |
| 0 ); |
| assertTrue( ( result & SWT.VERTICAL ) != 0 ); |
| assertFalse( ( result & SWT.HORIZONTAL ) != 0 ); |
| } |
| } |