summaryrefslogtreecommitdiffstats
path: root/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/SwtTestCase.java
blob: d46197df2ea1e2a5be1c5a16509ac1b27c95ce41 (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
package org.eclipse.swt.tests.junit;

/*

 * (c) Copyright IBM Corp. 2000, 2002. All rights reserved.
 * This file is 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

 */

import java.lang.reflect.*;
import junit.framework.*;

public class SwtTestCase extends TestCase {
	/**

	 * The following flags are used to mark test cases that

	 * are not handled correctly by SWT at this time, or test

	 * cases that maybe themselves dubious (eg. when the correct

	 * behaviour may not be clear). Most of these flagged test

	 * cases involve handling error conditions.

	 *

	 * Setting these flags to true will run those tests. As api

	 * is implemented this gives us a convenient way to include

	 * it in the junit tests.

	 */

	// call should result in an 'Argument cannot be null' SWT error

	public static boolean fCheckSwtNullExceptions = false;

	// an out of range value is not handled gracefully according to our SWT policy

	public static boolean fCheckOutOfRangeBehaviour = false;

	// run test cases that may themselves be dubious

	// these should be eventually checked to see if 

	// there is a valid failure or the test is bogus

	public static boolean fCheckBogusTestCases = false;

	// check multi select tree api

	public static boolean fCheckMultiSelectTree = false;

	// check visibility api (eg in menu)

	public static boolean fCheckVisibility = false;

	// run test cases that check SWT policy not covered by the flags above

	public static boolean fCheckSWTPolicy = false;

	// make dialog open calls, operator must then close them

	public static boolean fTestDialogOpen = false;

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

static public void assertEquals(String message, Object expected[], Object actual[]) {
	if (expected == null && actual == null)
		return;
	boolean equal = false;
	if (expected != null && actual != null && expected.length == actual.length) {
		if (expected.length == 0)
			return;
		equal = true;
		for (int i = 0; i < expected.length; i++) {
			if (!expected[i].equals(actual[i])) {
				equal = false;
			}
		}
	}
	if (!equal) {
		failNotEquals(message, expected, actual);
	}
}
static public void assertEquals(Object expected[], Object actual[]) {
    assertEquals(null, expected, actual);
}
static public void assertEquals(String message, int expected[], int actual[]) {
	if (expected == null && actual == null)
		return;
	boolean equal = false;
	if (expected != null && actual != null && expected.length == actual.length) {
		if (expected.length == 0)
			return;
		equal = true;
		for (int i = 0; i < expected.length; i++) {
			if (expected[i] != actual[i]) {
				equal = false;
			}
		}
	}
	if (!equal) {
		failNotEquals(message, expected, actual);
	}
}
static public void assertEquals(int expected[], int actual[]) {
    assertEquals(null, expected, actual);
}
// copied exactly from junit.framework.TestCase so that it can be called from here even though private

static private void failNotEquals(String message, Object expected, Object actual) {
	String formatted= "";
	if (message != null)
		formatted= message+" ";
	fail(formatted+"expected:<"+expected+"> but was:<"+actual+">");
}

protected void warnUnimpl(String message) {
	//System.out.println(this.getClass() + ": " + message);

	AllTests.unimplementedMethods++;
}
}