aboutsummaryrefslogtreecommitdiffstats
path: root/src/testcases/org/apache/poi/ss/util/TestWorkbookUtil.java
diff options
context:
space:
mode:
authorNick Burch <nick@apache.org>2010-08-04 14:13:42 +0000
committerNick Burch <nick@apache.org>2010-08-04 14:13:42 +0000
commitba5f6a5cf3c995d0896b1d2c8a4937f6cd9128aa (patch)
treef8a42f7b3b41d9951eec94adbcaf384a4e4950b8 /src/testcases/org/apache/poi/ss/util/TestWorkbookUtil.java
parent79c4de256f76c7b372333552975c8701c7f6a798 (diff)
downloadpoi-ba5f6a5cf3c995d0896b1d2c8a4937f6cd9128aa.tar.gz
poi-ba5f6a5cf3c995d0896b1d2c8a4937f6cd9128aa.zip
Add patch from bug #49690 - Add WorkbookUtil, which provies a way of generating valid sheet names
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@982260 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org/apache/poi/ss/util/TestWorkbookUtil.java')
-rw-r--r--src/testcases/org/apache/poi/ss/util/TestWorkbookUtil.java84
1 files changed, 84 insertions, 0 deletions
diff --git a/src/testcases/org/apache/poi/ss/util/TestWorkbookUtil.java b/src/testcases/org/apache/poi/ss/util/TestWorkbookUtil.java
new file mode 100644
index 0000000000..c1e49cab67
--- /dev/null
+++ b/src/testcases/org/apache/poi/ss/util/TestWorkbookUtil.java
@@ -0,0 +1,84 @@
+/* ====================================================================
+ 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.util;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests WorkbookUtil.
+ *
+ * @see org.apache.poi.ss.util.WorkbookUtil
+ */
+public final class TestWorkbookUtil extends TestCase {
+ /**
+ * borrowed test cases from
+ * {@link org.apache.poi.hssf.record.TestBoundSheetRecord#testValidNames()}
+ */
+ public void testCreateSafeNames() {
+
+ String p = "Sheet1";
+ String actual = WorkbookUtil.createSafeSheetName(p);
+ assertEquals(p, actual);
+
+ p = "O'Brien's sales";
+ actual = WorkbookUtil.createSafeSheetName(p);
+ assertEquals(p, actual);
+
+ p = " data # ";
+ actual = WorkbookUtil.createSafeSheetName(p);
+ assertEquals(p, actual);
+
+ p = "data $1.00";
+ actual = WorkbookUtil.createSafeSheetName(p);
+ assertEquals(p, actual);
+
+ // now the replaced versions ...
+ actual = WorkbookUtil.createSafeSheetName("data?");
+ assertEquals("data ", actual);
+
+ actual = WorkbookUtil.createSafeSheetName("abc/def");
+ assertEquals("abc def", actual);
+
+ actual = WorkbookUtil.createSafeSheetName("data[0]");
+ assertEquals("data 0 ", actual);
+
+ actual = WorkbookUtil.createSafeSheetName("data*");
+ assertEquals("data ", actual);
+
+ actual = WorkbookUtil.createSafeSheetName("abc\\def");
+ assertEquals("abc def", actual);
+
+ actual = WorkbookUtil.createSafeSheetName("'data");
+ assertEquals(" data", actual);
+
+ actual = WorkbookUtil.createSafeSheetName("data'");
+ assertEquals("data ", actual);
+
+ actual = WorkbookUtil.createSafeSheetName("d'at'a");
+ assertEquals("d'at'a", actual);
+
+ actual = WorkbookUtil.createSafeSheetName(null);
+ assertEquals("null", actual);
+
+ actual = WorkbookUtil.createSafeSheetName("");
+ assertEquals("empty", actual);
+
+ actual = WorkbookUtil.createSafeSheetName("1234567890123456789012345678901TOOLONG");
+ assertEquals("1234567890123456789012345678901", actual);
+ }
+}