Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorRüdiger Herrmann2011-01-28 12:53:03 +0000
committerRüdiger Herrmann2011-01-28 12:53:03 +0000
commit4d90552d48700171b6c59901258b13d92191cd95 (patch)
tree3e8212671f5466a4e88a5945963a4074e3e09593 /tests
parent681dd359a25f5307c368a8e8c88c057e8508ca06 (diff)
downloadorg.eclipse.rap-4d90552d48700171b6c59901258b13d92191cd95.tar.gz
org.eclipse.rap-4d90552d48700171b6c59901258b13d92191cd95.tar.xz
org.eclipse.rap-4d90552d48700171b6c59901258b13d92191cd95.zip
RESOLVED 334637: Refactor GC
Diffstat (limited to 'tests')
-rw-r--r--tests/org.eclipse.rap.rwt.q07.test/src/org/eclipse/swt/internal/widgets/canvaskit/CanvasLCA_Test.java6
-rw-r--r--tests/org.eclipse.rap.rwt.test/src/org/eclipse/RWTHostTestSuite.java2
-rw-r--r--tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/graphics/ControlGC_Test.java583
-rw-r--r--tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/graphics/DeviceGC_Test.java99
-rw-r--r--tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/graphics/GC_Test.java706
5 files changed, 714 insertions, 682 deletions
diff --git a/tests/org.eclipse.rap.rwt.q07.test/src/org/eclipse/swt/internal/widgets/canvaskit/CanvasLCA_Test.java b/tests/org.eclipse.rap.rwt.q07.test/src/org/eclipse/swt/internal/widgets/canvaskit/CanvasLCA_Test.java
index baf4969970..7780c95992 100644
--- a/tests/org.eclipse.rap.rwt.q07.test/src/org/eclipse/swt/internal/widgets/canvaskit/CanvasLCA_Test.java
+++ b/tests/org.eclipse.rap.rwt.q07.test/src/org/eclipse/swt/internal/widgets/canvaskit/CanvasLCA_Test.java
@@ -119,8 +119,7 @@ public class CanvasLCA_Test extends TestCase {
adapter.addGCOperation( new DrawLine( 5, 6, 7, 8 ) );
Font font = new Font( display, "Arial", 15, SWT.NORMAL );
adapter.addGCOperation( new SetFont( font ) );
- SetProperty operation
- = new SetProperty( SetProperty.LINE_WIDTH, new Integer( 5 ) );
+ SetProperty operation = new SetProperty( SetProperty.LINE_WIDTH, 5 );
adapter.addGCOperation( operation );
new CanvasLCA().renderChanges( canvas );
String expected
@@ -146,8 +145,7 @@ public class CanvasLCA_Test extends TestCase {
GCAdapter adapter = ( GCAdapter )canvas.getAdapter( IGCAdapter.class );
Font font = new Font( display, "Arial", 15, SWT.NORMAL );
adapter.addGCOperation( new SetFont( font ) );
- SetProperty operation
- = new SetProperty( SetProperty.LINE_WIDTH, new Integer( 5 ) );
+ SetProperty operation = new SetProperty( SetProperty.LINE_WIDTH, 5 );
adapter.addGCOperation( operation );
new CanvasLCA().renderChanges( canvas );
assertEquals( "", Fixture.getAllMarkup() );
diff --git a/tests/org.eclipse.rap.rwt.test/src/org/eclipse/RWTHostTestSuite.java b/tests/org.eclipse.rap.rwt.test/src/org/eclipse/RWTHostTestSuite.java
index b8c0d97c0d..95dfbe291a 100644
--- a/tests/org.eclipse.rap.rwt.test/src/org/eclipse/RWTHostTestSuite.java
+++ b/tests/org.eclipse.rap.rwt.test/src/org/eclipse/RWTHostTestSuite.java
@@ -189,6 +189,8 @@ public class RWTHostTestSuite {
suite.addTestSuite( Cursor_Test.class );
suite.addTestSuite( Device_Test.class );
suite.addTestSuite( GC_Test.class );
+ suite.addTestSuite( ControlGC_Test.class );
+ suite.addTestSuite( DeviceGC_Test.class );
suite.addTestSuite( FontMetrics_Test.class );
suite.addTestSuite( TextSizeEstimation_Test.class );
suite.addTestSuite( TextSizeDetermination_Test.class );
diff --git a/tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/graphics/ControlGC_Test.java b/tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/graphics/ControlGC_Test.java
new file mode 100644
index 0000000000..bc4e87d736
--- /dev/null
+++ b/tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/graphics/ControlGC_Test.java
@@ -0,0 +1,583 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Rdiger Herrmann and others. 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:
+ * Rdiger Herrmann - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.swt.graphics;
+
+import java.util.Arrays;
+
+import org.eclipse.rwt.Fixture;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.internal.graphics.*;
+import org.eclipse.swt.internal.graphics.GCOperation.*;
+import org.eclipse.swt.widgets.*;
+
+import junit.framework.TestCase;
+
+
+public class ControlGC_Test extends TestCase {
+ private Display display;
+ private Canvas canvas;
+ private GC gc;
+
+ public void testInitialValues() {
+ assertEquals( canvas.getFont(), gc.getFont() );
+ assertEquals( canvas.getBackground(), gc.getBackground() );
+ assertEquals( canvas.getForeground(), gc.getForeground() );
+ }
+
+
+ public void testSetFont() {
+ Font font = createFont();
+ gc.setFont( font );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ SetFont operation = ( SetFont )gcOperations[ 0 ];
+ assertEquals( font, operation.font );
+ }
+
+ public void testSetFontWithNullFont() {
+ Font font = createFont();
+ gc.setFont( font );
+ gc.setFont( null );
+ assertEquals( display.getSystemFont(), gc.getFont() );
+ }
+
+ public void testSetFontWithSameFont() {
+ Font font = createFont();
+ gc.setFont( font );
+ IGCAdapter adapter = getGCAdapter( gc );
+ adapter.clearGCOperations();
+ gc.setFont( font );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ assertEquals( 0, gcOperations.length );
+ }
+
+ public void testSetBackground() {
+ Color color = createColor();
+ gc.setBackground( color );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ SetProperty operation = ( SetProperty )gcOperations[ 0 ];
+ assertEquals( SetProperty.BACKGROUND, operation.id );
+ assertEquals( color, operation.value );
+ }
+
+ public void testSetForeground() {
+ Shell shell = new Shell( display );
+ GC gc = new GC( shell );
+ Color color = createColor();
+ gc.setForeground( color );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ SetProperty operation = ( SetProperty )gcOperations[ 0 ];
+ assertEquals( SetProperty.FOREGROUND, operation.id );
+ assertEquals( color, operation.value );
+ }
+
+ public void testGetGCAdapterForCanvasWidget() {
+ IGCAdapter adapter1 = getGCAdapter( gc );
+ assertNotNull( adapter1 );
+ IGCAdapter adapter2 = getGCAdapter( gc );
+ assertSame( adapter2, adapter1 );
+ }
+
+ public void testGetGCAdapterForNonCanvasWidget() {
+ Shell shell = new Shell( display );
+ Button button = new Button( shell, SWT.NONE );
+ GC gc = new GC( button );
+ assertNull( getGCAdapter( gc ) );
+ }
+
+ public void testDrawOperationWithNonCanvas() {
+ gc.drawLine( 1, 2, 3, 4 );
+ // This test has no assert. Ensures that no NPE is thrown.
+ }
+
+ public void testSetAlpha() {
+ gc.setAlpha( 123 );
+ assertEquals( 123, gc.getAlpha() );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ SetProperty operation = ( SetProperty )gcOperations[ 0 ];
+ assertEquals( SetProperty.ALPHA, operation.id );
+ assertEquals( new Integer( 123 ), operation.value );
+ }
+
+ public void testSetAlphaWithSameValue() {
+ gc.setAlpha( 123 );
+ getGCAdapter( gc ).clearGCOperations();
+ gc.setAlpha( 123 );
+ assertEquals( 0, getGCOperations( gc ).length );
+ }
+
+ public void testSetAlphaWithInvalidValue() {
+ gc.setAlpha( 777 );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ assertEquals( 0, gcOperations.length );
+ }
+
+ public void testSetLineWidth() {
+ gc.setLineWidth( 5 );
+ assertEquals( 5, gc.getLineWidth() );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ SetProperty operation = ( SetProperty )gcOperations[ 0 ];
+ assertEquals( SetProperty.LINE_WIDTH, operation.id );
+ assertEquals( new Integer( 5 ), operation.value );
+ }
+
+ public void testSetLineCap() {
+ gc.setLineCap( SWT.CAP_ROUND );
+ assertEquals( SWT.CAP_ROUND, gc.getLineCap() );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ SetProperty operation = ( SetProperty )gcOperations[ 0 ];
+ assertEquals( SetProperty.LINE_CAP, operation.id );
+ assertEquals( new Integer( SWT.CAP_ROUND ), operation.value );
+ }
+
+ public void testSetLineCapWithUnchangeValue() {
+ gc.setLineCap( SWT.CAP_ROUND );
+ getGCAdapter( gc ).clearGCOperations();
+ gc.setLineCap( SWT.CAP_ROUND );
+ assertEquals( 0, getGCOperations( gc ).length );
+ }
+
+ public void testSetLineJoin() {
+ gc.setLineJoin( SWT.JOIN_ROUND );
+ assertEquals( SWT.JOIN_ROUND, gc.getLineJoin() );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ SetProperty operation = ( SetProperty )gcOperations[ 0 ];
+ assertEquals( SetProperty.LINE_JOIN, operation.id );
+ assertEquals( new Integer( SWT.JOIN_ROUND ), operation.value );
+ }
+
+ public void testSetLineJoinWithUnchangedValue() {
+ gc.setLineJoin( SWT.JOIN_ROUND );
+ getGCAdapter( gc ).clearGCOperations();
+ gc.setLineJoin( SWT.JOIN_ROUND );
+ assertEquals( 0, getGCOperations( gc ).length );
+ }
+
+ public void testSetLineAttributes() {
+ LineAttributes attributes
+ = new LineAttributes( 5, SWT.CAP_ROUND, SWT.JOIN_BEVEL );
+ gc.setLineAttributes( attributes );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ SetProperty operation = ( SetProperty )gcOperations[ 0 ];
+ assertEquals( SetProperty.LINE_WIDTH, operation.id );
+ assertEquals( new Integer( 5 ), operation.value );
+ operation = ( SetProperty )gcOperations[ 1 ];
+ assertEquals( SetProperty.LINE_CAP, operation.id );
+ assertEquals( new Integer( SWT.CAP_ROUND ), operation.value );
+ operation = ( SetProperty )gcOperations[ 2 ];
+ assertEquals( SetProperty.LINE_JOIN, operation.id );
+ assertEquals( new Integer( SWT.JOIN_BEVEL ), operation.value );
+ }
+
+ public void testDrawLine() {
+ gc.drawLine( 1, 2, 3, 4 );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ DrawLine operation = ( DrawLine )gcOperations[ 0 ];
+ assertEquals( 1, operation.x1 );
+ assertEquals( 2, operation.y1 );
+ assertEquals( 3, operation.x2 );
+ assertEquals( 4, operation.y2 );
+ }
+
+ public void testDrawPoint() {
+ gc.drawPoint( 1, 2 );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ DrawPoint operation = ( DrawPoint )gcOperations[ 0 ];
+ assertEquals( 1, operation.x );
+ assertEquals( 2, operation.y );
+ }
+
+ public void testDrawRectangle() {
+ gc.drawRectangle( 1, 2, 3, 4 );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ DrawRectangle operation = ( DrawRectangle )gcOperations[ 0 ];
+ assertEquals( 1, operation.x );
+ assertEquals( 2, operation.y );
+ assertEquals( 3, operation.width );
+ assertEquals( 4, operation.height );
+ assertFalse( operation.fill );
+ }
+
+ public void testDrawRectangleWithZeroWidthAndHeight() {
+ gc.drawRectangle( 1, 2, 0, 0 );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ assertEquals( 0, gcOperations.length );
+ }
+
+ public void testDrawFocus() {
+ gc.drawFocus( 1, 2, 3, 4 );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ DrawRectangle operation = ( DrawRectangle )gcOperations[ 0 ];
+ assertEquals( 1, operation.x );
+ assertEquals( 2, operation.y );
+ assertEquals( 3, operation.width );
+ assertEquals( 4, operation.height );
+ assertFalse( operation.fill );
+ }
+
+ public void testFillRectangle() {
+ gc.fillRectangle( 1, 2, 3, 4 );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ DrawRectangle operation = ( DrawRectangle )gcOperations[ 0 ];
+ assertEquals( 1, operation.x );
+ assertEquals( 2, operation.y );
+ assertEquals( 3, operation.width );
+ assertEquals( 4, operation.height );
+ assertTrue( operation.fill );
+ }
+
+ public void testFillGradientRectangle() {
+ gc.fillGradientRectangle( 1, 2, 3, 4, true );
+ gc.fillGradientRectangle( 5, 6, 7, 8, false );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ FillGradientRectangle operation
+ = ( FillGradientRectangle )gcOperations[ 0 ];
+ assertEquals( 1, operation.x );
+ assertEquals( 2, operation.y );
+ assertEquals( 3, operation.width );
+ assertEquals( 4, operation.height );
+ assertTrue( operation.vertical );
+ assertTrue( operation.fill );
+ operation = ( FillGradientRectangle )gcOperations[ 1 ];
+ assertEquals( 5, operation.x );
+ assertEquals( 6, operation.y );
+ assertEquals( 7, operation.width );
+ assertEquals( 8, operation.height );
+ assertFalse( operation.vertical );
+ assertTrue( operation.fill );
+ }
+
+ public void testDrawRoundRectangle() {
+ gc.drawRoundRectangle( 1, 2, 3, 4, 5, 6 );
+ IGCAdapter adapter = getGCAdapter( gc );
+ GCOperation[] gcOperations = adapter.getGCOperations();
+ DrawRoundRectangle operation = ( DrawRoundRectangle )gcOperations[ 0 ];
+ assertEquals( 1, operation.x );
+ assertEquals( 2, operation.y );
+ assertEquals( 3, operation.width );
+ assertEquals( 4, operation.height );
+ assertEquals( 5, operation.arcWidth );
+ assertEquals( 6, operation.arcHeight );
+ assertFalse( operation.fill );
+ }
+
+ public void testDrawRoundRectangleWithZeroArcWidth() {
+ gc.drawRoundRectangle( 1, 2, 3, 4, 0, 6 );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ DrawRectangle operation = ( DrawRectangle )gcOperations[ 0 ];
+ assertEquals( 1, operation.x );
+ assertEquals( 2, operation.y );
+ assertEquals( 3, operation.width );
+ assertEquals( 4, operation.height );
+ assertFalse( operation.fill );
+ }
+
+ public void testDrawRoundRectangleWithZeroArcHeight() {
+ gc.drawRoundRectangle( 1, 2, 3, 4, 5, 0 );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ DrawRectangle operation = ( DrawRectangle )gcOperations[ 0 ];
+ assertEquals( 1, operation.x );
+ assertEquals( 2, operation.y );
+ assertEquals( 3, operation.width );
+ assertEquals( 4, operation.height );
+ assertFalse( operation.fill );
+ }
+
+ public void testFillRoundRectangle() {
+ gc.fillRoundRectangle( 1, 2, 3, 4, 5, 6 );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ DrawRoundRectangle operation = ( DrawRoundRectangle )gcOperations[ 0 ];
+ assertEquals( 1, operation.x );
+ assertEquals( 2, operation.y );
+ assertEquals( 3, operation.width );
+ assertEquals( 4, operation.height );
+ assertEquals( 5, operation.arcWidth );
+ assertEquals( 6, operation.arcHeight );
+ assertTrue( operation.fill );
+ }
+
+ public void testFillRoundRectangleWithZeroArcWidth() {
+ gc.fillRoundRectangle( 1, 2, 3, 4, 0, 6 );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ DrawRectangle operation = ( DrawRectangle )gcOperations[ 0 ];
+ assertEquals( 1, operation.x );
+ assertEquals( 2, operation.y );
+ assertEquals( 3, operation.width );
+ assertEquals( 4, operation.height );
+ assertTrue( operation.fill );
+ }
+
+ public void testFillRoundRectangleWithZeroArcHeight() {
+ gc.fillRoundRectangle( 1, 2, 3, 4, 5, 0 );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ DrawRectangle operation = ( DrawRectangle )gcOperations[ 0 ];
+ assertEquals( 1, operation.x );
+ assertEquals( 2, operation.y );
+ assertEquals( 3, operation.width );
+ assertEquals( 4, operation.height );
+ assertTrue( operation.fill );
+ }
+
+ public void testDrawArc() {
+ gc.drawArc( 1, 2, 3, 4, 5, 6 );
+ IGCAdapter adapter = getGCAdapter( gc );
+ GCOperation[] gcOperations = adapter.getGCOperations();
+ DrawArc operation = ( DrawArc )gcOperations[ 0 ];
+ assertEquals( 1, operation.x );
+ assertEquals( 2, operation.y );
+ assertEquals( 3, operation.width );
+ assertEquals( 4, operation.height );
+ assertEquals( 5, operation.startAngle );
+ assertEquals( 6, operation.arcAngle );
+ assertFalse( operation.fill );
+ }
+
+ public void testDrawArcWithZeroWidth() {
+ gc.drawArc( 1, 2, 0, 5, 5, 5 );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ assertEquals( 0, gcOperations.length );
+ }
+
+ public void testDrawArcWithZeroHeight() {
+ gc.drawArc( 1, 2, 3, 0, 5, 5 );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ assertEquals( 0, gcOperations.length );
+ }
+
+ public void testDrawArcWithZeroArcAngle() {
+ gc.drawArc( 1, 2, 3, 4, 5, 0 );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ assertEquals( 0, gcOperations.length );
+ }
+
+ public void testFillArc() {
+ gc.fillArc( 1, 2, 3, 4, 5, 6 );
+ IGCAdapter adapter = getGCAdapter( gc );
+ GCOperation[] gcOperations = adapter.getGCOperations();
+ DrawArc operation = ( DrawArc )gcOperations[ 0 ];
+ assertEquals( 1, operation.x );
+ assertEquals( 2, operation.y );
+ assertEquals( 3, operation.width );
+ assertEquals( 4, operation.height );
+ assertEquals( 5, operation.startAngle );
+ assertEquals( 6, operation.arcAngle );
+ }
+
+ public void testFillArcWithNegativeWidthAndHeight() {
+ gc.fillArc( 1, 2, -3, -4, 5, 6 );
+ IGCAdapter adapter = getGCAdapter( gc );
+ GCOperation[] gcOperations = adapter.getGCOperations();
+ DrawArc operation = ( DrawArc )gcOperations[ 0 ];
+ assertEquals( -2, operation.x );
+ assertEquals( -2, operation.y );
+ assertEquals( 3, operation.width );
+ assertEquals( 4, operation.height );
+ assertEquals( 5, operation.startAngle );
+ assertEquals( 6, operation.arcAngle );
+ assertTrue( operation.fill );
+ }
+
+ public void testFillArcWithZeroWidth() {
+ gc.fillArc( 1, 2, 0, 4, 5, 6 );
+ IGCAdapter adapter = getGCAdapter( gc );
+ GCOperation[] gcOperations = adapter.getGCOperations();
+ assertEquals( 0, gcOperations.length );
+ }
+
+ public void testFillArcWithZeroHeight() {
+ gc.fillArc( 1, 2, 3, 0, 5, 6 );
+ IGCAdapter adapter = getGCAdapter( gc );
+ GCOperation[] gcOperations = adapter.getGCOperations();
+ assertEquals( 0, gcOperations.length );
+ }
+
+ public void testFillArcWithZeroArcAngle() {
+ gc.fillArc( 1, 2, 3, 4, 5, 0 );
+ IGCAdapter adapter = getGCAdapter( gc );
+ GCOperation[] gcOperations = adapter.getGCOperations();
+ assertEquals( 0, gcOperations.length );
+ }
+
+ public void testFillPolygon() {
+ Control control = new Shell( display );
+ GC gc = new GC( control );
+ int[] pointArray = new int[] { 1, 2, 3, 4 };
+ gc.fillPolygon( pointArray );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ DrawPolyline operation = ( DrawPolyline )gcOperations[ 0 ];
+ assertTrue( Arrays.equals( pointArray, operation.points ) );
+ assertTrue( operation.close );
+ assertTrue( operation.fill );
+ }
+
+ public void testDrawPolyline() {
+ Control control = new Shell( display );
+ GC gc = new GC( control );
+ int[] pointArray = new int[] { 1, 2, 3, 4 };
+ gc.drawPolyline( pointArray );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ DrawPolyline operation = ( DrawPolyline )gcOperations[ 0 ];
+ assertTrue( Arrays.equals( pointArray, operation.points ) );
+ assertFalse( operation.close );
+ assertFalse( operation.fill );
+ }
+
+ public void testDrawOval() {
+ gc.drawOval( 1, 2, 3, 4 );
+ IGCAdapter adapter = getGCAdapter( gc );
+ GCOperation[] gcOperations = adapter.getGCOperations();
+ DrawArc operation = ( DrawArc )gcOperations[ 0 ];
+ assertEquals( 1, operation.x );
+ assertEquals( 2, operation.y );
+ assertEquals( 3, operation.width );
+ assertEquals( 4, operation.height );
+ assertEquals( 0, operation.startAngle );
+ assertEquals( 360, operation.arcAngle );
+ assertFalse( operation.fill );
+ }
+
+ public void testDrawOvalWithZeroWidthAndHeight() {
+ gc.drawOval( 1, 2, 0, 0 );
+ IGCAdapter adapter = getGCAdapter( gc );
+ GCOperation[] gcOperations = adapter.getGCOperations();
+ assertEquals( 0, gcOperations.length );
+ }
+
+ public void testFillOval() {
+ gc.fillOval( 1, 2, 3, 4 );
+ IGCAdapter adapter = getGCAdapter( gc );
+ GCOperation[] gcOperations = adapter.getGCOperations();
+ DrawArc operation = ( DrawArc )gcOperations[ 0 ];
+ assertEquals( 1, operation.x );
+ assertEquals( 2, operation.y );
+ assertEquals( 3, operation.width );
+ assertEquals( 4, operation.height );
+ assertEquals( 0, operation.startAngle );
+ assertEquals( 360, operation.arcAngle );
+ assertTrue( operation.fill );
+ adapter.clearGCOperations();
+ }
+
+ public void testDrawPolygon() {
+ int[] pointArray = new int[] { 1, 2, 3, 4 };
+ gc.drawPolygon( pointArray );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ DrawPolyline operation = ( DrawPolyline )gcOperations[ 0 ];
+ assertTrue( Arrays.equals( pointArray, operation.points ) );
+ assertTrue( operation.close );
+ assertFalse( operation.fill );
+ }
+
+ public void testDrawStringWithEmptyString() {
+ gc.drawString( "", 10, 10, false );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ assertEquals( 0, gcOperations.length );
+ }
+
+ public void testDrawImage() {
+ Image image = display.getSystemImage( SWT.ICON_INFORMATION );
+ gc.drawImage( image, 1, 2 );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ DrawImage operation = ( DrawImage )gcOperations[ 0 ];
+ assertSame( image, operation.image );
+ assertEquals( 0, operation.srcX );
+ assertEquals( 0, operation.srcY );
+ assertEquals( -1, operation.srcWidth );
+ assertEquals( -1, operation.srcHeight );
+ assertEquals( 1, operation.destX );
+ assertEquals( 2, operation.destY );
+ assertEquals( -1, operation.destWidth );
+ assertEquals( -1, operation.destHeight );
+ assertTrue( operation.simple );
+ }
+
+ public void testDrawImageCopy() {
+ Image image = display.getSystemImage( SWT.ICON_INFORMATION );
+ gc.drawImage( image, 1, 2, 3, 4, 5, 6, 7, 8 );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ DrawImage operation = ( DrawImage )gcOperations[ 0 ];
+ assertSame( image, operation.image );
+ assertEquals( 1, operation.srcX );
+ assertEquals( 2, operation.srcY );
+ assertEquals( 3, operation.srcWidth );
+ assertEquals( 4, operation.srcHeight );
+ assertEquals( 5, operation.destX );
+ assertEquals( 6, operation.destY );
+ assertEquals( 7, operation.destWidth );
+ assertEquals( 8, operation.destHeight );
+ assertFalse( operation.simple );
+ }
+
+ public void testDrawText() {
+ gc.drawText( "text", 10, 10, SWT.DRAW_TRANSPARENT );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ DrawText operation = ( DrawText )gcOperations[ 0 ];
+ assertEquals( "text", operation.text );
+ assertEquals( 10, operation.x );
+ assertEquals( 10, operation.y );
+ assertEquals( SWT.DRAW_TRANSPARENT, operation.flags );
+ }
+
+ public void testDrawTextWithEmptyString() {
+ gc.drawText( "", 10, 10, SWT.DRAW_TRANSPARENT );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ assertEquals( 0, gcOperations.length );
+ }
+
+ public void testDrawString() {
+ gc.drawString( "text", 10, 10, true );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ DrawText operation = ( DrawText )gcOperations[ 0 ];
+ assertEquals( "text", operation.text );
+ assertEquals( 10, operation.x );
+ assertEquals( 10, operation.y );
+ assertEquals( SWT.DRAW_TRANSPARENT, operation.flags );
+ }
+
+ public void testGetClipping() {
+ canvas.setSize( 100, 100 );
+ GC gc = new GC( canvas );
+ Rectangle clipping = gc.getClipping();
+ assertEquals( new Rectangle( 0, 0, 100, 100 ), clipping );
+ }
+
+ protected void setUp() throws Exception {
+ Fixture.setUp();
+ display = new Display();
+ Shell shell = new Shell( display );
+ canvas = new Canvas( shell, SWT.NONE );
+ gc = new GC( canvas );
+ }
+
+ protected void tearDown() throws Exception {
+ Fixture.tearDown();
+ }
+
+ private static GCOperation[] getGCOperations( final GC gc ) {
+ GCAdapter adapter = getGCAdapter( gc );
+ return adapter.getGCOperations();
+ }
+
+ private static GCAdapter getGCAdapter( GC gc ) {
+ GCAdapter result = null;
+ GCDelegate delegate = gc.getGCDelegate();
+ if( delegate instanceof ControlGC ) {
+ result = ( ( ControlGC )delegate ).getGCAdapter();
+ }
+ return result;
+ }
+
+ private Font createFont() {
+ return new Font( display, "font-name", 11, SWT.NORMAL );
+ }
+
+ private Color createColor() {
+ return new Color( display, 1, 2, 3 );
+ }
+}
diff --git a/tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/graphics/DeviceGC_Test.java b/tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/graphics/DeviceGC_Test.java
new file mode 100644
index 0000000000..7c1694c5cd
--- /dev/null
+++ b/tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/graphics/DeviceGC_Test.java
@@ -0,0 +1,99 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Rdiger Herrmann and others. 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:
+ * Rdiger Herrmann - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.swt.graphics;
+
+import junit.framework.TestCase;
+
+import org.eclipse.rwt.Fixture;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Display;
+
+
+public class DeviceGC_Test extends TestCase {
+
+ private Display display;
+ private GC gc;
+
+ public void testInitialValues() {
+ assertEquals( display.getSystemFont(), gc.getFont() );
+ Color white = display.getSystemColor( SWT.COLOR_WHITE );
+ assertEquals( white, gc.getBackground() );
+ Color black = display.getSystemColor( SWT.COLOR_BLACK );
+ assertEquals( black, gc.getForeground() );
+ }
+
+ public void testSetAlpha() {
+ gc.setAlpha( 123 );
+ assertEquals( 123, gc.getAlpha() );
+ }
+
+ public void testSetLineWidth() {
+ gc.setLineWidth( 5 );
+ assertEquals( 5, gc.getLineWidth() );
+ }
+
+ public void testSetLineJoin() {
+ gc.setLineJoin( SWT.JOIN_ROUND );
+ assertEquals( SWT.JOIN_ROUND, gc.getLineJoin() );
+ }
+
+ public void testSetLineCap() {
+ gc.setLineCap( SWT.CAP_ROUND );
+ assertEquals( SWT.CAP_ROUND, gc.getLineCap() );
+ }
+
+ public void testSetFont() {
+ Font font = createFont();
+ gc.setFont( font );
+ assertEquals( font, gc.getFont() );
+ }
+
+ public void testSetFontWithNullFont() {
+ Font font = createFont();
+ gc.setFont( font );
+ gc.setFont( null );
+ assertEquals( display.getSystemFont(), gc.getFont() );
+ }
+
+ public void testSetBackground() {
+ Color color = createColor();
+ gc.setBackground( color );
+ assertEquals( color, gc.getBackground() );
+ }
+
+ public void testSetForeground() {
+ Color color = createColor();
+ gc.setForeground( color );
+ assertEquals( color, gc.getForeground() );
+ }
+
+ public void testGetClipping() {
+ Rectangle clipping = gc.getClipping();
+ assertEquals( display.getBounds(), clipping );
+ }
+
+ protected void setUp() throws Exception {
+ Fixture.setUp();
+ display = new Display();
+ gc = new GC( display );
+ }
+
+ protected void tearDown() throws Exception {
+ Fixture.tearDown();
+ }
+
+ private Font createFont() {
+ return new Font( display, "font-name", 11, SWT.NORMAL );
+ }
+
+ private Color createColor() {
+ return new Color( display, 1, 2, 3 );
+ }
+}
diff --git a/tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/graphics/GC_Test.java b/tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/graphics/GC_Test.java
index 53b671660c..0dfa11d219 100644
--- a/tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/graphics/GC_Test.java
+++ b/tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/graphics/GC_Test.java
@@ -10,7 +10,6 @@
package org.eclipse.swt.graphics;
import java.io.InputStream;
-import java.util.Arrays;
import junit.framework.TestCase;
@@ -18,14 +17,13 @@ import org.eclipse.rwt.Fixture;
import org.eclipse.rwt.graphics.Graphics;
import org.eclipse.swt.SWT;
import org.eclipse.swt.SWTException;
-import org.eclipse.swt.internal.graphics.*;
-import org.eclipse.swt.internal.graphics.GCOperation.*;
import org.eclipse.swt.widgets.*;
public class GC_Test extends TestCase {
private Display display;
+ private GC gc;
public void testConstructorWithNullArgument() {
try {
@@ -37,7 +35,6 @@ public class GC_Test extends TestCase {
}
public void testInitialValues() {
- GC gc = new GC( display );
assertEquals( 255, gc.getAlpha() );
assertEquals( SWT.CAP_FLAT, gc.getLineCap() );
assertEquals( SWT.JOIN_MITER, gc.getLineJoin() );
@@ -48,66 +45,7 @@ public class GC_Test extends TestCase {
assertEquals( 0, ( int )lineAttributes.width );
}
- public void testControlGCFont() {
- Shell shell = new Shell( display );
- Control control = new Label( shell, SWT.NONE );
- GC gc = new GC( control );
- assertEquals( control.getFont(), gc.getFont() );
- }
-
- public void testDisplayGCFont() {
- GC gc = new GC( display );
- assertEquals( display.getSystemFont(), gc.getFont() );
- }
-
- public void testDisplayGCSetFont() {
- GC gc = new GC( display );
- Font font = createFont();
- gc.setFont( font );
- assertEquals( font, gc.getFont() );
- }
-
- public void testDisplayGCSetFontWithNullFont() {
- GC gc = new GC( display );
- Font font = createFont();
- gc.setFont( font );
- gc.setFont( null );
- assertEquals( display.getSystemFont(), gc.getFont() );
- }
-
- public void testControlGCSetFont() {
- Shell shell = new Shell( display );
- GC gc = new GC( shell );
- Font font = createFont();
- gc.setFont( font );
- GCOperation[] gcOperations = getGCOperations( gc );
- SetFont operation = ( SetFont )gcOperations[ 0 ];
- assertEquals( font, operation.font );
- }
-
- public void testControlGCSetFontWithNullFont() {
- Shell shell = new Shell( display );
- GC gc = new GC( shell );
- Font font = createFont();
- gc.setFont( font );
- gc.setFont( null );
- assertEquals( display.getSystemFont(), gc.getFont() );
- }
-
- public void testControlGCSetFontWithSameFont() {
- Shell shell = new Shell( display );
- GC gc = new GC( shell );
- Font font = createFont();
- gc.setFont( font );
- IGCAdapter adapter = gc.getGCAdapter();
- adapter.clearGCOperations();
- gc.setFont( font );
- GCOperation[] gcOperations = getGCOperations( gc );
- assertEquals( 0, gcOperations.length );
- }
-
- public void testSetFontWithDisposedFoont() {
- GC gc = new GC( display );
+ public void testSetFontWithDisposedFont() {
Font disposedFont = createFont();
disposedFont.dispose();
try {
@@ -117,7 +55,6 @@ public class GC_Test extends TestCase {
}
public void testDisposedGC() {
- GC gc = new GC( display );
gc.dispose();
assertTrue( gc.isDisposed() );
try {
@@ -345,7 +282,6 @@ public class GC_Test extends TestCase {
}
public void testTextExtentWithNullArgument() {
- GC gc = new GC( display );
try {
gc.textExtent( null );
fail( "textExtent must not allow null-argument" );
@@ -355,7 +291,6 @@ public class GC_Test extends TestCase {
}
public void testTextExtent() {
- GC gc = new GC( display );
String string = "foo";
Font systemFont = display.getSystemFont();
Point gcTextExtent = gc.textExtent( string );
@@ -364,7 +299,6 @@ public class GC_Test extends TestCase {
}
public void testStringExtent() {
- GC gc = new GC( display );
String string = "foo";
Font systemFont = display.getSystemFont();
Point gcStringExtent = gc.stringExtent( string );
@@ -373,54 +307,19 @@ public class GC_Test extends TestCase {
}
public void testGetCharWidth() {
- GC gc = new GC( display );
int width = gc.getCharWidth( 'A' );
assertTrue( width > 0 );
}
- public void testControlGCBackground() {
- Shell shell = new Shell( display );
- Control control = new Label( shell, SWT.NONE );
- GC gc = new GC( control );
- assertEquals( control.getBackground(), gc.getBackground() );
- }
-
- public void testDisplayGCBackground() {
- GC gc = new GC( display );
- assertEquals( display.getSystemColor( SWT.COLOR_WHITE ),
- gc.getBackground() );
- }
-
- public void testDisplayGCSetBackground() {
- GC gc = new GC( display );
- Color color = createColor();
- gc.setBackground( color );
- assertEquals( color, gc.getBackground() );
- }
-
- public void testControlGCSetBackground() {
- Shell shell = new Shell( display );
- GC gc = new GC( shell );
- Color color = createColor();
- gc.setBackground( color );
- GCOperation[] gcOperations = getGCOperations( gc );
- SetProperty operation = ( SetProperty )gcOperations[ 0 ];
- assertEquals( SetProperty.BACKGROUND, operation.id );
- assertEquals( color, operation.value );
- }
-
- public void testSetBackgroundNullArgument() {
- GC gc = new GC( display );
+ public void testSetBackgroundWithNullArgument() {
try {
gc.setBackground( null );
fail( "null not allowed on setBackground" );
- } catch( IllegalArgumentException e ) {
- // expected
+ } catch( IllegalArgumentException expected ) {
}
}
public void testSetBackgroundWithDisposedColor() {
- GC gc = new GC( display );
Color color = createColor();
color.dispose();
try {
@@ -431,39 +330,7 @@ public class GC_Test extends TestCase {
}
}
- public void testControlGCForeground() {
- Shell shell = new Shell( display );
- Control control = new Label( shell, SWT.NONE );
- GC gc = new GC( control );
- assertEquals( control.getForeground(), gc.getForeground() );
- }
-
- public void testDisplayGCForeground() {
- GC gc = new GC( display );
- Color black = display.getSystemColor( SWT.COLOR_BLACK );
- assertEquals( black, gc.getForeground() );
- }
-
- public void testDisplayGCSetForeground() {
- GC gc = new GC( display );
- Color color = createColor();
- gc.setForeground( color );
- assertEquals( color, gc.getForeground() );
- }
-
- public void testControlGCSetForeground() {
- Shell shell = new Shell( display );
- GC gc = new GC( shell );
- Color color = createColor();
- gc.setForeground( color );
- GCOperation[] gcOperations = getGCOperations( gc );
- SetProperty operation = ( SetProperty )gcOperations[ 0 ];
- assertEquals( SetProperty.FOREGROUND, operation.id );
- assertEquals( color, operation.value );
- }
-
- public void testSetForegroundNullArgument() {
- GC gc = new GC( display );
+ public void testSetForegroundWithNullArgument() {
try {
gc.setForeground( null );
fail( "null not allowed on setForeground" );
@@ -473,7 +340,6 @@ public class GC_Test extends TestCase {
}
public void testSetForegroundWithDisposedColor() {
- GC gc = new GC( display );
Color color = createColor();
color.dispose();
try {
@@ -484,119 +350,45 @@ public class GC_Test extends TestCase {
}
}
- public void testControlGCGetGCAdapterForCanvasWidget() {
- Shell shell = new Shell( display );
- GC gc = new GC( shell );
- IGCAdapter adapter1 = gc.getGCAdapter();
- assertNotNull( adapter1 );
- IGCAdapter adapter2 = gc.getGCAdapter();
- assertSame( adapter2, adapter1 );
- }
-
- public void testControlGCGetGCAdapterForNonCanvasWidget() {
- Shell shell = new Shell( display );
- Button button = new Button( shell, SWT.NONE );
- GC gc = new GC( button );
- assertNull( gc.getGCAdapter() );
- }
-
- public void testDisplayGCGetGCAdapter() {
- GC gc = new GC( display );
- assertNull( gc.getGCAdapter() );
- }
-
- public void testDrawOperationWithNonCanvas() {
- Shell shell = new Shell( display );
- Button button = new Button( shell, SWT.NONE );
- GC gc = new GC( button );
- gc.drawLine( 1, 2, 3, 4 );
- // This test has no assert. Ensures that no NPE is thrown.
- }
-
public void testSetAlpha() {
- Control control = new Shell( display );
- GC gc = new GC( control );
gc.setAlpha( 123 );
assertEquals( 123, gc.getAlpha() );
- GCOperation[] gcOperations = getGCOperations( gc );
- SetProperty operation = ( SetProperty )gcOperations[ 0 ];
- assertEquals( SetProperty.ALPHA, operation.id );
- assertEquals( new Integer( 123 ), operation.value );
}
public void testSetAlphaWithInvalidValue() {
- Control control = new Shell( display );
- GC gc = new GC( control );
gc.setAlpha( 777 );
assertEquals( 255, gc.getAlpha() );
- GCOperation[] gcOperations = getGCOperations( gc );
- assertEquals( 0, gcOperations.length );
}
-
+
public void testSetLineWidth() {
- Control control = new Shell( display );
- GC gc = new GC( control );
gc.setLineWidth( 5 );
assertEquals( 5, gc.getLineWidth() );
- GCOperation[] gcOperations = getGCOperations( gc );
- SetProperty operation = ( SetProperty )gcOperations[ 0 ];
- assertEquals( SetProperty.LINE_WIDTH, operation.id );
- assertEquals( new Integer( 5 ), operation.value );
}
- public void testSetLineCap() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- gc.setLineCap( SWT.CAP_ROUND );
- assertEquals( SWT.CAP_ROUND, gc.getLineCap() );
- GCOperation[] gcOperations = getGCOperations( gc );
- SetProperty operation = ( SetProperty )gcOperations[ 0 ];
- assertEquals( SetProperty.LINE_CAP, operation.id );
- assertEquals( new Integer( SWT.CAP_ROUND ), operation.value );
+ public void testSetLineWidthWithNegativeValue() {
+ gc.setLineWidth( -2 );
+ assertEquals( -2, gc.getLineWidth() );
}
- public void testSetLineCapWithUnchangeValue() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- gc.setLineCap( SWT.CAP_ROUND );
- gc.getGCAdapter().clearGCOperations();
+ public void testSetLineCap() {
gc.setLineCap( SWT.CAP_ROUND );
- assertEquals( 0, getGCOperations( gc ).length );
+ assertEquals( SWT.CAP_ROUND, gc.getLineCap() );
}
public void testSetLineCapWithInvalidValue() {
- Control control = new Shell( display );
- GC gc = new GC( control );
try {
gc.setLineCap( 500 );
fail( "value not allowed" );
} catch( IllegalArgumentException expected ) {
}
}
-
+
public void testSetLineJoin() {
- Control control = new Shell( display );
- GC gc = new GC( control );
gc.setLineJoin( SWT.JOIN_ROUND );
assertEquals( SWT.JOIN_ROUND, gc.getLineJoin() );
- GCOperation[] gcOperations = getGCOperations( gc );
- SetProperty operation = ( SetProperty )gcOperations[ 0 ];
- assertEquals( SetProperty.LINE_JOIN, operation.id );
- assertEquals( new Integer( SWT.JOIN_ROUND ), operation.value );
- }
-
- public void testSetLineJoinWithUnchangedValue() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- gc.setLineJoin( SWT.JOIN_ROUND );
- gc.getGCAdapter().clearGCOperations();
- gc.setLineJoin( SWT.JOIN_ROUND );
- assertEquals( 0, getGCOperations( gc ).length );
}
public void testSetLineJoinWithInvalidValue() {
- Control control = new Shell( display );
- GC gc = new GC( control );
try {
gc.setLineCap( 500 );
fail( "value not allowed" );
@@ -605,8 +397,6 @@ public class GC_Test extends TestCase {
}
public void testSetLineAttributes() {
- Control control = new Shell( display );
- GC gc = new GC( control );
LineAttributes attributes
= new LineAttributes( 5, SWT.CAP_ROUND, SWT.JOIN_BEVEL );
gc.setLineAttributes( attributes );
@@ -616,50 +406,27 @@ public class GC_Test extends TestCase {
assertEquals( 5, gc.getLineAttributes().width, 0 );
assertEquals( SWT.CAP_ROUND, gc.getLineAttributes().cap );
assertEquals( SWT.JOIN_BEVEL, gc.getLineAttributes().join );
- GCOperation[] gcOperations = getGCOperations( gc );
- SetProperty operation = ( SetProperty )gcOperations[ 0 ];
- assertEquals( SetProperty.LINE_WIDTH, operation.id );
- assertEquals( new Integer( 5 ), operation.value );
- operation = ( SetProperty )gcOperations[ 1 ];
- assertEquals( SetProperty.LINE_CAP, operation.id );
- assertEquals( new Integer( SWT.CAP_ROUND ), operation.value );
- operation = ( SetProperty )gcOperations[ 2 ];
- assertEquals( SetProperty.LINE_JOIN, operation.id );
- assertEquals( new Integer( SWT.JOIN_BEVEL ), operation.value );
}
public void testSetLineAttributesWithNullArgument() {
- GC gc = new GC( display );
try {
gc.setLineAttributes( null );
fail( "null value not allowed" );
- } catch( IllegalArgumentException e ) {
- // expected
+ } catch( IllegalArgumentException expected ) {
}
}
- public void testDrawLine() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- gc.drawLine( 1, 2, 3, 4 );
- GCOperation[] gcOperations = getGCOperations( gc );
- DrawLine operation = ( DrawLine )gcOperations[ 0 ];
- assertEquals( 1, operation.x1 );
- assertEquals( 2, operation.y1 );
- assertEquals( 3, operation.x2 );
- assertEquals( 4, operation.y2 );
- }
-
- public void testDrawPoint() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- gc.drawPoint( 1, 2 );
- GCOperation[] gcOperations = getGCOperations( gc );
- DrawPoint operation = ( DrawPoint )gcOperations[ 0 ];
- assertEquals( 1, operation.x );
- assertEquals( 2, operation.y );
+ public void testGetLineAttributes() {
+ LineAttributes attributes
+ = new LineAttributes( 5, SWT.CAP_ROUND, SWT.JOIN_BEVEL );
+ gc.setLineAttributes( attributes );
+ LineAttributes returnedAttributes = gc.getLineAttributes();
+ assertNotSame( attributes, returnedAttributes );
+ assertEquals( attributes.cap, returnedAttributes.cap );
+ assertEquals( attributes.join, returnedAttributes.join );
+ assertEquals( attributes.width, returnedAttributes.width, 0 );
}
-
+
public void testCheckBounds() {
Rectangle rectangle = GC.checkBounds( 1, 2, 3, 4 );
assertEquals( 1, rectangle.x );
@@ -676,29 +443,7 @@ public class GC_Test extends TestCase {
assertEquals( 4, rectangle.height );
}
- public void testDrawRectangle() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- gc.drawRectangle( 1, 2, 3, 4 );
- GCOperation[] gcOperations = getGCOperations( gc );
- DrawRectangle operation = ( DrawRectangle )gcOperations[ 0 ];
- assertEquals( 1, operation.x );
- assertEquals( 2, operation.y );
- assertEquals( 3, operation.width );
- assertEquals( 4, operation.height );
- assertFalse( operation.fill );
- }
-
- public void testControlGCDrawRectangleWithZeroWidthAndHeight() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- gc.drawRectangle( 1, 2, 0, 0 );
- GCOperation[] gcOperations = getGCOperations( gc );
- assertEquals( 0, gcOperations.length );
- }
-
public void testDrawRectangeWithNullArgument() {
- GC gc = new GC( display );
try {
gc.drawRectangle( null );
fail( "null argument is not allowed on drawRectangle" );
@@ -707,34 +452,7 @@ public class GC_Test extends TestCase {
}
}
- public void testDrawFocus() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- gc.drawFocus( 1, 2, 3, 4 );
- GCOperation[] gcOperations = getGCOperations( gc );
- DrawRectangle operation = ( DrawRectangle )gcOperations[ 0 ];
- assertEquals( 1, operation.x );
- assertEquals( 2, operation.y );
- assertEquals( 3, operation.width );
- assertEquals( 4, operation.height );
- assertFalse( operation.fill );
- }
-
- public void testFillRectangle() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- gc.fillRectangle( 1, 2, 3, 4 );
- GCOperation[] gcOperations = getGCOperations( gc );
- DrawRectangle operation = ( DrawRectangle )gcOperations[ 0 ];
- assertEquals( 1, operation.x );
- assertEquals( 2, operation.y );
- assertEquals( 3, operation.width );
- assertEquals( 4, operation.height );
- assertTrue( operation.fill );
- }
-
public void testFillRectangleWithNullArgument() {
- GC gc = new GC( display );
try {
gc.fillRectangle( null );
fail( "null argument is not allowed on fillRectangle" );
@@ -742,309 +460,28 @@ public class GC_Test extends TestCase {
}
}
- public void testFillGradientRectangle() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- gc.fillGradientRectangle( 1, 2, 3, 4, true );
- gc.fillGradientRectangle( 5, 6, 7, 8, false );
- GCOperation[] gcOperations = getGCOperations( gc );
- FillGradientRectangle operation
- = ( FillGradientRectangle )gcOperations[ 0 ];
- assertEquals( 1, operation.x );
- assertEquals( 2, operation.y );
- assertEquals( 3, operation.width );
- assertEquals( 4, operation.height );
- assertTrue( operation.vertical );
- assertTrue( operation.fill );
- operation = ( FillGradientRectangle )gcOperations[ 1 ];
- assertEquals( 5, operation.x );
- assertEquals( 6, operation.y );
- assertEquals( 7, operation.width );
- assertEquals( 8, operation.height );
- assertFalse( operation.vertical );
- assertTrue( operation.fill );
- }
-
- public void testDrawRoundRectangle() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- gc.drawRoundRectangle( 1, 2, 3, 4, 5, 6 );
- IGCAdapter adapter = gc.getGCAdapter();
- GCOperation[] gcOperations = adapter.getGCOperations();
- DrawRoundRectangle operation = ( DrawRoundRectangle )gcOperations[ 0 ];
- assertEquals( 1, operation.x );
- assertEquals( 2, operation.y );
- assertEquals( 3, operation.width );
- assertEquals( 4, operation.height );
- assertEquals( 5, operation.arcWidth );
- assertEquals( 6, operation.arcHeight );
- assertFalse( operation.fill );
- }
-
- public void testDrawRoundRectangleWithZeroArcWidth() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- gc.drawRoundRectangle( 1, 2, 3, 4, 0, 6 );
- GCOperation[] gcOperations = getGCOperations( gc );
- DrawRectangle operation = ( DrawRectangle )gcOperations[ 0 ];
- assertEquals( 1, operation.x );
- assertEquals( 2, operation.y );
- assertEquals( 3, operation.width );
- assertEquals( 4, operation.height );
- assertFalse( operation.fill );
- }
-
- public void testDrawRoundRectangleWithZeroArcHeight() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- gc.drawRoundRectangle( 1, 2, 3, 4, 5, 0 );
- GCOperation[] gcOperations = getGCOperations( gc );
- DrawRectangle operation = ( DrawRectangle )gcOperations[ 0 ];
- assertEquals( 1, operation.x );
- assertEquals( 2, operation.y );
- assertEquals( 3, operation.width );
- assertEquals( 4, operation.height );
- assertFalse( operation.fill );
- }
-
- public void testFillRoundRectangle() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- gc.fillRoundRectangle( 1, 2, 3, 4, 5, 6 );
- GCOperation[] gcOperations = getGCOperations( gc );
- DrawRoundRectangle operation = ( DrawRoundRectangle )gcOperations[ 0 ];
- assertEquals( 1, operation.x );
- assertEquals( 2, operation.y );
- assertEquals( 3, operation.width );
- assertEquals( 4, operation.height );
- assertEquals( 5, operation.arcWidth );
- assertEquals( 6, operation.arcHeight );
- assertTrue( operation.fill );
- }
-
- public void testFillRoundRectangleWithZeroArcWidth() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- gc.fillRoundRectangle( 1, 2, 3, 4, 0, 6 );
- GCOperation[] gcOperations = getGCOperations( gc );
- DrawRectangle operation = ( DrawRectangle )gcOperations[ 0 ];
- assertEquals( 1, operation.x );
- assertEquals( 2, operation.y );
- assertEquals( 3, operation.width );
- assertEquals( 4, operation.height );
- assertTrue( operation.fill );
- }
-
- public void testFillRoundRectangleWithZeroArcHeight() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- gc.fillRoundRectangle( 1, 2, 3, 4, 5, 0 );
- GCOperation[] gcOperations = getGCOperations( gc );
- DrawRectangle operation = ( DrawRectangle )gcOperations[ 0 ];
- assertEquals( 1, operation.x );
- assertEquals( 2, operation.y );
- assertEquals( 3, operation.width );
- assertEquals( 4, operation.height );
- assertTrue( operation.fill );
- }
-
- public void testDrawArc() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- gc.drawArc( 1, 2, 3, 4, 5, 6 );
- IGCAdapter adapter = gc.getGCAdapter();
- GCOperation[] gcOperations = adapter.getGCOperations();
- DrawArc operation = ( DrawArc )gcOperations[ 0 ];
- assertEquals( 1, operation.x );
- assertEquals( 2, operation.y );
- assertEquals( 3, operation.width );
- assertEquals( 4, operation.height );
- assertEquals( 5, operation.startAngle );
- assertEquals( 6, operation.arcAngle );
- assertFalse( operation.fill );
- }
-
- public void testDrawArcWithZeroWidth() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- gc.drawArc( 1, 2, 0, 5, 5, 5 );
- GCOperation[] gcOperations = getGCOperations( gc );
- assertEquals( 0, gcOperations.length );
- }
-
- public void testDrawArcWithZeroHeight() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- gc.drawArc( 1, 2, 3, 0, 5, 5 );
- GCOperation[] gcOperations = getGCOperations( gc );
- assertEquals( 0, gcOperations.length );
- }
-
- public void testDrawArcWithZeroArcAngle() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- gc.drawArc( 1, 2, 3, 4, 5, 0 );
- GCOperation[] gcOperations = getGCOperations( gc );
- assertEquals( 0, gcOperations.length );
- }
-
- public void testFillArc() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- gc.fillArc( 1, 2, 3, 4, 5, 6 );
- IGCAdapter adapter = gc.getGCAdapter();
- GCOperation[] gcOperations = adapter.getGCOperations();
- DrawArc operation = ( DrawArc )gcOperations[ 0 ];
- assertEquals( 1, operation.x );
- assertEquals( 2, operation.y );
- assertEquals( 3, operation.width );
- assertEquals( 4, operation.height );
- assertEquals( 5, operation.startAngle );
- assertEquals( 6, operation.arcAngle );
- adapter.clearGCOperations();
-
- gc.fillArc( 1, 2, -3, -4, 5, 6 );
- gcOperations = adapter.getGCOperations();
- operation = ( DrawArc )gcOperations[ 0 ];
- assertEquals( -2, operation.x );
- assertEquals( -2, operation.y );
- assertEquals( 3, operation.width );
- assertEquals( 4, operation.height );
- assertEquals( 5, operation.startAngle );
- assertEquals( 6, operation.arcAngle );
- assertTrue( operation.fill );
- adapter.clearGCOperations();
-
- gc.fillArc( 1, 2, 0, 4, 5, 6 );
- gcOperations = adapter.getGCOperations();
- assertEquals( 0, gcOperations.length );
-
- gc.fillArc( 1, 2, 3, 0, 5, 6 );
- gcOperations = adapter.getGCOperations();
- assertEquals( 0, gcOperations.length );
-
- gc.fillArc( 1, 2, 3, 4, 5, 0 );
- gcOperations = adapter.getGCOperations();
- assertEquals( 0, gcOperations.length );
- }
-
- public void testDrawOval() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- gc.drawOval( 1, 2, 3, 4 );
- IGCAdapter adapter = gc.getGCAdapter();
- GCOperation[] gcOperations = adapter.getGCOperations();
- DrawArc operation = ( DrawArc )gcOperations[ 0 ];
- assertEquals( 1, operation.x );
- assertEquals( 2, operation.y );
- assertEquals( 3, operation.width );
- assertEquals( 4, operation.height );
- assertEquals( 0, operation.startAngle );
- assertEquals( 360, operation.arcAngle );
- assertFalse( operation.fill );
- }
-
- public void testDrawOvalWithZeroWidthAndHeight() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- gc.drawOval( 1, 2, 0, 0 );
- IGCAdapter adapter = gc.getGCAdapter();
- GCOperation[] gcOperations = adapter.getGCOperations();
- assertEquals( 0, gcOperations.length );
- }
-
- public void testFillOval() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- gc.fillOval( 1, 2, 3, 4 );
- IGCAdapter adapter = gc.getGCAdapter();
- GCOperation[] gcOperations = adapter.getGCOperations();
- DrawArc operation = ( DrawArc )gcOperations[ 0 ];
- assertEquals( 1, operation.x );
- assertEquals( 2, operation.y );
- assertEquals( 3, operation.width );
- assertEquals( 4, operation.height );
- assertEquals( 0, operation.startAngle );
- assertEquals( 360, operation.arcAngle );
- assertTrue( operation.fill );
- adapter.clearGCOperations();
- }
-
- public void testDrawPolygon() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- int[] pointArray = new int[] { 1, 2, 3, 4 };
- gc.drawPolygon( pointArray );
- GCOperation[] gcOperations = getGCOperations( gc );
- DrawPolyline operation = ( DrawPolyline )gcOperations[ 0 ];
- assertTrue( Arrays.equals( pointArray, operation.points ) );
- assertTrue( operation.close );
- assertFalse( operation.fill );
- }
-
public void testDrawPolygonWithNullArgument() {
- GC gc = new GC( display );
try {
gc.drawPolygon( null );
} catch( IllegalArgumentException expected ) {
}
}
- public void testFillPolygon() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- int[] pointArray = new int[] { 1, 2, 3, 4 };
- gc.fillPolygon( pointArray );
- GCOperation[] gcOperations = getGCOperations( gc );
- DrawPolyline operation = ( DrawPolyline )gcOperations[ 0 ];
- assertTrue( Arrays.equals( pointArray, operation.points ) );
- assertTrue( operation.close );
- assertTrue( operation.fill );
- }
-
public void testFillPolygonWithNullArgument() {
- GC gc = new GC( display );
try {
gc.fillPolygon( null );
} catch( IllegalArgumentException expected ) {
}
}
- public void testDrawPolyline() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- int[] pointArray = new int[] { 1, 2, 3, 4 };
- gc.drawPolyline( pointArray );
- GCOperation[] gcOperations = getGCOperations( gc );
- DrawPolyline operation = ( DrawPolyline )gcOperations[ 0 ];
- assertTrue( Arrays.equals( pointArray, operation.points ) );
- assertFalse( operation.close );
- assertFalse( operation.fill );
- }
-
public void testDrawPolylineWithNullArgument() {
- GC gc = new GC( display );
try {
gc.drawPolyline( null );
} catch( IllegalArgumentException expected ) {
}
}
- public void testDrawText() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- gc.drawText( "text", 10, 10, SWT.DRAW_TRANSPARENT );
- GCOperation[] gcOperations = getGCOperations( gc );
- DrawText operation = ( DrawText )gcOperations[ 0 ];
- assertEquals( "text", operation.text );
- assertEquals( 10, operation.x );
- assertEquals( 10, operation.y );
- assertEquals( SWT.DRAW_TRANSPARENT, operation.flags );
- }
-
public void testDrawTextWithNullString() {
- Control control = new Shell( display );
- GC gc = new GC( control );
try {
gc.drawText( null, 10, 10, SWT.DRAW_TRANSPARENT );
fail( "null argument is not allowed on drawText" );
@@ -1053,29 +490,7 @@ public class GC_Test extends TestCase {
}
}
- public void testDrawTextWithEmptyString() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- gc.drawText( "", 10, 10, SWT.DRAW_TRANSPARENT );
- GCOperation[] gcOperations = getGCOperations( gc );
- assertEquals( 0, gcOperations.length );
- }
-
- public void testDrawString() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- gc.drawString( "text", 10, 10, true );
- GCOperation[] gcOperations = getGCOperations( gc );
- DrawText operation = ( DrawText )gcOperations[ 0 ];
- assertEquals( "text", operation.text );
- assertEquals( 10, operation.x );
- assertEquals( 10, operation.y );
- assertEquals( SWT.DRAW_TRANSPARENT, operation.flags );
- }
-
public void testDrawStringWithNullString() {
- Control control = new Shell( display );
- GC gc = new GC( control );
try {
gc.drawString( null, 10, 10, true );
fail( "null argument is not allowed on drawText" );
@@ -1083,14 +498,6 @@ public class GC_Test extends TestCase {
}
}
- public void testDrawStringWithEmptyString() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- gc.drawString( "", 10, 10, false );
- GCOperation[] gcOperations = getGCOperations( gc );
- assertEquals( 0, gcOperations.length );
- }
-
public void testDrawImageWithNullImage() {
Control control = new Shell( display );
GC gc = new GC( control );
@@ -1103,8 +510,6 @@ public class GC_Test extends TestCase {
}
public void testDrawImageWithDisposedImage() {
- Control control = new Shell( display );
- GC gc = new GC( control );
Image disposedImage = createImage();
disposedImage.dispose();
try {
@@ -1115,73 +520,22 @@ public class GC_Test extends TestCase {
}
}
- public void testDrawImage() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- Image image = display.getSystemImage( SWT.ICON_INFORMATION );
- gc.drawImage( image, 1, 2 );
- GCOperation[] gcOperations = getGCOperations( gc );
- DrawImage operation = ( DrawImage )gcOperations[ 0 ];
- assertSame( image, operation.image );
- assertEquals( 0, operation.srcX );
- assertEquals( 0, operation.srcY );
- assertEquals( -1, operation.srcWidth );
- assertEquals( -1, operation.srcHeight );
- assertEquals( 1, operation.destX );
- assertEquals( 2, operation.destY );
- assertEquals( -1, operation.destWidth );
- assertEquals( -1, operation.destHeight );
- assertTrue( operation.simple );
- gc.drawImage( image, 1, 2, 3, 4, 5, 6, 7, 8 );
- gcOperations = getGCOperations( gc );
- operation = ( DrawImage )gcOperations[ 1 ];
- assertSame( image, operation.image );
- assertEquals( 1, operation.srcX );
- assertEquals( 2, operation.srcY );
- assertEquals( 3, operation.srcWidth );
- assertEquals( 4, operation.srcHeight );
- assertEquals( 5, operation.destX );
- assertEquals( 6, operation.destY );
- assertEquals( 7, operation.destWidth );
- assertEquals( 8, operation.destHeight );
- assertFalse( operation.simple );
- }
-
public void testDrawImageWithInvalidSourceRegion() {
- Control control = new Shell( display );
- GC gc = new GC( control );
Image image = display.getSystemImage( SWT.ICON_INFORMATION );
- assertTrue( image.getBounds().width < 40 );
- assertTrue( image.getBounds().height < 40 );
+ assertTrue( image.getBounds().width < 40 ); // precondition
+ assertTrue( image.getBounds().height < 40 ); // precondition
try {
gc.drawImage( image, 10, 0, 50, 16, 0, 0, 100, 100 );
fail( "srcWidth larger than srcX + image.width is not allowed" );
- } catch( IllegalArgumentException e ) {
- // expected
+ } catch( IllegalArgumentException expected ) {
}
try {
gc.drawImage( image, 0, 10, 16, 50, 0, 0, 100, 100 );
fail( "srcHeight larger than srcY + image.height is not allowed" );
- } catch( IllegalArgumentException e ) {
- // expected
+ } catch( IllegalArgumentException expected ) {
}
}
- public void testControlGCGetClipping() {
- Shell shell = new Shell( display );
- Canvas canvas = new Canvas( shell, SWT.NONE );
- canvas.setSize( 100, 100 );
- GC gc = new GC( canvas );
- Rectangle clipping = gc.getClipping();
- assertEquals( new Rectangle( 0, 0, 100, 100), clipping );
- }
-
- public void testDisplayGCGetClipping() {
- GC gc = new GC( display );
- Rectangle clipping = gc.getClipping();
- assertEquals( display.getBounds(), clipping );
- }
-
public void testStyle() {
GC gc = new GC( display, SWT.NONE );
assertEquals( SWT.LEFT_TO_RIGHT, gc.getStyle() );
@@ -1194,17 +548,13 @@ public class GC_Test extends TestCase {
protected void setUp() throws Exception {
Fixture.setUp();
display = new Display();
+ gc = new GC( display );
}
protected void tearDown() throws Exception {
Fixture.tearDown();
}
- private static GCOperation[] getGCOperations( final GC gc ) {
- GCAdapter adapter = gc.getGCAdapter();
- return adapter.getGCOperations();
- }
-
private Image createImage() {
ClassLoader loader = Fixture.class.getClassLoader();
InputStream stream = loader.getResourceAsStream( Fixture.IMAGE1 );

Back to the top