poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r1690778 - in /poi/trunk/src: java/org/apache/poi/hssf/record/ ooxml/testcases/org/apache/poi/xssf/usermodel/ testcases/org/apache/poi/hssf/record/ testcases/org/apache/poi/hssf/usermodel/ testcases/org/apache/poi/ss/usermodel/
Date Mon, 13 Jul 2015 17:54:28 GMT
Author: nick
Date: Mon Jul 13 17:54:28 2015
New Revision: 1690778

URL: http://svn.apache.org/r1690778
Log:
CFRule12 tests

Modified:
    poi/trunk/src/java/org/apache/poi/hssf/record/CFRule12Record.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFConditionalFormatting.java
    poi/trunk/src/testcases/org/apache/poi/hssf/record/TestCFRuleRecord.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFConditionalFormatting.java
    poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/CFRule12Record.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/CFRule12Record.java?rev=1690778&r1=1690777&r2=1690778&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/CFRule12Record.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/CFRule12Record.java Mon Jul 13 17:54:28
2015
@@ -214,6 +214,7 @@ public final class CFRule12Record extend
         
         getFormula1().serializeTokens(out);
         getFormula2().serializeTokens(out);
+        out.writeShort(getFormulaSize(formula_scale));
         formula_scale.serializeTokens(out);
         
         out.writeByte(ext_opts);
@@ -243,7 +244,7 @@ public final class CFRule12Record extend
         }
         len += getFormulaSize(getFormula1());
         len += getFormulaSize(getFormula2());
-        len += 4 + getFormulaSize(formula_scale);
+        len += 2 + getFormulaSize(formula_scale);
         len += 6 + template_params.length;
         
         byte type = getConditionType();
@@ -278,7 +279,7 @@ public final class CFRule12Record extend
         buffer.append("    .formula_1 =").append(Arrays.toString(getFormula1().getTokens())).append("\n");
         buffer.append("    .formula_2 =").append(Arrays.toString(getFormula2().getTokens())).append("\n");
         buffer.append("    .formula_S =").append(Arrays.toString(formula_scale.getTokens())).append("\n");
