001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Alexey A. Ivanov
019: * @version $Revision$
020: */package javax.swing.text.html;
021:
022: import javax.swing.BasicSwingTestCase;
023: import javax.swing.text.MutableAttributeSet;
024: import javax.swing.text.SimpleAttributeSet;
025: import javax.swing.text.html.CSS.Attribute;
026:
027: import junit.framework.TestCase;
028:
029: public class StyleSheet_ConvertAttr_BackgroundPositionTest extends
030: TestCase {
031: static final String[] validValues = new String[] { "top left",
032: "left top", "top", "top center", "center top", "right top",
033: "top right", "left", "left center", "center left",
034: "center", "center center", "right", "right center",
035: "center right", "bottom left", "left bottom", "bottom",
036: "bottom center", "center bottom", "bottom right",
037: "right bottom" };
038:
039: static final String[] percentValues = new String[] { "0%", "0% 0%",
040: "10%", "10% 0%", "50%", "50% 50%", "50% 100%", "100% 50%",
041: "100%", "100% 100%", "100% 85%", "100%", "100% 100%",
042: "100% 85%" };
043:
044: static final String[] otherValues = new String[] { "1.11px",
045: "1.11px 50%", "1.11px 1.11px", "1.11pt", "1.11pt 50%",
046: "1.11pt 1.11pt", "1.11mm", "1.11mm 50%", "1.11mm 1.11mm",
047: "1.11cm", "1.11cm 50%", "1.11cm 1.11cm", "1.11in",
048: "1.11in 50%", "1.11in 1.11in", "1.11pc", "1.11pc 50%",
049: "1.11pc 1.11pc", "1.11em", "1.11em 50%", "1.11em 1.11em",
050: "1.11ex", "1.11ex 50%", "1.11ex 1.11ex",
051:
052: "-1.11px", "-1.11px 50%", "-1.11px 1.11px", "-50%",
053: "1.11pt -50%", "1.11px -1.11px", "-1.11px -1.11px" };
054:
055: private static final String[] invalidValues = new String[] {
056: "top top", "left left", "right right", "bottom bottom",
057:
058: "top 50%", "25% right", "1pt center", "bottom 1px",
059:
060: "10px 10px 10px" };
061:
062: private StyleSheet ss;
063: private MutableAttributeSet simple;
064: private Attribute cssKey;
065: private Object cssValue;
066:
067: protected void setUp() throws Exception {
068: super .setUp();
069: cssKey = Attribute.BACKGROUND_POSITION;
070: ss = new StyleSheet();
071: simple = new SimpleAttributeSet();
072: }
073:
074: public void testBackgroundPositionValidKeywords() throws Exception {
075: for (int i = 0; i < validValues.length; i++) {
076: simple.removeAttribute(cssKey);
077: ss.addCSSAttribute(simple, cssKey, validValues[i]);
078: cssValue = simple.getAttribute(cssKey);
079: assertEquals("@ " + i, validValues[i], cssValue.toString());
080: }
081: }
082:
083: public void testBackgroundPositionInvalidKeywords()
084: throws Exception {
085: for (int i = 0; i < invalidValues.length; i++) {
086: simple.removeAttribute(cssKey);
087: ss.addCSSAttribute(simple, cssKey, invalidValues[i]);
088: cssValue = simple.getAttribute(cssKey);
089: if (BasicSwingTestCase.isHarmony()) {
090: assertNull("@ " + i, cssValue);
091: } else {
092: assertEquals("@ " + i, invalidValues[i], cssValue
093: .toString());
094: }
095: }
096: }
097:
098: public void testBackgroundPositionPercentage() throws Exception {
099: for (int i = 0; i < percentValues.length; i++) {
100: simple.removeAttribute(cssKey);
101: ss.addCSSAttribute(simple, cssKey, percentValues[i]);
102: cssValue = simple.getAttribute(cssKey);
103: assertEquals("@ " + i, percentValues[i], cssValue
104: .toString());
105: }
106: }
107:
108: public void testBackgroundPositionOther() throws Exception {
109: for (int i = 0; i < otherValues.length; i++) {
110: simple.removeAttribute(cssKey);
111: ss.addCSSAttribute(simple, cssKey, otherValues[i]);
112: cssValue = simple.getAttribute(cssKey);
113: assertEquals("@ " + i, otherValues[i], cssValue.toString());
114: }
115: }
116: }
|