Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Ross2011-11-21 14:02:23 +0000
committerJohn Ross2011-11-21 14:02:23 +0000
commitd294f4ca033aa48961cff82eeaec61431a1ad2dc (patch)
tree09266bea76f832485e822cd66575e6e6c27d1398 /bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype
parent82fc12f75e778e1832afcd9eab8fb561269fca76 (diff)
downloadrt.equinox.bundles-d294f4ca033aa48961cff82eeaec61431a1ad2dc.tar.gz
rt.equinox.bundles-d294f4ca033aa48961cff82eeaec61431a1ad2dc.tar.xz
rt.equinox.bundles-d294f4ca033aa48961cff82eeaec61431a1ad2dc.zip
Bug 349189: New icon tests to ensure proper icon size is returned.
Diffstat (limited to 'bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype')
-rw-r--r--bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/AbstractTest.java45
-rw-r--r--bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/AllTests.java1
-rw-r--r--bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/IconTest.java60
3 files changed, 105 insertions, 1 deletions
diff --git a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/AbstractTest.java b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/AbstractTest.java
index 99b08069d..f3d41e91e 100644
--- a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/AbstractTest.java
+++ b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/AbstractTest.java
@@ -10,12 +10,15 @@
*******************************************************************************/
package org.eclipse.equinox.metatype.tests;
+import java.io.*;
+import javax.swing.Icon;
+import javax.swing.ImageIcon;
import junit.framework.TestCase;
import org.eclipse.equinox.compendium.tests.Activator;
import org.eclipse.equinox.metatype.EquinoxMetaTypeService;
import org.eclipse.osgi.tests.bundles.BundleInstaller;
import org.osgi.framework.ServiceReference;
-import org.osgi.service.metatype.AttributeDefinition;
+import org.osgi.service.metatype.*;
public abstract class AbstractTest extends TestCase {
protected BundleInstaller bundleInstaller;
@@ -33,6 +36,11 @@ public abstract class AbstractTest extends TestCase {
assertEquals("Wrong type", type, ad.getType()); //$NON-NLS-1$
}
+ protected void assertAttributeDefinitions(AttributeDefinition[] ads, int size) {
+ assertNotNull("Null attribute definitions", ads); //$NON-NLS-1$
+ assertEquals("Wrong attribute definitions size", size, ads.length); //$NON-NLS-1$
+ }
+
protected void assertEquals(String message, String[] s1, String[] s2) {
if (s1 == s2)
return;
@@ -45,6 +53,41 @@ public abstract class AbstractTest extends TestCase {
assertEquals(message, s1[i], s2[i]);
}
+ protected void assertIcon(InputStream icon, int size) throws IOException {
+ assertNotNull("Icon was null", icon); //$NON-NLS-1$
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ try {
+ byte[] bytes = new byte[2048];
+ int read;
+ try {
+ while ((read = icon.read(bytes)) != -1) {
+ baos.write(bytes, 0, read);
+ }
+ } finally {
+ icon.close();
+ }
+ Icon i = new ImageIcon(baos.toByteArray());
+ assertEquals("Wrong icon size", size, i.getIconHeight() * i.getIconWidth()); //$NON-NLS-1$
+ } finally {
+ baos.close();
+ }
+ }
+
+ protected void assertNotNull(MetaTypeInformation mti) {
+ assertNotNull("Metatype information was null", mti); //$NON-NLS-1$
+ }
+
+ protected void assertNotNull(ObjectClassDefinition ocd) {
+ assertNotNull("Object class definition was null", ocd); //$NON-NLS-1$
+ }
+
+ protected void assertObjectClassDefinition(ObjectClassDefinition ocd, String id, String name, String description) {
+ assertNotNull(ocd);
+ assertEquals("Wrong object class definition ID", id, ocd.getID()); //$NON-NLS-1$
+ assertEquals("Wrong object class definition name", name, ocd.getName()); //$NON-NLS-1$
+ assertEquals("Wrong object class definition description", description, ocd.getDescription()); //$NON-NLS-1$
+ }
+
protected void assertValidationFail(String value, AttributeDefinition ad) {
String result = assertValidationPresent(value, ad);
assertTrue("Validation passed", result.length() > 0); //$NON-NLS-1$
diff --git a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/AllTests.java b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/AllTests.java
index c741b07c6..f97bf31a6 100644
--- a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/AllTests.java
+++ b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/AllTests.java
@@ -25,6 +25,7 @@ public class AllTests {
suite.addTestSuite(Bug358969Test.class);
suite.addTestSuite(UnresolvedBundleTest.class);
suite.addTestSuite(GetDefaultValueTest.class);
+ suite.addTestSuite(IconTest.class);
return suite;
}
}
diff --git a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/IconTest.java b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/IconTest.java
new file mode 100644
index 000000000..89a0c51e2
--- /dev/null
+++ b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/IconTest.java
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * Copyright (c) 2011 IBM Corporation and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.equinox.metatype.tests;
+
+import org.osgi.framework.Bundle;
+import org.osgi.service.metatype.*;
+
+/*
+ * Ensure icons for object class definitions are properly supported.
+ *
+ * Although an object class definition conceptually has only one icon, it may
+ * come in a variety of sizes. Since a metatype implementation is not expected
+ * to scale images itself, users must be able to declare the same icon multiple
+ * times with different sizes within the XML. The spec simply says
+ * implementations may return an icon greater or less than the requested size
+ * to provide maximum freedom when no icon of the requested size exists. The
+ * Equinox implementation will return the icon that is closest to the requested
+ * size in either direction.
+ *
+ * See https://bugs.eclipse.org/bugs/show_bug.cgi?id=349189.
+ */
+public class IconTest extends AbstractTest {
+ private Bundle bundle;
+
+ public void testIcon() throws Exception {
+ MetaTypeInformation mti = metatype.getMetaTypeInformation(bundle);
+ assertNotNull(mti);
+ ObjectClassDefinition ocd = mti.getObjectClassDefinition("org.eclipse.equinox.metatype.tests.tb9", null); //$NON-NLS-1$
+ assertObjectClassDefinition(ocd, "1", "ocd1", null); //$NON-NLS-1$ //$NON-NLS-2$
+ AttributeDefinition[] ads = ocd.getAttributeDefinitions(ObjectClassDefinition.ALL);
+ assertAttributeDefinitions(ads, 1);
+ assertAttributeDefinition(ads[0], 0, null, null, "1", "ad1", null, null, AttributeDefinition.STRING); //$NON-NLS-1$ //$NON-NLS-2$
+ assertIcon(ocd.getIcon(10000), 10000);
+ assertIcon(ocd.getIcon(22500), 22500);
+ assertIcon(ocd.getIcon(40000), 40000);
+ assertIcon(ocd.getIcon(5000), 10000);
+ assertIcon(ocd.getIcon(50000), 40000);
+ assertIcon(ocd.getIcon(16249), 10000);
+ assertIcon(ocd.getIcon(16251), 22500);
+ assertIcon(ocd.getIcon(31249), 22500);
+ assertIcon(ocd.getIcon(31251), 40000);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ bundle = bundleInstaller.installBundle("tb9"); //$NON-NLS-1$
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+}

Back to the top