-        buffer.append("    .ext Opts  =").append(ext_opts).append("\n");
+        buffer.append("    .ext_opts  =").append(ext_opts).append("\n");
         buffer.append("    .priority  =").append(priority).append("\n");
         buffer.append("    .template_type  =").append(template_type).append("\n");
         buffer.append("    .template_params=").append(HexDump.toHex(template_params)).append("\n");

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFConditionalFormatting.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFConditionalFormatting.java?rev=1690778&r1=1690777&r2=1690778&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFConditionalFormatting.java
(original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFConditionalFormatting.java
Mon Jul 13 17:54:28 2015
@@ -22,7 +22,7 @@ import org.apache.poi.ss.usermodel.BaseT
 import org.apache.poi.xssf.XSSFITestDataProvider;
 
 /**
- * @author Yegor Kozlov
+ * XSSF-specific Conditional Formatting tests
  */
 public class TestXSSFConditionalFormatting extends BaseTestConditionalFormatting {
     public TestXSSFConditionalFormatting(){
@@ -32,4 +32,9 @@ public class TestXSSFConditionalFormatti
     public void testRead(){
         testRead("WithConditionalFormatting.xlsx");
     }
+    
+    public void IGNORED_testReadOffice2007() {
+        // TODO Bring the XSSF support up to the same level
+        testReadOffice2007("NewStyleConditionalFormattings.xlsx");
+    }
 }

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/TestCFRuleRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/TestCFRuleRecord.java?rev=1690778&r1=1690777&r2=1690778&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/TestCFRuleRecord.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/TestCFRuleRecord.java Mon Jul 13 17:54:28
2015
@@ -21,6 +21,7 @@ import static org.junit.Assert.assertArr
 import junit.framework.AssertionFailedError;
 import junit.framework.TestCase;
 
+import org.apache.poi.hssf.HSSFITestDataProvider;
 import org.apache.poi.hssf.record.CFRuleBase.ComparisonOperator;
 import org.apache.poi.hssf.record.cf.BorderFormatting;
 import org.apache.poi.hssf.record.cf.FontFormatting;
@@ -36,8 +37,8 @@ import org.apache.poi.util.LittleEndian;
 /**
  * Tests the serialization and deserialization of the TestCFRuleRecord
  * class works correctly.
- * TODO Add {@link CFRule12Record} tests
  */
+@SuppressWarnings("resource")
 public final class TestCFRuleRecord extends TestCase {
     public void testConstructors () {
         HSSFWorkbook workbook = new HSSFWorkbook();
@@ -90,19 +91,37 @@ public final class TestCFRuleRecord exte
         }
     }
 
-    private void testCFRuleRecord(CFRuleRecord record) {
-        FontFormatting fontFormatting = new FontFormatting();
-        testFontFormattingAccessors(fontFormatting);
-        assertFalse(record.containsFontFormattingBlock());
-        record.setFontFormatting(fontFormatting);
-        assertTrue(record.containsFontFormattingBlock());
+    public void testCreateCFRule12Record() {
+        HSSFWorkbook workbook = new HSSFWorkbook();
+        HSSFSheet sheet = workbook.createSheet();
+        CFRule12Record record = CFRule12Record.create(sheet, "7");
+        testCFRule12Record(record);
 
-        BorderFormatting borderFormatting = new BorderFormatting();
-        testBorderFormattingAccessors(borderFormatting);
-        assertFalse(record.containsBorderFormattingBlock());
-        record.setBorderFormatting(borderFormatting);
-        assertTrue(record.containsBorderFormattingBlock());
+        // Serialize
+        byte [] serializedRecord = record.serialize();
 
+        // Strip header
+        byte [] recordData = new byte[serializedRecord.length-4];
+        System.arraycopy(serializedRecord, 4, recordData, 0, recordData.length);
+
+        // Deserialize
+        record = new CFRule12Record(TestcaseRecordInputStream.create(CFRule12Record.sid,
recordData));
+
+        // Serialize again
+        byte[] output = record.serialize();
+
+        // Compare
+        assertEquals("Output size", recordData.length+4, output.length); //includes sid+recordlength
+
+        for (int i = 0; i < recordData.length;i++)
+        {
+            assertEquals("CFRule12Record doesn't match", recordData[i], output[i+4]);
+        }
+    }
+
+    private void testCFRuleRecord(CFRuleRecord record) {
+        testCFRuleBase(record);
+        
         assertFalse(record.isLeftBorderModified());
         record.setLeftBorderModified(true);
         assertTrue(record.isLeftBorderModified());
@@ -128,12 +147,6 @@ public final class TestCFRuleRecord exte
         assertTrue(record.isBottomLeftTopRightBorderModified());
 
 
-        PatternFormatting patternFormatting = new PatternFormatting();
-        testPatternFormattingAccessors(patternFormatting);
-        assertFalse(record.containsPatternFormattingBlock());
-        record.setPatternFormatting(patternFormatting);
-        assertTrue(record.containsPatternFormattingBlock());
-
         assertFalse(record.isPatternBackgroundColorModified());
         record.setPatternBackgroundColorModified(true);
         assertTrue(record.isPatternBackgroundColorModified());
@@ -146,6 +159,30 @@ public final class TestCFRuleRecord exte
         record.setPatternStyleModified(true);
         assertTrue(record.isPatternStyleModified());
     }
+    private void testCFRule12Record(CFRule12Record record) {
+        assertEquals(CFRule12Record.sid, record.getFutureRecordType());
+        assertEquals("A1", record.getAssociatedRange().formatAsString());
+        testCFRuleBase(record);
+    }
+    private void testCFRuleBase(CFRuleBase record) {
+        FontFormatting fontFormatting = new FontFormatting();
+        testFontFormattingAccessors(fontFormatting);
+        assertFalse(record.containsFontFormattingBlock());
+        record.setFontFormatting(fontFormatting);
+        assertTrue(record.containsFontFormattingBlock());
+
+        BorderFormatting borderFormatting = new BorderFormatting();
+        testBorderFormattingAccessors(borderFormatting);
+        assertFalse(record.containsBorderFormattingBlock());
+        record.setBorderFormatting(borderFormatting);
+        assertTrue(record.containsBorderFormattingBlock());
+
+        PatternFormatting patternFormatting = new PatternFormatting();
+        testPatternFormattingAccessors(patternFormatting);
+        assertFalse(record.containsPatternFormattingBlock());
+        record.setPatternFormatting(patternFormatting);
+        assertTrue(record.containsPatternFormattingBlock());
+    }
 
     private void testPatternFormattingAccessors(PatternFormatting patternFormatting) {
         patternFormatting.setFillBackgroundColor(HSSFColor.GREEN.index);
@@ -364,4 +401,12 @@ public final class TestCFRuleRecord exte
         byte [] serializedClone = clone.serialize();
         assertArrayEquals(serializedRecord, serializedClone);
     }
+    
+    // TODO Fix this test!
+    public void IGNORED_testBug57231_rewrite() {
+        HSSFWorkbook wb = HSSFITestDataProvider.instance.openSampleWorkbook("57231_MixedGasReport.xls");
+        assertEquals(7, wb.getNumberOfSheets());
+        wb = HSSFITestDataProvider.instance.writeOutAndReadBack(wb);
+        assertEquals(7, wb.getNumberOfSheets());
+    }
 }

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFConditionalFormatting.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFConditionalFormatting.java?rev=1690778&r1=1690777&r2=1690778&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFConditionalFormatting.java
(original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFConditionalFormatting.java
Mon Jul 13 17:54:28 2015
@@ -28,17 +28,20 @@ import org.apache.poi.ss.usermodel.Sheet
 import org.apache.poi.ss.usermodel.Workbook;
 
 /**
- *
- * @author Dmitriy Kumshayev
+ * HSSF-specific Conditional Formatting tests
  */
 public final class TestHSSFConditionalFormatting extends BaseTestConditionalFormatting {
     public TestHSSFConditionalFormatting(){
         super(HSSFITestDataProvider.instance);
     }
 
-    public void testRead(){
+    public void testRead() {
         testRead("WithConditionalFormatting.xls");
     }
+    
+    public void testReadOffice2007() {
+        testReadOffice2007("NewStyleConditionalFormattings.xls");
+    }
 
     public void test53691() throws IOException {
         SheetConditionalFormatting cf;

Modified: poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java?rev=1690778&r1=1690777&r2=1690778&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java
(original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java
Mon Jul 13 17:54:28 2015
@@ -24,8 +24,7 @@ import org.apache.poi.ss.ITestDataProvid
 import org.apache.poi.ss.util.CellRangeAddress;
 
 /**
- * @author Dmitriy Kumshayev
- * @author Yegor Kozlov
+ * Base tests for Conditional Formatting, for both HSSF and XSSF
  */
 public abstract class BaseTestConditionalFormatting extends TestCase {
     private final ITestDataProvider _testDataProvider;
@@ -525,6 +524,31 @@ public abstract class BaseTestConditiona
         assertEquals("\"AAA\"", rule5.getFormula2());
     }
 
+    public void testReadOffice2007(String filename) {
+        Workbook wb = _testDataProvider.openSampleWorkbook(filename);
+        Sheet s = wb.getSheet("CF");
+        ConditionalFormatting cf = null;
+        
+        // Sanity check data
+        assertEquals("Values", s.getRow(0).getCell(0).toString());
+        assertEquals("10.0", s.getRow(2).getCell(0).toString());
+
+        // Check we found all the conditional formattings rules we should have
+        SheetConditionalFormatting sheetCF = s.getSheetConditionalFormatting();
+        assertEquals(1, sheetCF.getNumConditionalFormattings()); // TODO Should be more!
+        
+        cf = sheetCF.getConditionalFormattingAt(0);
+        //System.out.println(cf);
+        
+        
+        // Check the rules / values in detail
+        
+        // Highlight Positive values - Column C
+        // TODO
+        
+        // Highlight 10-30 - Column D
+        // TODO
+    }
 
     public void testCreateFontFormatting() {
         Workbook workbook = _testDataProvider.createWorkbook();



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


Mime
View raw message