Source Code Cross Referenced for StyleContext_RemoveTest.java in  » Apache-Harmony-Java-SE » javax-package » javax » swing » text » 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 
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;
021:
022:        import java.util.Enumeration;
023:        import javax.swing.BasicSwingTestCase;
024:        import javax.swing.text.StyleContext.SmallAttributeSet;
025:        import junit.framework.TestCase;
026:
027:        /**
028:         * Tests for removeAttribute, removeAttributes(Enumeration),
029:         * removeAttributes(AttributeSet) methods.
030:         *
031:         */
032:        public class StyleContext_RemoveTest extends TestCase {
033:            /**
034:             * Class supporting testing of removeAttributes(Enumeration) method
035:             * of StyleContext.
036:             */
037:            @SuppressWarnings("unchecked")
038:            private class AttributeNameEnumeration implements  Enumeration {
039:                private int count;
040:
041:                private int index;
042:
043:                /**
044:                 * Creates a new enumeration with the specified number of
045:                 * attribute names, starting at index 0.
046:                 *
047:                 * @param count the number of elements
048:                 */
049:                public AttributeNameEnumeration(final int count) {
050:                    this .index = 0;
051:                    this .count = count;
052:                }
053:
054:                /**
055:                 * Creates a new enumeration with the specified number of
056:                 * attribute names, starting at index specified.
057:                 *
058:                 * @param start the start index in internal attribute array
059:                 * @param count the number of elements
060:                 */
061:                public AttributeNameEnumeration(final int start, final int count) {
062:                    this .index = start;
063:                    this .count = count + start;
064:                }
065:
066:                public boolean hasMoreElements() {
067:                    return index < count;
068:                }
069:
070:                public Object nextElement() {
071:                    return StyleContextTest.attr[2 * index++];
072:                }
073:            }
074:
075:            private StyleContext sc;
076:
077:            /**
078:             * Just removes an attribute.
079:             */
080:            public void testRemoveAttribute() {
081:                AttributeSet as = StyleContextTest.addAttribute(5);
082:                as = sc.removeAttribute(as, StyleContextTest.attr[2]);
083:                assertEquals(4, as.getAttributeCount());
084:            }
085:
086:            /**
087:             * Removes an attribute, and the new set should be from cache.
088:             */
089:            public void testRemoveAttributeCache() {
090:                AttributeSet as = StyleContextTest.addAttribute(4);
091:                SimpleAttributeSet sas = new SimpleAttributeSet(as);
092:                sas.addAttribute(StyleContextTest.attr[5 * 2],
093:                        StyleContextTest.attr[5 * 2 + 1]);
094:                AttributeSet test = sc.removeAttribute(sas,
095:                        StyleContextTest.attr[5 * 2]);
096:                assertEquals(4, test.getAttributeCount());
097:                assertSame(as, test);
098:            }
099:
100:            /**
101:             * Removes 1 attribute from a set, and the set is converted to
102:             * SmallAttributeSet
103:             *
104:             */
105:            public void testRemoveAttributeCollapse() {
106:                AttributeSet as = StyleContextTest.addAttribute(10);
107:                assertTrue(as instanceof  SimpleAttributeSet);
108:                as = sc.removeAttribute(as, StyleContextTest.attr[0]);
109:                assertEquals(9, as.getAttributeCount());
110:                assertTrue(as instanceof  SmallAttributeSet);
111:            }
112:
113:            /**
114:             * Removes the last attribute from a set.
115:             */
116:            public void testRemoveAttributeFromOne() {
117:                AttributeSet as = StyleContextTest.addAttribute(1);
118:                as = sc.removeAttribute(as, StyleContextTest.attr[0]);
119:                assertEquals(0, as.getAttributeCount());
120:                if (!BasicSwingTestCase.isHarmony()) {
121:                    assertTrue(as instanceof  SmallAttributeSet);
122:                } else {
123:                    assertSame(as, sc.getEmptySet());
124:                }
125:            }
126:
127:            /**
128:             * Removes an attribute, the new set being placed in the cache.
129:             * Check that the set is in the cached with creation another
130:             * set with the same attributes.
131:             */
132:            public void testRemoveAttributeNoCache() {
133:                SimpleAttributeSet sas = new SimpleAttributeSet();
134:                for (int i = 0; i < 6; i += 2) {
135:                    sas.addAttribute(StyleContextTest.attr[i],
136:                            StyleContextTest.attr[i + 1]);
137:                }
138:                AttributeSet test = sc.removeAttribute(sas,
139:                        StyleContextTest.attr[4]);
140:                // Create the same set as test
141:                AttributeSet as = StyleContextTest.addAttribute(2);
142:                assertSame(test, as);
143:            }
144:
145:            public void testRemoveAttributeNoKey() {
146:                AttributeSet as = StyleContextTest.addAttribute(2);
147:                AttributeSet test = sc.removeAttribute(as,
148:                        StyleContextTest.attr[4]);
149:                assertSame(as, test);
150:            }
151:
152:            /**
153:             * Removes some attributes from the set. The result should be
154:             * from the cache.
155:             */
156:            public void testRemoveAttributesEnumCache() {
157:                AttributeSet cached = StyleContextTest.addAttribute(1);
158:                AttributeSet as = StyleContextTest.addAttribute(cached, 1, 2);
159:                AttributeSet test = sc.removeAttributes(as,
160:                        new AttributeNameEnumeration(1, 2));
161:                assertEquals(1, test.getAttributeCount());
162:                assertSame(cached, test);
163:            }
164:
165:            /**
166:             * Removes all the attributes from a set.
167:             * The result should be EmptyAttributeSet.
168:             */
169:            public void testRemoveAttributesEnumEmpty() {
170:                AttributeSet as = StyleContextTest.addAttribute(3);
171:                AttributeSet test = sc.removeAttributes(as,
172:                        new AttributeNameEnumeration(3));
173:                assertEquals(0, test.getAttributeCount());
174:                if (BasicSwingTestCase.isHarmony()) {
175:                    assertSame(test, sc.getEmptySet());
176:                }
177:            }
178:
179:            /**
180:             * Removes some attributes from a set. The result shouldn't be
181:             * in the cache.
182:             */
183:            public void testRemoveAttributesEnumNoCache() {
184:                AttributeSet as = StyleContextTest.addAttribute(4);
185:                AttributeSet test = sc.removeAttributes(as,
186:                        new AttributeNameEnumeration(1, 2));
187:                assertEquals(2, test.getAttributeCount());
188:                // Create the same set as test
189:                AttributeSet cached = StyleContextTest.addAttribute(1);
190:                cached = StyleContextTest.addAttribute(cached, 3, 1);
191:                assertSame(test, cached);
192:            }
193:
194:            /**
195:             * Removes several attributes from a set. The name enumeration
196:             * contains names that are not in the set.
197:             */
198:            public void testRemoveAttributesEnumNoKey() {
199:                AttributeSet as = StyleContextTest.addAttribute(2);
200:                as = StyleContextTest.addAttribute(as, 4, 2);
201:                assertEquals(4, as.getAttributeCount());
202:                AttributeSet test = sc.removeAttributes(as,
203:                        new AttributeNameEnumeration(1, 4));
204:                assertEquals(2, test.getAttributeCount());
205:            }
206:
207:            /**
208:             * Removes one attribute from a set. The resulting set should become
209:             * SmallAttributeSet.
210:             */
211:            public void testRemoveAttributesEnumSmall() {
212:                AttributeSet as = StyleContextTest.addAttribute(10);
213:                assertTrue(as instanceof  SimpleAttributeSet);
214:                // Remove one element
215:                AttributeSet test = sc.removeAttributes(as,
216:                        new AttributeNameEnumeration(1));
217:                assertEquals(9, test.getAttributeCount());
218:                if (BasicSwingTestCase.isHarmony()) {
219:                    assertTrue(test instanceof  SmallAttributeSet);
220:                }
221:            }
222:
223:            /**
224:             * Removes some attributes from the set. The result should be
225:             * from the cache.
226:             */
227:            public void testRemoveAttributesSetCache() {
228:                AttributeSet cached = StyleContextTest.addAttribute(1);
229:                AttributeSet as = StyleContextTest.addAttribute(cached, 1, 2);
230:                AttributeSet test = sc.removeAttributes(as, StyleContextTest
231:                        .addAttribute(null, 1, 2));
232:                assertEquals(1, test.getAttributeCount());
233:                assertSame(cached, test);
234:            }
235:
236:            /**
237:             * Removes some attributes from the set. The result should be
238:             * from the cache. The set to remove contains a key with a different
239:             * value.
240:             */
241:            public void testRemoveAttributesSetCacheSameKeys() {
242:                AttributeSet cached = StyleContextTest.addAttribute(2);
243:                AttributeSet as = StyleContextTest.addAttribute(cached, 2, 3);
244:                AttributeSet test = sc.removeAttributes(as, sc.addAttribute(
245:                        StyleContextTest.addAttribute(null, 1, 4),
246:                        StyleConstants.Italic, Boolean.FALSE));
247:                assertEquals(2, test.getAttributeCount());
248:                assertSame(cached, test);
249:            }
250:
251:            /**
252:             * Removes all the attributes from a set. The set to be removed is
253:             * the same as the set to remove from.
254:             * The result should be EmptyAttributeSet.
255:             */
256:            public void testRemoveAttributesSetEmpty() {
257:                AttributeSet as = StyleContextTest.addAttribute(3);
258:                AttributeSet test = sc.removeAttributes(as, as);
259:                assertEquals(0, test.getAttributeCount());
260:                if (BasicSwingTestCase.isHarmony()) {
261:                    assertSame(test, sc.getEmptySet());
262:                }
263:            }
264:
265:            /**
266:             * Removes all the attributes from a set. The set to be removed
267:             * contains the same attribute key but has different values.
268:             * The result should be EmptyAttributeSet.
269:             */
270:            public void testRemoveAttributesSetEmptySameKey() {
271:                AttributeSet as = StyleContextTest.addAttribute(3);
272:                AttributeSet test = sc.removeAttributes(as, sc.addAttribute(as,
273:                        StyleConstants.Bold, Boolean.FALSE));
274:                assertEquals(1, test.getAttributeCount());
275:            }
276:
277:            /**
278:             * Removes some attributes from a set. The result shouldn't be
279:             * in the cache. The set to remove contains a key with a different
280:             * value.
281:             */
282:            public void testRemoveAttributesSetNoCacheSameKeys() {
283:                AttributeSet as = StyleContextTest.addAttribute(4);
284:                AttributeSet test = sc.removeAttributes(as, sc.addAttribute(
285:                        StyleContextTest.addAttribute(null, 1, 2),
286:                        StyleConstants.Underline, Boolean.FALSE));
287:                assertEquals(3, test.getAttributeCount());
288:                // Create the same set as test
289:                AttributeSet cached = StyleContextTest.addAttribute(1);
290:                cached = StyleContextTest.addAttribute(cached, 2, 2);
291:                assertSame(test, cached);
292:            }
293:
294:            /**
295:             * Removes several attributes from a set. The set to be removed
296:             * contains attributes with names that are not in the set from which
297:             * attributes are to be removed.
298:             */
299:            public void testRemoveAttributesSetNoKey() {
300:                AttributeSet as = StyleContextTest.addAttribute(2);
301:                as = StyleContextTest.addAttribute(as, 4, 2);
302:                assertEquals(4, as.getAttributeCount());
303:                AttributeSet test = sc.removeAttributes(as, StyleContextTest
304:                        .addAttribute(null, 1, 4));
305:                assertEquals(2, test.getAttributeCount());
306:            }
307:
308:            /**
309:             * Removes one attribute from a set. The resulting set should become
310:             * SmallAttributeSet.
311:             */
312:            public void testRemoveAttributesSetSmall() {
313:                AttributeSet as = StyleContextTest.addAttribute(10);
314:                assertTrue(as instanceof  SimpleAttributeSet);
315:                // Remove one element
316:                AttributeSet test = sc.removeAttributes(as, StyleContextTest
317:                        .addAttribute(1));
318:                assertEquals(9, test.getAttributeCount());
319:                if (BasicSwingTestCase.isHarmony()) {
320:                    assertTrue(test instanceof  SmallAttributeSet);
321:                }
322:            }
323:
324:            @Override
325:            protected void setUp() throws Exception {
326:                sc = StyleContextTest.sc = new StyleContext();
327:            }
328:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.