From a4cfce51067541b77f65603212f0eaa5f07fbb4f Mon Sep 17 00:00:00 2001 From: Josh Micich Date: Thu, 8 May 2008 23:02:43 +0000 Subject: [PATCH] fixed mistake in FuncPtg.clone(), added test case, cleaned up outdated (since bug 13292) test method. git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@654649 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/hssf/record/formula/FuncPtg.java | 8 ++- .../poi/hssf/record/formula/TestFuncPtg.java | 53 +++++++------------ 2 files changed, 22 insertions(+), 39 deletions(-) diff --git a/src/java/org/apache/poi/hssf/record/formula/FuncPtg.java b/src/java/org/apache/poi/hssf/record/formula/FuncPtg.java index 7901fb675d..2585bd764f 100644 --- a/src/java/org/apache/poi/hssf/record/formula/FuncPtg.java +++ b/src/java/org/apache/poi/hssf/record/formula/FuncPtg.java @@ -75,11 +75,9 @@ public final class FuncPtg extends AbstractFunctionPtg { } public Object clone() { - FuncPtg ptg = new FuncPtg(); - //ptg.field_1_num_args = field_1_num_args; - ptg.field_2_fnc_index = field_2_fnc_index; - ptg.setClass(ptgClass); - return ptg; + FuncPtg ptg = new FuncPtg(field_2_fnc_index); + ptg.setClass(ptgClass); + return ptg; } public int getSize() { diff --git a/src/testcases/org/apache/poi/hssf/record/formula/TestFuncPtg.java b/src/testcases/org/apache/poi/hssf/record/formula/TestFuncPtg.java index fd2b1cd124..89997b59d1 100644 --- a/src/testcases/org/apache/poi/hssf/record/formula/TestFuncPtg.java +++ b/src/testcases/org/apache/poi/hssf/record/formula/TestFuncPtg.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -26,45 +25,31 @@ import org.apache.poi.hssf.record.TestcaseRecordInputStream; * * @author Danny Mui (dmui at apache dot org) */ +public final class TestFuncPtg extends TestCase { -public class TestFuncPtg extends TestCase -{ - - public TestFuncPtg( String name ) - { - super( name ); - } - - - public static void main( java.lang.String[] args ) - { - junit.textui.TestRunner.run( TestFuncPtg.class ); - } - - /** - * Make sure the left overs are re-serialized on excel file reads to avoid - * the "Warning: Data may have been lost" prompt in excel. - *

- * This ptg represents a LEN function extracted from excel - */ - - public void testLeftOvers() - { - byte[] fakeData = new byte[4]; - - //fakeData[0] = (byte) 0x41; - fakeData[0] = (byte) 0x20; //function index - fakeData[1] = (byte) 0; - fakeData[2] = (byte) 8; + public void testRead() { + // This ptg represents a LEN function extracted from excel + byte[] fakeData = { + 0x20, //function index + 0, + }; FuncPtg ptg = new FuncPtg( new TestcaseRecordInputStream((short)0, (short)fakeData.length, fakeData) ); - assertEquals( "Len formula index is not 32(20H)", (int) 0x20, ptg.getFunctionIndex() ); + assertEquals( "Len formula index is not 32(20H)", 0x20, ptg.getFunctionIndex() ); assertEquals( "Number of operands in the len formula", 1, ptg.getNumberOfOperands() ); assertEquals( "Function Name", "LEN", ptg.getName() ); assertEquals( "Ptg Size", 3, ptg.getSize() ); - //assertEquals("first leftover byte is not 0", (byte)0, ptg.leftOvers[0]); - //assertEquals("second leftover byte is not 8", (byte)8, ptg.leftOvers[1]); - + } + + public void testClone() { + FuncPtg funcPtg = new FuncPtg(27); // ROUND() - takes 2 args + + FuncPtg clone = (FuncPtg) funcPtg.clone(); + if (clone.getNumberOfOperands() == 0) { + fail("clone() did copy field numberOfOperands"); + } + assertEquals(2, clone.getNumberOfOperands()); + assertEquals("ROUND", clone.getName()); } } -- 2.39.5