summaryrefslogtreecommitdiffstats
path: root/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/performance/Test_org_eclipse_swt_graphics_Font.java
blob: 91d3cf8485394d9fd1e3ae6a9c089d9aaec58167 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
/*******************************************************************************
 * Copyright (c) 2000, 2003 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials 
 * are made available under the terms of the Common Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.swt.tests.junit.performance;


import org.eclipse.swt.*;
import org.eclipse.swt.tests.junit.SwtJunit;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.test.performance.PerformanceMeter;

import junit.framework.*;
import junit.textui.*;

/**
 * Automated Performance Test Suite for class org.eclipse.swt.graphics.Font
 *
 * @see org.eclipse.swt.graphics.Font
 */
public class Test_org_eclipse_swt_graphics_Font extends SwtPerformanceTestCase {
	Display display;

public Test_org_eclipse_swt_graphics_Font(String name) {
	super(name);
}

public static void main(String[] args) {
	TestRunner.run(suite());
}

protected void setUp() throws Exception {
	super.setUp();
	display = Display.getDefault();
}

public void test_ConstructorLorg_eclipse_swt_graphics_Device$Lorg_eclipse_swt_graphics_FontData() {
	final int COUNT = 160000;
	
	FontData[] data = new FontData [1];
	data[0] = new FontData (SwtJunit.testFontName, 10, SWT.BOLD | SWT.ITALIC); 
	
	PerformanceMeter meter = createMeter("Font constr.(Device,$FontData");
	meter.start();
	for (int i = 0; i < COUNT; i++) {
		/*
		* This test is not really valid since it's measuring both creation and
		* disposal of the Fonts.  This is done because attempting to pre-create
		* more than 20000 Fonts for disposal causes a No More Handles error.
		*/ 
		new Font(display, data).dispose();
	}
	meter.stop();

	disposeMeter(meter);
}

public void test_ConstructorLorg_eclipse_swt_graphics_DeviceLorg_eclipse_swt_graphics_FontData() {
	final int COUNT = 170000;
	
	FontData data = new FontData (SwtJunit.testFontName, 10, SWT.BOLD | SWT.ITALIC);
	
	PerformanceMeter meter = createMeter("Font constr.(Device,FontData)");
	meter.start();
	for (int i = 0; i < COUNT; i++) {
		/*
		* This test is not really valid since it's measuring both creation and
		* disposal of the Fonts.  This is done because attempting to pre-create
		* more than 20000 Fonts for disposal causes a No More Handles error.
		*/ 
		new Font(display, data).dispose();
	}
	meter.stop();

	disposeMeter(meter);
}

public void test_ConstructorLorg_eclipse_swt_graphics_DeviceLjava_lang_StringII() {
	final int COUNT = 150000;
	
	PerformanceMeter meter = createMeter("Font constr.(Device,String,II) - no name");
	meter.start();
	for (int i = 0; i < COUNT; i++) {
		/*
		* This test is not really valid since it's measuring both creation and
		* disposal of the Fonts.  This is done because attempting to pre-create
		* more than 20000 Fonts for disposal causes a No More Handles error.
		*/ 
		// valid font with no name
		new Font(display, "", 10, SWT.NORMAL).dispose();
	}
	meter.stop();

	disposeMeter(meter);
		
	meter = createMeter("Font constr.(Device,String,II) - unknown");
	meter.start();
	for (int i = 0; i < COUNT; i++) {
		/*
		* This test is not really valid since it's measuring both creation and
		* disposal of the Fonts.  This is done because attempting to pre-create
		* more than 20000 Fonts for disposal causes a No More Handles error.
		*/ 
		// valid font with unknown name
		new Font(display, "bad-font", 10, SWT.NORMAL).dispose();
	}
	meter.stop();

	disposeMeter(meter);
	
	meter = createMeter("Font constr.(Device,String,II) - 0 height");
	meter.start();
	for (int i = 0; i < COUNT; i++) {
		/*
		* This test is not really valid since it's measuring both creation and
		* disposal of the Fonts.  This is done because attempting to pre-create
		* more than 20000 Fonts for disposal causes a No More Handles error.
		*/ 
		// valid font with 0 height
		new Font(display, SwtJunit.testFontName, 0, SWT.NORMAL).dispose();
	}
	meter.stop();

	disposeMeter(meter);

	meter = createMeter("Font constr.(Device,String,II) - 10 pt");
	meter.start();
	for (int i = 0; i < COUNT; i++) {
		/*
		* This test is not really valid since it's measuring both creation and
		* disposal of the Fonts.  This is done because attempting to pre-create
		* more than 20000 Fonts for disposal causes a No More Handles error.
		*/ 
		// valid normal 10-point font
		new Font(display, SwtJunit.testFontName, 10, SWT.NORMAL).dispose();
	}
	meter.stop();

	disposeMeter(meter);

	meter = createMeter("Font constr.(Device,String,II) - 100 pt");
	meter.start();
	for (int i = 0; i < COUNT; i++) {
		/*
		* This test is not really valid since it's measuring both creation and
		* disposal of the Fonts.  This is done because attempting to pre-create
		* more than 20000 Fonts for disposal causes a No More Handles error.
		*/ 
		// valid normal 100-point font
		new Font(display, SwtJunit.testFontName, 100, SWT.NORMAL).dispose();
	}
	meter.stop();

	disposeMeter(meter);
	
	meter = createMeter("Font constr.(Device,String,II) - BI");
	meter.start();
	for (int i = 0; i < COUNT; i++) {
		/*
		* This test is not really valid since it's measuring both creation and
		* disposal of the Fonts.  This is done because attempting to pre-create
		* more than 20000 Fonts for disposal causes a No More Handles error.
		*/ 
		// valid bold italic 10-point font
		new Font(display, SwtJunit.testFontName, 10, SWT.BOLD | SWT.ITALIC).dispose();
	}
	meter.stop();

	disposeMeter(meter);

	meter = createMeter("Font constr.(Device,String,II) - null dev");
	meter.start();
	for (int i = 0; i < COUNT; i++) {
		/*
		* This test is not really valid since it's measuring both creation and
		* disposal of the Fonts.  This is done because attempting to pre-create
		* more than 20000 Fonts for disposal causes a No More Handles error.
		*/ 
		// device == null (valid)
		new Font(null, SwtJunit.testFontName, 10, SWT.NORMAL).dispose();
	}
	meter.stop();

	disposeMeter(meter);
}

public void test_dispose() {
	final int COUNT = 55000000;
	
	/*
	 * The typical dispose() case is covered in the constructor tests, since
	 * they must dispose created Fonts within their timed blocks. 
	 */

	Font disposedFont = new Font(display, SwtJunit.testFontName, 10, SWT.NORMAL);
	disposedFont.dispose();

	PerformanceMeter meter = createMeter("Font dispose - disposed");
	meter.start();
	for (int i = 0; i < COUNT; i++) {
		disposedFont.dispose();
	}
	meter.stop();
	
    disposeMeter(meter);
}

public void test_equalsLjava_lang_Object() {
	final int COUNT = 57000000;
	
	// Fonts are only equal if their handles are the same
	Font font = new Font(display, SwtJunit.testFontName, 10, SWT.NORMAL);

	PerformanceMeter meter = createMeter("Font equals - yes");
	meter.start();
	for (int i = 0; i < COUNT; i++) {
		font.equals(font);	// same
	}
	meter.stop();

	font.dispose();
	
	disposeMeter(meter);
	
	font = new Font(display, SwtJunit.testFontName, 10, SWT.NORMAL);
	Font otherFont = new Font(display, SwtJunit.testFontName, 20, SWT.NORMAL);

	meter = createMeter("Font equals - no");
	meter.start();
	for (int i = 0; i < COUNT; i++) {
		font.equals(otherFont);	// different
	}
	meter.stop();

	font.dispose();
	otherFont.dispose();
	
	disposeMeter(meter);
}

public void test_getFontData() {
	final int COUNT = 250000;
	
	Font font = new Font(display, SwtJunit.testFontName, 40, SWT.BOLD | SWT.ITALIC);
	
	PerformanceMeter meter = createMeter("Font getFontData");
	meter.start();
	for (int i = 0; i < COUNT; i++) {
		font.getFontData();
	}
	meter.stop();
	
	font.dispose();
	
	disposeMeter(meter);
}

public void test_hashCode() {
	final int COUNT = 600000000;
	
	Font font = new Font(display, SwtJunit.testFontName, 40, SWT.BOLD | SWT.ITALIC);
	
	PerformanceMeter meter = createMeter("Font hashCode");
	meter.start();
	for (int i = 0; i < COUNT; i++) {
		font.hashCode();
	}
	meter.stop();
	
	font.dispose();
	
	disposeMeter(meter);
}

public void test_isDisposed() {
	final int COUNT = 500000000;
	
	Font font = new Font(display, SwtJunit.testFontName, 10, SWT.NORMAL);
	
	PerformanceMeter meter = createMeter("Font isDisposed - no");
	meter.start();
	for (int i = 0; i < COUNT; i++) {
		font.isDisposed();	// not disposed
	}
	meter.stop();
	
	font.dispose();
	
	disposeMeter(meter);
	
	meter = createMeter("Font isDisposed - yes");
	meter.start();
	for (int i = 0; i < COUNT; i++) {
		font.isDisposed();	// disposed
	}
	meter.stop();
	
	disposeMeter(meter);
}

public void test_win32_newLorg_eclipse_swt_graphics_DeviceI() {
	// do not test - Windows only
}

public static Test suite() {
	TestSuite suite = new TestSuite();
	java.util.Vector methodNames = methodNames();
	java.util.Enumeration e = methodNames.elements();
	while (e.hasMoreElements()) {
		suite.addTest(new Test_org_eclipse_swt_graphics_Font((String)e.nextElement()));
	}
	return suite;
}
public static java.util.Vector methodNames() {
	java.util.Vector methodNames = new java.util.Vector();
	methodNames.addElement("test_ConstructorLorg_eclipse_swt_graphics_Device$Lorg_eclipse_swt_graphics_FontData");
	methodNames.addElement("test_ConstructorLorg_eclipse_swt_graphics_DeviceLorg_eclipse_swt_graphics_FontData");
	methodNames.addElement("test_ConstructorLorg_eclipse_swt_graphics_DeviceLjava_lang_StringII");
	methodNames.addElement("test_dispose");
	methodNames.addElement("test_equalsLjava_lang_Object");
	methodNames.addElement("test_getFontData");
	methodNames.addElement("test_hashCode");
	methodNames.addElement("test_isDisposed");
	methodNames.addElement("test_win32_newLorg_eclipse_swt_graphics_DeviceI");
	return methodNames;
}
protected void runTest() throws Throwable {
	if (getName().equals("test_ConstructorLorg_eclipse_swt_graphics_Device$Lorg_eclipse_swt_graphics_FontData")) test_ConstructorLorg_eclipse_swt_graphics_Device$Lorg_eclipse_swt_graphics_FontData();
	else if (getName().equals("test_ConstructorLorg_eclipse_swt_graphics_DeviceLorg_eclipse_swt_graphics_FontData")) test_ConstructorLorg_eclipse_swt_graphics_DeviceLorg_eclipse_swt_graphics_FontData();
	else if (getName().equals("test_ConstructorLorg_eclipse_swt_graphics_DeviceLjava_lang_StringII")) test_ConstructorLorg_eclipse_swt_graphics_DeviceLjava_lang_StringII();
	else if (getName().equals("test_dispose")) test_dispose();
	else if (getName().equals("test_equalsLjava_lang_Object")) test_equalsLjava_lang_Object();
	else if (getName().equals("test_getFontData")) test_getFontData();
	else if (getName().equals("test_hashCode")) test_hashCode();
	else if (getName().equals("test_isDisposed")) test_isDisposed();
	else if (getName().equals("test_win32_newLorg_eclipse_swt_graphics_DeviceI")) test_win32_newLorg_eclipse_swt_graphics_DeviceI();
}
}