1 2 17 18 19 20 package org.apache.poi.hssf.record; 21 22 23 import junit.framework.TestCase; 24 25 31 public class TestFormulaRecord 32 extends TestCase 33 { 34 35 public TestFormulaRecord(String name) 36 { 37 super(name); 38 } 39 40 public void testCreateFormulaRecord () { 41 FormulaRecord record = new FormulaRecord(); 42 record.setColumn((short)0); 43 record.setRow(1); 45 record.setXFIndex((short)4); 46 47 assertEquals(record.getColumn(),(short)0); 48 assertEquals((short)record.getRow(),(short)1); 50 assertEquals(record.getXFIndex(),(short)4); 51 } 52 53 57 public void testCheckNanPreserve() { 58 byte[] formulaByte = new byte[29]; 59 for (int i = 0; i < formulaByte.length; i++) formulaByte[i] = (byte)0; 60 formulaByte[4] = (byte)0x0F; 61 formulaByte[6] = (byte)0x02; 62 formulaByte[8] = (byte)0x07; 63 formulaByte[12] = (byte)0xFF; 64 formulaByte[13] = (byte)0xFF; 65 formulaByte[18] = (byte)0xE0; 66 formulaByte[19] = (byte)0xFC; 67 formulaByte[20] = (byte)0x07; 68 formulaByte[22] = (byte)0x1E; 69 formulaByte[23] = (byte)0x01; 70 formulaByte[25] = (byte)0x1E; 71 formulaByte[28] = (byte)0x06; 72 73 FormulaRecord record = new FormulaRecord(FormulaRecord.sid, (short)29, formulaByte); 74 assertEquals("Row", 0, record.getRow()); 75 assertEquals("Column", 0, record.getColumn()); 76 assertTrue("Value is not NaN", Double.isNaN(record.getValue())); 77 78 byte[] output = record.serialize(); 79 assertEquals("Output size", 33, output.length); 81 for (int i = 5; i < 13;i++) { 82 assertEquals("FormulaByte NaN doesn't match", formulaByte[i], output[i+4]); 83 } 84 85 } 86 87 91 public void testExpFormula() { 92 byte[] formulaByte = new byte[27]; 93 94 for (int i = 0; i < formulaByte.length; i++) formulaByte[i] = (byte)0; 95 96 formulaByte[4] =(byte)0x0F; 97 formulaByte[14]=(byte)0x08; 98 formulaByte[18]=(byte)0xE0; 99 formulaByte[19]=(byte)0xFD; 100 formulaByte[20]=(byte)0x05; 101 formulaByte[22]=(byte)0x01; 102 FormulaRecord record = new FormulaRecord(FormulaRecord.sid, (short)27, formulaByte); 103 assertEquals("Row", 0, record.getRow()); 104 assertEquals("Column", 0, record.getColumn()); 105 byte[] output = record.serialize(); 106 assertEquals("Output size", 31, output.length); assertEquals("Offset 22", 1, output[26]); 108 } 109 110 111 public static void main(String [] ignored_args) 112 { 113 String filename = System.getProperty("HSSF.testdata.path"); 114 115 System.out 116 .println("Testing org.apache.poi.hssf.record.FormulaRecord"); 117 junit.textui.TestRunner.run(TestFormulaRecord.class); 118 } 119 120 121 } 122 | Popular Tags |