poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r676203 - in /poi/trunk/src: java/org/apache/poi/hssf/record/ExtendedFormatRecord.java testcases/org/apache/poi/hssf/record/AllRecordTests.java testcases/org/apache/poi/hssf/record/TestExtendedFormatRecord.java
Date Sat, 12 Jul 2008 17:21:54 GMT
Author: nick
Date: Sat Jul 12 10:21:54 2008
New Revision: 676203

URL: http://svn.apache.org/viewvc?rev=676203&view=rev
Log:
Support for cloning one extended format record onto another, plus tests

Added:
    poi/trunk/src/testcases/org/apache/poi/hssf/record/TestExtendedFormatRecord.java   (with
props)
Modified:
    poi/trunk/src/java/org/apache/poi/hssf/record/ExtendedFormatRecord.java
    poi/trunk/src/testcases/org/apache/poi/hssf/record/AllRecordTests.java

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/ExtendedFormatRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/ExtendedFormatRecord.java?rev=676203&r1=676202&r2=676203&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/ExtendedFormatRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/ExtendedFormatRecord.java Sat Jul 12 10:21:54
2008
@@ -1814,6 +1814,27 @@
     {
         return sid;
     }
+    
+    /**
+     * Clones all the style information from another
+     *  ExtendedFormatRecord, onto this one. This 
+     *  will then hold all the same style options.
+     *  
+     * If The source ExtendedFormatRecord comes from
+     *  a different Workbook, you will need to sort
+     *  out the font and format indicies yourself!
+     */
+    public void cloneStyleFrom(ExtendedFormatRecord source) {
+        field_1_font_index           = source.field_1_font_index;
+        field_2_format_index         = source.field_2_format_index;
+        field_3_cell_options         = source.field_3_cell_options;
+        field_4_alignment_options    = source.field_4_alignment_options;
+        field_5_indention_options    = source.field_5_indention_options;
+        field_6_border_options       = source.field_6_border_options;
+        field_7_palette_options      = source.field_7_palette_options;
+        field_8_adtl_palette_options = source.field_8_adtl_palette_options;
+        field_9_fill_palette_options = source.field_9_fill_palette_options;
+    }
 
 	public int hashCode() {
 		final int prime = 31;

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/AllRecordTests.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/AllRecordTests.java?rev=676203&r1=676202&r2=676203&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/AllRecordTests.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/AllRecordTests.java Sat Jul 12 10:21:54
2008
@@ -61,6 +61,7 @@
 		result.addTestSuite(TestEmbeddedObjectRefSubRecord.class);
 		result.addTestSuite(TestEndSubRecord.class);
 		result.addTestSuite(TestEscherAggregate.class);
+		result.addTestSuite(TestExtendedFormatRecord.class);
 		result.addTestSuite(TestExternalNameRecord.class);
 		result.addTestSuite(TestFontRecord.class);
 		result.addTestSuite(TestFontBasisRecord.class);

Added: poi/trunk/src/testcases/org/apache/poi/hssf/record/TestExtendedFormatRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/TestExtendedFormatRecord.java?rev=676203&view=auto
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/TestExtendedFormatRecord.java (added)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/TestExtendedFormatRecord.java Sat Jul
12 10:21:54 2008
@@ -0,0 +1,138 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hssf.record;
+
+import junit.framework.TestCase;
+/**
+ */
+public final class TestExtendedFormatRecord extends TestCase {
+	byte[] header = new byte[] {
+    		0xE0-256, 00, 0x14, 00 // sid=e0, 20 bytes long 
+	};
+    byte[] data = new byte[] {
+    		00, 00, // Font 0 
+    		00, 00, // Format 0
+    		0xF5-256, 0xFF-256, // Cell opts ...
+    		0x20, 00, // Alignment 20 
+    		00, 00,   // Ident 0
+    		00, 00,   // Border 0
+    		00, 00,   // Palette 0 
+    		00, 00, 00, 00, // ADTL Palette 0
+    		0xC0-256, 0x20  // Fill Palette 20c0
+    };
+
+    public TestExtendedFormatRecord(String name)
+    {
+        super(name);
+    }
+
+    public void testLoad()
+            throws Exception
+    {
+        ExtendedFormatRecord record = new ExtendedFormatRecord(new TestcaseRecordInputStream((short)0xe0,
(short)data.length, data));
+        assertEquals(0, record.getFontIndex());
+        assertEquals(0, record.getFormatIndex());
+        assertEquals(0xF5-256, record.getCellOptions());
+        assertEquals(0x20, record.getAlignmentOptions());
+        assertEquals(0, record.getIndentionOptions());
+        assertEquals(0, record.getBorderOptions());
+        assertEquals(0, record.getPaletteOptions());
+        assertEquals(0, record.getAdtlPaletteOptions());
+        assertEquals(0x20c0, record.getFillPaletteOptions());
+
+        assertEquals( 20 + 4, record.getRecordSize() );
+        record.validateSid((short)0xe0);
+    }
+
+    public void testStore()
+    {
+//    .fontindex       = 0
+//    .formatindex     = 0
+//    .celloptions     = fffffff5
+//          .islocked  = true
+//          .ishidden  = false
+//          .recordtype= 1
+//          .parentidx = fff
+//    .alignmentoptions= 20
+//          .alignment = 0
+//          .wraptext  = false
+//          .valignment= 2
+//          .justlast  = 0
+//          .rotation  = 0
+//    .indentionoptions= 0
+//          .indent    = 0
+//          .shrinktoft= false
+//          .mergecells= false
+//          .readngordr= 0
+//          .formatflag= false
+//          .fontflag  = false
+//          .prntalgnmt= false
+//          .borderflag= false
+//          .paternflag= false
+//          .celloption= false
+//    .borderoptns     = 0
+//          .lftln     = 0
+//          .rgtln     = 0
+//          .topln     = 0
+//          .btmln     = 0
+//    .paleteoptns     = 0
+//          .leftborder= 0
+//          .rghtborder= 0
+//          .diag      = 0
+//    .paleteoptn2     = 0
+//          .topborder = 0
+//          .botmborder= 0
+//          .adtldiag  = 0
+//          .diaglnstyl= 0
+//          .fillpattrn= 0
+//    .fillpaloptn     = 20c0
+//          .foreground= 40
+//          .background= 41
+
+    	ExtendedFormatRecord record = new ExtendedFormatRecord();
+    	record.setFontIndex((short)0);
+    	record.setFormatIndex((short)0);
+    	
+    	record.setLocked(true);
+    	record.setHidden(false);
+    	record.setXFType((short)1);
+    	record.setParentIndex((short)0xfff);
+    	
+    	record.setVerticalAlignment((short)2);
+    	
+    	record.setFillForeground((short)0x40);
+    	record.setFillBackground((short)0x41);
+
+        byte [] recordBytes = record.serialize();
+        assertEquals(recordBytes.length - 4, data.length);
+        for (int i = 0; i < data.length; i++)
+            assertEquals("At offset " + i, data[i], recordBytes[i+4]);
+    }
+    
+    public void testCloneOnto() throws Exception {
+        ExtendedFormatRecord base = new ExtendedFormatRecord(new TestcaseRecordInputStream((short)0xe0,
(short)data.length, data));
+    	
+    	ExtendedFormatRecord other = new ExtendedFormatRecord();
+        other.cloneStyleFrom(base);
+
+        byte [] recordBytes = other.serialize();
+        assertEquals(recordBytes.length - 4, data.length);
+        for (int i = 0; i < data.length; i++)
+            assertEquals("At offset " + i, data[i], recordBytes[i+4]);
+    }
+}

Propchange: poi/trunk/src/testcases/org/apache/poi/hssf/record/TestExtendedFormatRecord.java
------------------------------------------------------------------------------
    svn:eol-style = native



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message