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 abstract class StyleSheet_ConvertAttr_LengthTestCase extends
030: TestCase {
031: protected StyleSheet ss;
032: protected MutableAttributeSet simple;
033: protected Attribute cssKey;
034: protected Object cssValue;
035: protected boolean negativeValuesInvalid;
036: protected boolean percentageValuesInvalid;
037:
038: protected void setUp() throws Exception {
039: super .setUp();
040: ss = new StyleSheet();
041: simple = new SimpleAttributeSet();
042: negativeValuesInvalid = false;
043: percentageValuesInvalid = false;
044: }
045:
046: public void testLength0_75em() {
047: ss.addCSSAttribute(simple, cssKey, "0.75em");
048: cssValue = simple.getAttribute(cssKey);
049: assertEquals("0.75em", cssValue.toString());
050: }
051:
052: public void testLength1_25ex() {
053: ss.addCSSAttribute(simple, cssKey, "1.25ex");
054: cssValue = simple.getAttribute(cssKey);
055: assertEquals("1.25ex", cssValue.toString());
056: }
057:
058: public void testLength0() {
059: ss.addCSSAttribute(simple, cssKey, "0");
060: cssValue = simple.getAttribute(cssKey);
061: assertEquals("0", cssValue.toString());
062: }
063:
064: public void testLength0px() {
065: ss.addCSSAttribute(simple, cssKey, "0px");
066: cssValue = simple.getAttribute(cssKey);
067: assertEquals("0px", cssValue.toString());
068: }
069:
070: public void testLength11_1() {
071: ss.addCSSAttribute(simple, cssKey, "11.1");
072: cssValue = simple.getAttribute(cssKey);
073: if (!BasicSwingTestCase.isHarmony()) {
074: assertEquals(1, simple.getAttributeCount());
075: assertEquals("11.1", cssValue.toString());
076: return;
077: }
078: assertEquals(0, simple.getAttributeCount());
079: assertNull(cssValue);
080: }
081:
082: public void testLength11_1pt() {
083: ss.addCSSAttribute(simple, cssKey, "11.1pt");
084: cssValue = simple.getAttribute(cssKey);
085: assertEquals("11.1pt", cssValue.toString());
086: }
087:
088: public void testLength11_1px() {
089: ss.addCSSAttribute(simple, cssKey, "11.1px");
090: cssValue = simple.getAttribute(cssKey);
091: assertEquals("11.1px", cssValue.toString());
092: }
093:
094: public void testLength11_1mm() {
095: ss.addCSSAttribute(simple, cssKey, "11.1mm");
096: cssValue = simple.getAttribute(cssKey);
097: assertEquals("11.1mm", cssValue.toString());
098: }
099:
100: public void testLength11_1cm() {
101: ss.addCSSAttribute(simple, cssKey, "11.1cm");
102: cssValue = simple.getAttribute(cssKey);
103: assertEquals("11.1cm", cssValue.toString());
104: }
105:
106: public void testLength11_1pc() {
107: ss.addCSSAttribute(simple, cssKey, "11.1pc");
108: cssValue = simple.getAttribute(cssKey);
109: assertEquals("11.1pc", cssValue.toString());
110: }
111:
112: public void testLength11_1in() {
113: ss.addCSSAttribute(simple, cssKey, "11.1in");
114: cssValue = simple.getAttribute(cssKey);
115: assertEquals("11.1in", cssValue.toString());
116: }
117:
118: public void testLengthMinus11_1pt() {
119: ss.addCSSAttribute(simple, cssKey, "-11.1pt");
120: cssValue = simple.getAttribute(cssKey);
121: if (negativeValuesInvalid) {
122: assertEquals(0, simple.getAttributeCount());
123: assertNull(cssValue);
124: } else {
125: assertEquals("-11.1pt", cssValue.toString());
126: }
127: }
128:
129: public void testLengthPlus11_1pt() {
130: ss.addCSSAttribute(simple, cssKey, "+11.1pt");
131: cssValue = simple.getAttribute(cssKey);
132: assertEquals("+11.1pt", cssValue.toString());
133: }
134:
135: public void testLength11_1Percent() {
136: ss.addCSSAttribute(simple, cssKey, "11.1%");
137: cssValue = simple.getAttribute(cssKey);
138: if (percentageValuesInvalid) {
139: assertEquals(0, simple.getAttributeCount());
140: assertNull(cssValue);
141: } else {
142: assertEquals("11.1%", cssValue.toString());
143: }
144: }
145:
146: public void testLengthPlus11_1Percent() {
147: ss.addCSSAttribute(simple, cssKey, "+11.1%");
148: cssValue = simple.getAttribute(cssKey);
149: if (percentageValuesInvalid) {
150: assertEquals(0, simple.getAttributeCount());
151: assertNull(cssValue);
152: } else {
153: assertEquals("+11.1%", cssValue.toString());
154: }
155: }
156:
157: public void testLengthMinus11_1Percent() {
158: ss.addCSSAttribute(simple, cssKey, "-11.1%");
159: cssValue = simple.getAttribute(cssKey);
160: if (percentageValuesInvalid || negativeValuesInvalid) {
161: assertEquals(0, simple.getAttributeCount());
162: assertNull(cssValue);
163: } else {
164: assertEquals("-11.1%", cssValue.toString());
165: }
166: }
167: }
|