Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 8aff3d48fab7e2a50585f9f4bebda60916c4d32b (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
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
/*******************************************************************************
 * Copyright (c) 2000, 2015 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.swt.tests.junit;


import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.CoolBar;
import org.eclipse.swt.widgets.CoolItem;
import org.junit.Before;
import org.junit.Test;

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

@Override
@Before
public void setUp() {
	super.setUp();
	CoolBar coolBar = new CoolBar(shell, 0);
	CoolItem coolItem = new CoolItem(coolBar, 0);
	setWidget(coolItem);
}

@Test
public void test_ConstructorLorg_eclipse_swt_widgets_CoolBarI() {
	CoolBar coolBar = new CoolBar(shell, 0);
	new CoolItem(coolBar, 0);

	try {
		new CoolItem(null, 0);
		fail("No exception thrown for parent == null");
	}
	catch (IllegalArgumentException e) {
	}
}

@Test
public void test_ConstructorLorg_eclipse_swt_widgets_CoolBarII() {
	CoolBar coolBar = new CoolBar(shell, 0);
	CoolItem coolItem = new CoolItem(coolBar, 0, 0);
	try {
		coolItem = new CoolItem(coolBar, 0, -1);
		fail("No exception thrown for index == -1");
	}
	catch (IllegalArgumentException e){
	}
	try {
		coolItem = new CoolItem(coolBar, 0, 2);
		fail("No exception thrown for index == 2");
	}
	catch (IllegalArgumentException e){
	}
	assertEquals(1, coolBar.getItemCount());
	coolItem = new CoolItem(coolBar, 0, 1);
	assertEquals(2, coolBar.getItemCount());
	coolItem = new CoolItem(coolBar, 0, 0);
	assertEquals(3, coolBar.getItemCount());
	assertEquals(coolItem, coolBar.getItem(0));
}

@Test
public void test_computeSizeII() {
	CoolBar coolBar = new CoolBar(shell, 0);
	CoolItem coolItem = new CoolItem(coolBar, 0);
	Button button = new Button(coolBar, SWT.PUSH);
	button.setText("foo");

	Point size = coolItem.computeSize(SWT.DEFAULT, SWT.DEFAULT);
	coolItem.setControl(button);
	Point size2 = coolItem.computeSize(SWT.DEFAULT, SWT.DEFAULT);
	assertTrue(size2.x == size.x);

	size = coolItem.computeSize(50, 25);
	size2 = coolItem.computeSize(100, 25);
	assertEquals(size.x + 50, size2.x);
	assertEquals(size.y, size2.y);

	size = coolItem.computeSize(1,1);
	size2 = coolItem.computeSize(26, 26);
	assertEquals(25, size2.x - size.x);
}

@Test
public void test_getBounds() {
	CoolBar coolBar = new CoolBar(shell, 0);
	CoolItem coolItem = new CoolItem(coolBar, 0);
	Button button = new Button(coolBar, SWT.PUSH);
	button.setText("foo");
	coolItem.setControl(button);

	Rectangle rect = coolItem.getBounds();
	Point size = coolItem.getSize();
	assertEquals(size.x, rect.width);
	assertEquals(size.y, rect.height);

	coolItem.setSize(25, 25);
	rect = coolItem.getBounds();
	coolItem.setSize(100, 25);
	Rectangle newRect = coolItem.getBounds();
	assertEquals(rect.width + 75, newRect.width);
	assertEquals(rect.x, newRect.x);
	assertEquals(rect.y, newRect.y);
}

@Test
public void test_getControl() {
	CoolBar coolBar = new CoolBar(shell, 0);
	CoolItem coolItem = new CoolItem(coolBar, 0);
	assertNull(coolItem.getControl());

	Button button = new Button(coolBar, SWT.PUSH);
	coolItem.setControl(button);
	Control control = coolItem.getControl();
	assertEquals(button, control);

	button = new Button(coolBar, SWT.PUSH);
	coolItem.setControl(button);
	control = coolItem.getControl();
	assertEquals(button, control);
}

@Test
public void test_getParent() {
	CoolBar coolBar = new CoolBar(shell, 0);
	CoolItem coolItem = new CoolItem(coolBar, 0);
	assertEquals(coolBar, coolItem.getParent());
}

@Test
public void test_getPreferredSize() {
	CoolBar coolBar = new CoolBar(shell, 0);
	CoolItem coolItem = new CoolItem(coolBar, 0);
	Button button = new Button(coolBar, SWT.PUSH);
	button.setText("foobar");
	coolItem.setControl(button);

	Point pref = coolItem.getPreferredSize();
	coolItem.setPreferredSize(pref);
	assertEquals(pref, coolItem.getPreferredSize());
}

@Test
public void test_getSize() {
	CoolBar coolBar = new CoolBar(shell, 0);
	CoolItem coolItem = new CoolItem(coolBar, 0);
	Button button = new Button(coolBar, SWT.PUSH);
	button.setText("foo");
	coolItem.setControl(button);

	Point size = coolItem.getSize();
	Rectangle rect = coolItem.getBounds();
	assertEquals(rect.width, size.x);
	assertEquals(rect.height, size.y);
}

@Test
public void test_setControlLorg_eclipse_swt_widgets_Control() {
	CoolBar coolBar = new CoolBar(shell, 0);
	CoolItem coolItem = new CoolItem(coolBar, 0);
	coolItem.setControl(null);

	Button button = new Button(coolBar, SWT.PUSH);
	button.setText("foobar");

	Point size = coolItem.getSize();
	coolItem.setControl(button);
	Point size2 = coolItem.getSize();
	assertTrue(size2.x > size.x);

	if (!MINIMAL_CONFORMANCE) {
		size = button.computeSize(SWT.DEFAULT, SWT.DEFAULT);
		size2 = coolItem.computeSize(size.x, size.y);
		assertEquals(size2, coolItem.getSize());
	}

	button = new Button(coolBar, SWT.PUSH);
	button.dispose();
	try {
		coolItem.setControl(button);
		fail("No exception when control.isDisposed()");
	}
	catch (IllegalArgumentException e) {
	}

	button = new Button(shell, SWT.PUSH);
	try {
		coolItem.setControl(button);
		fail("No exception thrown when control has wrong parent");
	}
	catch (IllegalArgumentException e) {
	}
}

@Test
public void test_setPreferredSizeII() {
	CoolBar coolBar = new CoolBar(shell, 0);
	CoolItem coolItem = new CoolItem(coolBar, 0);
	Button button = new Button(coolBar, SWT.PUSH);
	button.setText("foobar");
	coolItem.setControl(button);

	Point size = coolItem.getSize();
	coolItem.setPreferredSize(size);
	assertEquals(size.x, coolItem.getSize().x);
	coolItem.setSize(coolItem.getPreferredSize());
	assertEquals(size, coolItem.getSize());
}

@Test
public void test_setPreferredSizeLorg_eclipse_swt_graphics_Point() {
	CoolBar coolBar = new CoolBar(shell, 0);
	CoolItem coolItem = new CoolItem(coolBar, 0);
	Button button = new Button(coolBar, SWT.PUSH);
	button.setText("foobar");
	coolItem.setControl(button);

	Point size = new Point(50, 30);
	coolItem.setPreferredSize(size);
	Point size2 = coolItem.getPreferredSize();
	coolItem.setPreferredSize(50, 30);
	assertEquals(size2, coolItem.getPreferredSize());
}

@Test
public void test_setSizeII() {
	CoolBar coolBar = new CoolBar(shell, 0);
	CoolItem coolItem = new CoolItem(coolBar, 0);
	Button button = new Button(coolBar, SWT.PUSH);
	button.setText("foo");
	coolItem.setControl(button);

	coolItem.setSize(50, 50);
	assertEquals(new Point(50, 50), coolItem.getSize());

	coolItem.setSize(0, 0);
	Point smallest = coolItem.getSize();
	coolItem.setSize(1, 1);
	assertEquals(smallest, coolItem.getSize());

	Rectangle rect = coolItem.getBounds();
	Point size = coolItem.getSize();
	coolItem.setSize(rect.width, rect.height);
	assertEquals(size, coolItem.getSize());
}

@Test
public void test_setSizeLorg_eclipse_swt_graphics_Point() {
	CoolBar coolBar = new CoolBar(shell, 0);
	CoolItem coolItem = new CoolItem(coolBar, 0);
	Button button = new Button(coolBar, SWT.PUSH);
	button.setText("foo");
	coolItem.setControl(button);

	Point size = new Point(50, 50);
	coolItem.setSize(size);
	Point size2 = coolItem.getSize();
	coolItem.setSize(50, 50);
	assertEquals(size2, coolItem.getSize());
}

/* custom */
static final boolean MINIMAL_CONFORMANCE = false;

}

Back to the top