Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 157625 Details for
Bug 300980
[TextSizeDetermination] fails with disposed fonts
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Another test case
clipboard.txt (text/plain), 10.39 KB, created by
RĂ¼diger Herrmann
on 2010-01-29 09:50:46 EST
(
hide
)
Description:
Another test case
Filename:
MIME Type:
Creator:
RĂ¼diger Herrmann
Created:
2010-01-29 09:50:46 EST
Size:
10.39 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.rap.rwt.test >Index: src/org/eclipse/swt/internal/graphics/TextSizeDetermination_Test.java >=================================================================== >RCS file: /cvsroot/rt/org.eclipse.rap/runtime.rwt.test/org.eclipse.rap.rwt.test/src/org/eclipse/swt/internal/graphics/TextSizeDetermination_Test.java,v >retrieving revision 1.13 >diff -u -r1.13 TextSizeDetermination_Test.java >--- src/org/eclipse/swt/internal/graphics/TextSizeDetermination_Test.java 11 Dec 2009 15:19:56 -0000 1.13 >+++ src/org/eclipse/swt/internal/graphics/TextSizeDetermination_Test.java 29 Jan 2010 14:48:29 -0000 >@@ -20,11 +20,11 @@ > import org.eclipse.rwt.Fixture; > import org.eclipse.rwt.graphics.Graphics; > import org.eclipse.swt.SWT; >-import org.eclipse.swt.graphics.Font; >-import org.eclipse.swt.graphics.Point; >+import org.eclipse.swt.graphics.*; > import org.eclipse.swt.internal.graphics.TextSizeDetermination.ICalculationItem; > import org.eclipse.swt.internal.graphics.TextSizeProbeStore.IProbe; > import org.eclipse.swt.internal.graphics.TextSizeProbeStore.IProbeResult; >+import org.eclipse.swt.widgets.Display; > > > public class TextSizeDetermination_Test extends TestCase { >@@ -53,11 +53,14 @@ > Point storedSize = new Point( 100, 10 ); > IProbe[] probeRequests = TextSizeProbeStore.getProbeRequests(); > assertEquals( 1, probeRequests.length ); >- assertSame( font, probeRequests[ 0 ].getFont() ); >+ assertSame( font.getFontData()[ 0 ], probeRequests[ 0 ].getFontData() ); > > TextSizeProbeStore probeStore = TextSizeProbeStore.getInstance(); > probeStore.createProbeResult( probeRequests[ 0 ], new Point( 10, 10 ) ); >- TextSizeDataBase.store( font, TEST_STRING, SWT.DEFAULT, storedSize ); >+ TextSizeDataBase.store( font.getFontData()[ 0 ], >+ TEST_STRING, >+ SWT.DEFAULT, >+ storedSize ); > calculated = TextSizeDetermination.stringExtent( font, TEST_STRING ); > assertEquals( storedSize, calculated ); > >@@ -110,7 +113,7 @@ > > probeRequests = TextSizeProbeStore.getProbeRequests(); > assertEquals( 1, probeRequests.length ); >- assertSame( font0, probeRequests[ 0 ].getFont() ); >+ assertSame( font0.getFontData()[ 0 ], probeRequests[ 0 ].getFontData() ); > > TextSizeProbeStore probeStore = TextSizeProbeStore.getInstance(); > Point probeSize = new Point( 10, 13 ); >@@ -130,7 +133,7 @@ > > probeRequests = TextSizeProbeStore.getProbeRequests(); > assertEquals( 1, probeRequests.length ); >- assertSame( font0, probeRequests[ 0 ].getFont() ); >+ assertSame( font0.getFontData()[ 0 ], probeRequests[ 0 ].getFontData() ); > > TextSizeProbeStore probeStore = TextSizeProbeStore.getInstance(); > Point probeSize = new Point( TextSizeProbeStore.DEFAULT_PROBE.length() * 4, 10 ); >@@ -141,16 +144,19 @@ > > public void testFontSizeDataBase() { > Font font0 = Graphics.getFont( "arial", 10, SWT.NORMAL ); >+ FontData fontData0 = font0.getFontData()[ 0 ]; > Font font1 = Graphics.getFont( "helvetia", 12, SWT.NORMAL ); >+ FontData fontData1 = font1.getFontData()[ 0 ]; > >- Point textSize = TextSizeDataBase.lookup( font0, TEST_STRING, SWT.DEFAULT ); >+ Point textSize; >+ textSize = TextSizeDataBase.lookup( fontData0, TEST_STRING, SWT.DEFAULT ); > assertNull( textSize ); >- textSize = TextSizeDataBase.lookup( font1, TEST_STRING, SWT.DEFAULT ); >+ textSize = TextSizeDataBase.lookup( fontData1, TEST_STRING, SWT.DEFAULT ); > assertNull( textSize ); > > try { > Point point = new Point( 1, 1 ); >- TextSizeDataBase.store( font1, TEST_STRING, SWT.DEFAULT, point ); >+ TextSizeDataBase.store( fontData1, TEST_STRING, SWT.DEFAULT, point ); > fail( "No probe available." ); > } catch( final IllegalStateException ise ) { > } >@@ -163,64 +169,68 @@ > probeStore.createProbeResult( findRequestedProbe( 1 ), probeSize1 ); > > Point calculatedTextSize0 = new Point( 100, 10 ); >- TextSizeDataBase.store( font0, >+ TextSizeDataBase.store( fontData0, > TEST_STRING, > SWT.DEFAULT, > calculatedTextSize0 ); > Point calculatedTextSize1 = new Point( 100, 12 ); >- TextSizeDataBase.store( font1, >+ TextSizeDataBase.store( fontData1, > TEST_STRING, > SWT.DEFAULT, > calculatedTextSize1 ); >- textSize = TextSizeDataBase.lookup( font0, TEST_STRING, SWT.DEFAULT ); >+ textSize = TextSizeDataBase.lookup( fontData0, TEST_STRING, SWT.DEFAULT ); > assertEquals( calculatedTextSize0, textSize ); >- textSize = TextSizeDataBase.lookup( font1, TEST_STRING, SWT.DEFAULT ); >+ textSize = TextSizeDataBase.lookup( fontData1, TEST_STRING, SWT.DEFAULT ); > assertEquals( calculatedTextSize1, textSize ); > } > > private IProbe findRequestedProbe( final int i ) { > IProbe[] probeRequests = TextSizeProbeStore.getProbeRequests(); >- return TextSizeProbeStore.getProbe( probeRequests[ i ].getFont() ); >+ return TextSizeProbeStore.getProbe( probeRequests[ i ].getFontData() ); > } > > public void testProbeStorage() { > Font font0 = Graphics.getFont( "arial", 10, SWT.NORMAL ); >+ FontData fontData0 = font0.getFontData()[ 0 ]; > IProbe[] probeList = TextSizeProbeStore.getProbeList(); > assertEquals( 0, probeList.length ); >- IProbe probe0 = TextSizeProbeStore.getProbe( font0 ); >+ IProbe probe0 = TextSizeProbeStore.getProbe( fontData0 ); > assertNull( probe0 ); > > String probeText0 = "ProbeText0"; >- probe0 = TextSizeProbeStore.createProbe( font0, probeText0 ); >+ probe0 = TextSizeProbeStore.createProbe( fontData0, probeText0 ); > probeList = TextSizeProbeStore.getProbeList(); > assertEquals( 1, probeList.length ); > assertSame( probe0, probeList[ 0 ] ); >- assertSame( probe0, TextSizeProbeStore.getProbe( font0 ) ); >- assertTrue( TextSizeProbeStore.containsProbe( font0 ) ); >- assertSame( probe0.getFont(), font0 ); >+ assertSame( probe0, TextSizeProbeStore.getProbe( fontData0 ) ); >+ assertTrue( TextSizeProbeStore.containsProbe( fontData0 ) ); >+ assertSame( probe0.getFontData(), fontData0 ); > assertSame( probe0.getString(), probeText0 ); > > Font font1 = Graphics.getFont( "arial", 12, SWT.NORMAL ); >- assertFalse( TextSizeProbeStore.containsProbe( font1 ) ); >+ FontData fontData1 = font1.getFontData()[ 0 ]; >+ assertFalse( TextSizeProbeStore.containsProbe( fontData1 ) ); > > TextSizeProbeStore probeStore = TextSizeProbeStore.getInstance(); >- IProbeResult probeResult0 = probeStore.getProbeResult( font0 ); >+ IProbeResult probeResult0 = probeStore.getProbeResult( fontData0 ); > assertNull( probeResult0 ); > > Point probeSize0 = new Point( 10, 10 ); > probeResult0 = probeStore.createProbeResult( probe0, probeSize0 ); > assertSame( probeResult0.getProbe(), probe0 ); > assertSame( probeResult0.getSize(), probeSize0 ); >- assertTrue( probeStore.containsProbeResult( font0 ) ); >- assertFalse( probeStore.containsProbeResult( font1 ) ); >+ assertTrue( probeStore.containsProbeResult( fontData0 ) ); >+ assertFalse( probeStore.containsProbeResult( fontData1 ) ); > } > > public void testDefaultFontSizeStorage() throws IOException { > DefaultTextSizeStorage storage = new DefaultTextSizeStorage(); > Font font0 = Graphics.getFont( "arial", 10, SWT.NORMAL ); >+ FontData fontData0 = font0.getFontData()[ 0 ]; > Font font1 = Graphics.getFont( "helvetia", 12, SWT.NORMAL ); >- storage.storeFont( font0 ); >- storage.storeFont( font1 ); >+ FontData fontData1 = font1.getFontData()[ 0 ]; >+ storage.storeFont( fontData0 ); >+ storage.storeFont( fontData1 ); > > Point point0 = new Point( 9, 10 ); > Integer key0 = new Integer( 0 ); >@@ -252,17 +262,17 @@ > assertEquals( point0, actual ); > actual = storage.lookupTextSize( key1 ); > assertEquals( point1, actual ); >- Font[] fontList = storage.getFontList(); >- List fonts = Arrays.asList( fontList ); >- assertEquals( 2, fonts.size() ); >- assertTrue( fonts.contains( font0 ) ); >- assertTrue( fonts.contains( font1 ) ); >+ FontData[] fontDatas = storage.getFontList(); >+ assertEquals( 2, fontDatas.length ); >+ List fontDataList = Arrays.asList( fontDatas ); >+ assertTrue( fontDataList.contains( fontData0 ) ); >+ assertTrue( fontDataList.contains( fontData1 ) ); > } > > public void testStorageOverflow() { > DefaultTextSizeStorage storage = new DefaultTextSizeStorage(); > int storeSize = DefaultTextSizeStorage.MIN_STORE_SIZE; >- DefaultTextSizeStorage.setStoreSize( storeSize ); >+ storage.setStoreSize( storeSize ); > > for( int i = 0; i < storeSize - 1; i++ ) { > Integer key = new Integer( i ); >@@ -286,15 +296,16 @@ > } > > public void testTextSizeDatabaseKey() { >- final Font font = Graphics.getFont( "name", 10, SWT.NORMAL ); >+ Font font = Graphics.getFont( "name", 10, SWT.NORMAL ); >+ final FontData fontData = font.getFontData()[ 0 ]; > Set takenKeys = new HashSet(); > StringBuffer generatedText = new StringBuffer(); > for( int i = 0; i < 100; i++ ) { > generatedText.append( "a" ); > final String text = generatedText.toString(); > IProbe probe = new IProbe() { >- public Font getFont() { >- return font; >+ public FontData getFontData() { >+ return fontData; > } > public String getString() { > return text; >@@ -305,12 +316,23 @@ > }; > Point size = new Point( 1, 2 ); > TextSizeProbeStore.getInstance().createProbeResult( probe, size ); >- Integer key = TextSizeDataBase.getKey( font, text, -1 ); >+ Integer key = TextSizeDataBase.getKey( fontData, text, -1 ); > assertFalse( takenKeys.contains( key ) ); > takenKeys.add( key ); > } > } >- >+ >+ public void testDisposedFont() { >+ Display device = new Display(); >+ Font disposedFont = new Font( device, "disposedFont", 10, SWT.NORMAL ); >+ disposedFont.dispose(); >+ try { >+ TextSizeDetermination.stringExtent( disposedFont, "" ); >+ } catch( Throwable e ) { >+ fail( "Text size determination must also work with dispoed font" ); >+ } >+ } >+ > protected void setUp() throws Exception { > Fixture.setUp(); > TextSizeDataBase.reset();
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 300980
:
157388
| 157625