aboutsummaryrefslogtreecommitdiffstats
path: root/eclipse/plugins/com.android.ide.eclipse.tests/unittests
diff options
context:
space:
mode:
authorTor Norbye <tnorbye@google.com>2010-11-15 14:28:47 -0800
committerAndroid Code Review <code-review@android.com>2010-11-15 14:28:47 -0800
commit83412cba4fb281192358f367be0413799cd78258 (patch)
tree2f25198134a5969d21e62d12b273d8a93be92dfa /eclipse/plugins/com.android.ide.eclipse.tests/unittests
parenta9cdba53a2fed851cad5f3cffb47431b005b0f5a (diff)
parent5d08915fe9014124566a2cdd7c1aa4219e01acea (diff)
downloadsdk-83412cba4fb281192358f367be0413799cd78258.zip
sdk-83412cba4fb281192358f367be0413799cd78258.tar.gz
sdk-83412cba4fb281192358f367be0413799cd78258.tar.bz2
Merge "Add drop shadow to dragged items"
Diffstat (limited to 'eclipse/plugins/com.android.ide.eclipse.tests/unittests')
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/ImageUtilsTest.java191
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/SwtUtilsTest.java162
2 files changed, 206 insertions, 147 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/ImageUtilsTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/ImageUtilsTest.java
new file mode 100644
index 0000000..e4ddde3
--- /dev/null
+++ b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/ImageUtilsTest.java
@@ -0,0 +1,191 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Eclipse Public License, Version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.eclipse.org/org/documents/epl-v10.php
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.ide.eclipse.adt.internal.editors.layout.gle2;
+
+import com.android.ide.common.api.Rect;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.image.BufferedImage;
+
+import junit.framework.TestCase;
+
+public class ImageUtilsTest extends TestCase {
+ public void testCropBlank() throws Exception {
+ BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB_PRE);
+ Graphics g = image.getGraphics();
+ g.setColor(new Color(0, true));
+ g.fillRect(0, 0, image.getWidth(), image.getHeight());
+ g.dispose();
+
+ BufferedImage crop = ImageUtils.cropBlank(image, null);
+ assertNull(crop);
+ }
+
+ public void testCropBlankPre() throws Exception {
+ BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB_PRE);
+ Graphics g = image.getGraphics();
+ g.setColor(new Color(0, true));
+ g.fillRect(0, 0, image.getWidth(), image.getHeight());
+ g.dispose();
+
+ BufferedImage crop = ImageUtils.cropBlank(image, new Rect(5, 5, 80, 80));
+ assertNull(crop);
+ }
+
+ public void testCropNonblank() throws Exception {
+ BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB_PRE);
+ Graphics g = image.getGraphics();
+ g.setColor(new Color(0, false));
+ g.fillRect(0, 0, image.getWidth(), image.getHeight());
+ g.dispose();
+
+ BufferedImage crop = ImageUtils.cropBlank(image, null);
+ assertNotNull(crop);
+ assertEquals(image.getWidth(), crop.getWidth());
+ assertEquals(image.getHeight(), crop.getHeight());
+ }
+
+ public void testCropSomething() throws Exception {
+ BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB_PRE);
+ Graphics g = image.getGraphics();
+ g.setColor(new Color(0, true));
+ g.fillRect(0, 0, image.getWidth(), image.getHeight());
+ g.setColor(new Color(0xFF00FF00, true));
+ g.fillRect(25, 25, 50, 50);
+ g.dispose();
+
+ BufferedImage crop = ImageUtils.cropBlank(image, null);
+ assertNotNull(crop);
+ assertEquals(50, crop.getWidth());
+ assertEquals(50, crop.getHeight());
+ assertEquals(0xFF00FF00, crop.getRGB(0, 0));
+ assertEquals(0xFF00FF00, crop.getRGB(49, 49));
+ }
+
+ public void testCropSomethingPre() throws Exception {
+ BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB_PRE);
+ Graphics g = image.getGraphics();
+ g.setColor(new Color(0, true));
+ g.fillRect(0, 0, image.getWidth(), image.getHeight());
+ g.setColor(new Color(0xFF00FF00, true));
+ g.fillRect(25, 25, 50, 50);
+ g.dispose();
+
+ BufferedImage crop = ImageUtils.cropBlank(image, new Rect(0, 0, 100, 100));
+ assertNotNull(crop);
+ assertEquals(50, crop.getWidth());
+ assertEquals(50, crop.getHeight());
+ assertEquals(0xFF00FF00, crop.getRGB(0, 0));
+ assertEquals(0xFF00FF00, crop.getRGB(49, 49));
+ }
+
+ public void testCropSomethingPre2() throws Exception {
+ BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB_PRE);
+ Graphics g = image.getGraphics();
+ g.setColor(new Color(0, true));
+ g.fillRect(0, 0, image.getWidth(), image.getHeight());
+ g.setColor(new Color(0xFF00FF00, true));
+ g.fillRect(25, 25, 50, 50);
+ g.dispose();
+
+ BufferedImage crop = ImageUtils.cropBlank(image, new Rect(5, 5, 80, 80));
+ assertNotNull(crop);
+ assertEquals(50, crop.getWidth());
+ assertEquals(50, crop.getHeight());
+ assertEquals(0xFF00FF00, crop.getRGB(0, 0));
+ assertEquals(0xFF00FF00, crop.getRGB(49, 49));
+ }
+
+ public void testCropColor() throws Exception {
+ BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB_PRE);
+ Graphics g = image.getGraphics();
+ g.setColor(new Color(0xFF00FF00, true));
+ g.fillRect(0, 0, image.getWidth(), image.getHeight());
+ g.dispose();
+
+ BufferedImage crop = ImageUtils.cropColor(image, 0xFF00FF00, null);
+ assertNull(crop);
+ }
+
+ public void testCropNonColor() throws Exception {
+ BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB_PRE);
+ Graphics g = image.getGraphics();
+ g.setColor(new Color(0xFF00FF00, true));
+ g.fillRect(0, 0, image.getWidth(), image.getHeight());
+ g.dispose();
+
+ BufferedImage crop = ImageUtils.cropColor(image, 0xFFFF0000, null);
+ assertNotNull(crop);
+ assertEquals(image.getWidth(), crop.getWidth());
+ assertEquals(image.getHeight(), crop.getHeight());
+ }
+
+ public void testCropColorSomething() throws Exception {
+ BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB_PRE);
+ Graphics g = image.getGraphics();
+ g.setColor(new Color(0xFF00FF00, true));
+ g.fillRect(0, 0, image.getWidth(), image.getHeight());
+ g.setColor(new Color(0xFFFF0000, true));
+ g.fillRect(25, 25, 50, 50);
+ g.dispose();
+
+ BufferedImage crop = ImageUtils.cropColor(image, 0xFF00FF00, null);
+ assertEquals(50, crop.getWidth());
+ assertEquals(50, crop.getHeight());
+ assertEquals(0xFFFF0000, crop.getRGB(0, 0));
+ assertEquals(0xFFFF0000, crop.getRGB(49, 49));
+ }
+
+ public void testNullOk() throws Exception {
+ ImageUtils.cropBlank(null, null);
+ ImageUtils.cropColor(null, 0, null);
+ }
+
+
+ public void testNothingTodo() throws Exception {
+ BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB_PRE);
+ Graphics g = image.getGraphics();
+ g.setColor(new Color(0xFF00FF00, true));
+ g.fillRect(0, 0, image.getWidth(), image.getHeight());
+ g.dispose();
+
+ BufferedImage crop = ImageUtils.cropColor(image, 0xFFFF0000, new Rect(40, 40, 0, 0));
+ assertNull(crop);
+ }
+
+ public void testContainsDarkPixels() throws Exception {
+ BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB_PRE);
+ Graphics g = image.getGraphics();
+ g.setColor(new Color(0, true));
+ g.fillRect(0, 0, image.getWidth(), image.getHeight());
+ g.dispose();
+
+ assertFalse(ImageUtils.containsDarkPixels(image));
+
+ image.setRGB(50, 50, 0xFFFFFFFF);
+ assertFalse(ImageUtils.containsDarkPixels(image));
+ image.setRGB(50, 50, 0xFFAAAAAA);
+ assertFalse(ImageUtils.containsDarkPixels(image));
+ image.setRGB(50, 50, 0xFF00FF00);
+ assertFalse(ImageUtils.containsDarkPixels(image));
+ image.setRGB(50, 50, 0xFFFF8800);
+ assertFalse(ImageUtils.containsDarkPixels(image));
+ image.setRGB(50, 50, 0xFF333333);
+ assertTrue(ImageUtils.containsDarkPixels(image));
+
+ }
+}
diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/SwtUtilsTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/SwtUtilsTest.java
index 30bb82e..e383796 100644
--- a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/SwtUtilsTest.java
+++ b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/SwtUtilsTest.java
@@ -16,8 +16,6 @@
package com.android.ide.eclipse.adt.internal.editors.layout.gle2;
-import com.android.ide.common.api.Rect;
-
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.widgets.Display;
@@ -30,136 +28,6 @@ import java.awt.image.BufferedImage;
import junit.framework.TestCase;
public class SwtUtilsTest extends TestCase {
- public void testCropBlank() throws Exception {
- BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB_PRE);
- Graphics g = image.getGraphics();
- g.setColor(new Color(0, true));
- g.fillRect(0, 0, image.getWidth(), image.getHeight());
- g.dispose();
-
- BufferedImage crop = SwtUtils.cropBlank(image, null);
- assertNull(crop);
- }
-
- public void testCropBlankPre() throws Exception {
- BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB_PRE);
- Graphics g = image.getGraphics();
- g.setColor(new Color(0, true));
- g.fillRect(0, 0, image.getWidth(), image.getHeight());
- g.dispose();
-
- BufferedImage crop = SwtUtils.cropBlank(image, new Rect(5, 5, 80, 80));
- assertNull(crop);
- }
-
- public void testCropNonblank() throws Exception {
- BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB_PRE);
- Graphics g = image.getGraphics();
- g.setColor(new Color(0, false));
- g.fillRect(0, 0, image.getWidth(), image.getHeight());
- g.dispose();
-
- BufferedImage crop = SwtUtils.cropBlank(image, null);
- assertNotNull(crop);
- assertEquals(image.getWidth(), crop.getWidth());
- assertEquals(image.getHeight(), crop.getHeight());
- }
-
- public void testCropSomething() throws Exception {
- BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB_PRE);
- Graphics g = image.getGraphics();
- g.setColor(new Color(0, true));
- g.fillRect(0, 0, image.getWidth(), image.getHeight());
- g.setColor(new Color(0xFF00FF00, true));
- g.fillRect(25, 25, 50, 50);
- g.dispose();
-
- BufferedImage crop = SwtUtils.cropBlank(image, null);
- assertNotNull(crop);
- assertEquals(50, crop.getWidth());
- assertEquals(50, crop.getHeight());
- assertEquals(0xFF00FF00, crop.getRGB(0, 0));
- assertEquals(0xFF00FF00, crop.getRGB(49, 49));
- }
-
- public void testCropSomethingPre() throws Exception {
- BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB_PRE);
- Graphics g = image.getGraphics();
- g.setColor(new Color(0, true));
- g.fillRect(0, 0, image.getWidth(), image.getHeight());
- g.setColor(new Color(0xFF00FF00, true));
- g.fillRect(25, 25, 50, 50);
- g.dispose();
-
- BufferedImage crop = SwtUtils.cropBlank(image, new Rect(0, 0, 100, 100));
- assertNotNull(crop);
- assertEquals(50, crop.getWidth());
- assertEquals(50, crop.getHeight());
- assertEquals(0xFF00FF00, crop.getRGB(0, 0));
- assertEquals(0xFF00FF00, crop.getRGB(49, 49));
- }
-
- public void testCropSomethingPre2() throws Exception {
- BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB_PRE);
- Graphics g = image.getGraphics();
- g.setColor(new Color(0, true));
- g.fillRect(0, 0, image.getWidth(), image.getHeight());
- g.setColor(new Color(0xFF00FF00, true));
- g.fillRect(25, 25, 50, 50);
- g.dispose();
-
- BufferedImage crop = SwtUtils.cropBlank(image, new Rect(5, 5, 80, 80));
- assertNotNull(crop);
- assertEquals(50, crop.getWidth());
- assertEquals(50, crop.getHeight());
- assertEquals(0xFF00FF00, crop.getRGB(0, 0));
- assertEquals(0xFF00FF00, crop.getRGB(49, 49));
- }
-
- public void testCropColor() throws Exception {
- BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB_PRE);
- Graphics g = image.getGraphics();
- g.setColor(new Color(0xFF00FF00, true));
- g.fillRect(0, 0, image.getWidth(), image.getHeight());
- g.dispose();
-
- BufferedImage crop = SwtUtils.cropColor(image, 0xFF00FF00, null);
- assertNull(crop);
- }
-
- public void testCropNonColor() throws Exception {
- BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB_PRE);
- Graphics g = image.getGraphics();
- g.setColor(new Color(0xFF00FF00, true));
- g.fillRect(0, 0, image.getWidth(), image.getHeight());
- g.dispose();
-
- BufferedImage crop = SwtUtils.cropColor(image, 0xFFFF0000, null);
- assertNotNull(crop);
- assertEquals(image.getWidth(), crop.getWidth());
- assertEquals(image.getHeight(), crop.getHeight());
- }
-
- public void testCropColorSomething() throws Exception {
- BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB_PRE);
- Graphics g = image.getGraphics();
- g.setColor(new Color(0xFF00FF00, true));
- g.fillRect(0, 0, image.getWidth(), image.getHeight());
- g.setColor(new Color(0xFFFF0000, true));
- g.fillRect(25, 25, 50, 50);
- g.dispose();
-
- BufferedImage crop = SwtUtils.cropColor(image, 0xFF00FF00, null);
- assertEquals(50, crop.getWidth());
- assertEquals(50, crop.getHeight());
- assertEquals(0xFFFF0000, crop.getRGB(0, 0));
- assertEquals(0xFFFF0000, crop.getRGB(49, 49));
- }
-
- public void testNullOk() throws Exception {
- SwtUtils.cropBlank(null, null);
- SwtUtils.cropColor(null, 0, null);
- }
public void testImageConvertNoAlpha() throws Exception {
BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB_PRE);
@@ -170,7 +38,7 @@ public class SwtUtilsTest extends TestCase {
Shell shell = new Shell();
Display display = shell.getDisplay();
- Image swtImage = SwtUtils.convertImage(display, image, false, -1);
+ Image swtImage = SwtUtils.convertToSwt(display, image, false, -1);
assertNotNull(swtImage);
ImageData data = swtImage.getImageData();
assertEquals(image.getWidth(), data.width);
@@ -181,6 +49,17 @@ public class SwtUtilsTest extends TestCase {
assertEquals(image.getRGB(x, y) & 0xFFFFFF, data.getPixel(x, y));
}
}
+
+ // Convert back to AWT and compare with original AWT image
+ BufferedImage awtImage = SwtUtils.convertToAwt(swtImage);
+ assertNotNull(awtImage);
+ for (int y = 0; y < data.height; y++) {
+ for (int x = 0; x < data.width; x++) {
+ assertEquals(image.getRGB(x, y), awtImage.getRGB(x, y));
+ }
+ }
+
+
}
public void testImageConvertGlobalAlpha() throws Exception {
@@ -192,7 +71,7 @@ public class SwtUtilsTest extends TestCase {
Shell shell = new Shell();
Display display = shell.getDisplay();
- Image swtImage = SwtUtils.convertImage(display, image, false, 128);
+ Image swtImage = SwtUtils.convertToSwt(display, image, false, 128);
assertNotNull(swtImage);
ImageData data = swtImage.getImageData();
assertEquals(image.getWidth(), data.width);
@@ -215,7 +94,7 @@ public class SwtUtilsTest extends TestCase {
Shell shell = new Shell();
Display display = shell.getDisplay();
- Image swtImage = SwtUtils.convertImage(display, image, true, -1);
+ Image swtImage = SwtUtils.convertToSwt(display, image, true, -1);
assertNotNull(swtImage);
ImageData data = swtImage.getImageData();
assertEquals(image.getWidth(), data.width);
@@ -239,7 +118,7 @@ public class SwtUtilsTest extends TestCase {
Shell shell = new Shell();
Display display = shell.getDisplay();
- Image swtImage = SwtUtils.convertImage(display, image, true, 32);
+ Image swtImage = SwtUtils.convertToSwt(display, image, true, 32);
assertNotNull(swtImage);
ImageData data = swtImage.getImageData();
assertEquals(image.getWidth(), data.width);
@@ -255,15 +134,4 @@ public class SwtUtilsTest extends TestCase {
}
}
- public void testNothingTodo() throws Exception {
- BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB_PRE);
- Graphics g = image.getGraphics();
- g.setColor(new Color(0xFF00FF00, true));
- g.fillRect(0, 0, image.getWidth(), image.getHeight());
- g.dispose();
-
- BufferedImage crop = SwtUtils.cropColor(image, 0xFFFF0000, new Rect(40, 40, 0, 0));
- assertNull(crop);
- }
-
}