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

/*
 * (c) Copyright IBM Corp. 2000, 2001.
 * All Rights Reserved
 */

import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.graphics.*;
import junit.framework.*;
import junit.textui.*;

/**
 * Automated Test Suite for class org.eclipse.swt.widgets.Item
 *
 * @see org.eclipse.swt.widgets.Item
 */
public class Test_org_eclipse_swt_widgets_Item extends Test_org_eclipse_swt_widgets_Widget {

Item item;
protected Image[] images = new Image [3];

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

protected void setUp() {
	super.setUp();
	loadImages();
}

protected void tearDown() {
	super.tearDown();
	freeImages();
}

// this method must be private or protected so the auto-gen tool keeps it

private void loadImages() {
	java.io.InputStream in1 = this.getClass().getResourceAsStream("folder.bmp");
	java.io.InputStream in2 = this.getClass().getResourceAsStream("folderOpen.bmp");
	java.io.InputStream in3 = this.getClass().getResourceAsStream("target.bmp");
	Display display = shell.getDisplay();
		
	images [0] = new Image (display, in1);
	images [1] = new Image (display, in2);
	images [2] = new Image (display, in3);
	
	try {
		in1.close();
		in2.close();
		in3.close();
	} catch (java.io.IOException e) {
	}
}
protected void setWidget(Widget widget) {
	item = (Item) widget;
	super.setWidget(widget);
}
// this method must be private or protected so the auto-gen tool keeps it

private void freeImages() {
	for (int i=0; i<images.length; i++) {
		if (images[i] != null)
			images[i].dispose();
	}
}

public void test_getImage() {
	// tested in test_setImageLorg_eclipse_swt_graphics_Image

}

public void test_getText() {
	// tested in test_setTextLjava_lang_String

}

public void test_setImageLorg_eclipse_swt_graphics_Image() {
	assertNull(item.getImage());
	item.setImage(images[0]);
	assertEquals(images[0], item.getImage());
	assertTrue(item.getImage() != images[1]);
	item.setImage(null);
	assertNull(item.getImage());
}

public void test_setTextLjava_lang_String() {
	String testStr = "test string";
	item.setText(testStr);
	assertTrue("a", item.getText().equals(testStr));
	item.setText("");
	assertTrue("b", item.getText().equals(""));
	if (fCheckSwtNullExceptions) {
		try {
			item.setText(null);
			fail("No exception thrown for string == null");
		}
		catch (IllegalArgumentException e) {
		}
	}
}

public static java.util.Vector methodNames() {
	java.util.Vector methodNames = new java.util.Vector();
	methodNames.addElement("test_getImage");
	methodNames.addElement("test_getText");
	methodNames.addElement("test_setImageLorg_eclipse_swt_graphics_Image");
	methodNames.addElement("test_setTextLjava_lang_String");
	methodNames.addAll(Test_org_eclipse_swt_widgets_Widget.methodNames()); // add superclass method names
	return methodNames;
}
protected void runTest() throws Throwable {
	if (getName().equals("test_getImage")) test_getImage();
	else if (getName().equals("test_getText")) test_getText();
	else if (getName().equals("test_setImageLorg_eclipse_swt_graphics_Image")) test_setImageLorg_eclipse_swt_graphics_Image();
	else if (getName().equals("test_setTextLjava_lang_String")) test_setTextLjava_lang_String();
	else super.runTest();
}
}