Removed
Link Here
|
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2007 IBM Corporation and others. |
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
6 |
* http://www.eclipse.org/legal/epl-v10.html |
7 |
* |
8 |
* Contributors: |
9 |
* IBM Corporation - initial API and implementation |
10 |
*******************************************************************************/ |
11 |
|
12 |
package org.eclipse.ua.tests.forms.util; |
13 |
|
14 |
import org.eclipse.swt.graphics.Color; |
15 |
import org.eclipse.swt.graphics.Image; |
16 |
import org.eclipse.swt.widgets.Display; |
17 |
import org.eclipse.ui.internal.forms.widgets.FormImages; |
18 |
|
19 |
import junit.framework.Assert; |
20 |
import junit.framework.TestCase; |
21 |
|
22 |
public class FormImagesTests extends TestCase { |
23 |
public void testSingleton() { |
24 |
Display display = Display.getCurrent(); |
25 |
FormImages instance = FormImages.getInstance(); |
26 |
// ensure the singleton is returning the same instance |
27 |
Assert.assertTrue("getInstance() returned a different FormImages instance", instance.equals(FormImages.getInstance())); |
28 |
Image gradient = instance.getGradient(display, new Color(display, 1, 1, 1), new Color(display, 7, 7, 7), 21, 21, 0); |
29 |
instance.markFinished(gradient); |
30 |
// ensure the singleton is returning the same instance after creating and disposing one gradient |
31 |
Assert.assertTrue("getInstance() returned a different FormImages instance after creation and disposal of one image", instance.equals(FormImages.getInstance())); |
32 |
} |
33 |
|
34 |
public void testDisposeOne() { |
35 |
Display display = Display.getCurrent(); |
36 |
Image gradient = FormImages.getInstance().getGradient(display, new Color(display, 255, 255, 255), new Color(display, 0, 0, 0), 21, 21, 0); |
37 |
FormImages.getInstance().markFinished(gradient); |
38 |
// ensure that getting a single gradient and marking it as finished disposed it |
39 |
Assert.assertTrue("markFinished(...) did not dispose an image after a single getGradient()", gradient.isDisposed()); |
40 |
} |
41 |
|
42 |
public void testMultipleSimpleInstances() { |
43 |
Display display = Display.getCurrent(); |
44 |
Image gradient = FormImages.getInstance().getGradient(display, new Color(display, 200, 200, 200), new Color(display, 0, 0, 0), 30, 16, 3); |
45 |
int count; |
46 |
// ensure that the same image is returned for many calls with the same parameter |
47 |
for (count = 1; count < 20; count ++) |
48 |
Assert.assertEquals("getGradient(...) returned a different image for the same params on iteration "+count, |
49 |
gradient, FormImages.getInstance().getGradient(display, new Color(display, 200, 200, 200), new Color(display, 0, 0, 0), 30, 16, 3)); |
50 |
for ( ;count > 0; count--) { |
51 |
FormImages.getInstance().markFinished(gradient); |
52 |
if (count != 1) |
53 |
// ensure that the gradient is not disposed early |
54 |
Assert.assertFalse("markFinished(...) disposed a shared image early on iteration "+count,gradient.isDisposed()); |
55 |
else |
56 |
// ensure that the gradient is disposed on the last markFinished |
57 |
Assert.assertTrue("markFinished(...) did not dispose a shared image on the last call",gradient.isDisposed()); |
58 |
} |
59 |
} |
60 |
|
61 |
public void testMultipleComplexInstances() { |
62 |
Display display = Display.getCurrent(); |
63 |
Image gradient = FormImages.getInstance().getGradient(display, new Color[] {new Color(display, 200, 200, 200), new Color(display, 0, 0, 0)}, |
64 |
new int[] {100}, 31, true, null); |
65 |
int count; |
66 |
// ensure that the same image is returned for many calls with the same parameter |
67 |
for (count = 1; count < 20; count ++) |
68 |
Assert.assertEquals("getGradient(...) returned a different image for the same params on iteration "+count, |
69 |
gradient, FormImages.getInstance().getGradient(display, new Color[] {new Color(display, 200, 200, 200), new Color(display, 0, 0, 0)}, |
70 |
new int[] {100}, 31, true, null)); |
71 |
for ( ;count > 0; count--) { |
72 |
FormImages.getInstance().markFinished(gradient); |
73 |
if (count != 1) |
74 |
// ensure that the gradient is not disposed early |
75 |
Assert.assertFalse("markFinished(...) disposed a shared image early on iteration "+count,gradient.isDisposed()); |
76 |
else |
77 |
// ensure that the gradient is disposed on the last markFinished |
78 |
Assert.assertTrue("markFinished(...) did not dispose a shared image on the last call",gradient.isDisposed()); |
79 |
} |
80 |
} |
81 |
|
82 |
public void testMultipleUniqueInstances() { |
83 |
Display display = Display.getCurrent(); |
84 |
Image[] images = new Image[24]; |
85 |
images[0] = FormImages.getInstance().getGradient(display, new Color(display, 1, 0, 0), new Color(display, 100, 100, 100), 25, 23, 1); |
86 |
images[1] = FormImages.getInstance().getGradient(display, new Color(display, 0, 1, 0), new Color(display, 100, 100, 100), 25, 23, 1); |
87 |
images[2] = FormImages.getInstance().getGradient(display, new Color(display, 0, 0, 1), new Color(display, 100, 100, 100), 25, 23, 1); |
88 |
images[3] = FormImages.getInstance().getGradient(display, new Color(display, 0, 0, 0), new Color(display, 101, 100, 100), 25, 23, 1); |
89 |
images[4] = FormImages.getInstance().getGradient(display, new Color(display, 0, 0, 0), new Color(display, 100, 101, 100), 25, 23, 1); |
90 |
images[5] = FormImages.getInstance().getGradient(display, new Color(display, 0, 0, 0), new Color(display, 100, 100, 101), 25, 23, 1); |
91 |
images[6] = FormImages.getInstance().getGradient(display, new Color(display, 0, 0, 0), new Color(display, 100, 100, 100), 20, 23, 1); |
92 |
images[7] = FormImages.getInstance().getGradient(display, new Color(display, 0, 0, 0), new Color(display, 100, 100, 100), 25, 10, 1); |
93 |
images[8] = FormImages.getInstance().getGradient(display, new Color(display, 0, 0, 0), new Color(display, 100, 100, 100), 25, 23, 2); |
94 |
images[9] = FormImages.getInstance().getGradient(display, new Color(display, 1, 1, 1), new Color(display, 101, 101, 101), 20, 10, 2); |
95 |
images[10] = FormImages.getInstance().getGradient(display, new Color[]{new Color(display,0,0,0)}, new int[] {}, 31, true, null); |
96 |
images[11] = FormImages.getInstance().getGradient(display, new Color[]{new Color(display,0,0,0), new Color(display,1,1,1)}, |
97 |
new int[] {80}, 31, true, new Color(display,255,255,255)); |
98 |
images[12] = FormImages.getInstance().getGradient(display, new Color[]{new Color(display,0,0,0), new Color(display,1,1,1)}, |
99 |
new int[] {80}, 31, true, new Color(display,0,0,0)); |
100 |
images[13] = FormImages.getInstance().getGradient(display, new Color[]{new Color(display,0,0,0), new Color(display,100,100,100)}, |
101 |
new int[] {100}, 31, true, null); |
102 |
images[14] = FormImages.getInstance().getGradient(display, new Color[]{new Color(display,1,0,0), new Color(display,100,100,100)}, |
103 |
new int[] {100}, 31, true, null); |
104 |
images[15] = FormImages.getInstance().getGradient(display, new Color[]{new Color(display,0,1,0), new Color(display,100,100,100)}, |
105 |
new int[] {100}, 31, true, null); |
106 |
images[16] = FormImages.getInstance().getGradient(display, new Color[]{new Color(display,0,0,1), new Color(display,100,100,100)}, |
107 |
new int[] {100}, 31, true, null); |
108 |
images[17] = FormImages.getInstance().getGradient(display, new Color[]{new Color(display,0,0,0), new Color(display,101,100,100)}, |
109 |
new int[] {100}, 31, true, null); |
110 |
images[18] = FormImages.getInstance().getGradient(display, new Color[]{new Color(display,0,0,0), new Color(display,100,101,100)}, |
111 |
new int[] {100}, 31, true, null); |
112 |
images[19] = FormImages.getInstance().getGradient(display, new Color[]{new Color(display,0,0,0), new Color(display,100,100,101)}, |
113 |
new int[] {100}, 31, true, null); |
114 |
images[20] = FormImages.getInstance().getGradient(display, new Color[]{new Color(display,0,0,0), new Color(display,100,100,100)}, |
115 |
new int[] {100}, 20, true, null); |
116 |
images[21] = FormImages.getInstance().getGradient(display, new Color[]{new Color(display,0,0,0), new Color(display,100,100,100)}, |
117 |
new int[] {100}, 31, false, null); |
118 |
images[22] = FormImages.getInstance().getGradient(display, new Color[]{new Color(display,0,0,0), new Color(display,100,100,100)}, |
119 |
new int[] {50}, 31, true, new Color(display,1,1,1)); |
120 |
images[23] = FormImages.getInstance().getGradient(display, new Color[]{new Color(display,1,1,1), new Color(display,101,101,101)}, |
121 |
new int[] {50}, 20, false, new Color(display,1,1,1)); |
122 |
// ensure none of the images are the same |
123 |
for (int i = 0; i < images.length - 1; i++) { |
124 |
for (int j = i+1; j < images.length; j++) { |
125 |
Assert.assertNotSame("getGradient(...) returned the same image for different parameters: i = " + i + "; j = " + j, images[i], images[j]); |
126 |
} |
127 |
} |
128 |
// ensure all of the images are disposed with one call to markFinished |
129 |
for (int i = 0; i < images.length; i++) { |
130 |
FormImages.getInstance().markFinished(images[i]); |
131 |
Assert.assertTrue("markFinished(...) did not dispose an image that was only requested once: i = " + i, images[i].isDisposed()); |
132 |
} |
133 |
} |
134 |
|
135 |
public void testComplexEquality() { |
136 |
Display display = Display.getCurrent(); |
137 |
Image image1 = FormImages.getInstance().getGradient(display, new Color[] {new Color(display,0,0,0), new Color(display,255,255,255)}, |
138 |
new int[] {100}, 20, true, new Color(display,100,100,100)); |
139 |
Image image2 = FormImages.getInstance().getGradient(display, new Color[] {new Color(display,0,0,0), new Color(display,255,255,255)}, |
140 |
new int[] {100}, 20, true, new Color(display,0,0,0)); |
141 |
Assert.assertEquals("different images were created with only the background color differing when that difference is irrelevant", image1, image2); |
142 |
FormImages.getInstance().markFinished(image1); |
143 |
FormImages.getInstance().markFinished(image2); |
144 |
image1 = FormImages.getInstance().getGradient(display, new Color[] {new Color(display,0,0,0), new Color(display,255,255,255)}, |
145 |
new int[] {80}, 20, true, new Color(display,100,100,100)); |
146 |
image2 = FormImages.getInstance().getGradient(display, new Color[] {new Color(display,0,0,0), new Color(display,255,255,255)}, |
147 |
new int[] {80}, 20, true, new Color(display,0,0,0)); |
148 |
Assert.assertNotSame("the same image was used when different background colors were specified", image1, image2); |
149 |
FormImages.getInstance().markFinished(image1); |
150 |
FormImages.getInstance().markFinished(image2); |
151 |
} |
152 |
|
153 |
public void testDisposeUnknown() { |
154 |
Display display = Display.getCurrent(); |
155 |
Image image = new Image(display, 10, 10); |
156 |
FormImages.getInstance().markFinished(image); |
157 |
Assert.assertTrue("markFinished(...) did not dispose of an unknown image", image.isDisposed()); |
158 |
} |
159 |
} |