aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Ross2011-11-21 09:02:23 (EST)
committerJohn Ross2011-11-21 09:02:23 (EST)
commitd294f4ca033aa48961cff82eeaec61431a1ad2dc (patch)
tree09266bea76f832485e822cd66575e6e6c27d1398
parent82fc12f75e778e1832afcd9eab8fb561269fca76 (diff)
downloadrt.equinox.bundles-d294f4ca033aa48961cff82eeaec61431a1ad2dc.zip
rt.equinox.bundles-d294f4ca033aa48961cff82eeaec61431a1ad2dc.tar.gz
rt.equinox.bundles-d294f4ca033aa48961cff82eeaec61431a1ad2dc.tar.bz2
Bug 349189: New icon tests to ensure proper icon size is returned.
-rw-r--r--bundles/org.eclipse.equinox.compendium.tests/.classpath1
-rw-r--r--bundles/org.eclipse.equinox.compendium.tests/bundles_src/metatype/tb8/OSGI-INF/metatype/images/tn_ibm_turns_100-100x100.jpgbin0 -> 4931 bytes
-rw-r--r--bundles/org.eclipse.equinox.compendium.tests/bundles_src/metatype/tb8/OSGI-INF/metatype/images/tn_ibm_turns_100-150x150.jpgbin0 -> 7933 bytes
-rw-r--r--bundles/org.eclipse.equinox.compendium.tests/bundles_src/metatype/tb8/OSGI-INF/metatype/images/tn_ibm_turns_100-200x200.jpgbin0 -> 10182 bytes
-rw-r--r--bundles/org.eclipse.equinox.compendium.tests/bundles_src/metatype/tb9/META-INF/MANIFEST.MF6
-rw-r--r--bundles/org.eclipse.equinox.compendium.tests/bundles_src/metatype/tb9/OSGI-INF/metatype/metadata.xml15
-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
9 files changed, 127 insertions, 1 deletions
diff --git a/bundles/org.eclipse.equinox.compendium.tests/.classpath b/bundles/org.eclipse.equinox.compendium.tests/.classpath
index 854e6df..083dc88 100644
--- a/bundles/org.eclipse.equinox.compendium.tests/.classpath
+++ b/bundles/org.eclipse.equinox.compendium.tests/.classpath
@@ -11,6 +11,7 @@
<classpathentry kind="src" output="bundle_tests/metatype/tb6" path="bundles_src/metatype/tb6"/>
<classpathentry kind="src" output="bundle_tests/metatype/tb7" path="bundles_src/metatype/tb7"/>
<classpathentry kind="src" output="bundle_tests/metatype/tb8" path="bundles_src/metatype/tb8"/>
+ <classpathentry kind="src" output="bundle_tests/metatype/tb9" path="bundles_src/metatype/tb9"/>
<classpathentry kind="src" output="bundle_tests/metatype/extendable.tb1" path="bundles_src/metatype/extendable.tb1"/>
<classpathentry kind="output" path="bin"/>
</classpath>
diff --git a/bundles/org.eclipse.equinox.compendium.tests/bundles_src/metatype/tb8/OSGI-INF/metatype/images/tn_ibm_turns_100-100x100.jpg b/bundles/org.eclipse.equinox.compendium.tests/bundles_src/metatype/tb8/OSGI-INF/metatype/images/tn_ibm_turns_100-100x100.jpg
new file mode 100644
index 0000000..27e7c93
--- /dev/null
+++ b/bundles/org.eclipse.equinox.compendium.tests/bundles_src/metatype/tb8/OSGI-INF/metatype/images/tn_ibm_turns_100-100x100.jpg
Binary files differ
diff --git a/bundles/org.eclipse.equinox.compendium.tests/bundles_src/metatype/tb8/OSGI-INF/metatype/images/tn_ibm_turns_100-150x150.jpg b/bundles/org.eclipse.equinox.compendium.tests/bundles_src/metatype/tb8/OSGI-INF/metatype/images/tn_ibm_turns_100-150x150.jpg
new file mode 100644
index 0000000..62ee85e
--- /dev/null
+++ b/bundles/org.eclipse.equinox.compendium.tests/bundles_src/metatype/tb8/OSGI-INF/metatype/images/tn_ibm_turns_100-150x150.jpg
Binary files differ
diff --git a/bundles/org.eclipse.equinox.compendium.tests/bundles_src/metatype/tb8/OSGI-INF/metatype/images/tn_ibm_turns_100-200x200.jpg b/bundles/org.eclipse.equinox.compendium.tests/bundles_src/metatype/tb8/OSGI-INF/metatype/images/tn_ibm_turns_100-200x200.jpg
new file mode 100644
index 0000000..aff2021
--- /dev/null
+++ b/bundles/org.eclipse.equinox.compendium.tests/bundles_src/metatype/tb8/OSGI-INF/metatype/images/tn_ibm_turns_100-200x200.jpg
Binary files differ
diff --git a/bundles/org.eclipse.equinox.compendium.tests/bundles_src/metatype/tb9/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.compendium.tests/bundles_src/metatype/tb9/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..6df6e95
--- /dev/null
+++ b/bundles/org.eclipse.equinox.compendium.tests/bundles_src/metatype/tb9/META-INF/MANIFEST.MF
@@ -0,0 +1,6 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: MetaType TB9
+Bundle-SymbolicName: org.eclipse.equinox.metatype.tests.tb9
+Bundle-Version: 1.0.0
+Bundle-Vendor: IBM
diff --git a/bundles/org.eclipse.equinox.compendium.tests/bundles_src/metatype/tb9/OSGI-INF/metatype/metadata.xml b/bundles/org.eclipse.equinox.compendium.tests/bundles_src/metatype/tb9/OSGI-INF/metatype/metadata.xml
new file mode 100644
index 0000000..59288f1
--- /dev/null
+++ b/bundles/org.eclipse.equinox.compendium.tests/bundles_src/metatype/tb9/OSGI-INF/metatype/metadata.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<MetaData
+ xmlns="http://www.org.osgi/xmlns/metatype/v1.2.0/md"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.org.osgi/xmlns/metatype/v1.2.0/md metatype.xsd">
+ <OCD id="1" name="ocd1">
+ <AD name="ad1" id="1" type="String"/>
+ <Icon size="10000" resource="images/tn_ibm_turns_100-100x100.jpg"/>
+ <Icon size="22500" resource="images/tn_ibm_turns_100-150x150.jpg"/>
+ <Icon size="40000" resource="images/tn_ibm_turns_100-200x200.jpg"/>
+ </OCD>
+ <Designate pid="org.eclipse.equinox.metatype.tests.tb9">
+ <Object ocdref="1"/>
+ </Designate>
+</MetaData>
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 99b0806..f3d41e9 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 c741b07..f97bf31 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 0000000..89a0c51
--- /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();
+ }
+}