From 125d197e1ba27c1708fe7531d36a9306debbd189 Mon Sep 17 00:00:00 2001 From: Josh Micich Date: Wed, 1 Oct 2008 20:56:21 +0000 Subject: [PATCH] Fixed bug in CellCacheEntry (support for caching blank evaluation results) git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@700916 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/ss/formula/CellCacheEntry.java | 4 ++ .../poi/ss/formula/AllSSFormulaTests.java | 11 ++-- .../poi/ss/formula/TestCellCacheEntry.java | 53 +++++++++++++++++++ 3 files changed, 63 insertions(+), 5 deletions(-) create mode 100644 src/testcases/org/apache/poi/ss/formula/TestCellCacheEntry.java diff --git a/src/java/org/apache/poi/ss/formula/CellCacheEntry.java b/src/java/org/apache/poi/ss/formula/CellCacheEntry.java index 861874c25..bd7500023 100644 --- a/src/java/org/apache/poi/ss/formula/CellCacheEntry.java +++ b/src/java/org/apache/poi/ss/formula/CellCacheEntry.java @@ -20,6 +20,7 @@ package org.apache.poi.ss.formula; import java.util.HashSet; import java.util.Set; +import org.apache.poi.hssf.record.formula.eval.BlankEval; import org.apache.poi.hssf.record.formula.eval.BoolEval; import org.apache.poi.hssf.record.formula.eval.ErrorEval; import org.apache.poi.hssf.record.formula.eval.NumberEval; @@ -60,6 +61,9 @@ final class CellCacheEntry { // value type is changing return false; } + if (a == BlankEval.INSTANCE) { + return b == a; + } if (cls == NumberEval.class) { return ((NumberEval)a).getNumberValue() == ((NumberEval)b).getNumberValue(); } diff --git a/src/testcases/org/apache/poi/ss/formula/AllSSFormulaTests.java b/src/testcases/org/apache/poi/ss/formula/AllSSFormulaTests.java index dd1360f76..13e2cfecd 100644 --- a/src/testcases/org/apache/poi/ss/formula/AllSSFormulaTests.java +++ b/src/testcases/org/apache/poi/ss/formula/AllSSFormulaTests.java @@ -26,9 +26,10 @@ import junit.framework.TestSuite; */ public final class AllSSFormulaTests { public static Test suite() { - TestSuite result = new TestSuite(AllSSFormulaTests.class.getName()); - result.addTestSuite(TestEvaluationCache.class); - result.addTestSuite(TestWorkbookEvaluator.class); - return result; - } + TestSuite result = new TestSuite(AllSSFormulaTests.class.getName()); + result.addTestSuite(TestCellCacheEntry.class); + result.addTestSuite(TestEvaluationCache.class); + result.addTestSuite(TestWorkbookEvaluator.class); + return result; + } } diff --git a/src/testcases/org/apache/poi/ss/formula/TestCellCacheEntry.java b/src/testcases/org/apache/poi/ss/formula/TestCellCacheEntry.java new file mode 100644 index 000000000..e8ff03f8b --- /dev/null +++ b/src/testcases/org/apache/poi/ss/formula/TestCellCacheEntry.java @@ -0,0 +1,53 @@ +/* ==================================================================== + 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.ss.formula; + +import org.apache.poi.hssf.record.formula.eval.BlankEval; +import org.apache.poi.hssf.record.formula.eval.NumberEval; +import org.apache.poi.hssf.record.formula.eval.ValueEval; + +import junit.framework.AssertionFailedError; +import junit.framework.TestCase; + +/** + * Tests {@link CellCacheEntry}. + * + * @author Josh Micich + */ +public class TestCellCacheEntry extends TestCase { + + public void testBasic() { + CellCacheEntry cce = new CellCacheEntry(); + cce.updatePlainValue(new NumberEval(42.0)); + ValueEval ve = cce.getValue(); + assertEquals(42, ((NumberEval)ve).getNumberValue(), 0.0); + + cce.setFormulaResult(new NumberEval(10.0), new CellLocation[] { }); + } + + public void testBlank() { + CellCacheEntry cce = new CellCacheEntry(); + cce.updatePlainValue(BlankEval.INSTANCE); + try { + cce.updatePlainValue(BlankEval.INSTANCE); + } catch (IllegalStateException e) { + // bug was visible around svn r700356 + throw new AssertionFailedError("cache entry does not handle blank values properly"); + } + } +}