From ae7ef11c88cc14c9b33dfcbf3f41d084bda64fc8 Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Fri, 15 Jul 2016 18:24:02 +0000 Subject: [PATCH] Bug 59861: Adjust testcase, it works now for me. Also combine the two TestProper classes into one git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1752861 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/ss/formula/functions/TestProper.java | 53 ++++++++++++++-- .../poi/ss/formula/functions/TestProper.java | 62 ------------------- 2 files changed, 48 insertions(+), 67 deletions(-) delete mode 100644 src/testcases/org/apache/poi/ss/formula/functions/TestProper.java diff --git a/src/ooxml/testcases/org/apache/poi/ss/formula/functions/TestProper.java b/src/ooxml/testcases/org/apache/poi/ss/formula/functions/TestProper.java index a9095982c4..dd3eeb5996 100644 --- a/src/ooxml/testcases/org/apache/poi/ss/formula/functions/TestProper.java +++ b/src/ooxml/testcases/org/apache/poi/ss/formula/functions/TestProper.java @@ -19,6 +19,8 @@ package org.apache.poi.ss.formula.functions; import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator; import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.ss.formula.eval.StringEval; +import org.apache.poi.ss.formula.eval.ValueEval; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.CellValue; @@ -30,11 +32,15 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook; import junit.framework.AssertionFailedError; import junit.framework.TestCase; +import org.junit.Test; -public final class TestProper extends TestCase { +import static org.junit.Assert.assertEquals; + +public final class TestProper { private Cell cell11; private FormulaEvaluator evaluator; + @Test public void testValidHSSF() { HSSFWorkbook wb = new HSSFWorkbook(); evaluator = new HSSFFormulaEvaluator(wb); @@ -42,6 +48,7 @@ public final class TestProper extends TestCase { confirm(wb); } + @Test public void testValidXSSF() { XSSFWorkbook wb = new XSSFWorkbook(); evaluator = new XSSFFormulaEvaluator(wb); @@ -65,14 +72,13 @@ public final class TestProper extends TestCase { confirm("PROPER(\"Apache POI\")", "Apache Poi"); //acronyms are not special confirm("PROPER(\" hello world\")", " Hello World"); //leading whitespace is ignored - final String scharfes = "\u00df$"; //German lowercase eszett, scharfes s, sharp s - // CURRENTLY FAILS: result: "Stra"+scharfes+"E" - // confirm("PROPER(\"stra"+scharfes+"e\")", "Stra"+scharfes+"e"); + final String scharfes = "\u00df"; //German lowercase eszett, scharfes s, sharp s + confirm("PROPER(\"stra"+scharfes+"e\")", "Stra"+scharfes+"e"); // CURRENTLY FAILS: result: "SSUnd"+scharfes // LibreOffice 5.0.3.2 behavior: "Sund"+scharfes // Excel 2013 behavior: ??? - //confirm("PROPER(\""+scharfes+"und"+scharfes+"\")", "SSund"+scharfes); + confirm("PROPER(\""+scharfes+"und"+scharfes+"\")", "SSund"+scharfes); // also test longer string StringBuilder builder = new StringBuilder("A"); @@ -94,4 +100,41 @@ public final class TestProper extends TestCase { String actualValue = cv.getStringValue(); assertEquals(expectedResult, actualValue); } + + @Test + public void test() { + checkProper("", ""); + checkProper("a", "A"); + checkProper("abc", "Abc"); + checkProper("abc abc", "Abc Abc"); + checkProper("abc/abc", "Abc/Abc"); + checkProper("ABC/ABC", "Abc/Abc"); + checkProper("aBc/ABC", "Abc/Abc"); + checkProper("aBc@#$%^&*()_+=-ABC", "Abc@#$%^&*()_+=-Abc"); + checkProper("aBc25aerg/ABC", "Abc25Aerg/Abc"); + checkProper("aBc/\u00C4\u00F6\u00DF\u00FC/ABC", "Abc/\u00C4\u00F6\u00DF\u00FC/Abc"); // Some German umlauts with uppercase first letter is not changed + checkProper("\u00FC", "\u00DC"); + checkProper("\u00DC", "\u00DC"); + checkProper("\u00DF", "SS"); // German "scharfes s" is uppercased to "SS" + checkProper("\u00DFomesing", "SSomesing"); // German "scharfes s" is uppercased to "SS" + checkProper("aBc/\u00FC\u00C4\u00F6\u00DF\u00FC/ABC", "Abc/\u00DC\u00E4\u00F6\u00DF\u00FC/Abc"); // Some German umlauts with lowercase first letter is changed to uppercase + } + + @Test + public void testMicroBenchmark() { + ValueEval strArg = new StringEval("some longer text that needs a number of replacements to check for runtime of different implementations"); + long start = System.currentTimeMillis(); + for(int i = 0;i < 300000;i++) { + final ValueEval ret = TextFunction.PROPER.evaluate(new ValueEval[]{strArg}, 0, 0); + assertEquals("Some Longer Text That Needs A Number Of Replacements To Check For Runtime Of Different Implementations", ((StringEval)ret).getStringValue()); + } + // Took aprox. 600ms on a decent Laptop in July 2016 + System.out.println("Took: " + (System.currentTimeMillis() - start) + "ms"); + } + + private void checkProper(String input, String expected) { + ValueEval strArg = new StringEval(input); + final ValueEval ret = TextFunction.PROPER.evaluate(new ValueEval[]{strArg}, 0, 0); + assertEquals(expected, ((StringEval)ret).getStringValue()); + } } diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestProper.java b/src/testcases/org/apache/poi/ss/formula/functions/TestProper.java deleted file mode 100644 index 9e148cc58d..0000000000 --- a/src/testcases/org/apache/poi/ss/formula/functions/TestProper.java +++ /dev/null @@ -1,62 +0,0 @@ -/* ==================================================================== - 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.functions; - -import org.apache.poi.ss.formula.eval.StringEval; -import org.apache.poi.ss.formula.eval.ValueEval; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -public class TestProper { - @Test - public void test() { - checkProper("", ""); - checkProper("a", "A"); - checkProper("abc", "Abc"); - checkProper("abc abc", "Abc Abc"); - checkProper("abc/abc", "Abc/Abc"); - checkProper("ABC/ABC", "Abc/Abc"); - checkProper("aBc/ABC", "Abc/Abc"); - checkProper("aBc@#$%^&*()_+=-ABC", "Abc@#$%^&*()_+=-Abc"); - checkProper("aBc25aerg/ABC", "Abc25Aerg/Abc"); - checkProper("aBc/\u00C4\u00F6\u00DF\u00FC/ABC", "Abc/\u00C4\u00F6\u00DF\u00FC/Abc"); // Some German umlauts with uppercase first letter is not changed - checkProper("\u00FC", "\u00DC"); - checkProper("\u00DC", "\u00DC"); - checkProper("\u00DF", "SS"); // German "scharfes s" is uppercased to "SS" - checkProper("aBc/\u00FC\u00C4\u00F6\u00DF\u00FC/ABC", "Abc/\u00DC\u00E4\u00F6\u00DF\u00FC/Abc"); // Some German umlauts with lowercase first letter is changed to uppercase - } - - @Test - public void testMicroBenchmark() { - ValueEval strArg = new StringEval("some longer text that needs a number of replacements to check for runtime of different implementations"); - long start = System.currentTimeMillis(); - for(int i = 0;i < 300000;i++) { - final ValueEval ret = TextFunction.PROPER.evaluate(new ValueEval[]{strArg}, 0, 0); - assertEquals("Some Longer Text That Needs A Number Of Replacements To Check For Runtime Of Different Implementations", ((StringEval)ret).getStringValue()); - } - // Took aprox. 600ms on a decent Laptop in July 2016 - System.out.println("Took: " + (System.currentTimeMillis() - start) + "ms"); - } - - private void checkProper(String input, String expected) { - ValueEval strArg = new StringEval(input); - final ValueEval ret = TextFunction.PROPER.evaluate(new ValueEval[]{strArg}, 0, 0); - assertEquals(expected, ((StringEval)ret).getStringValue()); - } -} -- 2.39.5