harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mloe...@apache.org
Subject svn commit: r427121 [21/29] - in /incubator/harmony/enhanced/classlib/trunk/modules/swing: make/ src/main/java/common/javax/swing/ src/main/java/common/javax/swing/text/ src/main/java/common/javax/swing/text/html/ src/main/java/common/javax/swing/text/...
Date Mon, 31 Jul 2006 14:08:55 GMT
Added: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/ImageViewTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/ImageViewTest.java?rev=427121&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/ImageViewTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/ImageViewTest.java Mon Jul 31 07:08:47 2006
@@ -0,0 +1,734 @@
+/*
+ *  Copyright 2005 - 2006 The Apache Software Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
+ *
+ *  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.
+ */
+/**
+ * @author Alexey A. Ivanov
+ * @version $Revision$
+ */
+package javax.swing.text.html;
+
+import java.awt.FontMetrics;
+import java.awt.Image;
+import java.awt.Rectangle;
+import java.awt.Toolkit;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.StringReader;
+import java.net.URL;
+
+import javax.swing.BasicSwingTestCase;
+import javax.swing.Icon;
+import javax.swing.event.DocumentEvent;
+import javax.swing.text.AttributeSet;
+import javax.swing.text.Document;
+import javax.swing.text.Element;
+import javax.swing.text.SimpleAttributeSet;
+import javax.swing.text.View;
+import javax.swing.text.Position.Bias;
+
+public class ImageViewTest extends BasicSwingTestCase {
+    private static final String DEFAULT_SRC = "image.jpg";
+    private static final String DEFAULT_ALT = "image description";
+    /**
+     * Natural size of the image in <code>IMAGE_BYTES</code>.
+     */
+    private static final int    IMAGE_SIZE  = 16;
+    /**
+     * Size specified with attributes, as <code>int</code>.
+     */
+    private static final int    SIZE        = 20;
+    /**
+     * Size specified with attributes, as <code>String</code>.
+     */
+    private static final String SIZE_VALUE  = "20";
+    private static final String WIDTH_HTML  = "width=\"20";
+    private static final String HEIGHT_HTML = "height=\"20";
+    private static final String WIDTH_CSS   = "width: 20pt";
+    private static final String HEIGHT_CSS  = "height: 20pt";
+
+    /**
+     * Test image in GIF format. It is written to a temporary file and loaded
+     * into the view.
+     */
+    private static final short[] IMAGE_BYTES = {
+        0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x10, 0x00, 0x10, 0x00, 0xf7,
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00,
+        0x80, 0x80, 0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0x80, 0x00, 0x80,
+        0x80, 0x80, 0x80, 0x80, 0xc0, 0xc0, 0xc0, 0xff, 0x00, 0x00, 0x00,
+        0xff, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0xff,
+        0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00,
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x33, 0x00, 0x00, 0x66, 0x00,
+        0x00, 0x99, 0x00, 0x00, 0xcc, 0x00, 0x00, 0xff, 0x00, 0x33, 0x00,
+        0x00, 0x33, 0x33, 0x00, 0x33, 0x66, 0x00, 0x33, 0x99, 0x00, 0x33,
+        0xcc, 0x00, 0x33, 0xff, 0x00, 0x66, 0x00, 0x00, 0x66, 0x33, 0x00,
+        0x66, 0x66, 0x00, 0x66, 0x99, 0x00, 0x66, 0xcc, 0x00, 0x66, 0xff,
+        0x00, 0x99, 0x00, 0x00, 0x99, 0x33, 0x00, 0x99, 0x66, 0x00, 0x99,
+        0x99, 0x00, 0x99, 0xcc, 0x00, 0x99, 0xff, 0x00, 0xcc, 0x00, 0x00,
+        0xcc, 0x33, 0x00, 0xcc, 0x66, 0x00, 0xcc, 0x99, 0x00, 0xcc, 0xcc,
+        0x00, 0xcc, 0xff, 0x00, 0xff, 0x00, 0x00, 0xff, 0x33, 0x00, 0xff,
+        0x66, 0x00, 0xff, 0x99, 0x00, 0xff, 0xcc, 0x00, 0xff, 0xff, 0x33,
+        0x00, 0x00, 0x33, 0x00, 0x33, 0x33, 0x00, 0x66, 0x33, 0x00, 0x99,
+        0x33, 0x00, 0xcc, 0x33, 0x00, 0xff, 0x33, 0x33, 0x00, 0x33, 0x33,
+        0x33, 0x33, 0x33, 0x66, 0x33, 0x33, 0x99, 0x33, 0x33, 0xcc, 0x33,
+        0x33, 0xff, 0x33, 0x66, 0x00, 0x33, 0x66, 0x33, 0x33, 0x66, 0x66,
+        0x33, 0x66, 0x99, 0x33, 0x66, 0xcc, 0x33, 0x66, 0xff, 0x33, 0x99,
+        0x00, 0x33, 0x99, 0x33, 0x33, 0x99, 0x66, 0x33, 0x99, 0x99, 0x33,
+        0x99, 0xcc, 0x33, 0x99, 0xff, 0x33, 0xcc, 0x00, 0x33, 0xcc, 0x33,
+        0x33, 0xcc, 0x66, 0x33, 0xcc, 0x99, 0x33, 0xcc, 0xcc, 0x33, 0xcc,
+        0xff, 0x33, 0xff, 0x00, 0x33, 0xff, 0x33, 0x33, 0xff, 0x66, 0x33,
+        0xff, 0x99, 0x33, 0xff, 0xcc, 0x33, 0xff, 0xff, 0x66, 0x00, 0x00,
+        0x66, 0x00, 0x33, 0x66, 0x00, 0x66, 0x66, 0x00, 0x99, 0x66, 0x00,
+        0xcc, 0x66, 0x00, 0xff, 0x66, 0x33, 0x00, 0x66, 0x33, 0x33, 0x66,
+        0x33, 0x66, 0x66, 0x33, 0x99, 0x66, 0x33, 0xcc, 0x66, 0x33, 0xff,
+        0x66, 0x66, 0x00, 0x66, 0x66, 0x33, 0x66, 0x66, 0x66, 0x66, 0x66,
+        0x99, 0x66, 0x66, 0xcc, 0x66, 0x66, 0xff, 0x66, 0x99, 0x00, 0x66,
+        0x99, 0x33, 0x66, 0x99, 0x66, 0x66, 0x99, 0x99, 0x66, 0x99, 0xcc,
+        0x66, 0x99, 0xff, 0x66, 0xcc, 0x00, 0x66, 0xcc, 0x33, 0x66, 0xcc,
+        0x66, 0x66, 0xcc, 0x99, 0x66, 0xcc, 0xcc, 0x66, 0xcc, 0xff, 0x66,
+        0xff, 0x00, 0x66, 0xff, 0x33, 0x66, 0xff, 0x66, 0x66, 0xff, 0x99,
+        0x66, 0xff, 0xcc, 0x66, 0xff, 0xff, 0x99, 0x00, 0x00, 0x99, 0x00,
+        0x33, 0x99, 0x00, 0x66, 0x99, 0x00, 0x99, 0x99, 0x00, 0xcc, 0x99,
+        0x00, 0xff, 0x99, 0x33, 0x00, 0x99, 0x33, 0x33, 0x99, 0x33, 0x66,
+        0x99, 0x33, 0x99, 0x99, 0x33, 0xcc, 0x99, 0x33, 0xff, 0x99, 0x66,
+        0x00, 0x99, 0x66, 0x33, 0x99, 0x66, 0x66, 0x99, 0x66, 0x99, 0x99,
+        0x66, 0xcc, 0x99, 0x66, 0xff, 0x99, 0x99, 0x00, 0x99, 0x99, 0x33,
+        0x99, 0x99, 0x66, 0x99, 0x99, 0x99, 0x99, 0x99, 0xcc, 0x99, 0x99,
+        0xff, 0x99, 0xcc, 0x00, 0x99, 0xcc, 0x33, 0x99, 0xcc, 0x66, 0x99,
+        0xcc, 0x99, 0x99, 0xcc, 0xcc, 0x99, 0xcc, 0xff, 0x99, 0xff, 0x00,
+        0x99, 0xff, 0x33, 0x99, 0xff, 0x66, 0x99, 0xff, 0x99, 0x99, 0xff,
+        0xcc, 0x99, 0xff, 0xff, 0xcc, 0x00, 0x00, 0xcc, 0x00, 0x33, 0xcc,
+        0x00, 0x66, 0xcc, 0x00, 0x99, 0xcc, 0x00, 0xcc, 0xcc, 0x00, 0xff,
+        0xcc, 0x33, 0x00, 0xcc, 0x33, 0x33, 0xcc, 0x33, 0x66, 0xcc, 0x33,
+        0x99, 0xcc, 0x33, 0xcc, 0xcc, 0x33, 0xff, 0xcc, 0x66, 0x00, 0xcc,
+        0x66, 0x33, 0xcc, 0x66, 0x66, 0xcc, 0x66, 0x99, 0xcc, 0x66, 0xcc,
+        0xcc, 0x66, 0xff, 0xcc, 0x99, 0x00, 0xcc, 0x99, 0x33, 0xcc, 0x99,
+        0x66, 0xcc, 0x99, 0x99, 0xcc, 0x99, 0xcc, 0xcc, 0x99, 0xff, 0xcc,
+        0xcc, 0x00, 0xcc, 0xcc, 0x33, 0xcc, 0xcc, 0x66, 0xcc, 0xcc, 0x99,
+        0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xff, 0xcc, 0xff, 0x00, 0xcc, 0xff,
+        0x33, 0xcc, 0xff, 0x66, 0xcc, 0xff, 0x99, 0xcc, 0xff, 0xcc, 0xcc,
+        0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0x00, 0x33, 0xff, 0x00, 0x66,
+        0xff, 0x00, 0x99, 0xff, 0x00, 0xcc, 0xff, 0x00, 0xff, 0xff, 0x33,
+        0x00, 0xff, 0x33, 0x33, 0xff, 0x33, 0x66, 0xff, 0x33, 0x99, 0xff,
+        0x33, 0xcc, 0xff, 0x33, 0xff, 0xff, 0x66, 0x00, 0xff, 0x66, 0x33,
+        0xff, 0x66, 0x66, 0xff, 0x66, 0x99, 0xff, 0x66, 0xcc, 0xff, 0x66,
+        0xff, 0xff, 0x99, 0x00, 0xff, 0x99, 0x33, 0xff, 0x99, 0x66, 0xff,
+        0x99, 0x99, 0xff, 0x99, 0xcc, 0xff, 0x99, 0xff, 0xff, 0xcc, 0x00,
+        0xff, 0xcc, 0x33, 0xff, 0xcc, 0x66, 0xff, 0xcc, 0x99, 0xff, 0xcc,
+        0xcc, 0xff, 0xcc, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0x33, 0xff,
+        0xff, 0x66, 0xff, 0xff, 0x99, 0xff, 0xff, 0xcc, 0xff, 0xff, 0xff,
+        0x21, 0xf9, 0x04, 0x01, 0x00, 0x00, 0x10, 0x00, 0x2c, 0x00, 0x00,
+        0x00, 0x00, 0x10, 0x00, 0x10, 0x00, 0x00, 0x08, 0x63, 0x00, 0xbf,
+        0xfd, 0x1b, 0x48, 0x90, 0x5f, 0x3f, 0x82, 0x04, 0xbd, 0xfd, 0x13,
+        0x88, 0xb0, 0x1f, 0x3f, 0x84, 0xff, 0x14, 0x0e, 0x64, 0x38, 0xd0,
+        0x20, 0x42, 0x89, 0x04, 0x29, 0x3a, 0x4c, 0x08, 0x71, 0x62, 0xc5,
+        0x83, 0x11, 0x3b, 0x66, 0xfc, 0xb7, 0x11, 0xa3, 0xc8, 0x85, 0x06,
+        0x4d, 0x0e, 0xcc, 0xf1, 0x83, 0xa5, 0xcb, 0x6f, 0xde, 0x5a, 0xca,
+        0x64, 0x39, 0x53, 0xa6, 0xb7, 0x6f, 0x2e, 0x67, 0x76, 0xf4, 0xe6,
+        0x90, 0xe2, 0x49, 0x85, 0x16, 0x7d, 0x42, 0x94, 0xb8, 0x71, 0xa1,
+        0x48, 0x8c, 0x16, 0x3d, 0x5e, 0x6c, 0xf8, 0x70, 0xe4, 0x40, 0x95,
+        0x49, 0x47, 0xaa, 0x24, 0xd9, 0x14, 0xe1, 0xb7, 0x80, 0x00, 0x3b,
+    };
+
+    private HTMLEditorKit kit;
+    private HTMLDocument doc;
+    private Element img;
+    private ImageView view;
+    private AttributeSet attrs;
+
+    private Icon noIcon;
+    private int iconWidth;
+    private int iconHeight;
+    private static File imageFile;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        setIgnoreNotImplemented(true);
+        init();
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        if (imageFile != null) {
+            imageFile.delete();
+        }
+    }
+
+    public void testImageView() {
+        final Marker properties = new Marker();
+        view = new ImageView(img) {
+            protected void setPropertiesFromAttributes() {
+                properties.setOccurred();
+                super.setPropertiesFromAttributes();
+            }
+        };
+        if (isHarmony()) {
+            assertTrue(properties.isOccurred());
+        } else {
+            assertFalse(properties.isOccurred());
+        }
+        assertSame(img, view.getElement());
+    }
+
+    public void testGetImage() {
+        assertNull(view.getImageURL());
+        assertNull(view.getImage());
+    }
+
+    public void testGetImage_Image() throws Exception {
+        initImage();
+        view.setLoadsSynchronously(false);
+        assertEquals(imageFile.toURL(), view.getImageURL());
+        assertNotNull(view.getImage());
+        waitForImage();
+    }
+
+    // URL lacks protocol specification
+    public void testGetImageURL() {
+        assertNull(view.getImageURL());
+    }
+
+    // HTTP protocol
+    public void testGetImageURL_HTTP() throws Exception {
+        init("http://base.url.test/" + DEFAULT_SRC);
+        assertEquals("http://base.url.test/" + DEFAULT_SRC,
+                     view.getImageURL().toString());
+    }
+
+    // Unknown protocol
+    public void testGetImageURL_IMG() throws Exception {
+        init("img://" + DEFAULT_SRC);
+        assertNull(view.getImageURL());
+    }
+
+    // doc.getBase() is used to construct absolute URL
+    public void testGetImageURL_BASE01() throws Exception {
+        doc.setBase(new URL("http://base.url.test/"));
+        assertEquals("http://base.url.test/" + DEFAULT_SRC,
+                     view.getImageURL().toString());
+    }
+
+    // doc.getBase() is used to construct absolute URL
+    public void testGetImageURL_BASE02() throws Exception {
+        assertNull(view.getImageURL());
+        assertNull(view.getImage());
+        doc.setBase(new URL("http://base.url.test/"));
+        assertEquals("http://base.url.test/" + DEFAULT_SRC,
+                     view.getImageURL().toString());
+        assertNull(view.getImage());
+    }
+
+    // No src attribute is set on <img>
+    public void testGetImageURL_Null() throws Exception {
+        init(null, null);
+        assertNull(view.getImageURL());
+    }
+
+    public void testGetLoadingImageIcon() {
+        final Icon icon = view.getLoadingImageIcon();
+        assertNotNull(icon);
+        assertSame(icon, view.getLoadingImageIcon());
+        assertSame(icon, new ImageView(img).getLoadingImageIcon());
+
+        assertEquals(isHarmony() ? 20 : 38, icon.getIconWidth());
+        assertEquals(isHarmony() ? 18 : 38, icon.getIconHeight());
+    }
+
+    public void testGetNoImageIcon() {
+        final Icon icon = view.getNoImageIcon();
+        assertNotNull(icon);
+        assertSame(icon, view.getNoImageIcon());
+        assertSame(icon, new ImageView(img).getNoImageIcon());
+
+        assertEquals(isHarmony() ? 20 : 38, icon.getIconWidth());
+        assertEquals(isHarmony() ? 18 : 38, icon.getIconHeight());
+    }
+
+    public void testSetLoadsSynchronously() {
+        assertFalse(view.getLoadsSynchronously());
+
+        view.setLoadsSynchronously(true);
+        assertTrue(view.getLoadsSynchronously());
+
+        view.setLoadsSynchronously(false);
+        assertFalse(view.getLoadsSynchronously());
+    }
+
+    public void testGetLoadsSynchronously() {
+        assertFalse(view.getLoadsSynchronously());
+    }
+
+    // Has null image, alt text is not null
+    public void testGetPreferredSpan01() {
+        assertNull(attrs.getAttribute(CSS.Attribute.WIDTH));
+        assertNull(attrs.getAttribute(CSS.Attribute.HEIGHT));
+
+        final FontMetrics metrics = Toolkit.getDefaultToolkit()
+                                    .getFontMetrics(view.getStyleSheet()
+                                                    .getFont(attrs));
+        assertEquals(metrics.stringWidth(DEFAULT_ALT) + iconWidth,
+                     (int)view.getPreferredSpan(View.X_AXIS));
+        if (isHarmony()) {
+            assertEquals(Math.max(metrics.getHeight(), iconHeight),
+                         (int)view.getPreferredSpan(View.Y_AXIS));
+        } else {
+            assertEquals(metrics.getHeight() + iconHeight,
+                         (int)view.getPreferredSpan(View.Y_AXIS));
+        }
+    }
+
+    // Has null image, alt text is null
+    public void testGetPreferredSpan02() throws Exception {
+        init(null, null);
+
+        assertEquals(iconWidth,
+                     (int)view.getPreferredSpan(View.X_AXIS));
+        assertEquals(iconHeight,
+                     (int)view.getPreferredSpan(View.Y_AXIS));
+    }
+
+    // Image has width and height HTML attributes set
+    public void testGetPreferredSpan03() throws Exception {
+        init(DEFAULT_SRC + "\" " + WIDTH_HTML + "\" " + HEIGHT_HTML, null);
+        assertEquals(SIZE_VALUE,
+                     img.getAttributes().getAttribute(HTML.Attribute.WIDTH));
+        assertEquals(SIZE_VALUE,
+                     img.getAttributes().getAttribute(HTML.Attribute.HEIGHT));
+
+        assertEquals(iconWidth,
+                     (int)view.getPreferredSpan(View.X_AXIS));
+        assertEquals(iconHeight,
+                     (int)view.getPreferredSpan(View.Y_AXIS));
+    }
+
+    // Image has width and height CSS attributes set
+    public void testGetPreferredSpan04() throws Exception {
+        init(DEFAULT_SRC + "\" style=\"" + WIDTH_CSS + "; " + HEIGHT_CSS, null);
+        assertEquals(SIZE_VALUE + "pt",
+                     img.getAttributes().getAttribute(CSS.Attribute.WIDTH)
+                     .toString());
+        assertEquals(SIZE_VALUE + "pt",
+                     img.getAttributes().getAttribute(CSS.Attribute.HEIGHT)
+                     .toString());
+
+        assertEquals(iconWidth,
+                     (int)view.getPreferredSpan(View.X_AXIS));
+        assertEquals(iconHeight,
+                     (int)view.getPreferredSpan(View.Y_AXIS));
+    }
+
+    // Loads external image. No attributes specified.
+//    public void testGetPreferredSpan05() throws Exception {
+//        initImage();
+//        waitForImage();
+//        assertNotNull(view.getImage());
+//
+//        // These assertions should pass but they don't
+//        assertEquals(IMAGE_SIZE,
+//                     (int)view.getPreferredSpan(View.X_AXIS));
+//        assertEquals(IMAGE_SIZE,
+//                     (int)view.getPreferredSpan(View.Y_AXIS));
+//    }
+
+    // Loads external image. HTML attributes are set.
+    public void testGetPreferredSpan06() throws Exception {
+        initImage();
+        init(imageFile.toURL().toString() + "\" "
+             + WIDTH_HTML + "\" " + HEIGHT_HTML, null);
+        waitForImage();
+
+        assertEquals(SIZE_VALUE,
+                     img.getAttributes().getAttribute(HTML.Attribute.WIDTH));
+        assertEquals(SIZE_VALUE,
+                     img.getAttributes().getAttribute(HTML.Attribute.HEIGHT));
+
+        assertNotNull(view.getImage());
+
+        assertEquals(SIZE,
+                     (int)view.getPreferredSpan(View.X_AXIS));
+        assertEquals(SIZE,
+                     (int)view.getPreferredSpan(View.Y_AXIS));
+    }
+
+    public void testGetToolTipText01() {
+        assertEquals(view.getAltText(),
+                     view.getToolTipText(0, 0, new Rectangle()));
+    }
+
+    public void testGetToolTipText02() {
+        final Marker marker = new Marker();
+        view = new ImageView(img) {
+            public String getAltText() {
+                marker.setOccurred();
+                return null;
+            }
+        };
+        assertFalse(marker.isOccurred());
+        assertNull(view.getToolTipText(0, 0, new Rectangle()));
+        assertTrue(marker.isOccurred());
+    }
+
+    public void testGetToolTipText03() {
+        final String alt = view.getAltText();
+        final Rectangle shape = new Rectangle(121, 219, 574, 38);
+
+        assertEquals(alt, view.getToolTipText(-121, -219, shape));
+        assertEquals(alt, view.getToolTipText(shape.x + shape.width + 41,
+                                              shape.y + shape.height + 94,
+                                              shape));
+    }
+
+    public void testGetAltText01() {
+        assertEquals(DEFAULT_ALT, view.getAltText());
+    }
+
+    public void testGetAltText02() throws Exception {
+        init(null, null);
+        assertNull(view.getAltText());
+    }
+
+    public void testGetAltText03() throws Exception {
+        final Marker marker = new Marker();
+        final AttributeSet vas = new SimpleAttributeSet() {
+            public Object getAttribute(final Object key) {
+                marker.setOccurred();
+                return attrs.getAttribute(key);
+            }
+        };
+        view = new ImageView(img) {
+            public AttributeSet getAttributes() {
+                return vas;
+            }
+        };
+        marker.reset();
+        view.getAltText();
+        assertFalse(marker.isOccurred());
+    }
+
+    public void testGetAltText04() throws Exception {
+        final Marker marker = new Marker();
+
+        final String value = "attribute value";
+        final AttributeSet eas = new SimpleAttributeSet() {
+            public Object getAttribute(final Object key) {
+                marker.setOccurred();
+                if (key == HTML.Attribute.ALT) {
+                    return value;
+                }
+                return attrs.getAttribute(key);
+            }
+        };
+        final Element e = new Element() {
+            public AttributeSet getAttributes() {
+                return eas;
+            }
+
+            public Document getDocument() {
+                return img.getDocument();
+            }
+            public Element getElement(int index) {
+                return img.getElement(index);
+            }
+            public int getElementCount() {
+                return img.getElementCount();
+            }
+            public int getElementIndex(int offset) {
+                return img.getElementIndex(offset);
+            }
+            public int getEndOffset() {
+                return img.getEndOffset();
+            }
+            public String getName() {
+                return img.getName();
+            }
+            public Element getParentElement() {
+                return img.getParentElement();
+            }
+            public int getStartOffset() {
+                return img.getStartOffset();
+            }
+            public boolean isLeaf() {
+                return img.isLeaf();
+            }
+        };
+
+        view = new ImageView(e);
+        marker.reset();
+        assertSame(value, view.getAltText());
+        assertTrue(marker.isOccurred());
+    }
+
+    public void testSetParent() {
+        final Marker properties = new Marker();
+        view = new ImageView(img) {
+            protected void setPropertiesFromAttributes() {
+                properties.setOccurred();
+                super.setPropertiesFromAttributes();
+            }
+        };
+        if (isHarmony()) {
+            assertTrue(properties.isOccurred());
+        } else {
+            assertFalse(properties.isOccurred());
+        }
+
+        view.setParent(new InlineView(img));
+
+        if (isHarmony()) {
+            assertTrue(properties.isOccurred());
+        } else {
+            assertFalse(properties.isOccurred());
+        }
+    }
+
+    public void testSetSize() throws Exception {
+        init(null, null);
+        assertEquals(iconWidth,
+                     (int)view.getPreferredSpan(View.X_AXIS));
+        assertEquals(iconHeight,
+                     (int)view.getPreferredSpan(View.Y_AXIS));
+
+        view.setSize(231, 231);
+
+        assertEquals(iconWidth,
+                     (int)view.getPreferredSpan(View.X_AXIS));
+        assertEquals(iconHeight,
+                     (int)view.getPreferredSpan(View.Y_AXIS));
+    }
+
+    // modelToView(int, Shape, Bias)
+    public void testModelToView() throws Exception {
+        init(null, null);
+        assertEquals(iconWidth,
+                     (int)view.getPreferredSpan(View.X_AXIS));
+        assertEquals(1, view.getEndOffset() - view.getStartOffset());
+        Rectangle shape = new Rectangle(21, 33, 132, 129);
+        assertEquals(new Rectangle(21, 33, 0, 129),
+                     view.modelToView(view.getStartOffset(), shape,
+                                      Bias.Forward));
+        assertEquals(new Rectangle(21, 33, 0, 129),
+                     view.modelToView(view.getStartOffset(), shape,
+                                      Bias.Backward));
+        assertEquals(new Rectangle(21 + shape.width, 33, 0, 129),
+                     view.modelToView(view.getEndOffset(), shape,
+                                      Bias.Forward));
+        assertEquals(new Rectangle(21 + shape.width, 33, 0, 129),
+                     view.modelToView(view.getEndOffset(), shape,
+                                      Bias.Backward));
+    }
+
+    public void testModelToViewWithAltText() throws Exception {
+        final FontMetrics metrics = Toolkit.getDefaultToolkit()
+                                    .getFontMetrics(view.getStyleSheet()
+                                                    .getFont(attrs));
+        int textWidth = metrics.stringWidth(view.getAltText());
+        assertEquals(iconWidth + textWidth,
+                     (int)view.getPreferredSpan(View.X_AXIS));
+        assertEquals(1, view.getEndOffset() - view.getStartOffset());
+        Rectangle shape = new Rectangle(21, 33, 132, 129);
+        assertEquals(new Rectangle(21, 33, 0, 129),
+                     view.modelToView(view.getStartOffset(), shape,
+                                      Bias.Forward));
+        assertEquals(new Rectangle(21, 33, 0, 129),
+                     view.modelToView(view.getStartOffset(), shape,
+                                      Bias.Backward));
+
+
+        assertEquals(new Rectangle(21 + shape.width, 33, 0, 129),
+                     view.modelToView(view.getEndOffset(), shape,
+                                      Bias.Forward));
+        assertEquals(new Rectangle(21 + shape.width, 33, 0, 129),
+                     view.modelToView(view.getEndOffset(), shape,
+                                      Bias.Backward));
+    }
+
+    // viewToModel(float, float, Shape, Bias[]
+    public void testViewToModel() {
+        Rectangle shape = new Rectangle(21, 33, 132, 129);
+        Bias[] bias = new Bias[1];
+        assertEquals(view.getStartOffset(),
+                     view.viewToModel(0, 0, shape, bias));
+        assertSame(Bias.Forward, bias[0]);                      bias[0] = null;
+        assertEquals(view.getStartOffset(),
+                     view.viewToModel(shape.x + shape.width / 2 - 1, shape.y,
+                                      shape, bias));
+        assertSame(Bias.Forward, bias[0]);                      bias[0] = null;
+
+
+        assertEquals(view.getStartOffset(),
+                     view.viewToModel(shape.x + shape.width / 2 + 1, shape.y,
+                                      shape, bias));
+        assertSame(Bias.Forward, bias[0]);                      bias[0] = null;
+        assertEquals(view.getEndOffset(),
+                     view.viewToModel(shape.x + shape.width + 31,
+                                      shape.y + shape.height + 33,
+                                      shape, bias));
+        assertSame(Bias.Backward, bias[0]);                     bias[0] = null;
+
+
+        assertEquals(view.getStartOffset(),
+                     view.viewToModel(shape.x + shape.width - 1,
+                                      shape.y, shape, bias));
+        assertSame(Bias.Forward, bias[0]);                      bias[0] = null;
+        assertEquals(view.getEndOffset(),
+                     view.viewToModel(shape.x + shape.width,
+                                      shape.y, shape, bias));
+        assertSame(Bias.Backward, bias[0]);                     bias[0] = null;
+    }
+
+    public void testGetAlignment() {
+        assertEquals(0.5f, view.getAlignment(View.X_AXIS), 0);
+        assertEquals(1.0f, view.getAlignment(View.Y_AXIS), 0);
+    }
+
+    public void testGetAttributes() {
+        assertSame(attrs, view.getAttributes());
+        assertNotSame(attrs, view.getElement().getAttributes());
+    }
+
+    public void testChangedUpdate() {
+        final Marker properties = new Marker(true);
+        view = new ImageView(img) {
+            protected void setPropertiesFromAttributes() {
+                properties.setOccurred();
+                super.setPropertiesFromAttributes();
+            }
+        };
+
+        if (isHarmony()) {
+            assertTrue(properties.isOccurred());
+        } else {
+            assertFalse(properties.isOccurred());
+        }
+
+        view.changedUpdate(new DocumentEvent() {
+            public int getOffset() {
+                return img.getStartOffset();
+            }
+            public int getLength() {
+                return img.getEndOffset() - img.getStartOffset();
+            }
+            public Document getDocument() {
+                return doc;
+            }
+            public EventType getType() {
+                return EventType.CHANGE;
+            }
+            public ElementChange getChange(Element elem) {
+                return null;
+            }
+        }, new Rectangle(), null);
+        if (isHarmony()) {
+            assertTrue(properties.isOccurred());
+        } else {
+            assertFalse(properties.isOccurred());
+        }
+    }
+
+    public void testGetStyleSheet() {
+        assertSame(doc.getStyleSheet(), view.getStyleSheet());
+    }
+
+    public void testSetPropertiesFromAttributes() {
+        final Marker color = new Marker(true);
+        view = new ImageView(img) {
+            private AttributeSet attributes;
+            public AttributeSet getAttributes() {
+                if (attributes == null) {
+                    attributes = new SimpleAttributeSet(super.getAttributes()) {
+                        public Object getAttribute(Object key) {
+                            if (key == CSS.Attribute.COLOR) {
+                                color.setOccurred();
+                            }
+                            return super.getAttribute(key);
+                        }
+                    };
+                }
+                return attributes;
+            }
+        };
+        color.reset();
+        view.setPropertiesFromAttributes();
+        assertTrue(color.isOccurred());
+    }
+
+//    public void testPaint() {
+//
+//    }
+
+    private void init() throws Exception {
+        init(DEFAULT_SRC);
+    }
+
+    private void init(final String src) throws Exception {
+        init(src, DEFAULT_ALT);
+    }
+
+    private void init(final String src, final String alt) throws Exception {
+        kit = new HTMLEditorKit();
+        doc = (HTMLDocument)kit.createDefaultDocument();
+        StringReader reader = new StringReader("<html><head></head>" +
+               "<body>" +
+               "<img" +
+               (src != null ? " src=\"" + src + "\"" : "") +
+               (alt != null ? " alt=\"" + alt + "\"" : "") + ">" +
+               "</body></html>");
+        kit.read(reader, doc, 0);
+
+        img = doc.getCharacterElement(1);
+        assertEquals(HTML.Tag.IMG.toString(), img.getName());
+
+        view = new ImageView(img);
+        attrs = view.getAttributes();
+
+        noIcon = view.getNoImageIcon();
+        iconWidth = noIcon.getIconWidth();
+        iconHeight = noIcon.getIconHeight();
+    }
+
+    private void initImage() throws Exception {
+        writeImage();
+        init(imageFile.toURL().toString());
+    }
+
+    private static void writeImage() throws IOException {
+        imageFile = File.createTempFile("imageViewTest", ".gif");
+        FileOutputStream out = new FileOutputStream(imageFile);
+        for (int i = 0; i < IMAGE_BYTES.length; i++) {
+            out.write(IMAGE_BYTES[i]);
+        }
+        out.close();
+    }
+
+    private void waitForImage() throws Exception {
+        final Image image = view.getImage();
+
+        int w = -1;
+        int h = -1;
+        while (w == -1 || h == -1) {
+            w = image.getWidth(null);
+            h = image.getHeight(null);
+            Thread.sleep(1000);
+        };
+        assertEquals(IMAGE_SIZE, w);
+        assertEquals(IMAGE_SIZE, h);
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/InlineViewTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/InlineViewTest.java?rev=427121&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/InlineViewTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/InlineViewTest.java Mon Jul 31 07:08:47 2006
@@ -0,0 +1,475 @@
+/*
+ *  Copyright 2005 - 2006 The Apache Software Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
+ *
+ *  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.
+ */
+/**
+ * @author Alexey A. Ivanov
+ * @version $Revision$
+ */
+package javax.swing.text.html;
+
+import java.awt.Graphics;
+import java.awt.Shape;
+import java.io.StringReader;
+
+import javax.swing.BasicSwingTestCase;
+import javax.swing.event.DocumentEvent;
+import javax.swing.text.AttributeSet;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.DefaultStyledDocument;
+import javax.swing.text.Document;
+import javax.swing.text.Element;
+import javax.swing.text.GlyphView;
+import javax.swing.text.SimpleAttributeSet;
+import javax.swing.text.StyleConstants;
+import javax.swing.text.StyledDocument;
+import javax.swing.text.TabExpander;
+import javax.swing.text.View;
+import javax.swing.text.GlyphView.GlyphPainter;
+import javax.swing.text.Position.Bias;
+
+public class InlineViewTest extends BasicSwingTestCase {
+    public static class FixedPainter extends GlyphPainter {
+        public static final int CHAR_WIDTH = 7;
+
+        public float getSpan(GlyphView v, int startOffset, int endOffset,
+                             TabExpander tabExpander, float x) {
+            return CHAR_WIDTH * (endOffset - startOffset);
+        }
+
+        public int getBoundedPosition(GlyphView v, int startOffset,
+                                      float x, float len) {
+            int result = (int)len / CHAR_WIDTH + startOffset;
+            return result <= v.getEndOffset() ? result : v.getEndOffset();
+        }
+
+        public float getHeight(GlyphView v) {
+            return 0;
+        }
+        public float getAscent(GlyphView v) {
+            return 0;
+        }
+        public float getDescent(GlyphView v) {
+            return 0;
+        }
+        public void paint(GlyphView v, Graphics g, Shape alloc,
+                          int startOffset, int endOffset) {
+        }
+        public Shape modelToView(GlyphView v, int offset, Bias bias,
+                                 Shape alloc) throws BadLocationException {
+            return null;
+        }
+        public int viewToModel(GlyphView v, float x, float y,
+                               Shape alloc, Bias[] biasReturn) {
+            return -1;
+        }
+    }
+
+    private class Event implements DocumentEvent {
+        public int getOffset() {
+            return inline.getStartOffset() + 1;
+        }
+
+        public int getLength() {
+            return inline.getEndOffset() - inline.getStartOffset() - 2;
+        }
+
+        public Document getDocument() {
+            return doc;
+        }
+
+        public EventType getType() {
+            return null;
+        }
+
+        public ElementChange getChange(final Element elem) {
+            return null;
+        }
+    }
+
+    private HTMLEditorKit kit;
+    private HTMLDocument doc;
+    private Element inline;
+    private InlineView view;
+    private AttributeSet attrs;
+
+    private int startOffset;
+    private String text;
+    private int whitespace;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        setIgnoreNotImplemented(true);
+        kit = new HTMLEditorKit();
+        doc = (HTMLDocument)kit.createDefaultDocument();
+        StringReader reader = new StringReader("<html><head></head>" +
+               "<body>" +
+               "<p>Normal paragraph: <em>em inside</em>" +
+               "   paragraph." +
+               "</body></html>");
+        kit.read(reader, doc, 0);
+
+        inline = doc.getCharacterElement(20);
+        assertNotNull(inline.getAttributes().getAttribute(HTML.Tag.EM));
+
+        view = new InlineView(inline);
+        attrs = view.getAttributes();
+
+        startOffset = inline.getStartOffset();
+        text = doc.getText(startOffset, inline.getEndOffset() - startOffset);
+        whitespace = text.indexOf(' ');
+    }
+
+    public void testInlineView() {
+        assertSame(inline, view.getElement());
+        assertNotSame(inline.getAttributes(), view.getAttributes());
+    }
+
+    public void testInlineViewUponParagraph() throws BadLocationException {
+        final Element paragraph = doc.getParagraphElement(20);
+        view = new InlineView(paragraph);
+        assertSame(paragraph, view.getElement());
+        assertNotSame(paragraph.getAttributes(), view.getAttributes());
+    }
+
+    public void testInlineViewUponStyledDocument() throws BadLocationException {
+        final StyledDocument styledDoc = new DefaultStyledDocument();
+        styledDoc.insertString(0, "a simple paragraph", null);
+        inline = styledDoc.getCharacterElement(1);
+        testExceptionalCase(new ClassCastCase() {
+            public void exceptionalAction() throws Exception {
+                new InlineView(inline);
+            }
+
+            public String expectedExceptionMessage() {
+                return styledDoc.getClass().getName();
+            }
+        });
+    }
+
+    public void testGetAttributes() {
+        assertEquals(2, attrs.getAttributeCount());
+        assertEquals("italic",
+                     attrs.getAttribute(CSS.Attribute.FONT_STYLE).toString());
+        assertEquals(HTML.Tag.EM.toString(),
+                     attrs.getAttribute(AttributeSet.NameAttribute));
+
+        assertTrue(StyleConstants.isItalic(attrs));
+    }
+
+    public void testGetAttributesUpdate() {
+        assertEquals(2, attrs.getAttributeCount());
+        assertEquals("italic",
+                     attrs.getAttribute(CSS.Attribute.FONT_STYLE).toString());
+        assertEquals(HTML.Tag.EM.toString(),
+                     attrs.getAttribute(AttributeSet.NameAttribute));
+        assertNull(attrs.getAttribute(CSS.Attribute.BACKGROUND_COLOR));
+
+        doc.getStyleSheet().addRule("em { background-color: white }");
+        assertEquals(4, attrs.getAttributeCount());
+        assertEquals("white", attrs.getAttribute(CSS.Attribute.BACKGROUND_COLOR)
+                              .toString());
+    }
+
+    public void testGetAttributesStyleSheet() {
+        final Marker ssMarker = new Marker();
+        view = new InlineView(inline) {
+            protected StyleSheet getStyleSheet() {
+                ssMarker.setOccurred();
+                return super.getStyleSheet();
+            };
+        };
+        assertTrue(ssMarker.isOccurred());
+        ssMarker.reset();
+        view.getAttributes();
+        assertFalse(ssMarker.isOccurred());
+    }
+
+    public void testGetAttributesSame() {
+        assertSame(attrs, view.getAttributes());
+    }
+
+    public void testGetBreakWeight() throws BadLocationException {
+        view.setGlyphPainter(new FixedPainter());
+        assertNull(attrs.getAttribute(CSS.Attribute.WHITE_SPACE));
+
+        assertEquals(View.BadBreakWeight,
+                     view.getBreakWeight(View.X_AXIS, startOffset,
+                                         FixedPainter.CHAR_WIDTH - 0.01f));
+        assertEquals(View.GoodBreakWeight,
+                     view.getBreakWeight(View.X_AXIS, startOffset,
+                                         FixedPainter.CHAR_WIDTH));
+
+        assertEquals(View.GoodBreakWeight,
+                     view.getBreakWeight(View.X_AXIS, startOffset,
+                                         FixedPainter.CHAR_WIDTH * whitespace));
+
+        assertEquals(View.ExcellentBreakWeight,
+                     view.getBreakWeight(View.X_AXIS, startOffset,
+                                         FixedPainter.CHAR_WIDTH
+                                         * (whitespace + 1)));
+    }
+
+    public void testGetBreakWeightNowrap() throws BadLocationException {
+        view.setGlyphPainter(new FixedPainter());
+
+        assertNull(attrs.getAttribute(CSS.Attribute.WHITE_SPACE));
+        doc.getStyleSheet().addRule("em { white-space: nowrap }");
+        view.setPropertiesFromAttributes();
+        assertNotNull(attrs.getAttribute(CSS.Attribute.WHITE_SPACE));
+
+        assertEquals(View.BadBreakWeight,
+                     view.getBreakWeight(View.X_AXIS, startOffset,
+                                         FixedPainter.CHAR_WIDTH - 0.01f));
+        assertEquals(View.BadBreakWeight,
+                     view.getBreakWeight(View.X_AXIS, startOffset,
+                                         FixedPainter.CHAR_WIDTH));
+
+        assertEquals(View.BadBreakWeight,
+                     view.getBreakWeight(View.X_AXIS, startOffset,
+                                         FixedPainter.CHAR_WIDTH * whitespace));
+
+        assertEquals(View.BadBreakWeight,
+                     view.getBreakWeight(View.X_AXIS, startOffset,
+                                         FixedPainter.CHAR_WIDTH
+                                         * (whitespace + 1)));
+    }
+
+    public void testBreakView() throws BadLocationException {
+        view.setGlyphPainter(new FixedPainter());
+        assertNull(attrs.getAttribute(CSS.Attribute.WHITE_SPACE));
+
+        View fragment = view.breakView(View.X_AXIS, startOffset, 0,
+                                       FixedPainter.CHAR_WIDTH - 0.01f);
+        assertTrue(fragment instanceof InlineView);
+        assertNotSame(view, fragment);
+        assertEquals(view.getStartOffset(), fragment.getStartOffset());
+        assertEquals(view.getEndOffset(), fragment.getEndOffset());
+
+        fragment = view.breakView(View.X_AXIS, startOffset, 0,
+                                  FixedPainter.CHAR_WIDTH);
+        assertEquals(view.getStartOffset(), fragment.getStartOffset());
+        assertEquals(view.getStartOffset() + 1, fragment.getEndOffset());
+
+        fragment = view.breakView(View.X_AXIS, startOffset, 0,
+                                  FixedPainter.CHAR_WIDTH * (whitespace + 1));
+        assertEquals(view.getStartOffset(), fragment.getStartOffset());
+        assertEquals(view.getStartOffset() + whitespace + 1,
+                     fragment.getEndOffset());
+    }
+
+    public void testBreakViewNowrap() {
+        view.setGlyphPainter(new FixedPainter());
+        doc.getStyleSheet().addRule("em { white-space: nowrap }");
+        view.setPropertiesFromAttributes();
+        assertNotNull(attrs.getAttribute(CSS.Attribute.WHITE_SPACE));
+
+        View fragment = view.breakView(View.X_AXIS, startOffset, 0,
+                                       FixedPainter.CHAR_WIDTH - 0.01f);
+        assertTrue(fragment instanceof InlineView);
+        if (isHarmony()) {
+            // The view is not breakable
+            // if the value of 'white-space' is 'nowrap'
+            assertSame(view, fragment);
+            return;
+        }
+        assertNotSame(view, fragment);
+        assertEquals(view.getStartOffset(), fragment.getStartOffset());
+        assertEquals(view.getEndOffset(), fragment.getEndOffset());
+
+        fragment = view.breakView(View.X_AXIS, startOffset, 0,
+                                  FixedPainter.CHAR_WIDTH);
+        assertEquals(view.getStartOffset(), fragment.getStartOffset());
+        assertEquals(view.getStartOffset() + 1, fragment.getEndOffset());
+
+        fragment = view.breakView(View.X_AXIS, startOffset, 0,
+                                  FixedPainter.CHAR_WIDTH * (whitespace + 1));
+        assertEquals(view.getStartOffset(), fragment.getStartOffset());
+        assertEquals(view.getStartOffset() + whitespace + 1,
+                     fragment.getEndOffset());
+    }
+
+    public void testChangedUpdate() {
+        final Marker prefChanged = new Marker();
+        final Marker setProps = new Marker();
+        view = new InlineView(inline) {
+            public void preferenceChanged(View child,
+                                          boolean width, boolean height) {
+                prefChanged.setOccurred();
+                assertNull(child);
+                assertTrue(width);
+                assertTrue(height);
+                super.preferenceChanged(child, width, height);
+            }
+
+            protected void setPropertiesFromAttributes() {
+                setProps.setOccurred();
+                super.setPropertiesFromAttributes();
+            }
+        };
+        assertFalse(prefChanged.isOccurred());
+        assertFalse(setProps.isOccurred());
+
+        view.changedUpdate(new Event(), null, null);
+        assertTrue(prefChanged.isOccurred());
+        assertFalse(setProps.isOccurred());
+    }
+
+    public void testChangedUpdateAttributes() {
+        final Marker viewAttrMarker = new Marker(true);
+        final StyleSheet ss = new StyleSheet() {
+            public AttributeSet getViewAttributes(final View v) {
+                viewAttrMarker.setOccurred();
+                return super.getViewAttributes(v);
+            }
+        };
+        view = new InlineView(inline) {
+            protected StyleSheet getStyleSheet() {
+                return ss;
+            }
+        };
+
+        assertTrue(viewAttrMarker.isOccurred());
+        attrs = view.getAttributes();
+        view.changedUpdate(new Event(), null, null);
+        assertTrue(viewAttrMarker.isOccurred());
+        assertNotSame(attrs, view.getAttributes());
+    }
+
+    public void testInsertUpdate() {
+        final Marker prefChanged = new Marker();
+        final Marker setProps = new Marker();
+        view = new InlineView(inline) {
+            public void preferenceChanged(View child,
+                                          boolean width, boolean height) {
+                prefChanged.setOccurred();
+                assertNull(child);
+                assertTrue(width);
+                assertFalse(height);
+                super.preferenceChanged(child, width, height);
+            }
+
+            protected void setPropertiesFromAttributes() {
+                setProps.setOccurred();
+                super.setPropertiesFromAttributes();
+            }
+        };
+        assertFalse(prefChanged.isOccurred());
+        assertFalse(setProps.isOccurred());
+
+        view.insertUpdate(new Event(), null, null);
+        assertTrue(prefChanged.isOccurred());
+        assertFalse(setProps.isOccurred());
+    }
+
+    public void testRemoveUpdate() {
+        final Marker prefChanged = new Marker();
+        final Marker setProps = new Marker();
+        view = new InlineView(inline) {
+            public void preferenceChanged(View child,
+                                          boolean width, boolean height) {
+                prefChanged.setOccurred();
+                assertNull(child);
+                assertTrue(width);
+                assertFalse(height);
+                super.preferenceChanged(child, width, height);
+            }
+
+            protected void setPropertiesFromAttributes() {
+                setProps.setOccurred();
+                super.setPropertiesFromAttributes();
+            }
+        };
+        assertFalse(prefChanged.isOccurred());
+        assertFalse(setProps.isOccurred());
+
+        view.removeUpdate(new Event(), null, null);
+        assertTrue(prefChanged.isOccurred());
+        assertFalse(setProps.isOccurred());
+    }
+
+    public void testSetPropertiesFromAttributes() {
+        assertTrue(view.getFont().isItalic());
+        assertFalse(view.isUnderline());
+        doc.getStyleSheet().addRule("em { text-decoration: underline }");
+        assertFalse(view.isUnderline());
+        view.setPropertiesFromAttributes();
+        assertTrue(view.isUnderline());
+    }
+
+    public void testSetPropertiesFromAttributesBoxPainter() {
+        final Marker boxMarker = new Marker();
+        final Marker listMarker = new Marker();
+        final StyleSheet ss = new StyleSheet() {
+            public BoxPainter getBoxPainter(final AttributeSet attr) {
+                boxMarker.setOccurred();
+                return null;
+            }
+            public ListPainter getListPainter(final AttributeSet attr) {
+                listMarker.setOccurred();
+                return null;
+            }
+        };
+        view = new InlineView(inline) {
+            protected StyleSheet getStyleSheet() {
+                return ss;
+            }
+        };
+        assertFalse(boxMarker.isOccurred());
+        assertFalse(listMarker.isOccurred());
+        view.setPropertiesFromAttributes();
+        assertFalse(boxMarker.isOccurred());
+        assertFalse(listMarker.isOccurred());
+    }
+
+    public void testSetPropertiesFromAttributesAttributes() {
+        final Marker verticalAlign = new Marker();
+        final Marker textDecoration = new Marker();
+        final Marker whiteSpace = new Marker();
+        view = new InlineView(inline) {
+            private AttributeSet attributes;
+            public AttributeSet getAttributes() {
+                if (attributes == null) {
+                    attributes = new SimpleAttributeSet(super.getAttributes()) {
+                        public Object getAttribute(Object name) {
+                            if (name == CSS.Attribute.VERTICAL_ALIGN) {
+                                verticalAlign.setOccurred();
+                            } else if (name == CSS.Attribute.TEXT_DECORATION) {
+                                textDecoration.setOccurred();
+                            } else if (name == CSS.Attribute.WHITE_SPACE) {
+                                whiteSpace.setOccurred();
+                            }
+                            return super.getAttribute(name);
+                        }
+                    };
+                }
+                return attributes;
+            }
+        };
+        view.setPropertiesFromAttributes();
+        assertTrue(whiteSpace.isOccurred());
+        if (isHarmony()) {
+            assertFalse(verticalAlign.isOccurred());
+            assertFalse(textDecoration.isOccurred());
+        } else {
+            assertTrue(verticalAlign.isOccurred());
+            assertTrue(textDecoration.isOccurred());
+        }
+    }
+
+    public void testGetStyleSheet() {
+        assertSame(doc.getStyleSheet(), view.getStyleSheet());
+    }
+
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/ListViewTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/ListViewTest.java?rev=427121&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/ListViewTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/ListViewTest.java Mon Jul 31 07:08:47 2006
@@ -0,0 +1,163 @@
+/*
+ *  Copyright 2005 - 2006 The Apache Software Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
+ *
+ *  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.
+ */
+/**
+ * @author Alexey A. Ivanov
+ * @version $Revision$
+ */
+package javax.swing.text.html;
+
+import java.io.StringReader;
+
+import javax.swing.BasicSwingTestCase;
+import javax.swing.SizeRequirements;
+import javax.swing.text.AttributeSet;
+import javax.swing.text.Element;
+import javax.swing.text.SimpleAttributeSet;
+import javax.swing.text.View;
+import javax.swing.text.ViewFactory;
+import javax.swing.text.ViewTestHelpers.ChildrenFactory;
+import javax.swing.text.html.BlockViewTest.InlineViewFactory;
+
+public class ListViewTest extends BasicSwingTestCase {
+    private class ListViewImpl extends ListView {
+        public ListViewImpl(final Element element) {
+            super(element);
+            loadChildren();
+        }
+
+        public ViewFactory getViewFactory() {
+            return factory;
+        }
+
+        public void loadChildren() {
+            loadChildren(getViewFactory());
+        }
+    }
+
+    private HTMLEditorKit kit;
+    private HTMLDocument doc;
+    private Element listU;
+    private ListView view;
+    private ViewFactory factory;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        setIgnoreNotImplemented(true);
+        kit = new HTMLEditorKit();
+        doc = (HTMLDocument)kit.createDefaultDocument();
+        StringReader reader = new StringReader("<html><head></head>" +
+               "<body>" +
+               "<ul>" +
+               "    <li>first</li>" +
+               "    <li>second</li>" +
+               "</ul>" +
+               "</body></html>");
+        kit.read(reader, doc, 0);
+
+        listU = doc.getDefaultRootElement().getElement(1).getElement(0);
+        //         | html                  | body        | ul
+        assertEquals(HTML.Tag.UL.toString(), listU.getName());
+
+        factory = new InlineViewFactory();
+        view = new ListViewImpl(listU);
+    }
+
+    public void testListView() {
+        assertEquals(View.Y_AXIS, view.getAxis());
+        assertNotSame(listU.getAttributes(), view.getAttributes());
+        assertEquals(listU.getElementCount(), view.getViewCount());
+    }
+
+    public void testGetAlignment() {
+        assertEquals(0.5f, view.getAlignment(View.X_AXIS), 0);
+        assertEquals(0.5f, view.getAlignment(View.Y_AXIS), 0);
+    }
+
+    public void testGetAlignmentFlexible() {
+        factory = new ChildrenFactory();
+        ((ChildrenFactory)factory).makeFlexible();
+        view = new ListViewImpl(listU);
+
+        assertEquals(0.5f, view.getAlignment(View.X_AXIS), 0);
+        assertEquals(0.5f, view.getAlignment(View.Y_AXIS), 0);
+
+        SizeRequirements r = view.calculateMajorAxisRequirements(View.Y_AXIS,
+                                                                 null);
+        assertEquals(0.5f, r.alignment, 0);
+
+        r = view.calculateMajorAxisRequirements(View.X_AXIS, r);
+        assertEquals(0.5f, r.alignment, 0);
+    }
+
+    public void testSetPropertiesFromAttributes() {
+        final Marker listImage = new Marker();
+        final Marker listType = new Marker();
+        view = new ListView(listU) {
+            private AttributeSet attributes;
+            public AttributeSet getAttributes() {
+                if (attributes == null) {
+                    attributes = new SimpleAttributeSet(super.getAttributes()) {
+                        public Object getAttribute(Object name) {
+                            if (name == CSS.Attribute.LIST_STYLE_IMAGE) {
+                                listImage.setOccurred();
+                            } else if (name == CSS.Attribute.LIST_STYLE_TYPE) {
+                                listType.setOccurred();
+                            }
+                            return super.getAttribute(name);
+                        }
+                    };
+                }
+                return attributes;
+            }
+        };
+        assertFalse(listImage.isOccurred());
+        assertFalse(listType.isOccurred());
+        view.setPropertiesFromAttributes();
+        assertEquals(!isHarmony(), listImage.isOccurred());
+        assertEquals(!isHarmony(), listType.isOccurred());
+    }
+
+    public void testSetPropertiesFromAttributesPainter() {
+        final Marker boxMarker = new Marker();
+        final Marker listMarker = new Marker();
+        final StyleSheet ss = new StyleSheet() {
+            public BoxPainter getBoxPainter(final AttributeSet attr) {
+                boxMarker.setOccurred();
+                return super.getBoxPainter(attr);
+            }
+            public ListPainter getListPainter(final AttributeSet attr) {
+                listMarker.setOccurred();
+                return null;
+            }
+        };
+        view = new ListView(listU) {
+            protected StyleSheet getStyleSheet() {
+                return ss;
+            }
+        };
+        assertFalse(boxMarker.isOccurred());
+        assertFalse(listMarker.isOccurred());
+        view.setPropertiesFromAttributes();
+        assertTrue(boxMarker.isOccurred());
+        assertTrue(listMarker.isOccurred());
+    }
+
+//    public void testPaint() {
+//    }
+
+//    public void testPaintChild() {
+//    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/MinimalHTMLWriterTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/MinimalHTMLWriterTest.java?rev=427121&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/MinimalHTMLWriterTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/MinimalHTMLWriterTest.java Mon Jul 31 07:08:47 2006
@@ -0,0 +1,453 @@
+/*
+ *  Copyright 2005 - 2006 The Apache Software Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
+ *
+ *  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.
+ */
+
+/**
+ * @author Vadim L. Bogdanov
+ * @version $Revision$
+ */
+package javax.swing.text.html;
+
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Graphics;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.Writer;
+
+import javax.swing.Icon;
+import javax.swing.JLabel;
+import javax.swing.SwingTestCase;
+import javax.swing.text.AbstractDocument;
+import javax.swing.text.AttributeSet;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.DefaultStyledDocument;
+import javax.swing.text.Element;
+import javax.swing.text.MutableAttributeSet;
+import javax.swing.text.SimpleAttributeSet;
+import javax.swing.text.Style;
+import javax.swing.text.StyleConstants;
+import javax.swing.text.StyledDocument;
+
+public class MinimalHTMLWriterTest extends SwingTestCase {
+    private static class TestMinimalHTMLWriter extends MinimalHTMLWriter {
+        public TestMinimalHTMLWriter(final Writer w, final StyledDocument doc) {
+            super(w, doc);
+        }
+
+        public TestMinimalHTMLWriter(final Writer w, final StyledDocument doc,
+                                        final int pos, final int len) {
+            super(w, doc, pos, len);
+        }
+
+        protected void incrIndent() {
+            super.incrIndent();
+        }
+
+        protected int getIndentLevel() {
+            return super.getIndentLevel();
+        }
+
+        protected int getLineLength() {
+            return super.getLineLength();
+        }
+    }
+
+    private StyledDocument doc;
+    private TestMinimalHTMLWriter writer;
+    private Writer out;
+    private Element iconElement;
+    private Element componentElement;
+
+    public MinimalHTMLWriterTest(final String name) {
+        super(name);
+    }
+
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        createDocument();
+        out = new StringWriter();
+        createWriter();
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    public void testText() throws Exception {
+        Element par = doc.getParagraphElement(0);
+        Element text = par.getElement(par.getElementCount() - 1);
+        writer.text(text);
+        assertEquals("green text", out.toString());
+    }
+
+    public void testWriteAttributes() throws Exception {
+        MutableAttributeSet attrs = new SimpleAttributeSet();
+        StyleConstants.setItalic(attrs, true);
+        StyleConstants.setFontFamily(attrs, "serif");
+
+        writer.writeAttributes(attrs);
+        if (isHarmony()) {
+            assertEquals("  font-style: italic;~  font-family: serif;~",
+                         out.toString());
+        } else {
+            assertEquals("  family:serif;~  italic:italic;~",
+                         out.toString());
+        }
+    }
+
+    public void testWrite() throws Exception {
+        writer = new TestMinimalHTMLWriter(out, doc) {
+            protected void writeHeader() throws IOException {
+                write("_header_");
+            }
+            protected void writeBody() throws IOException, BadLocationException {
+                write("_body");
+            }
+        };
+        setupWriter();
+
+        writer.write();
+        assertEquals("  <html>~_header__body  </html>~", out.toString());
+    }
+
+    public void testMinimalHTMLWriterWriterStyledDocumentIntInt() {
+        assertEquals(100, writer.getLineLength());
+        assertFalse(writer.inFontTag());
+    }
+
+    public void testMinimalHTMLWriterWriterStyledDocument() {
+        assertEquals(100, writer.getLineLength());
+        assertFalse(writer.inFontTag());
+    }
+
+    public void testInFontTag() throws Exception {
+        assertFalse(writer.inFontTag());
+
+        MutableAttributeSet attrs = new SimpleAttributeSet();
+        StyleConstants.setForeground(attrs, Color.GREEN);
+        writer.writeNonHTMLAttributes(attrs);
+        assertTrue(writer.inFontTag());
+    }
+
+    public void testIsText() {
+        assertFalse(writer.isText(doc.getParagraphElement(0)));
+        assertTrue(writer.isText(doc.getCharacterElement(0)));
+        assertFalse(writer.isText(iconElement));
+    }
+
+    public void testStartFontTag() throws Exception {
+        assertFalse(writer.inFontTag());
+        int indentLevel = writer.getIndentLevel();
+        writer.startFontTag("italic");
+        assertFalse(writer.inFontTag());
+        assertEquals(indentLevel + 1, writer.getIndentLevel());
+        writer.startFontTag("bold");
+        assertEquals("  <font style=\"italic\">~    <font style=\"bold\">~",
+                     out.toString());
+    }
+
+    public void testEndFontTag() throws Exception {
+        int indentLevel = writer.getIndentLevel();
+        writer.startFontTag("italic");
+        writer.endFontTag();
+        assertEquals(indentLevel, writer.getIndentLevel());
+        assertEquals("  <font style=\"italic\">~~  </font>~",
+                     out.toString());
+    }
+
+    public void testWriteBody() throws Exception {
+        writer = new TestMinimalHTMLWriter(out, doc)  {
+            protected void writeContent(final Element elem,
+                                        final boolean needsIndenting)
+                    throws IOException, BadLocationException {
+
+                if (needsIndenting) {
+                    indent();
+                }
+                write("_content_");
+            }
+
+            protected void writeLeaf(final Element elem) throws IOException {
+                write("_leaf_");
+            }
+        };
+        setupWriter();
+
+        writer.writeBody();
+        assertEquals("  <body>~    <p class=default>~"
+                     + "      _content__content__content_~    </p>~"
+                     + "    <p class=myStylea>~      _content__leaf__leaf_~"
+                     + "    </p>~  </body>~",
+                     out.toString());
+
+        out = new StringWriter();
+        Element e = doc.getParagraphElement(0).getElement(1);
+        writer = new TestMinimalHTMLWriter(out, doc, e.getStartOffset(),
+                                           e.getEndOffset() - e.getStartOffset());
+        setupWriter();
+        writer.writeBody();
+        assertEquals("  <body>~    <p class=default>~      <i>italic text</i>~"
+                     + "    </p>~  </body>~",
+                     out.toString());
+    }
+
+    public void testWriteContent() throws Exception {
+        writer.writeContent(doc.getCharacterElement(0), true);
+        writer.writeContent(doc.getCharacterElement(0), true);
+        assertEquals("  <b>bold text   bold text ",
+                     out.toString());
+
+        out = new StringWriter();
+        createWriter();
+        writer.writeContent(doc.getCharacterElement(0), false);
+        writer.writeContent(
+            doc.getParagraphElement(doc.getLength() - 1).getElement(0), false);
+        assertEquals("<b>bold text </b>  <span style=\"color: #00ff00\">~"
+                     + " more green text",
+                     out.toString());
+    }
+
+    public void testWriteHTMLTags() throws Exception {
+        MutableAttributeSet attrs = new SimpleAttributeSet();
+        StyleConstants.setItalic(attrs, true);
+        writer.writeHTMLTags(attrs);
+        assertEquals("<i>", out.toString());
+
+        StyleConstants.setBold(attrs, true);
+        writer.writeHTMLTags(attrs);
+        assertEquals("<i><b>", out.toString());
+
+        attrs = new SimpleAttributeSet();
+        StyleConstants.setUnderline(attrs, true);
+        StyleConstants.setStrikeThrough(attrs, true);
+        writer.writeHTMLTags(attrs);
+        assertEquals("<i><b><u>", out.toString());
+    }
+
+    public void testWriteHeader() throws Exception {
+        writer = new TestMinimalHTMLWriter(out, doc) {
+            protected void writeStyles() throws IOException {
+                indent();
+                write("...styles...");
+                writeLineSeparator();
+            }
+        };
+        setupWriter();
+
+        writer.writeHeader();
+        String result = out.toString();
+        if (!isHarmony()) {
+            result = result.replaceFirst("<style>", "<style type=\"text/css\">");
+        }
+        assertEquals("  <head>~    <style type=\"text/css\">~"
+                     + "      <!--~        ...styles...~"
+                     + "      -->~    </style>~  </head>~",
+                     result);
+    }
+
+    public void testWriteImage() throws Exception {
+        writer.incrIndent();
+        writer.writeLeaf(iconElement);
+        assertEquals("    ", out.toString());
+
+        writer.writeLeaf(doc.getCharacterElement(0));
+        assertEquals("        ", out.toString());
+    }
+
+    public void testWriteComponent() throws Exception {
+        writer.incrIndent();
+        writer.writeLeaf(componentElement);
+        assertEquals("    ", out.toString());
+
+        writer.writeLeaf(doc.getCharacterElement(0));
+        assertEquals("        ", out.toString());
+    }
+
+    public void testWriteLeaf() throws Exception {
+        writer = new TestMinimalHTMLWriter(out, doc) {
+            protected void writeImage(final Element elem) throws IOException {
+                super.writeImage(elem);
+                write("_image_");
+            }
+
+            protected void writeComponent(final Element elem) throws IOException {
+                super.writeComponent(elem);
+                write("_component_");
+            }
+        };
+        setupWriter();
+
+        writer.writeLeaf(doc.getCharacterElement(0));
+        assertEquals("  ", out.toString());
+
+        writer.writeLeaf(iconElement);
+        assertEquals("    _image_", out.toString());
+
+        writer.writeLeaf(componentElement);
+        assertEquals("    _image_  _component_", out.toString());
+    }
+
+    public void testWriteNonHTMLAttributes() throws Exception {
+        MutableAttributeSet attrs = new SimpleAttributeSet();
+        StyleConstants.setItalic(attrs, true);
+        StyleConstants.setForeground(attrs, Color.RED);
+        StyleConstants.setLineSpacing(attrs, 1.0f);
+        int indentLevel = writer.getIndentLevel();
+        writer.writeNonHTMLAttributes(attrs);
+
+        assertEquals("  <span style=\"color: #ff0000\">~",
+                     out.toString());
+        assertTrue(writer.inFontTag());
+        assertEquals(indentLevel + 1, writer.getIndentLevel());
+        writer.writeEndParagraph();
+
+        out = new StringWriter();
+        createWriter();
+        attrs = new SimpleAttributeSet();
+        writer.writeNonHTMLAttributes(attrs);
+        assertEquals("", out.toString());
+        assertFalse(writer.inFontTag());
+    }
+
+    public void testWriteStartParagraph() throws Exception {
+        Element par = doc.getParagraphElement(0);
+        writer.writeStartParagraph(par);
+        assertEquals("  <p class=default>~", out.toString());
+
+        out = new StringWriter();
+        createWriter();
+        par = doc.getParagraphElement(doc.getLength() - 1);
+        writer.writeStartParagraph(par);
+        assertEquals("  <p class=myStylea>~", out.toString());
+    }
+
+    public void testWriteEndParagraph() throws Exception {
+        writer.writeEndParagraph();
+        assertEquals("~</p>~", out.toString());
+
+        MutableAttributeSet attrs = new SimpleAttributeSet();
+        StyleConstants.setItalic(attrs, true);
+        StyleConstants.setFontFamily(attrs, "serif");
+        writer.incrIndent();
+
+        writer.writeNonHTMLAttributes(attrs);
+        writer.writeHTMLTags(attrs);
+        writer.writeEndParagraph();
+        assertEquals("~</p>~  <span style=\"font-family: serif\">~<i></i>"
+                     + "~  </span>~</p>~",
+                     out.toString());
+    }
+
+    public void testWriteStartTag() throws Exception {
+        int indentLevel = writer.getIndentLevel();
+        writer.writeStartTag("the_tag");
+        assertEquals("  the_tag~", out.toString());
+        assertEquals(indentLevel + 1, writer.getIndentLevel());
+    }
+
+    public void testWriteEndTag() throws Exception {
+        int indentLevel = writer.getIndentLevel();
+        writer.writeEndTag("the_tag");
+        assertEquals("the_tag~", out.toString());
+        assertEquals(indentLevel - 1, writer.getIndentLevel());
+    }
+
+    public void testWriteStyles() throws Exception {
+        writer = new TestMinimalHTMLWriter(out, doc) {
+            protected void writeAttributes(final AttributeSet attr)
+                    throws IOException {
+
+                indent();
+                write("_attributes_");
+                writeLineSeparator();
+            }
+        };
+        setupWriter();
+
+        writer.writeStyles();
+
+        String output = out.toString();
+        // order in which styles are written is not important
+        output = output.replaceFirst("p.myStylea", "p.myStyle");
+
+        assertEquals("  p.myStyle {~    _attributes_~  }~"
+                     + "  p.myStyle {~    _attributes_~  }~",
+                     output);
+    }
+
+    private void createWriter() {
+        writer = new TestMinimalHTMLWriter(out, doc);
+        setupWriter();
+    }
+
+    private void setupWriter() {
+        writer.setLineSeparator("~");
+        writer.incrIndent();
+    }
+
+    private void createDocument() throws Exception {
+        super.setUp();
+        doc = new DefaultStyledDocument();
+        MutableAttributeSet boldStyle = new SimpleAttributeSet();
+        StyleConstants.setBold(boldStyle, true);
+        MutableAttributeSet italicStyle = new SimpleAttributeSet();
+        StyleConstants.setItalic(italicStyle, true);
+        MutableAttributeSet colorStyle = new SimpleAttributeSet();
+        StyleConstants.setForeground(colorStyle, Color.GREEN);
+
+        Style style = doc.addStyle("myStyle", null);
+        StyleConstants.setBackground(style, Color.RED);
+        style = doc.addStyle("myStylea", null);
+        StyleConstants.setForeground(style, Color.GREEN);
+
+        doc.insertString(0, "bold text ", boldStyle);
+        doc.insertString(doc.getLength(), "italic text", italicStyle);
+        doc.insertString(doc.getLength(),
+                         "green text\n more green text",
+                         colorStyle);
+
+        doc.setLogicalStyle(doc.getLength() - 1, style);
+
+        MutableAttributeSet attrs = new SimpleAttributeSet();
+        Icon icon =  new Icon() {
+            public int getIconHeight() {
+                return 0;
+            }
+
+            public int getIconWidth() {
+                return 0;
+            }
+
+            public void paintIcon(final Component c, final Graphics g,
+                                  final int x, final int y) {
+            }
+        };
+        StyleConstants.setIcon(attrs, icon);
+        attrs.addAttribute(AbstractDocument.ElementNameAttribute,
+                           StyleConstants.IconElementName);
+        doc.insertString(doc.getLength(), "ppp", attrs);
+
+        iconElement = doc.getCharacterElement(doc.getLength() - 1);
+
+        attrs = new SimpleAttributeSet();
+        StyleConstants.setComponent(attrs, new JLabel("lab1"));
+        attrs.addAttribute(AbstractDocument.ElementNameAttribute,
+                           StyleConstants.ComponentElementName);
+        doc.insertString(doc.getLength(), "ccc", attrs);
+        componentElement = doc.getCharacterElement(doc.getLength() - 1);
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/OptionTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/OptionTest.java?rev=427121&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/OptionTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/OptionTest.java Mon Jul 31 07:08:47 2006
@@ -0,0 +1,202 @@
+/*
+ *  Copyright 2005 - 2006 The Apache Software Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
+ *
+ *  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.
+ */
+/**
+ * @author Alexey A. Ivanov
+ * @version $Revision$
+ */
+package javax.swing.text.html;
+
+import javax.swing.BasicSwingTestCase;
+import javax.swing.text.AttributeSet;
+import javax.swing.text.MutableAttributeSet;
+import javax.swing.text.SimpleAttributeSet;
+import javax.swing.text.StyleContext;
+import javax.swing.text.AbstractDocument.AttributeContext;
+
+public class OptionTest extends BasicSwingTestCase {
+    private AttributeSet attrs;
+    private Option item;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        item = new Option(attrs = new SimpleAttributeSet());
+    }
+
+    /**
+     * Tests constructor.
+     * Empty <code>SimpleAttributeSet</code> is passed
+     * as parameter (see initialization in <code>setUp()</code>).
+     */
+    public void testOption() {
+        assertTrue(item.getAttributes() instanceof MutableAttributeSet);
+        assertNotSame(attrs, item.getAttributes());
+        assertEquals(attrs, item.getAttributes());
+        assertNull(item.getLabel());
+        assertNull(item.getValue());
+        assertFalse(item.isSelected());
+        assertNull(item.toString());
+    }
+
+    /**
+     * Tests constructor.
+     * Non-mutable (<code>StyleContext.SmallAttributeSet</code>) is passed
+     * as parameter.
+     */
+    public void testOptionSmallAttrSet() {
+        AttributeContext context = new StyleContext();
+        attrs = context.addAttribute(context.getEmptySet(), "key", "value");
+
+        item = new Option(attrs);
+        final AttributeSet itAttrs = item.getAttributes();
+        assertFalse(itAttrs instanceof MutableAttributeSet);
+        assertTrue(itAttrs instanceof StyleContext.SmallAttributeSet);
+        assertSame(attrs, itAttrs);
+        assertEquals(attrs, itAttrs);
+        assertNull(item.getLabel());
+        assertNull(item.getValue());
+        assertFalse(item.isSelected());
+        assertNull(item.toString());
+
+        assertEquals("value", itAttrs.getAttribute("key"));
+    }
+
+    /**
+     * Tests constructor.
+     * Attribute set passed contains <em>relevant</em> attributes:
+     * <ul>
+     *     <li><code>HTML.Attribute.SELECTED</code> with no meaningful
+     *         value,</li>
+     *     <li><code>HTML.Attribute.VALUE</code>.</li>
+     * </ul>
+     */
+    public void testOptionSelected() {
+        MutableAttributeSet attr = (MutableAttributeSet)attrs;
+        attr.addAttribute(HTML.Attribute.SELECTED,
+                          "no meaning" /*HTML.Attribute.SELECTED.toString()*/);
+        final String value = "iVal";
+        attr.addAttribute(HTML.Attribute.VALUE, value);
+
+        item = new Option(attrs);
+        final AttributeSet itAttrs = item.getAttributes();
+        assertEquals(attrs, itAttrs);
+        assertNull(item.getLabel());
+        assertSame(value, item.getValue());
+        assertTrue(item.isSelected());
+        assertNull(item.toString());
+    }
+
+    /**
+     * Tests constructor.
+     * Attribute set passed contains <em>relevant</em> attributes:
+     * <ul>
+     *     <li><code>HTML.Attribute.SELECTED</code> with no meaningful
+     *         value,</li>
+     *     <li><code>HTML.Attribute.VALUE</code>.</li>
+     * </ul>
+     */
+    public void testOptionNull() {
+        testExceptionalCase(new NullPointerCase() {
+            public void exceptionalAction() throws Exception {
+                new Option(null);
+            }
+        });
+    }
+
+    /**
+     * Tests <code>getAttributes</code>.
+     * See also tests for constructor: <code>testOption()</code> and
+     * <code>testOptionSmallAttrSet()</code>.
+     */
+    public void testGetAttributes() {
+        assertEquals(attrs, item.getAttributes());
+    }
+
+    /**
+     * Tests three methods:
+     * <ul>
+     *     <li><code>getLabel</code>,</li>
+     *     <li><code>setLabel</code>,</li>
+     *     <li><code>toString</code>.</li>
+     * </ul>
+     */
+    public void testGetLabel() {
+        assertNull(item.getLabel());
+        assertNull(item.toString());
+
+        final String label = "itemLabel";
+        item.setLabel(label);
+
+        assertSame(label, item.getLabel());
+        assertSame(label, item.toString());
+
+        item.setLabel(null);
+        assertNull(item.getLabel());
+        assertNull(item.toString());
+    }
+
+    /**
+     * Tests <code>getValue</code>.
+     * See also test for constructor <code>testOptionSelected()</code>.
+     */
+    public void testGetValue() {
+        assertNull(item.getValue());
+
+        final String label = "label";
+        item.setLabel(label);
+        assertEquals(label, item.getValue());
+
+        final String value = "value";
+        ((MutableAttributeSet)attrs).addAttribute(HTML.Attribute.VALUE,
+                                                  value);
+        item = new Option(attrs);
+        assertEquals(value, item.getValue());
+
+        ((MutableAttributeSet)attrs).addAttribute(HTML.Attribute.VALUE,
+                                                  new Integer(1012));
+        item = new Option(attrs);
+        testExceptionalCase(new ClassCastCase() {
+            public void exceptionalAction() throws Exception {
+                item.getValue();
+            }
+        });
+    }
+
+    /**
+     * Tests two methods:
+     * <ul>
+     *     <li><code>isSelected</code>,</li>
+     *     <li><code>setSelection</code>.</li>
+     * </ul>
+     */
+    public void testIsSelected() {
+        assertFalse(item.isSelected());
+
+        item.setSelection(true);
+        assertTrue(item.isSelected());
+
+        item.setSelection(false);
+        assertFalse(item.isSelected());
+        // See also testOptionSelected()
+    }
+
+    /*
+    public void testSetLabel()     { }    ==> testGetLabel()
+
+    public void testSetSelection() { }    ==> testIsSelected()
+
+    public void testToString()     { }    ==> testGetLabel()
+    */
+}



Mime
View raw message