Source Code Cross Referenced for TestSheetAdditional.java in  » Collaboration » poi-3.0.2-beta2 » org » apache » poi » hssf » model » 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 » Collaboration » poi 3.0.2 beta2 » org.apache.poi.hssf.model 
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:        package org.apache.poi.hssf.model;
019:
020:        import java.lang.reflect.Field;
021:        import java.util.ArrayList;
022:        import java.util.Iterator;
023:        import java.util.List;
024:
025:        import junit.framework.TestCase;
026:
027:        import org.apache.poi.hssf.record.ColumnInfoRecord;
028:        import org.apache.poi.hssf.record.MergeCellsRecord;
029:        import org.apache.poi.hssf.record.PageBreakRecord;
030:        import org.apache.poi.hssf.record.RowRecord;
031:        import org.apache.poi.hssf.record.StringRecord;
032:
033:        /**
034:         * @author Tony Poppleton
035:         */
036:        public class TestSheetAdditional extends TestCase {
037:            /**
038:             * Constructor for SheetTest.
039:             * @param arg0
040:             */
041:            public TestSheetAdditional(String arg0) {
042:                super (arg0);
043:            }
044:
045:            public void testAddMergedRegion() {
046:                Sheet sheet = Sheet.createSheet();
047:                int regionsToAdd = 4096;
048:                int startRecords = sheet.getRecords().size();
049:
050:                //simple test that adds a load of regions
051:                for (int n = 0; n < regionsToAdd; n++) {
052:                    int index = sheet.addMergedRegion(0, (short) 0, 1,
053:                            (short) 1);
054:                    assertTrue("Merged region index expected to be " + n
055:                            + " got " + index, index == n);
056:                }
057:
058:                //test all the regions were indeed added 
059:                assertTrue(sheet.getNumMergedRegions() == regionsToAdd);
060:
061:                //test that the regions were spread out over the appropriate number of records
062:                int recordsAdded = sheet.getRecords().size() - startRecords;
063:                int recordsExpected = regionsToAdd / 1027;
064:                if ((regionsToAdd % 1027) != 0)
065:                    recordsExpected++;
066:                assertTrue("The " + regionsToAdd
067:                        + " merged regions should have been spread out over "
068:                        + recordsExpected + " records, not " + recordsAdded,
069:                        recordsAdded == recordsExpected);
070:
071:                // Check we can't add one with invalud date
072:                try {
073:                    sheet.addMergedRegion(10, (short) 10, 9, (short) 12);
074:                    fail();
075:                } catch (IllegalArgumentException e) {
076:                }
077:                try {
078:                    sheet.addMergedRegion(10, (short) 10, 12, (short) 9);
079:                    fail();
080:                } catch (IllegalArgumentException e) {
081:                }
082:            }
083:
084:            public void testRemoveMergedRegion() {
085:                Sheet sheet = Sheet.createSheet();
086:                int regionsToAdd = 4096;
087:
088:                for (int n = 0; n < regionsToAdd; n++)
089:                    sheet.addMergedRegion(0, (short) 0, 1, (short) 1);
090:
091:                int records = sheet.getRecords().size();
092:
093:                //remove a third from the beginning
094:                for (int n = 0; n < regionsToAdd / 3; n++) {
095:                    sheet.removeMergedRegion(0);
096:                    //assert they have been deleted
097:                    assertTrue("Num of regions should be "
098:                            + (regionsToAdd - n - 1) + " not "
099:                            + sheet.getNumMergedRegions(), sheet
100:                            .getNumMergedRegions() == regionsToAdd - n - 1);
101:                }
102:
103:                //assert any record removing was done
104:                int recordsRemoved = (regionsToAdd / 3) / 1027; //doesn't work for particular values of regionsToAdd
105:                assertTrue("Expected " + recordsRemoved
106:                        + " record to be removed from the starting " + records
107:                        + ".  Currently there are " + sheet.getRecords().size()
108:                        + " records",
109:                        records - sheet.getRecords().size() == recordsRemoved);
110:            }
111:
112:            /**
113:             * Bug: 22922 (Reported by Xuemin Guan)
114:             * <p>
115:             * Remove mergedregion fails when a sheet loses records after an initial CreateSheet
116:             * fills up the records.
117:             *
118:             */
119:            public void testMovingMergedRegion() {
120:                List records = new ArrayList();
121:
122:                MergeCellsRecord merged = new MergeCellsRecord();
123:                merged.addArea(0, (short) 0, 1, (short) 2);
124:                records.add(new RowRecord());
125:                records.add(new RowRecord());
126:                records.add(new RowRecord());
127:                records.add(merged);
128:
129:                Sheet sheet = Sheet.createSheet(records, 0);
130:                sheet.records.remove(0);
131:
132:                //stub object to throw off list INDEX operations
133:                sheet.removeMergedRegion(0);
134:                assertEquals("Should be no more merged regions", 0, sheet
135:                        .getNumMergedRegions());
136:            }
137:
138:            public void testGetMergedRegionAt() {
139:                //TODO
140:            }
141:
142:            public void testGetNumMergedRegions() {
143:                //TODO
144:            }
145:
146:            public void DISBALEDtestGetCellWidth() throws Exception {
147:                Sheet sheet = Sheet.createSheet();
148:                ColumnInfoRecord nci = (ColumnInfoRecord) sheet.createColInfo();
149:
150:                // Prepare test model
151:                nci.setFirstColumn((short) 5);
152:                nci.setLastColumn((short) 10);
153:                nci.setColumnWidth((short) 100);
154:
155:                Field f = null;
156:                f = Sheet.class.getDeclaredField("columnSizes");
157:                f.setAccessible(true);
158:                List columnSizes = new ArrayList();
159:                f.set(sheet, columnSizes);
160:                columnSizes.add(nci);
161:                sheet.records.add(1 + sheet.dimsloc, nci);
162:                sheet.dimsloc++;
163:
164:                assertEquals((short) 100, sheet.getColumnWidth((short) 5));
165:                assertEquals((short) 100, sheet.getColumnWidth((short) 6));
166:                assertEquals((short) 100, sheet.getColumnWidth((short) 7));
167:                assertEquals((short) 100, sheet.getColumnWidth((short) 8));
168:                assertEquals((short) 100, sheet.getColumnWidth((short) 9));
169:                assertEquals((short) 100, sheet.getColumnWidth((short) 10));
170:
171:                sheet.setColumnWidth((short) 6, (short) 200);
172:
173:                assertEquals((short) 100, sheet.getColumnWidth((short) 5));
174:                assertEquals((short) 200, sheet.getColumnWidth((short) 6));
175:                assertEquals((short) 100, sheet.getColumnWidth((short) 7));
176:                assertEquals((short) 100, sheet.getColumnWidth((short) 8));
177:                assertEquals((short) 100, sheet.getColumnWidth((short) 9));
178:                assertEquals((short) 100, sheet.getColumnWidth((short) 10));
179:            }
180:
181:            /**
182:             * Makes sure all rows registered for this sheet are aggregated, they were being skipped
183:             *
184:             */
185:            public void testRowAggregation() {
186:                List records = new ArrayList();
187:                RowRecord row = new RowRecord();
188:                row.setRowNumber(0);
189:                records.add(row);
190:
191:                row = new RowRecord();
192:                row.setRowNumber(1);
193:                records.add(row);
194:
195:                records.add(new StringRecord());
196:
197:                row = new RowRecord();
198:                row.setRowNumber(2);
199:                records.add(row);
200:
201:                Sheet sheet = Sheet.createSheet(records, 0);
202:                assertNotNull("Row [2] was skipped", sheet.getRow(2));
203:
204:            }
205:
206:            /**
207:             * Make sure page break functionality works (in memory)
208:             *
209:             */
210:            public void testRowPageBreaks() {
211:                short colFrom = 0;
212:                short colTo = 255;
213:
214:                Sheet sheet = Sheet.createSheet();
215:                sheet.setRowBreak(0, colFrom, colTo);
216:
217:                assertTrue("no row break at 0", sheet.isRowBroken(0));
218:                assertEquals("1 row break available", 1, sheet
219:                        .getNumRowBreaks());
220:
221:                sheet.setRowBreak(0, colFrom, colTo);
222:                sheet.setRowBreak(0, colFrom, colTo);
223:
224:                assertTrue("no row break at 0", sheet.isRowBroken(0));
225:                assertEquals("1 row break available", 1, sheet
226:                        .getNumRowBreaks());
227:
228:                sheet.setRowBreak(10, colFrom, colTo);
229:                sheet.setRowBreak(11, colFrom, colTo);
230:
231:                assertTrue("no row break at 10", sheet.isRowBroken(10));
232:                assertTrue("no row break at 11", sheet.isRowBroken(11));
233:                assertEquals("3 row break available", 3, sheet
234:                        .getNumRowBreaks());
235:
236:                boolean is10 = false;
237:                boolean is0 = false;
238:                boolean is11 = false;
239:
240:                Iterator iterator = sheet.getRowBreaks();
241:                while (iterator.hasNext()) {
242:                    PageBreakRecord.Break breakItem = (PageBreakRecord.Break) iterator
243:                            .next();
244:                    int main = (int) breakItem.main;
245:                    if (main != 0 && main != 10 && main != 11)
246:                        fail("Invalid page break");
247:                    if (main == 0)
248:                        is0 = true;
249:                    if (main == 10)
250:                        is10 = true;
251:                    if (main == 11)
252:                        is11 = true;
253:                }
254:
255:                assertTrue("one of the breaks didnt make it", is0 && is10
256:                        && is11);
257:
258:                sheet.removeRowBreak(11);
259:                assertFalse("row should be removed", sheet.isRowBroken(11));
260:
261:                sheet.removeRowBreak(0);
262:                assertFalse("row should be removed", sheet.isRowBroken(0));
263:
264:                sheet.removeRowBreak(10);
265:                assertFalse("row should be removed", sheet.isRowBroken(10));
266:
267:                assertEquals("no more breaks", 0, sheet.getNumRowBreaks());
268:
269:            }
270:
271:            /**
272:             * Make sure column pag breaks works properly (in-memory)
273:             *
274:             */
275:            public void testColPageBreaks() {
276:                short rowFrom = 0;
277:                short rowTo = (short) 65535;
278:
279:                Sheet sheet = Sheet.createSheet();
280:                sheet.setColumnBreak((short) 0, rowFrom, rowTo);
281:
282:                assertTrue("no col break at 0", sheet.isColumnBroken((short) 0));
283:                assertEquals("1 col break available", 1, sheet
284:                        .getNumColumnBreaks());
285:
286:                sheet.setColumnBreak((short) 0, rowFrom, rowTo);
287:
288:                assertTrue("no col break at 0", sheet.isColumnBroken((short) 0));
289:                assertEquals("1 col break available", 1, sheet
290:                        .getNumColumnBreaks());
291:
292:                sheet.setColumnBreak((short) 1, rowFrom, rowTo);
293:                sheet.setColumnBreak((short) 10, rowFrom, rowTo);
294:                sheet.setColumnBreak((short) 15, rowFrom, rowTo);
295:
296:                assertTrue("no col break at 1", sheet.isColumnBroken((short) 1));
297:                assertTrue("no col break at 10", sheet
298:                        .isColumnBroken((short) 10));
299:                assertTrue("no col break at 15", sheet
300:                        .isColumnBroken((short) 15));
301:                assertEquals("4 col break available", 4, sheet
302:                        .getNumColumnBreaks());
303:
304:                boolean is10 = false;
305:                boolean is0 = false;
306:                boolean is1 = false;
307:                boolean is15 = false;
308:
309:                Iterator iterator = sheet.getColumnBreaks();
310:                while (iterator.hasNext()) {
311:                    PageBreakRecord.Break breakItem = (PageBreakRecord.Break) iterator
312:                            .next();
313:                    int main = (int) breakItem.main;
314:                    if (main != 0 && main != 1 && main != 10 && main != 15)
315:                        fail("Invalid page break");
316:                    if (main == 0)
317:                        is0 = true;
318:                    if (main == 1)
319:                        is1 = true;
320:                    if (main == 10)
321:                        is10 = true;
322:                    if (main == 15)
323:                        is15 = true;
324:                }
325:
326:                assertTrue("one of the breaks didnt make it", is0 && is1
327:                        && is10 && is15);
328:
329:                sheet.removeColumnBreak((short) 15);
330:                assertFalse("column break should not be there", sheet
331:                        .isColumnBroken((short) 15));
332:
333:                sheet.removeColumnBreak((short) 0);
334:                assertFalse("column break should not be there", sheet
335:                        .isColumnBroken((short) 0));
336:
337:                sheet.removeColumnBreak((short) 1);
338:                assertFalse("column break should not be there", sheet
339:                        .isColumnBroken((short) 1));
340:
341:                sheet.removeColumnBreak((short) 10);
342:                assertFalse("column break should not be there", sheet
343:                        .isColumnBroken((short) 10));
344:
345:                assertEquals("no more breaks", 0, sheet.getNumColumnBreaks());
346:            }
347:
348:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.