Source Code Cross Referenced for StyleSheet_ConvertAttr_MarginTestCase.java in  » Apache-Harmony-Java-SE » javax-package » javax » swing » text » html » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Apache Harmony Java SE » javax package » javax.swing.text.html 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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 java.util.Enumeration;
023:
024:        import javax.swing.BasicSwingTestCase;
025:        import javax.swing.text.AttributeSet;
026:        import javax.swing.text.MutableAttributeSet;
027:        import javax.swing.text.SimpleAttributeSet;
028:        import javax.swing.text.html.CSS.Attribute;
029:
030:        public abstract class StyleSheet_ConvertAttr_MarginTestCase extends
031:                BasicSwingTestCase {
032:
033:            protected StyleSheet ss;
034:
035:            protected AttributeSet empty;
036:            protected AttributeSet attr;
037:            protected MutableAttributeSet simple;
038:
039:            protected Attribute cssKey;
040:            protected Object cssValue;
041:            protected Object scKey;
042:            protected Object scValue;
043:
044:            protected String defUnits;
045:
046:            protected void setUp() throws Exception {
047:                super .setUp();
048:                ss = new StyleSheet();
049:                empty = ss.getEmptySet();
050:                simple = new SimpleAttributeSet();
051:                defUnits = isHarmony() ? "pt" : "";
052:            }
053:
054:            // Specifies size in points.
055:            public void testLength() {
056:                attr = ss.addAttribute(empty, scKey, new Float(11.1));
057:
058:                Enumeration names = attr.getAttributeNames();
059:                Object name = names.nextElement();
060:                assertSame(cssKey, name);
061:                assertFalse(names.hasMoreElements());
062:
063:                cssValue = attr.getAttribute(cssKey);
064:                scValue = attr.getAttribute(scKey);
065:                assertSame(Float.class, scValue.getClass());
066:                assertNotSame(Float.class, cssValue.getClass());
067:                assertNotSame(String.class, cssValue.getClass());
068:                assertEquals(11.1f, ((Float) scValue).floatValue());
069:                assertEquals("11.1" + defUnits, cssValue.toString());
070:            }
071:
072:            public void testLengthString() {
073:                if (!isHarmony()) {
074:                    testExceptionalCase(new ClassCastCase() {
075:                        public void exceptionalAction() throws Exception {
076:                            ss.addAttribute(empty, scKey, "11.1pt");
077:                        }
078:                    });
079:                    return;
080:                }
081:                attr = ss.addAttribute(empty, scKey, "11.1pt");
082:
083:                cssValue = attr.getAttribute(cssKey);
084:                scValue = attr.getAttribute(scKey);
085:                assertEquals(11.1f, ((Float) scValue).floatValue());
086:                assertEquals("11.1pt", cssValue.toString());
087:            }
088:
089:            public void testLengthInteger() {
090:                testExceptionalCase(new ExceptionalCase() {
091:                    public void exceptionalAction() throws Exception {
092:                        ss.addAttribute(empty, scKey, new Integer(11));
093:                    }
094:
095:                    public Class expectedExceptionClass() {
096:                        return isHarmony() ? NullPointerException.class
097:                                : ClassCastException.class;
098:                    }
099:                });
100:            }
101:
102:            public void testLength11_1() {
103:                ss.addCSSAttribute(simple, cssKey, "11.1");
104:                if (isHarmony()) {
105:                    assertEquals(0, simple.getAttributeCount());
106:                    return;
107:                }
108:                attr = ss.createSmallAttributeSet(simple);
109:
110:                cssValue = attr.getAttribute(cssKey);
111:                scValue = attr.getAttribute(scKey);
112:                assertEquals("11.1", cssValue.toString());
113:                assertEquals(11.1f, ((Float) scValue).floatValue());
114:            }
115:
116:            public void testLength0() {
117:                ss.addCSSAttribute(simple, cssKey, "0");
118:                attr = ss.createSmallAttributeSet(simple);
119:
120:                cssValue = attr.getAttribute(cssKey);
121:                scValue = attr.getAttribute(scKey);
122:                assertEquals("0", cssValue.toString());
123:                assertEquals(0f, ((Float) scValue).floatValue());
124:            }
125:
126:            public void testLength0px() {
127:                ss.addCSSAttribute(simple, cssKey, "0px");
128:                attr = ss.createSmallAttributeSet(simple);
129:
130:                cssValue = attr.getAttribute(cssKey);
131:                scValue = attr.getAttribute(scKey);
132:                assertEquals("0px", cssValue.toString());
133:                assertEquals(0f, ((Float) scValue).floatValue());
134:            }
135:
136:            public void testLength11_1pt() {
137:                ss.addCSSAttribute(simple, cssKey, "11.1pt");
138:                attr = ss.createSmallAttributeSet(simple);
139:
140:                cssValue = attr.getAttribute(cssKey);
141:                scValue = attr.getAttribute(scKey);
142:                assertSame(Float.class, scValue.getClass());
143:                assertNotSame(Float.class, cssValue.getClass());
144:                assertNotSame(String.class, cssValue.getClass());
145:                assertEquals("11.1pt", cssValue.toString());
146:                assertEquals(11.1f, ((Float) scValue).floatValue());
147:            }
148:
149:            public void testLength11_1px() {
150:                ss.addCSSAttribute(simple, cssKey, "11.1px");
151:                attr = ss.createSmallAttributeSet(simple);
152:
153:                cssValue = attr.getAttribute(cssKey);
154:                scValue = attr.getAttribute(scKey);
155:                assertEquals("11.1px", cssValue.toString());
156:                assertEquals(14.43f, ((Float) scValue).floatValue());
157:            }
158:
159:            public void testLength11_1mm() {
160:                ss.addCSSAttribute(simple, cssKey, "11.1mm");
161:                attr = ss.createSmallAttributeSet(simple);
162:
163:                cssValue = attr.getAttribute(cssKey);
164:                scValue = attr.getAttribute(scKey);
165:                assertEquals("11.1mm", cssValue.toString());
166:                assertEquals(31.464506f, ((Float) scValue).floatValue(),
167:                        0.00007f);
168:            }
169:
170:            public void testLength11_1cm() {
171:                ss.addCSSAttribute(simple, cssKey, "11.1cm");
172:                attr = ss.createSmallAttributeSet(simple);
173:
174:                cssValue = attr.getAttribute(cssKey);
175:                scValue = attr.getAttribute(scKey);
176:                assertEquals("11.1cm", cssValue.toString());
177:                assertEquals(314.64506f, ((Float) scValue).floatValue(),
178:                        0.0007f);
179:            }
180:
181:            public void testLength11_1pc() {
182:                ss.addCSSAttribute(simple, cssKey, "11.1pc");
183:                attr = ss.createSmallAttributeSet(simple);
184:
185:                cssValue = attr.getAttribute(cssKey);
186:                scValue = attr.getAttribute(scKey);
187:                assertEquals("11.1pc", cssValue.toString());
188:                assertEquals(133.20001f, ((Float) scValue).floatValue());
189:            }
190:
191:            public void testLength11_1in() {
192:                ss.addCSSAttribute(simple, cssKey, "11.1in");
193:                attr = ss.createSmallAttributeSet(simple);
194:
195:                cssValue = attr.getAttribute(cssKey);
196:                scValue = attr.getAttribute(scKey);
197:                assertEquals("11.1in", cssValue.toString());
198:                assertEquals(799.2f, ((Float) scValue).floatValue());
199:            }
200:
201:            public void testLengthMinus11_1pt() {
202:                ss.addCSSAttribute(simple, cssKey, "-11.1pt");
203:                attr = ss.createSmallAttributeSet(simple);
204:
205:                cssValue = attr.getAttribute(cssKey);
206:                scValue = attr.getAttribute(scKey);
207:                assertEquals("-11.1pt", cssValue.toString());
208:                assertEquals(isHarmony() ? -11.1f : 0, ((Float) scValue)
209:                        .floatValue());
210:            }
211:
212:            private static void assertEquals(final float expected,
213:                    final float actual) {
214:                assertEquals(expected, actual, 0f);
215:            }
216:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.