File tree Expand file tree Collapse file tree
bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics
tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3786,6 +3786,7 @@ public void setXORMode(boolean xor) {
37863786 * </ul>
37873787 */
37883788public Point stringExtent (String string ) {
3789+ if (handle == 0 ) SWT .error (SWT .ERROR_GRAPHIC_DISPOSED );
37893790 return textExtentInPixels (string , 0 );
37903791}
37913792Point stringExtentInPixels (String string ) {
@@ -3812,6 +3813,7 @@ Point stringExtentInPixels(String string) {
38123813 * </ul>
38133814 */
38143815public Point textExtent (String string ) {
3816+ if (handle == 0 ) SWT .error (SWT .ERROR_GRAPHIC_DISPOSED );
38153817 return textExtentInPixels (string , SWT .DRAW_DELIMITER | SWT .DRAW_TAB );
38163818}
38173819
Original file line number Diff line number Diff line change 3535import java .util .concurrent .atomic .AtomicReference ;
3636
3737import org .eclipse .swt .SWT ;
38+ import org .eclipse .swt .SWTException ;
3839import org .eclipse .swt .graphics .Color ;
3940import org .eclipse .swt .graphics .Font ;
4041import org .eclipse .swt .graphics .FontMetrics ;
@@ -917,20 +918,29 @@ public void test_stringExtentLjava_lang_String() {
917918 Point pt = gc .stringExtent ("abc" );
918919 assertTrue (pt .x > 0 );
919920 assertTrue (pt .y > 0 );
921+ gc .dispose ();
922+ SWTException e = assertThrows (SWTException .class , () -> gc .stringExtent ("abc" ));
923+ assertEquals (SWT .ERROR_GRAPHIC_DISPOSED , e .code );
920924}
921925
922926@ Test
923927public void test_textExtentLjava_lang_String () {
924928 Point pt = gc .textExtent ("abc" );
925929 assertTrue (pt .x > 0 );
926930 assertTrue (pt .y > 0 );
931+ gc .dispose ();
932+ SWTException e = assertThrows (SWTException .class , () -> gc .textExtent ("abc" ));
933+ assertEquals (SWT .ERROR_GRAPHIC_DISPOSED , e .code );
927934}
928935
929936@ Test
930937public void test_textExtentLjava_lang_StringI () {
931938 Point pt = gc .textExtent ("abc" , 0 );
932939 assertTrue (pt .x > 0 );
933940 assertTrue (pt .y > 0 );
941+ gc .dispose ();
942+ SWTException e = assertThrows (SWTException .class , () -> gc .textExtent ("abc" , 0 ));
943+ assertEquals (SWT .ERROR_GRAPHIC_DISPOSED , e .code );
934944}
935945
936946@ Test
You can’t perform that action at this time.
0 commit comments