Skip to main content
summaryrefslogtreecommitdiffstats
blob: 4651f7addfe36bb1d1296a6f2dee08ffa84bc168 (plain) (blame)
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
/*******************************************************************************
 * Copyright (c) 2000, 2005 IBM Corporation 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:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.swt.tests.junit.performance;


import java.io.*;
import java.net.URL;

import junit.framework.TestCase;

import org.eclipse.swt.SWT;
import org.eclipse.swt.internal.*;
import org.eclipse.test.performance.*;


public class SwtPerformanceTestCase extends TestCase {
	// used to specify verbose mode, if true unimplemented warning messages will 
	// be written to System.out
	public static boolean verbose = false;

	public final static boolean isGTK = SWT.getPlatform().equals("gtk");
	public final static boolean isWindows = SWT.getPlatform().startsWith("win32");
	
	// allow specific image formats to be tested
	public static String[] imageFormats = new String[] {"bmp", "jpg", "gif", "png"};
	public static String[] imageFilenames = new String[] {"folder", "folderOpen", "target"};
	public static String[] transparentImageFilenames = new String[] {"transparent.png"};

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

protected PerformanceMeter createMeter(String id) {
	Performance performance = Performance.getDefault();
	String scenarioId = "org.eclipse.swt.test." + id;
	PerformanceMeter meter = performance.createPerformanceMeter(scenarioId);
	performance.tagAsSummary(meter, id, Dimension.ELAPSED_PROCESS);
	return meter;
}

protected void disposeMeter(PerformanceMeter meter) {
	try {
		meter.commit();
		Performance.getDefault().assertPerformance(meter);
	} finally {
		meter.dispose();
	}
}

protected String getPath(String fileName) {
	String urlPath;
	
	String pluginPath = System.getProperty("PLUGIN_PATH");
	if (verbose) {
		System.out.println("PLUGIN_PATH <"+pluginPath+">");
	}
	if (pluginPath == null) {
		URL url = getClass().getClassLoader().getResource(fileName);
		if (url == null) {
			fail("URL == null for file " + fileName);
		}
		urlPath = url.getFile();
	} else {
		urlPath = pluginPath + "/data/" + fileName;
	}
	
	if (File.separatorChar != '/') urlPath = urlPath.replace('/', File.separatorChar);	
	if (isWindows && urlPath.indexOf(File.separatorChar) == 0) urlPath = urlPath.substring(1);
	urlPath = urlPath.replaceAll("%20", " ");	
	
	if (verbose) {
		System.out.println("Resolved file name for " + fileName + " = " + urlPath);
	}
	return urlPath;
}

protected boolean isJ2ME() {
	try {
		Compatibility.newFileInputStream("");
	} catch (FileNotFoundException e) {
		return false;
	} catch (IOException e) {
	}
	return true;
}

}

Back to the top