| /******************************************************************************* |
| * Copyright (c) 2004 IBM Corporation and others. |
| * All rights reserved. This program and the accompanying materials |
| * are 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 |
| * |
| * Contributors: |
| * IBM Corporation - initial API and implementation |
| *******************************************************************************/ |
| |
| package org.eclipse.ui.tests.api; |
| |
| import java.util.Arrays; |
| |
| import org.eclipse.swt.graphics.Image; |
| import org.eclipse.swt.graphics.ImageData; |
| import org.eclipse.ui.plugin.AbstractUIPlugin; |
| import org.eclipse.ui.tests.util.UITestCase; |
| |
| /** |
| * Tests to ensure that various icon scenarios work. These are tested on |
| * editors but should be applicable for any client of |
| * AbstractUIPlugin.imageDescriptorFromPlugin() |
| * |
| * @since 3.0 |
| */ |
| public class EditorIconTest extends UITestCase { |
| |
| /** |
| * @param testName |
| */ |
| public EditorIconTest(String testName) { |
| super(testName); |
| } |
| |
| public void testDependantBundleIcon() { |
| Image i1 = fWorkbench.getEditorRegistry().getDefaultEditor( |
| "foo.icontest1").getImageDescriptor().createImage(); |
| Image i2 = AbstractUIPlugin.imageDescriptorFromPlugin("org.eclipse.ui", |
| "icons/full/obj16/font.gif").createImage(); |
| compareImages(i1, i2); |
| } |
| |
| public void testNonDependantBundleIcon() { |
| Image i1 = fWorkbench.getEditorRegistry().getDefaultEditor( |
| "foo.icontest2").getImageDescriptor().createImage(); |
| Image i2 = AbstractUIPlugin.imageDescriptorFromPlugin( |
| "org.eclipse.jdt.ui", "icons/full/obj16/class_obj.gif") |
| .createImage(); |
| compareImages(i1, i2); |
| } |
| |
| public void testBadIcon() { |
| Image i1 = fWorkbench.getEditorRegistry().getDefaultEditor( |
| "foo.icontest3").getImageDescriptor().createImage(); |
| Image i2 = AbstractUIPlugin.imageDescriptorFromPlugin("org.eclipse.ui", |
| "icons/full/obj16/file_obj.gif").createImage(); |
| compareImages(i1, i2); |
| } |
| |
| private void compareImages(Image i1, Image i2) { |
| ImageData data1 = i1.getImageData(); |
| ImageData data2 = i2.getImageData(); |
| assertTrue(Arrays.equals(data1.data, data2.data)); |
| } |
| } |