diff options
author | Grant Gayed <ggayed> | 2004-08-30 22:41:54 +0000 |
---|---|---|
committer | Grant Gayed <ggayed> | 2004-08-30 22:41:54 +0000 |
commit | f240d6dd2b74543a9c7254cca3bd363a117d0a68 (patch) | |
tree | 0a36d6d00889a5fbab2e549265c57d26bcba140c /tests | |
parent | 1f2d6d7e03d28796f88f1cd0a8579f8dd597bf43 (diff) | |
download | eclipse.platform.swt-f240d6dd2b74543a9c7254cca3bd363a117d0a68.tar.gz eclipse.platform.swt-f240d6dd2b74543a9c7254cca3bd363a117d0a68.tar.xz eclipse.platform.swt-f240d6dd2b74543a9c7254cca3bd363a117d0a68.zip |
*** empty log message ***
Diffstat (limited to 'tests')
8 files changed, 567 insertions, 48 deletions
diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/SwtTestCase.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/SwtTestCase.java index 9b66a4293b..495133933f 100644 --- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/SwtTestCase.java +++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/SwtTestCase.java @@ -15,6 +15,7 @@ import java.io.*; import junit.framework.*; import org.eclipse.swt.*; import org.eclipse.swt.internal.*; +import org.eclipse.test.performance.*; public class SwtTestCase extends TestCase { /** @@ -209,6 +210,31 @@ protected boolean isReparentablePlatform() { } return false; } + +protected void testPerformance (Runnable runnable) { + testPerformance (null, runnable); +} +protected void testPerformance (String id, Runnable runnable) { + if (!performanceTesting) return; + Performance perf = Performance.getDefault(); + PerformanceMeter meter; + if (id != null) { + meter = perf.createPerformanceMeter(perf.getDefaultScenarioId(this, id)); + } else { + meter = perf.createPerformanceMeter(perf.getDefaultScenarioId(this)); + } + try { + meter.start(); + for (int i = 0; i < 1000; i++) { + runnable.run(); + } + meter.stop(); + meter.commit(); + perf.assertPerformance(meter); + } finally { + meter.dispose(); + } +} protected void warnUnimpl(String message) { if (verbose) { System.out.println(this.getClass() + ": " + message); diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_Color.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_Color.java index 391b1714fb..1ec7ff8588 100644 --- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_Color.java +++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_Color.java @@ -83,6 +83,12 @@ public void test_ConstructorLorg_eclipse_swt_graphics_DeviceIII() { fail("No exception thrown for blue > 255"); } catch (IllegalArgumentException e) { } + + testPerformance (new Runnable () { + public void run() { + new Color(display, 102, 255, 0).dispose(); + } + }); } public void test_ConstructorLorg_eclipse_swt_graphics_DeviceLorg_eclipse_swt_graphics_RGB() { @@ -142,17 +148,36 @@ public void test_ConstructorLorg_eclipse_swt_graphics_DeviceLorg_eclipse_swt_gra } catch (IllegalArgumentException e) { } + + testPerformance(new Runnable () { + public void run() { + new Color(null, new RGB(244, 16, 99)).dispose(); + } + }); } public void test_dispose() { // tested in test_isDisposed + + testPerformance("dispose()", new Runnable () { + public void run() { + Color color = new Color (null, 0, 0, 0); + color.dispose(); + } + }); + final Color color = new Color (null, 0, 0, 0); + testPerformance("dispose() disposed", new Runnable() { + public void run() { + color.dispose(); + } + }); } public void test_equalsLjava_lang_Object() { - Color color = new Color(display, 1, 2, 3); - Color sameColor = new Color(display, 1, 2, 3); + final Color color = new Color(display, 1, 2, 3); + final Color sameColor = new Color(display, 1, 2, 3); Color sameColor2 = new Color(display, new RGB(1, 2, 3)); - Color otherColor = new Color(display, 5, 6, 7); + final Color otherColor = new Color(display, 5, 6, 7); try { // Test Color.equals(Object) assertTrue("!color.equals((Object)null)", !color.equals((Object)null)); @@ -163,6 +188,16 @@ public void test_equalsLjava_lang_Object() { assertTrue("color.equals(sameColor)", color.equals(sameColor)); assertTrue("color.equals(sameColor2)", color.equals(sameColor2)); assertTrue("!color.equals(otherColor)", !color.equals(otherColor)); + testPerformance ("equals same", new Runnable () { + public void run() { + color.equals (sameColor); + } + }); + testPerformance ("equals different", new Runnable () { + public void run() { + color.equals (otherColor); + } + }); } finally { color.dispose(); sameColor.dispose(); @@ -173,59 +208,102 @@ public void test_equalsLjava_lang_Object() { public void test_getBlue() { // Test Color.getBlue() - Color color = new Color(display, 0, 0, 255); + final Color color = new Color(display, 0, 0, 255); try { assertEquals("color.getBlue()", color.getBlue(), 255); + testPerformance(new Runnable () { + public void run() { + color.getBlue(); + } + }); } finally { color.dispose(); } - } public void test_getGreen() { // Test Color.getGreen() - Color color = new Color(display, 0, 255, 0); + final Color color = new Color(display, 0, 255, 0); try { assertEquals("color.getGreen()", color.getGreen(), 255); + testPerformance(new Runnable () { + public void run() { + color.getGreen(); + } + }); } finally { color.dispose(); } } public void test_getRGB() { - Color color = new Color(display, 255, 255, 255); - assertNotNull(color.getRGB()); - assertEquals(new RGB(255, 255, 255), color.getRGB()); + final Color color = new Color(display, 255, 255, 255); + try { + assertNotNull(color.getRGB()); + assertEquals(new RGB(255, 255, 255), color.getRGB()); + testPerformance(new Runnable () { + public void run() { + color.getRGB(); + } + }); + } finally { + color.dispose(); + } } public void test_getRed() { // Test Color.getRed() - Color color = new Color(display, 255, 0, 0); + final Color color = new Color(display, 255, 0, 0); try { assertEquals("color.getRed()", color.getRed(), 255); + testPerformance(new Runnable () { + public void run() { + color.getRed(); + } + }); } finally { color.dispose(); } } public void test_hashCode() { - Color color = new Color(display, 12, 34, 56); + final Color color = new Color(display, 12, 34, 56); Color otherColor = new Color(display, 12, 34, 56); - if (color.equals(otherColor)) { - assertEquals("Hash codes of equal objects should be equal", color.hashCode(), otherColor.hashCode()); + try { + if (color.equals(otherColor)) { + assertEquals("Hash codes of equal objects should be equal", color.hashCode(), otherColor.hashCode()); + } + testPerformance(new Runnable () { + public void run() { + color.hashCode(); + } + }); + } finally { + color.dispose(); + otherColor.dispose(); } } public void test_isDisposed() { // Test Color.isDisposed() false - Color color = new Color(display, 34, 67, 98); + final Color color = new Color(display, 34, 67, 98); try { assertTrue("Color should not be disposed", !color.isDisposed()); + testPerformance ("isDisposed()", new Runnable () { + public void run() { + color.isDisposed(); + } + }); } finally { // Test Color.isDisposed() true color.dispose(); assertTrue("Color should be disposed", color.isDisposed()); } + testPerformance ("disposed isDisposed()", new Runnable () { + public void run() { + color.isDisposed(); + } + }); } public void test_toString() { diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_Cursor.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_Cursor.java index fcb975e5cd..f46645a079 100644 --- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_Cursor.java +++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_Cursor.java @@ -131,6 +131,12 @@ public void test_ConstructorLorg_eclipse_swt_graphics_DeviceI() { fail("No exception thrown for style < 0"); } catch (IllegalArgumentException e) { } + + testPerformance(new Runnable() { + public void run() { + new Cursor(display, SWT.CURSOR_ARROW).dispose(); + } + }); } public void test_ConstructorLorg_eclipse_swt_graphics_DeviceLorg_eclipse_swt_graphics_ImageDataII() { @@ -145,11 +151,20 @@ public void test_ConstructorLorg_eclipse_swt_graphics_DeviceLorg_eclipse_swt_gra String format = SwtTestCase.imageFormats[i]; ImageLoader loader = new ImageLoader(); InputStream stream = SwtTestCase.class.getResourceAsStream(fileName + "." + format); - ImageData source = loader.load(stream)[0]; - ImageData mask = source.getTransparencyMask(); + final ImageData source = loader.load(stream)[0]; + final ImageData mask = source.getTransparencyMask(); if (mask != null && (source.depth == 1)) { - Cursor cursor = new Cursor(display, source, mask, 0, 0); - cursor.dispose(); + Runnable runnable = new Runnable () { + public void run() { + Cursor cursor = new Cursor(display, source, mask, 0, 0); + cursor.dispose(); + } + }; + if (performanceTesting) { + testPerformance(runnable); + } else { + runnable.run(); + } } try { stream.close(); @@ -167,8 +182,8 @@ public void test_equalsLjava_lang_Object() { * So since Windows reuses cursor handles, and other platforms do not, * it does not make sense to test whether cursor.equals(sameCursor). */ - Cursor cursor = new Cursor(display, SWT.CURSOR_WAIT); - Cursor otherCursor = new Cursor(display, SWT.CURSOR_CROSS); + final Cursor cursor = new Cursor(display, SWT.CURSOR_WAIT); + final Cursor otherCursor = new Cursor(display, SWT.CURSOR_CROSS); try { // Test Cursor.equals(Object) assertTrue("!cursor.equals((Object)null)", !cursor.equals((Object)null)); @@ -177,6 +192,16 @@ public void test_equalsLjava_lang_Object() { assertTrue("!cursor.equals((Cursor)null)", !cursor.equals((Cursor)null)); assertTrue("cursor.equals(cursor)", cursor.equals(cursor)); assertTrue("!cursor.equals(otherCursor)", !cursor.equals(otherCursor)); + testPerformance ("equals same", new Runnable () { + public void run() { + cursor.equals(cursor); + } + }); + testPerformance ("equals different", new Runnable () { + public void run() { + cursor.equals(otherCursor); + } + }); } finally { cursor.dispose(); otherCursor.dispose(); @@ -185,24 +210,43 @@ public void test_equalsLjava_lang_Object() { public void test_hashCode() { warnUnimpl("Test test_hashCode not written"); + + final Cursor cursor = new Cursor(display, SWT.CURSOR_WAIT); + testPerformance (new Runnable () { + public void run() { + cursor.hashCode(); + } + }); + cursor.dispose(); } public void test_isDisposed() { // Test Cursor.isDisposed() false - Cursor cursor = new Cursor(display, SWT.CURSOR_WAIT); + final Cursor cursor = new Cursor(display, SWT.CURSOR_WAIT); try { assertTrue("Cursor should not be disposed", !cursor.isDisposed()); + testPerformance("isDisposed()", new Runnable() { + public void run() { + cursor.isDisposed(); + } + }); } finally { // Test Cursor.isDisposed() true cursor.dispose(); assertTrue("Cursor should be disposed", cursor.isDisposed()); } + testPerformance("disposed isDisposed()", new Runnable() { + public void run() { + cursor.isDisposed(); + } + }); } public void test_toString() { Cursor cursor = new Cursor(display, SWT.CURSOR_WAIT); assertNotNull(cursor.toString()); assertTrue(cursor.toString().length() > 0); + cursor.dispose(); } public void test_win32_newLorg_eclipse_swt_graphics_DeviceI() { diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_DeviceData.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_DeviceData.java index c761475518..113cd72833 100644 --- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_DeviceData.java +++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_DeviceData.java @@ -40,6 +40,11 @@ public void test_Constructor() { DeviceData data = new DeviceData(); data.debug = true; data.tracking = true; + testPerformance(new Runnable() { + public void run() { + new DeviceData(); + } + }); } public static Test suite() { diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_Font.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_Font.java index 290b535fe4..655e0a3bb7 100644 --- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_Font.java +++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_Font.java @@ -114,6 +114,13 @@ public void test_ConstructorLorg_eclipse_swt_graphics_Device$Lorg_eclipse_swt_gr FontData[] returnedData = font.getFontData(); assertEquals(data,returnedData[0]); font.dispose(); + + final FontData fontData = new FontData(); + testPerformance(new Runnable() { + public void run() { + new Font(display, fontData).dispose(); + } + }); } public void test_ConstructorLorg_eclipse_swt_graphics_DeviceLorg_eclipse_swt_graphics_FontData() { @@ -176,6 +183,61 @@ public void test_ConstructorLorg_eclipse_swt_graphics_DeviceLorg_eclipse_swt_gra fail("No exception thrown for height < 0"); } catch (IllegalArgumentException e) { } + + testPerformance("normal", new Runnable() { + public void run() { + new Font(display, new FontData("", 10, SWT.NORMAL)).dispose(); + } + }); + + testPerformance("unknown name", new Runnable() { + public void run() { + // valid font with unknown name (strange, but apparently valid) + new Font(display, new FontData("bad-font", 10, SWT.NORMAL)).dispose(); + } + }); + + testPerformance("no height", new Runnable() { + public void run() { + // valid font with 0 height (strange, but apparently valid) + new Font(display, new FontData(SwtJunit.testFontName, 0, SWT.NORMAL)).dispose(); + } + }); + + testPerformance("100pt", new Runnable() { + public void run() { + // valid normal 100-point font + new Font(display, new FontData(SwtJunit.testFontName, 100, SWT.NORMAL)).dispose(); + } + }); + + testPerformance("10pt", new Runnable() { + public void run() { + // valid normal 10-point font + new Font(display, new FontData(SwtJunit.testFontName, 10, SWT.NORMAL)).dispose(); + } + }); + + testPerformance("bold", new Runnable() { + public void run() { + // valid bold 10-point font + new Font(display, new FontData(SwtJunit.testFontName, 10, SWT.BOLD)).dispose(); + } + }); + + testPerformance("italic", new Runnable() { + public void run() { + // valid italic 10-point font + new Font(display, new FontData(SwtJunit.testFontName, 10, SWT.ITALIC)).dispose(); + } + }); + + testPerformance("bold italic", new Runnable() { + public void run() { + // valid bold italic 10-point font + new Font(display, new FontData(SwtJunit.testFontName, 10, SWT.BOLD | SWT.ITALIC)).dispose(); + } + }); } public void test_ConstructorLorg_eclipse_swt_graphics_DeviceLjava_lang_StringII() { @@ -234,19 +296,92 @@ public void test_ConstructorLorg_eclipse_swt_graphics_DeviceLjava_lang_StringII( fail("No exception thrown for height < 0"); } catch (IllegalArgumentException e) { } + + testPerformance("no name", new Runnable() { + public void run() { + // valid font with no name (strange, but apparently valid) + new Font(display, "", 10, SWT.NORMAL).dispose(); + } + }); + + testPerformance("unknown name", new Runnable() { + public void run() { + // valid font with unknown name (strange, but apparently valid) + new Font(display, "bad-font", 10, SWT.NORMAL).dispose(); + } + }); + + testPerformance("no height", new Runnable() { + public void run() { + // valid font with 0 height (strange, but apparently valid) + new Font(display, SwtJunit.testFontName, 0, SWT.NORMAL).dispose(); + } + }); + + testPerformance("100pt", new Runnable() { + public void run() { + // valid normal 100-point font + new Font(display, SwtJunit.testFontName, 100, SWT.NORMAL).dispose(); + } + }); + + testPerformance("10pt", new Runnable() { + public void run() { + // valid normal 10-point font + new Font(display, SwtJunit.testFontName, 10, SWT.NORMAL).dispose(); + } + }); + + testPerformance("bold", new Runnable() { + public void run() { + // valid bold 10-point font + new Font(display, SwtJunit.testFontName, 10, SWT.BOLD).dispose(); + } + }); + + testPerformance("italic", new Runnable() { + public void run() { + // valid italic 10-point font + new Font(display, SwtJunit.testFontName, 10, SWT.ITALIC).dispose(); + } + }); + + testPerformance("bold italic", new Runnable() { + public void run() { + // valid bold italic 10-point font + new Font(display, SwtJunit.testFontName, 10, SWT.BOLD | SWT.ITALIC).dispose(); + } + }); + + testPerformance("null device", new Runnable() { + public void run() { + // device == null (valid) + new Font(null, SwtJunit.testFontName, 10, SWT.NORMAL).dispose(); + } + }); } public void test_dispose() { - Font font = new Font(display, SwtJunit.testFontName, 10, SWT.NORMAL); + final Font font = new Font(display, SwtJunit.testFontName, 10, SWT.NORMAL); assertFalse(font.isDisposed()); font.dispose(); assertTrue(font.isDisposed()); + testPerformance("disposed()", new Runnable() { + public void run() { + new Font(display, SwtJunit.testFontName, 10, SWT.NORMAL).dispose(); + } + }); + testPerformance("disposed dispose()", new Runnable() { + public void run() { + font.dispose(); + } + }); } public void test_equalsLjava_lang_Object() { // Fonts are only equal if their handles are the same (?!) - Font font = new Font(display, SwtJunit.testFontName, 10, SWT.NORMAL); - Font otherFont = new Font(display, SwtJunit.testFontName, 20, SWT.NORMAL); + final Font font = new Font(display, SwtJunit.testFontName, 10, SWT.NORMAL); + final Font otherFont = new Font(display, SwtJunit.testFontName, 20, SWT.NORMAL); try { // Test Font.equals(Object) assertTrue("!font.equals((Object)null)", !font.equals((Object)null)); @@ -255,6 +390,16 @@ public void test_equalsLjava_lang_Object() { assertTrue("!font.equals((Font)null)", !font.equals((Font)null)); assertTrue("font.equals(font)", font.equals(font)); assertTrue("!font.equals(otherFont)", !font.equals(otherFont)); + testPerformance("equals same", new Runnable() { + public void run() { + font.equals(font); + } + }); + testPerformance("equals different", new Runnable() { + public void run() { + font.equals(otherFont); + } + }); } finally { font.dispose(); otherFont.dispose(); @@ -323,27 +468,50 @@ public void test_getFontData() { } finally { font.dispose(); } + + final Font testFont = new Font(display, SwtJunit.testFontName, 40, SWT.BOLD | SWT.ITALIC); + testPerformance(new Runnable() { + public void run() { + testFont.getFontData(); + } + }); + testFont.dispose(); } public void test_hashCode() { Font font = new Font(display, SwtJunit.testFontName, 10, SWT.NORMAL); assertEquals(font,font); assertEquals(font.hashCode(),font.hashCode()); - Font boldFont = new Font(display, SwtJunit.testFontName, 10, SWT.BOLD); + final Font boldFont = new Font(display, SwtJunit.testFontName, 10, SWT.BOLD); assertFalse(font.hashCode() == boldFont.hashCode()); + testPerformance(new Runnable() { + public void run() { + boldFont.hashCode(); + } + }); boldFont.dispose(); font.dispose(); } public void test_isDisposed() { // Test Font.isDisposed() false - Font font = new Font(display, SwtJunit.testFontName, 10, SWT.NORMAL); + final Font font = new Font(display, SwtJunit.testFontName, 10, SWT.NORMAL); try { assertTrue("Font should not be disposed", !font.isDisposed()); + testPerformance ("isDisposed()", new Runnable() { + public void run() { + font.isDisposed(); + } + }); } finally { // Test Font.isDisposed() true font.dispose(); assertTrue("Font should be disposed", font.isDisposed()); + testPerformance ("disposed isDisposed()", new Runnable() { + public void run() { + font.isDisposed(); + } + }); } } diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_FontData.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_FontData.java index 1bc3480372..6081c5135f 100644 --- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_FontData.java +++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_FontData.java @@ -40,13 +40,23 @@ protected void tearDown() { public void test_Constructor() { // Test new FontData() FontData fd = new FontData(); + testPerformance (new Runnable() { + public void run() { + new FontData(); + } + }); } public void test_ConstructorLjava_lang_String() { // Test new FontData(String string) - FontData fd = new FontData(SwtJunit.testFontName, 10, SWT.NORMAL); + final FontData fd = new FontData(SwtJunit.testFontName, 10, SWT.NORMAL); FontData reconstructedFontData = new FontData(fd.toString()); assertEquals(fd, reconstructedFontData); + testPerformance(new Runnable() { + public void run() { + new FontData(fd.toString()); + } + }); } public void test_ConstructorLjava_lang_StringII() { @@ -88,38 +98,84 @@ public void test_ConstructorLjava_lang_StringII() { fail("No exception thrown for height < 0"); } catch (IllegalArgumentException e) { } + + testPerformance(new Runnable() { + public void run() { + // valid normal 10-point font data + new FontData(SwtJunit.testFontName, 10, SWT.NORMAL); + } + }); } public void test_equalsLjava_lang_Object() { - FontData fd1 = new FontData(SwtJunit.testFontName, 10, SWT.NORMAL); - FontData fd2 = new FontData(SwtJunit.testFontName, 10, SWT.NORMAL); + final FontData fd1 = new FontData(SwtJunit.testFontName, 10, SWT.NORMAL); + final FontData fd2 = new FontData(SwtJunit.testFontName, 10, SWT.NORMAL); assertEquals(fd1,fd1); assertEquals(fd1,fd2); + testPerformance("equals same", new Runnable() { + public void run() { + assertEquals(fd1,fd1); + } + }); + testPerformance("equals different", new Runnable() { + public void run() { + assertEquals(fd1,fd2); + } + }); } public void test_getHeight() { // Font.getHeight() tested in test_setHeightI + final FontData data = new FontData(SwtJunit.testFontName, 10, SWT.NORMAL); + testPerformance(new Runnable() { + public void run() { + data.getHeight(); + } + }); } public void test_getLocale() { // FontData.getLocale() tested in test_setLocaleLjava_lang_String + final FontData data = new FontData(SwtJunit.testFontName, 10, SWT.NORMAL); + testPerformance(new Runnable() { + public void run() { + data.getLocale(); + } + }); } public void test_getName() { // Font.getName() tested in test_setNameLjava_lang_String + final FontData data = new FontData(SwtJunit.testFontName, 10, SWT.NORMAL); + testPerformance(new Runnable() { + public void run() { + data.getName(); + } + }); } public void test_getStyle() { // Font.getStyle() tested in test_setStyleI + final FontData data = new FontData(SwtJunit.testFontName, 10, SWT.NORMAL); + testPerformance(new Runnable() { + public void run() { + data.getStyle(); + } + }); } public void test_hashCode() { - FontData fd1 = new FontData(SwtJunit.testFontName, 10, SWT.NORMAL); + final FontData fd1 = new FontData(SwtJunit.testFontName, 10, SWT.NORMAL); FontData fd2 = new FontData(SwtJunit.testFontName, 10, SWT.NORMAL); assertEquals(fd1,fd2); assertEquals(fd1.hashCode(),fd2.hashCode()); FontData fd3 = new FontData(SwtJunit.testFontName, 10, SWT.BOLD); assertFalse(fd1.hashCode() == fd3.hashCode()); + testPerformance(new Runnable() { + public void run() { + fd1.hashCode(); + } + }); } public void test_setHeightI() { @@ -151,6 +207,13 @@ public void test_setHeightI() { fontData.setHeight(height); assertEquals("Wrong height", fontData.getHeight(), height); } + + final FontData data = new FontData(); + testPerformance(new Runnable() { + public void run() { + data.setHeight(10); + } + }); } public void test_setLocaleLjava_lang_String() { @@ -158,6 +221,12 @@ public void test_setLocaleLjava_lang_String() { Locale locale = Locale.ENGLISH; fd.setLocale(locale.toString()); assertEquals(Locale.ENGLISH.toString(),fd.getLocale()); + final FontData data = new FontData(); + testPerformance(new Runnable() { + public void run() { + data.setLocale(Locale.ENGLISH.toString()); + } + }); } public void test_setNameLjava_lang_String() { @@ -186,6 +255,13 @@ public void test_setNameLjava_lang_String() { fail("No exception thrown for name == null"); } catch (IllegalArgumentException e) { } + + final FontData data = new FontData(); + testPerformance(new Runnable() { + public void run() { + data.setName("name"); + } + }); } public void test_setStyleI() { @@ -211,6 +287,12 @@ public void test_setStyleI() { fontData.setStyle(SWT.NORMAL); assertEquals("Wrong style", fontData.getStyle(), SWT.NORMAL); } + final FontData data = new FontData(); + testPerformance(new Runnable() { + public void run() { + data.setStyle(SWT.ITALIC); + } + }); } public void test_toString() { diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_FontMetrics.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_FontMetrics.java index 5d04d83a5c..4f16f89bbb 100644 --- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_FontMetrics.java +++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_FontMetrics.java @@ -43,42 +43,77 @@ protected void tearDown() { } public void test_equalsLjava_lang_Object() { - FontMetrics fm1 = gc.getFontMetrics(); - FontMetrics fm2 = gc.getFontMetrics(); + final FontMetrics fm1 = gc.getFontMetrics(); + final FontMetrics fm2 = gc.getFontMetrics(); assertTrue(fm1.equals(fm2)); + testPerformance(new Runnable() { + public void run() { + fm1.equals(fm2); + } + }); } public void test_getAscent() { - FontMetrics fm = gc.getFontMetrics(); + final FontMetrics fm = gc.getFontMetrics(); fm.getAscent(); + testPerformance(new Runnable() { + public void run() { + fm.getAscent(); + } + }); } public void test_getAverageCharWidth() { - FontMetrics fm = gc.getFontMetrics(); + final FontMetrics fm = gc.getFontMetrics(); fm.getAverageCharWidth(); + testPerformance(new Runnable() { + public void run() { + fm.getAverageCharWidth(); + } + }); } public void test_getDescent() { - FontMetrics fm = gc.getFontMetrics(); + final FontMetrics fm = gc.getFontMetrics(); fm.getDescent(); + testPerformance(new Runnable() { + public void run() { + fm.getDescent(); + } + }); } public void test_getHeight() { - FontMetrics fm = gc.getFontMetrics(); + final FontMetrics fm = gc.getFontMetrics(); fm.getHeight(); + testPerformance(new Runnable() { + public void run() { + fm.getHeight(); + } + }); } public void test_getLeading() { - FontMetrics fm = gc.getFontMetrics(); + final FontMetrics fm = gc.getFontMetrics(); fm.getLeading(); + testPerformance(new Runnable() { + public void run() { + fm.getLeading(); + } + }); } public void test_hashCode() { - FontMetrics fm1 = gc.getFontMetrics(); + final FontMetrics fm1 = gc.getFontMetrics(); FontMetrics fm2 = gc.getFontMetrics(); if (fm1.equals(fm2)) { assertEquals(fm1.hashCode(), fm2.hashCode()); } + testPerformance(new Runnable() { + public void run() { + fm1.hashCode(); + } + }); } public void test_win32_newLorg_eclipse_swt_internal_win32_TEXTMETRIC() { diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_GC.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_GC.java index 6da73cea70..ea8a43bbeb 100644 --- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_GC.java +++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_GC.java @@ -91,6 +91,20 @@ public void test_ConstructorLorg_eclipse_swt_graphics_Drawable() { } catch (IllegalAccessException e) { e.printStackTrace(); } + + final Object printer; + try { + printer = printerClass.newInstance(); + } catch (InstantiationException e1) { + return; + } catch (IllegalAccessException e1) { + return; + } + testPerformance(new Runnable() { + public void run() { + new GC((Printer) printer).dispose(); + } + }); } public void test_ConstructorLorg_eclipse_swt_graphics_DrawableI() { @@ -145,6 +159,19 @@ public void test_ConstructorLorg_eclipse_swt_graphics_DrawableI() { } catch (IllegalAccessException e) { e.printStackTrace(); } + final Object printer; + try { + printer = printerClass.newInstance(); + } catch (InstantiationException e1) { + return; + } catch (IllegalAccessException e1) { + return; + } + testPerformance(new Runnable() { + public void run() { + new GC((Printer) printer, SWT.RIGHT_TO_LEFT).dispose(); + } + }); } public void test_copyAreaIIIIII() { @@ -152,10 +179,10 @@ public void test_copyAreaIIIIII() { Color blue = display.getSystemColor(SWT.COLOR_BLUE); RGB whiteRGB = getRealRGB(white); RGB blueRGB = getRealRGB(blue); - int width = 20; - int height = 20; - int destX = 10; - int destY = 50; + final int width = 20; + final int height = 20; + final int destX = 10; + final int destY = 50; gc.setBackground(white); gc.setForeground(white); @@ -174,6 +201,12 @@ public void test_copyAreaIIIIII() { assertEquals(":c:", blueRGB, palette.getRGB(pixel)); pixel = imageData.getPixel(destX + 11, destY); assertEquals(":d:", whiteRGB, palette.getRGB(pixel)); + + testPerformance(new Runnable() { + public void run() { + gc.copyArea(0, 0, width, height, destX, destY); + } + }); } public void test_copyAreaLorg_eclipse_swt_graphics_ImageII() { @@ -187,7 +220,7 @@ public void test_copyAreaLorg_eclipse_swt_graphics_ImageII() { gc.fillRectangle(image.getBounds()); gc.setForeground(blue); gc.drawLine(5, 0, 10, 0); - Image image = new Image(display, 12, 12); + final Image image = new Image(display, 12, 12); gc.copyArea(image, 0, 0); ImageData imageData = image.getImageData(); PaletteData palette = imageData.palette; @@ -199,19 +232,47 @@ public void test_copyAreaLorg_eclipse_swt_graphics_ImageII() { assertEquals(":c:", blueRGB, palette.getRGB(pixel)); pixel = imageData.getPixel(11, 0); assertEquals(":d:", whiteRGB, palette.getRGB(pixel)); + + testPerformance(new Runnable() { + public void run() { + gc.copyArea(image, 0, 0); + } + }); image.dispose(); } public void test_dispose() { gc.dispose(); + final Image image = new Image(display, 10, 10); + testPerformance("dispose()", new Runnable() { + public void run() { + new GC(image).dispose(); + } + }); + image.dispose(); + testPerformance("dispose disposed()", new Runnable() { + public void run() { + gc.dispose(); + } + }); } public void test_drawArcIIIIII() { - gc.drawArc(10, 20, 50, 25, 90, 90); + gc.drawArc(10, 20, 50, 25, 90, 90); + testPerformance(new Runnable() { + public void run() { + gc.drawArc(10, 20, 50, 25, 90, 90); + } + }); } public void test_drawFocusIIII() { - gc.drawFocus(1, 1, 50, 25); + gc.drawFocus(1, 1, 50, 25); + testPerformance(new Runnable() { + public void run() { + gc.drawFocus(1, 1, 50, 25); + } + }); } public void test_drawImageLorg_eclipse_swt_graphics_ImageII() { @@ -228,17 +289,17 @@ public void test_drawImageLorg_eclipse_swt_graphics_ImageII() { else data.setPixel(x, y, paletteData.getPixel(c3.getRGB())); } } - Image image = new Image(display, data); + final Image image = new Image(display, data); data = image.getImageData(); data.transparentPixel = paletteData.getPixel(c1.getRGB()); - Image imageTransparent = new Image(display, data); + final Image imageTransparent = new Image(display, data); data.transparentPixel = -1; for (int y = 0; y < data.height; y++) { for (int x = 0; x < data.width; x++) { data.setAlpha(x, y, 127); } } - Image imageAlpha = new Image(display, data); + final Image imageAlpha = new Image(display, data); gc.drawImage(image, 100, 100); gc.drawImage(imageTransparent, 130, 100); @@ -249,6 +310,26 @@ public void test_drawImageLorg_eclipse_swt_graphics_ImageII() { } catch (IllegalArgumentException e) { } + final Image imageErase = new Image(display, image.getBounds().width, image.getBounds().height); + testPerformance("normal image", new Runnable() { + public void run() { + gc.drawImage(imageErase, 100, 100); + gc.drawImage(image, 100, 100); + } + }); + testPerformance("transparent image", new Runnable() { + public void run() { + gc.drawImage(imageErase, 130, 100); + gc.drawImage(imageTransparent, 130, 100); + } + }); + testPerformance("alpha image", new Runnable() { + public void run() { + gc.drawImage(imageErase, 160, 100); + gc.drawImage(imageAlpha, 160, 100); + } + }); + imageErase.dispose(); image.dispose(); imageTransparent.dispose(); imageAlpha.dispose(); |