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_SpaceTestCase extends
030: TestCase {
031: protected Attribute shorthandKey;
032: protected Attribute topKey;
033: protected Attribute rightKey;
034: protected Attribute bottomKey;
035: protected Attribute leftKey;
036:
037: protected StyleSheet ss;
038: protected MutableAttributeSet simple;
039:
040: protected Object top;
041: protected Object right;
042: protected Object bottom;
043: protected Object left;
044:
045: protected String defaultValue;
046:
047: protected void setUp() throws Exception {
048: super .setUp();
049: ss = new StyleSheet();
050: simple = new SimpleAttributeSet();
051: }
052:
053: public void testSpace01() throws Exception {
054: ss.addCSSAttribute(simple, shorthandKey, "7pt");
055: assertProperties();
056: assertEquals("7pt", top.toString());
057: assertEquals("7pt", right.toString());
058: assertEquals("7pt", bottom.toString());
059: assertEquals("7pt", left.toString());
060: }
061:
062: public void testSpace02() throws Exception {
063: ss.addCSSAttribute(simple, shorthandKey, "7pt 14mm");
064: assertProperties();
065: assertEquals("7pt", top.toString());
066: assertEquals("14mm", right.toString());
067: assertEquals("7pt", bottom.toString());
068: assertEquals("14mm", left.toString());
069: }
070:
071: public void testSpace03() throws Exception {
072: ss.addCSSAttribute(simple, shorthandKey, "7pt 14mm 21cm");
073: assertProperties();
074: assertEquals("7pt", top.toString());
075: assertEquals("14mm", right.toString());
076: assertEquals("21cm", bottom.toString());
077: assertEquals("14mm", left.toString());
078: }
079:
080: public void testSpace04() throws Exception {
081: ss.addCSSAttribute(simple, shorthandKey, "7pt 14mm 21cm 28in");
082: assertProperties();
083: assertEquals("7pt", top.toString());
084: assertEquals("14mm", right.toString());
085: assertEquals("21cm", bottom.toString());
086: assertEquals("28in", left.toString());
087: }
088:
089: public void testSpace05() throws Exception {
090: ss.addCSSAttribute(simple, shorthandKey,
091: "7pt 14mm 21cm 28in 144px");
092: assertProperties();
093: assertEquals("7pt", top.toString());
094: assertEquals("14mm", right.toString());
095: assertEquals("21cm", bottom.toString());
096: assertEquals("28in", left.toString());
097: }
098:
099: public void testSpace03x() throws Exception {
100: ss.addCSSAttribute(simple, shorthandKey, "7pt 14mm x 28in");
101: if (BasicSwingTestCase.isHarmony()) {
102: assertProperties(0);
103: assertAllNull();
104: return;
105: }
106: assertProperties(4);
107: assertEquals("7pt", top.toString());
108: assertEquals("14mm", right.toString());
109: assertEquals(defaultValue, bottom.toString());
110: assertEquals("28in", left.toString());
111: }
112:
113: public void testSpace01x() throws Exception {
114: ss.addCSSAttribute(simple, shorthandKey, "em 14mm 14pt ex");
115: if (BasicSwingTestCase.isHarmony()) {
116: assertProperties(0);
117: return;
118: }
119: assertProperties(4);
120: assertEquals(defaultValue, top.toString());
121: assertEquals("14mm", right.toString());
122: assertEquals("14pt", bottom.toString());
123: assertEquals(defaultValue, left.toString());
124: }
125:
126: public void testSpace01NoUnits() throws Exception {
127: ss.addCSSAttribute(simple, shorthandKey, "7");
128: if (BasicSwingTestCase.isHarmony()) {
129: assertProperties(0);
130: return;
131: }
132: assertProperties(4);
133: assertEquals("7", top.toString());
134: assertEquals("7", right.toString());
135: assertEquals("7", bottom.toString());
136: assertEquals("7", left.toString());
137: }
138:
139: public void testSpace02CommaSpace() throws Exception {
140: ss.addCSSAttribute(simple, shorthandKey, "7pt, 14mm");
141: if (BasicSwingTestCase.isHarmony()) {
142: assertProperties(0);
143: return;
144: }
145: assertProperties(4);
146: assertEquals(defaultValue, top.toString());
147: assertEquals("14mm", right.toString());
148: assertEquals(defaultValue, bottom.toString());
149: assertEquals("14mm", left.toString());
150: }
151:
152: public void testSpace02CommaNoSpace() throws Exception {
153: ss.addCSSAttribute(simple, shorthandKey, "7pt,14mm");
154: if (BasicSwingTestCase.isHarmony()) {
155: assertProperties(0);
156: return;
157: }
158: assertProperties(4);
159: assertEquals(defaultValue, top.toString());
160: assertEquals(defaultValue, right.toString());
161: assertEquals(defaultValue, bottom.toString());
162: assertEquals(defaultValue, left.toString());
163: }
164:
165: private void assertProperties() {
166: assertProperties(4);
167: }
168:
169: private void assertProperties(final int count) {
170: assertEquals(count, simple.getAttributeCount());
171: getProperties();
172: if (count == 0) {
173: assertAllNull();
174: }
175: }
176:
177: private void getProperties() {
178: top = simple.getAttribute(topKey);
179: right = simple.getAttribute(rightKey);
180: bottom = simple.getAttribute(bottomKey);
181: left = simple.getAttribute(leftKey);
182: }
183:
184: private void assertAllNull() {
185: assertNull(top);
186: assertNull(right);
187: assertNull(bottom);
188: assertNull(left);
189: }
190: }
|