-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-\r
-package org.apache.poi.openxml4j.opc;\r
-\r
-import junit.framework.Test;\r
-import junit.framework.TestSuite;\r
-\r
-import org.apache.poi.openxml4j.opc.compliance.AllOpenXML4JComplianceTests;\r
-import org.apache.poi.openxml4j.opc.internal.AllOpenXML4JInternalTests;\r
-\r
-public final class AllOpenXML4JTests {\r
-\r
- public static Test suite() {\r
- \r
- TestSuite suite = new TestSuite(AllOpenXML4JTests.class.getName());\r
- suite.addTestSuite(TestContentType.class);\r
- suite.addTestSuite(TestFileHelper.class);\r
- suite.addTestSuite(TestListParts.class);\r
- suite.addTestSuite(TestPackage.class);\r
- suite.addTestSuite(TestPackageCoreProperties.class);\r
- suite.addTestSuite(TestPackagePartName.class);\r
- suite.addTestSuite(TestPackageThumbnail.class);\r
- suite.addTestSuite(TestPackagingURIHelper.class);\r
- suite.addTestSuite(TestRelationships.class);\r
- suite.addTest(AllOpenXML4JComplianceTests.suite());\r
- suite.addTest(AllOpenXML4JInternalTests.suite());\r
- return suite;\r
- }\r
-}\r
+/* ====================================================================
+ 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.openxml4j.opc;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.poi.openxml4j.opc.compliance.AllOpenXML4JComplianceTests;
+import org.apache.poi.openxml4j.opc.internal.AllOpenXML4JInternalTests;
+
+public final class AllOpenXML4JTests {
+
+ public static Test suite() {
+
+ TestSuite suite = new TestSuite(AllOpenXML4JTests.class.getName());
+ suite.addTestSuite(TestContentType.class);
+ suite.addTestSuite(TestFileHelper.class);
+ suite.addTestSuite(TestListParts.class);
+ suite.addTestSuite(TestPackage.class);
+ suite.addTestSuite(TestPackageCoreProperties.class);
+ suite.addTestSuite(TestPackagePartName.class);
+ suite.addTestSuite(TestPackageThumbnail.class);
+ suite.addTestSuite(TestPackagingURIHelper.class);
+ suite.addTestSuite(TestRelationships.class);
+ suite.addTest(AllOpenXML4JComplianceTests.suite());
+ suite.addTest(AllOpenXML4JInternalTests.suite());
+ return suite;
+ }
+}
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-\r
-package org.apache.poi.openxml4j.opc;\r
-\r
-import junit.framework.TestCase;\r
-\r
-import org.apache.poi.openxml4j.exceptions.InvalidFormatException;\r
-import org.apache.poi.openxml4j.opc.internal.ContentType;\r
-\r
-/**\r
- * Tests for content type (ContentType class).\r
- * \r
- * @author Julien Chable\r
- */\r
-public class TestContentType extends TestCase {\r
-\r
- /**\r
- * Check rule M1.13: Package implementers shall only create and only\r
- * recognize parts with a content type; format designers shall specify a\r
- * content type for each part included in the format. Content types for\r
- * package parts shall fit the definition and syntax for media types as\r
- * specified in RFC 2616, \u00A73.7.\r
- */\r
- public void testContentTypeValidation() throws InvalidFormatException {\r
- String[] contentTypesToTest = new String[] { "text/xml",\r
- "application/pgp-key", "application/vnd.hp-PCLXL",\r
- "application/vnd.lotus-1-2-3" };\r
- for (int i = 0; i < contentTypesToTest.length; ++i) {\r
- new ContentType(contentTypesToTest[i]);\r
- }\r
- }\r
-\r
- /**\r
- * Check rule M1.13 : Package implementers shall only create and only\r
- * recognize parts with a content type; format designers shall specify a\r
- * content type for each part included in the format. Content types for\r
- * package parts shall fit the definition and syntax for media types as\r
- * specified in RFC 2616, \u00A3.7.\r
- * \r
- * Check rule M1.14: Content types shall not use linear white space either\r
- * between the type and subtype or between an attribute and its value.\r
- * Content types also shall not have leading or trailing white spaces.\r
- * Package implementers shall create only such content types and shall\r
- * require such content types when retrieving a part from a package; format\r
- * designers shall specify only such content types for inclusion in the\r
- * format.\r
- */\r
- public void testContentTypeValidationFailure() {\r
- String[] contentTypesToTest = new String[] { "text/xml/app", "",\r
- "test", "text(xml/xml", "text)xml/xml", "text<xml/xml",\r
- "text>/xml", "text@/xml", "text,/xml", "text;/xml",\r
- "text:/xml", "text\\/xml", "t/ext/xml", "t\"ext/xml",\r
- "text[/xml", "text]/xml", "text?/xml", "tex=t/xml",\r
- "te{xt/xml", "tex}t/xml", "te xt/xml",\r
- "text" + (char) 9 + "/xml", "text xml", " text/xml " };\r
- for (int i = 0; i < contentTypesToTest.length; ++i) {\r
- try {\r
- new ContentType(contentTypesToTest[i]);\r
- } catch (InvalidFormatException e) {\r
- continue;\r
- }\r
- fail("Must have fail for content type: '" + contentTypesToTest[i]\r
- + "' !");\r
- }\r
- }\r
-\r
- /**\r
- * Check rule [O1.2]: Format designers might restrict the usage of\r
- * parameters for content types.\r
- */\r
- public void testContentTypeParameterFailure() {\r
- String[] contentTypesToTest = new String[] { "mail/toto;titi=tata",\r
- "text/xml;a=b;c=d", "mail/toto;\"titi=tata\"" };\r
- for (int i = 0; i < contentTypesToTest.length; ++i) {\r
- try {\r
- new ContentType(contentTypesToTest[i]);\r
- } catch (InvalidFormatException e) {\r
- continue;\r
- }\r
- fail("Must have fail for content type: '" + contentTypesToTest[i]\r
- + "' !");\r
- }\r
- }\r
-\r
- /**\r
- * Check rule M1.15: The package implementer shall require a content type\r
- * that does not include comments and the format designer shall specify such\r
- * a content type.\r
- */\r
- public void testContentTypeCommentFailure() {\r
- String[] contentTypesToTest = new String[] { "text/xml(comment)" };\r
- for (int i = 0; i < contentTypesToTest.length; ++i) {\r
- try {\r
- new ContentType(contentTypesToTest[i]);\r
- } catch (InvalidFormatException e) {\r
- continue;\r
- }\r
- fail("Must have fail for content type: '" + contentTypesToTest[i]\r
- + "' !");\r
- }\r
- }\r
-}\r
+/* ====================================================================
+ 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.openxml4j.opc;
+
+import junit.framework.TestCase;
+
+import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
+import org.apache.poi.openxml4j.opc.internal.ContentType;
+
+/**
+ * Tests for content type (ContentType class).
+ *
+ * @author Julien Chable
+ */
+public final class TestContentType extends TestCase {
+
+ /**
+ * Check rule M1.13: Package implementers shall only create and only
+ * recognize parts with a content type; format designers shall specify a
+ * content type for each part included in the format. Content types for
+ * package parts shall fit the definition and syntax for media types as
+ * specified in RFC 2616, \u00A73.7.
+ */
+ public void testContentTypeValidation() throws InvalidFormatException {
+ String[] contentTypesToTest = new String[] { "text/xml",
+ "application/pgp-key", "application/vnd.hp-PCLXL",
+ "application/vnd.lotus-1-2-3" };
+ for (int i = 0; i < contentTypesToTest.length; ++i) {
+ new ContentType(contentTypesToTest[i]);
+ }
+ }
+
+ /**
+ * Check rule M1.13 : Package implementers shall only create and only
+ * recognize parts with a content type; format designers shall specify a
+ * content type for each part included in the format. Content types for
+ * package parts shall fit the definition and syntax for media types as
+ * specified in RFC 2616, \u00A3.7.
+ *
+ * Check rule M1.14: Content types shall not use linear white space either
+ * between the type and subtype or between an attribute and its value.
+ * Content types also shall not have leading or trailing white spaces.
+ * Package implementers shall create only such content types and shall
+ * require such content types when retrieving a part from a package; format
+ * designers shall specify only such content types for inclusion in the
+ * format.
+ */
+ public void testContentTypeValidationFailure() {
+ String[] contentTypesToTest = new String[] { "text/xml/app", "",
+ "test", "text(xml/xml", "text)xml/xml", "text<xml/xml",
+ "text>/xml", "text@/xml", "text,/xml", "text;/xml",
+ "text:/xml", "text\\/xml", "t/ext/xml", "t\"ext/xml",
+ "text[/xml", "text]/xml", "text?/xml", "tex=t/xml",
+ "te{xt/xml", "tex}t/xml", "te xt/xml",
+ "text" + (char) 9 + "/xml", "text xml", " text/xml " };
+ for (int i = 0; i < contentTypesToTest.length; ++i) {
+ try {
+ new ContentType(contentTypesToTest[i]);
+ } catch (InvalidFormatException e) {
+ continue;
+ }
+ fail("Must have fail for content type: '" + contentTypesToTest[i]
+ + "' !");
+ }
+ }
+
+ /**
+ * Check rule [O1.2]: Format designers might restrict the usage of
+ * parameters for content types.
+ */
+ public void testContentTypeParameterFailure() {
+ String[] contentTypesToTest = new String[] { "mail/toto;titi=tata",
+ "text/xml;a=b;c=d", "mail/toto;\"titi=tata\"" };
+ for (int i = 0; i < contentTypesToTest.length; ++i) {
+ try {
+ new ContentType(contentTypesToTest[i]);
+ } catch (InvalidFormatException e) {
+ continue;
+ }
+ fail("Must have fail for content type: '" + contentTypesToTest[i]
+ + "' !");
+ }
+ }
+
+ /**
+ * Check rule M1.15: The package implementer shall require a content type
+ * that does not include comments and the format designer shall specify such
+ * a content type.
+ */
+ public void testContentTypeCommentFailure() {
+ String[] contentTypesToTest = new String[] { "text/xml(comment)" };
+ for (int i = 0; i < contentTypesToTest.length; ++i) {
+ try {
+ new ContentType(contentTypesToTest[i]);
+ } catch (InvalidFormatException e) {
+ continue;
+ }
+ fail("Must have fail for content type: '" + contentTypesToTest[i]
+ + "' !");
+ }
+ }
+}
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-\r
-package org.apache.poi.openxml4j.opc;\r
-\r
-import java.io.File;\r
-import java.util.TreeMap;\r
-\r
-import org.apache.poi.openxml4j.opc.internal.FileHelper;\r
-\r
-import junit.framework.TestCase;\r
-\r
-/**\r
- * Test TestFileHelper class.\r
- * \r
- * @author Julien Chable\r
- */\r
-public class TestFileHelper extends TestCase {\r
-\r
- public void testGetDirectory() {\r
- TreeMap<String, String> expectedValue = new TreeMap<String, String>();\r
- expectedValue.put("/dir1/test.doc", "/dir1");\r
- expectedValue.put("/dir1/dir2/test.doc.xml", "/dir1/dir2");\r
-\r
- for (String filename : expectedValue.keySet()) {\r
- File f1 = new File(expectedValue.get(filename));\r
- File f2 = FileHelper.getDirectory(new File(filename));\r
-\r
- /*\r
- * YK: The original version asserted expected values against File#getAbsolutePath():\r
- * assertTrue(expectedValue.get(filename).equalsIgnoreCase(\r
- * FileHelper.getDirectory(new File(filename))\r
- * .getAbsolutePath()));\r
- *\r
- * This comparison is platform dependent and resulted in build errors in Gump since 21/02/2009.\r
- * Assertion via File#equals(File otherFile) is a better approach. \r
- */\r
- assertTrue(f1.equals(f2));\r
- }\r
- }\r
-}\r
+/* ====================================================================
+ 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.openxml4j.opc;
+
+import java.io.File;
+import java.util.TreeMap;
+
+import org.apache.poi.openxml4j.opc.internal.FileHelper;
+
+import junit.framework.TestCase;
+
+/**
+ * Test TestFileHelper class.
+ *
+ * @author Julien Chable
+ */
+public final class TestFileHelper extends TestCase {
+
+ /**
+ * TODO - use simple JDK methods on {@link File} instead:<br/>
+ * {@link File#getParentFile()} instead of {@link FileHelper#getDirectory(File)
+ * {@link File#getName()} instead of {@link FileHelper#getFilename(File)
+ */
+ public void testGetDirectory() {
+ TreeMap<String, String> expectedValue = new TreeMap<String, String>();
+ expectedValue.put("/dir1/test.doc", "/dir1");
+ expectedValue.put("/dir1/dir2/test.doc.xml", "/dir1/dir2");
+
+ for (String filename : expectedValue.keySet()) {
+ File f1 = new File(expectedValue.get(filename));
+ File f2 = FileHelper.getDirectory(new File(filename));
+
+ if (false) {
+ // YK: The original version asserted expected values against File#getAbsolutePath():
+ assertTrue(expectedValue.get(filename).equalsIgnoreCase(f2.getAbsolutePath()));
+ // This comparison is platform dependent. A better approach is below
+ }
+ assertTrue(f1.equals(f2));
+ }
+ }
+}
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-package org.apache.poi.openxml4j.opc;\r
-\r
-import org.apache.poi.openxml4j.opc.PackagePartName;\r
-import org.apache.poi.openxml4j.opc.PackagingURIHelper;\r
-\r
-import junit.framework.TestCase;\r
-\r
-public class TestPackagePartName extends TestCase {\r
-\r
- /**\r
- * Test method getExtension().\r
- */\r
- public void testGetExtension() throws Exception{\r
- PackagePartName name1 = PackagingURIHelper.createPartName("/doc/props/document.xml");\r
- PackagePartName name2 = PackagingURIHelper.createPartName("/root/document");\r
- assertEquals("xml", name1.getExtension());\r
- assertEquals("", name2.getExtension());\r
- }\r
-}\r
+/* ====================================================================
+ 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.openxml4j.opc;
+
+import org.apache.poi.openxml4j.opc.PackagePartName;
+import org.apache.poi.openxml4j.opc.PackagingURIHelper;
+
+import junit.framework.TestCase;
+
+public final class TestPackagePartName extends TestCase {
+
+ /**
+ * Test method getExtension().
+ */
+ public void testGetExtension() throws Exception{
+ PackagePartName name1 = PackagingURIHelper.createPartName("/doc/props/document.xml");
+ PackagePartName name2 = PackagingURIHelper.createPartName("/root/document");
+ assertEquals("xml", name1.getExtension());
+ assertEquals("", name2.getExtension());
+ }
+}
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-\r
-package org.apache.poi.openxml4j.opc.compliance;\r
-\r
-import junit.framework.Test;\r
-import junit.framework.TestSuite;\r
-\r
-public class AllOpenXML4JComplianceTests {\r
-\r
- public static Test suite() {\r
- TestSuite suite = new TestSuite(AllOpenXML4JComplianceTests.class.getName());\r
- suite.addTestSuite(TestOPCCompliancePartName.class);\r
- suite.addTestSuite(TestOPCComplianceCoreProperties.class);\r
- suite.addTestSuite(TestOPCCompliancePackageModel.class);\r
- return suite;\r
- }\r
-\r
-}\r
+/* ====================================================================
+ 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.openxml4j.opc.compliance;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+public final class AllOpenXML4JComplianceTests {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite(AllOpenXML4JComplianceTests.class.getName());
+ suite.addTestSuite(TestOPCCompliancePartName.class);
+ suite.addTestSuite(TestOPCComplianceCoreProperties.class);
+ suite.addTestSuite(TestOPCCompliancePackageModel.class);
+ return suite;
+ }
+
+}
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-\r
-package org.apache.poi.openxml4j.opc.internal;\r
-\r
-import junit.framework.Test;\r
-import junit.framework.TestSuite;\r
-\r
-public class AllOpenXML4JInternalTests {\r
-\r
- public static Test suite() {\r
- TestSuite suite = new TestSuite(AllOpenXML4JInternalTests.class.getName());\r
- suite.addTestSuite(TestContentTypeManager.class);\r
- return suite;\r
- }\r
-}\r
+/* ====================================================================
+ 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.openxml4j.opc.internal;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+public final class AllOpenXML4JInternalTests {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite(AllOpenXML4JInternalTests.class.getName());
+ suite.addTestSuite(TestContentTypeManager.class);
+ return suite;
+ }
+}
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-\r
-package org.apache.poi.openxml4j.opc.internal;\r
-\r
-import junit.framework.TestCase;\r
-\r
-import org.apache.poi.openxml4j.opc.PackagePartName;\r
-import org.apache.poi.openxml4j.opc.PackagingURIHelper;\r
-\r
-public class TestContentTypeManager extends TestCase {\r
-\r
- /**\r
- * Test the properties part content parsing.\r
- */\r
- public void testContentType() throws Exception {\r
- // File originalFile = new File(testCore.getTestRootPath() +\r
- // File.separator +\r
- // "sample.docx");\r
- //\r
- // // Retrieves core properties part\r
- // Package p = Package.open(originalFile.getAbsolutePath(),\r
- // PackageAccess.READ);\r
- // PackageRelationship corePropertiesRelationship = p\r
- // .getRelationshipsByType(\r
- // PackageRelationshipTypes.CORE_PROPERTIES)\r
- // .getRelationship(0);\r
- // PackagePart coreDocument = p.getPart(corePropertiesRelationship);\r
- //\r
- // ContentTypeManager ctm = new ZipContentTypeManager(coreDocument\r
- // .getInputStream());\r
- //\r
- // // TODO\r
- //fail();\r
- }\r
-\r
- /**\r
- * Test the addition of several default and override content types.\r
- */\r
- public void testContentTypeAddition() throws Exception {\r
- ContentTypeManager ctm = new ZipContentTypeManager(null, null);\r
-\r
- PackagePartName name1 = PackagingURIHelper\r
- .createPartName("/foo/foo.XML");\r
- PackagePartName name2 = PackagingURIHelper\r
- .createPartName("/foo/foo2.xml");\r
- PackagePartName name3 = PackagingURIHelper\r
- .createPartName("/foo/doc.rels");\r
- PackagePartName name4 = PackagingURIHelper\r
- .createPartName("/foo/doc.RELS");\r
-\r
- // Add content types\r
- ctm.addContentType(name1, "foo-type1");\r
- ctm.addContentType(name2, "foo-type2");\r
- ctm.addContentType(name3, "text/xml+rel");\r
- ctm.addContentType(name4, "text/xml+rel");\r
-\r
- assertEquals(ctm.getContentType(name1), "foo-type1");\r
- assertEquals(ctm.getContentType(name2), "foo-type2");\r
- assertEquals(ctm.getContentType(name3), "text/xml+rel");\r
- assertEquals(ctm.getContentType(name3), "text/xml+rel");\r
- }\r
-\r
- /**\r
- * Test the addition then removal of content types.\r
- */\r
- public void testContentTypeRemoval() throws Exception {\r
- ContentTypeManager ctm = new ZipContentTypeManager(null, null);\r
-\r
- PackagePartName name1 = PackagingURIHelper\r
- .createPartName("/foo/foo.xml");\r
- PackagePartName name2 = PackagingURIHelper\r
- .createPartName("/foo/foo2.xml");\r
- PackagePartName name3 = PackagingURIHelper\r
- .createPartName("/foo/doc.rels");\r
- PackagePartName name4 = PackagingURIHelper\r
- .createPartName("/foo/doc.RELS");\r
-\r
- // Add content types\r
- ctm.addContentType(name1, "foo-type1");\r
- ctm.addContentType(name2, "foo-type2");\r
- ctm.addContentType(name3, "text/xml+rel");\r
- ctm.addContentType(name4, "text/xml+rel");\r
- ctm.removeContentType(name2);\r
- ctm.removeContentType(name3);\r
-\r
- assertEquals(ctm.getContentType(name1), "foo-type1");\r
- assertEquals(ctm.getContentType(name2), "foo-type1");\r
- assertEquals(ctm.getContentType(name3), null);\r
-\r
- ctm.removeContentType(name1);\r
- assertEquals(ctm.getContentType(name1), null);\r
- assertEquals(ctm.getContentType(name2), null);\r
- }\r
-\r
- /**\r
- * Test the addition then removal of content types in a package.\r
- */\r
- public void testContentTypeRemovalPackage() throws Exception {\r
- // TODO\r
- }\r
-}\r
+/* ====================================================================
+ 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.openxml4j.opc.internal;
+
+import junit.framework.TestCase;
+
+import org.apache.poi.openxml4j.opc.PackagePartName;
+import org.apache.poi.openxml4j.opc.PackagingURIHelper;
+
+public final class TestContentTypeManager extends TestCase {
+
+ /**
+ * Test the properties part content parsing.
+ */
+ public void testContentType() throws Exception {
+ // File originalFile = new File(testCore.getTestRootPath() +
+ // File.separator +
+ // "sample.docx");
+ //
+ // // Retrieves core properties part
+ // Package p = Package.open(originalFile.getAbsolutePath(),
+ // PackageAccess.READ);
+ // PackageRelationship corePropertiesRelationship = p
+ // .getRelationshipsByType(
+ // PackageRelationshipTypes.CORE_PROPERTIES)
+ // .getRelationship(0);
+ // PackagePart coreDocument = p.getPart(corePropertiesRelationship);
+ //
+ // ContentTypeManager ctm = new ZipContentTypeManager(coreDocument
+ // .getInputStream());
+ //
+ // // TODO
+ //fail();
+ }
+
+ /**
+ * Test the addition of several default and override content types.
+ */
+ public void testContentTypeAddition() throws Exception {
+ ContentTypeManager ctm = new ZipContentTypeManager(null, null);
+
+ PackagePartName name1 = PackagingURIHelper
+ .createPartName("/foo/foo.XML");
+ PackagePartName name2 = PackagingURIHelper
+ .createPartName("/foo/foo2.xml");
+ PackagePartName name3 = PackagingURIHelper
+ .createPartName("/foo/doc.rels");
+ PackagePartName name4 = PackagingURIHelper
+ .createPartName("/foo/doc.RELS");
+
+ // Add content types
+ ctm.addContentType(name1, "foo-type1");
+ ctm.addContentType(name2, "foo-type2");
+ ctm.addContentType(name3, "text/xml+rel");
+ ctm.addContentType(name4, "text/xml+rel");
+
+ assertEquals(ctm.getContentType(name1), "foo-type1");
+ assertEquals(ctm.getContentType(name2), "foo-type2");
+ assertEquals(ctm.getContentType(name3), "text/xml+rel");
+ assertEquals(ctm.getContentType(name3), "text/xml+rel");
+ }
+
+ /**
+ * Test the addition then removal of content types.
+ */
+ public void testContentTypeRemoval() throws Exception {
+ ContentTypeManager ctm = new ZipContentTypeManager(null, null);
+
+ PackagePartName name1 = PackagingURIHelper
+ .createPartName("/foo/foo.xml");
+ PackagePartName name2 = PackagingURIHelper
+ .createPartName("/foo/foo2.xml");
+ PackagePartName name3 = PackagingURIHelper
+ .createPartName("/foo/doc.rels");
+ PackagePartName name4 = PackagingURIHelper
+ .createPartName("/foo/doc.RELS");
+
+ // Add content types
+ ctm.addContentType(name1, "foo-type1");
+ ctm.addContentType(name2, "foo-type2");
+ ctm.addContentType(name3, "text/xml+rel");
+ ctm.addContentType(name4, "text/xml+rel");
+ ctm.removeContentType(name2);
+ ctm.removeContentType(name3);
+
+ assertEquals(ctm.getContentType(name1), "foo-type1");
+ assertEquals(ctm.getContentType(name2), "foo-type1");
+ assertEquals(ctm.getContentType(name3), null);
+
+ ctm.removeContentType(name1);
+ assertEquals(ctm.getContentType(name1), null);
+ assertEquals(ctm.getContentType(name2), null);
+ }
+
+ /**
+ * Test the addition then removal of content types in a package.
+ */
+ public void testContentTypeRemovalPackage() throws Exception {
+ // TODO
+ }
+}
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-package org.apache.poi.xssf;\r
-\r
-import org.apache.poi.ss.ITestDataProvider;\r
-import org.apache.poi.ss.SpreadsheetVersion;\r
-import org.apache.poi.ss.usermodel.Workbook;\r
-import org.apache.poi.xssf.usermodel.XSSFWorkbook;\r
-import org.apache.poi.hssf.HSSFTestDataSamples;\r
-\r
-/**\r
- * @author Yegor Kozlov\r
- */\r
-public final class XSSFITestDataProvider implements ITestDataProvider {\r
-\r
- public XSSFWorkbook openSampleWorkbook(String sampleFileName) {\r
- return XSSFTestDataSamples.openSampleWorkbook(sampleFileName);\r
- }\r
-\r
- public XSSFWorkbook writeOutAndReadBack(Workbook original) {\r
- if(!(original instanceof XSSFWorkbook)) {\r
- throw new IllegalArgumentException("Expected an instance of XSSFWorkbook");\r
- }\r
-\r
- return XSSFTestDataSamples.writeOutAndReadBack((XSSFWorkbook)original);\r
- }\r
-\r
- public XSSFWorkbook createWorkbook(){\r
- return new XSSFWorkbook();\r
- }\r
-\r
- public byte[] getTestDataFileContent(String fileName) {\r
- return HSSFTestDataSamples.getTestDataFileContent(fileName);\r
- }\r
-\r
- public SpreadsheetVersion getSpreadsheetVersion(){\r
- return SpreadsheetVersion.EXCEL2007;\r
- }\r
-\r
- private XSSFITestDataProvider(){}\r
- private static XSSFITestDataProvider inst = new XSSFITestDataProvider();\r
- public static XSSFITestDataProvider getInstance(){\r
- return inst;\r
- }\r
-}\r
+/* ====================================================================
+ 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.xssf;
+
+import org.apache.poi.ss.ITestDataProvider;
+import org.apache.poi.ss.SpreadsheetVersion;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.apache.poi.hssf.HSSFTestDataSamples;
+
+/**
+ * @author Yegor Kozlov
+ */
+public final class XSSFITestDataProvider implements ITestDataProvider {
+
+ public XSSFWorkbook openSampleWorkbook(String sampleFileName) {
+ return XSSFTestDataSamples.openSampleWorkbook(sampleFileName);
+ }
+
+ public XSSFWorkbook writeOutAndReadBack(Workbook original) {
+ if(!(original instanceof XSSFWorkbook)) {
+ throw new IllegalArgumentException("Expected an instance of XSSFWorkbook");
+ }
+
+ return XSSFTestDataSamples.writeOutAndReadBack((XSSFWorkbook)original);
+ }
+
+ public XSSFWorkbook createWorkbook(){
+ return new XSSFWorkbook();
+ }
+
+ public byte[] getTestDataFileContent(String fileName) {
+ return HSSFTestDataSamples.getTestDataFileContent(fileName);
+ }
+
+ public SpreadsheetVersion getSpreadsheetVersion(){
+ return SpreadsheetVersion.EXCEL2007;
+ }
+
+ private XSSFITestDataProvider() {
+ // enforce singleton
+ }
+ private static XSSFITestDataProvider inst = new XSSFITestDataProvider();
+ public static XSSFITestDataProvider getInstance(){
+ return inst;
+ }
+}
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-\r
-package org.apache.poi.xssf.model;\r
-\r
-import java.io.ByteArrayInputStream;\r
-import java.io.ByteArrayOutputStream;\r
-import java.io.IOException;\r
-import java.util.List;\r
-\r
-import junit.framework.TestCase;\r
-\r
-import org.apache.poi.xssf.XSSFTestDataSamples;\r
-import org.apache.poi.xssf.usermodel.XSSFRichTextString;\r
-import org.apache.poi.xssf.usermodel.XSSFWorkbook;\r
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRElt;\r
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRPrElt;\r
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst;\r
-\r
-/**\r
- * Test {@link SharedStringsTable}, the cache of strings in a workbook\r
- *\r
- * @author Yegor Kozlov\r
- */\r
-public final class TestSharedStringsTable extends TestCase {\r
-\r
- public void testCreateNew() {\r
- SharedStringsTable sst = new SharedStringsTable();\r
- \r
- CTRst st;\r
- int idx;\r
-\r
- // Check defaults\r
- assertNotNull(sst.getItems());\r
- assertEquals(0, sst.getItems().size());\r
- assertEquals(0, sst.getCount());\r
- assertEquals(0, sst.getUniqueCount());\r
-\r
- st = CTRst.Factory.newInstance();\r
- st.setT("Hello, World!");\r
-\r
- idx = sst.addEntry(st);\r
- assertEquals(0, idx);\r
- assertEquals(1, sst.getCount());\r
- assertEquals(1, sst.getUniqueCount());\r
-\r
- //add the same entry egain\r
- idx = sst.addEntry(st);\r
- assertEquals(0, idx);\r
- assertEquals(2, sst.getCount());\r
- assertEquals(1, sst.getUniqueCount());\r
-\r
- //and egain\r
- idx = sst.addEntry(st);\r
- assertEquals(0, idx);\r
- assertEquals(3, sst.getCount());\r
- assertEquals(1, sst.getUniqueCount());\r
-\r
- st = CTRst.Factory.newInstance();\r
- st.setT("Second string");\r
-\r
- idx = sst.addEntry(st);\r
- assertEquals(1, idx);\r
- assertEquals(4, sst.getCount());\r
- assertEquals(2, sst.getUniqueCount());\r
-\r
- //add the same entry egain\r
- idx = sst.addEntry(st);\r
- assertEquals(1, idx);\r
- assertEquals(5, sst.getCount());\r
- assertEquals(2, sst.getUniqueCount());\r
-\r
- st = CTRst.Factory.newInstance();\r
- CTRElt r = st.addNewR();\r
- CTRPrElt pr = r.addNewRPr();\r
- pr.addNewColor().setRgb(new byte[]{(byte)0xFF, 0, 0}); //red\r
- pr.addNewI().setVal(true); //bold\r
- pr.addNewB().setVal(true); //italic\r
- r.setT("Second string");\r
-\r
- idx = sst.addEntry(st);\r
- assertEquals(2, idx);\r
- assertEquals(6, sst.getCount());\r
- assertEquals(3, sst.getUniqueCount());\r
-\r
- idx = sst.addEntry(st);\r
- assertEquals(2, idx);\r
- assertEquals(7, sst.getCount());\r
- assertEquals(3, sst.getUniqueCount());\r
-\r
- //ok. the sst table is filled, check the contents\r
- assertEquals(3, sst.getItems().size());\r
- assertEquals("Hello, World!", new XSSFRichTextString(sst.getEntryAt(0)).toString());\r
- assertEquals("Second string", new XSSFRichTextString(sst.getEntryAt(1)).toString());\r
- assertEquals("Second string", new XSSFRichTextString(sst.getEntryAt(2)).toString());\r
- }\r
- \r
- public void testReadWrite() {\r
- XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("sample.xlsx");\r
- SharedStringsTable sst1 = wb.getSharedStringSource();\r
-\r
- //serialize, read back and compare with the original\r
- SharedStringsTable sst2 = XSSFTestDataSamples.writeOutAndReadBack(wb).getSharedStringSource();\r
- \r
- assertEquals(sst1.getCount(), sst2.getCount());\r
- assertEquals(sst1.getUniqueCount(), sst2.getUniqueCount());\r
-\r
- List<CTRst> items1 = sst1.getItems();\r
- List<CTRst> items2 = sst2.getItems();\r
- assertEquals(items1.size(), items2.size());\r
- for (int i = 0; i < items1.size(); i++) {\r
- CTRst st1 = items1.get(i);\r
- CTRst st2 = items2.get(i);\r
- assertEquals(st1.toString(), st2.toString());\r
- }\r
- }\r
-}\r
+/* ====================================================================
+ 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.xssf.model;
+
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.poi.xssf.XSSFTestDataSamples;
+import org.apache.poi.xssf.usermodel.XSSFRichTextString;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRElt;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRPrElt;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst;
+
+/**
+ * Test {@link SharedStringsTable}, the cache of strings in a workbook
+ *
+ * @author Yegor Kozlov
+ */
+public final class TestSharedStringsTable extends TestCase {
+
+ public void testCreateNew() {
+ SharedStringsTable sst = new SharedStringsTable();
+
+ CTRst st;
+ int idx;
+
+ // Check defaults
+ assertNotNull(sst.getItems());
+ assertEquals(0, sst.getItems().size());
+ assertEquals(0, sst.getCount());
+ assertEquals(0, sst.getUniqueCount());
+
+ st = CTRst.Factory.newInstance();
+ st.setT("Hello, World!");
+
+ idx = sst.addEntry(st);
+ assertEquals(0, idx);
+ assertEquals(1, sst.getCount());
+ assertEquals(1, sst.getUniqueCount());
+
+ //add the same entry again
+ idx = sst.addEntry(st);
+ assertEquals(0, idx);
+ assertEquals(2, sst.getCount());
+ assertEquals(1, sst.getUniqueCount());
+
+ //and again
+ idx = sst.addEntry(st);
+ assertEquals(0, idx);
+ assertEquals(3, sst.getCount());
+ assertEquals(1, sst.getUniqueCount());
+
+ st = CTRst.Factory.newInstance();
+ st.setT("Second string");
+
+ idx = sst.addEntry(st);
+ assertEquals(1, idx);
+ assertEquals(4, sst.getCount());
+ assertEquals(2, sst.getUniqueCount());
+
+ //add the same entry again
+ idx = sst.addEntry(st);
+ assertEquals(1, idx);
+ assertEquals(5, sst.getCount());
+ assertEquals(2, sst.getUniqueCount());
+
+ st = CTRst.Factory.newInstance();
+ CTRElt r = st.addNewR();
+ CTRPrElt pr = r.addNewRPr();
+ pr.addNewColor().setRgb(new byte[]{(byte)0xFF, 0, 0}); //red
+ pr.addNewI().setVal(true); //bold
+ pr.addNewB().setVal(true); //italic
+ r.setT("Second string");
+
+ idx = sst.addEntry(st);
+ assertEquals(2, idx);
+ assertEquals(6, sst.getCount());
+ assertEquals(3, sst.getUniqueCount());
+
+ idx = sst.addEntry(st);
+ assertEquals(2, idx);
+ assertEquals(7, sst.getCount());
+ assertEquals(3, sst.getUniqueCount());
+
+ //OK. the sst table is filled, check the contents
+ assertEquals(3, sst.getItems().size());
+ assertEquals("Hello, World!", new XSSFRichTextString(sst.getEntryAt(0)).toString());
+ assertEquals("Second string", new XSSFRichTextString(sst.getEntryAt(1)).toString());
+ assertEquals("Second string", new XSSFRichTextString(sst.getEntryAt(2)).toString());
+ }
+
+ public void testReadWrite() {
+ XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("sample.xlsx");
+ SharedStringsTable sst1 = wb.getSharedStringSource();
+
+ //serialize, read back and compare with the original
+ SharedStringsTable sst2 = XSSFTestDataSamples.writeOutAndReadBack(wb).getSharedStringSource();
+
+ assertEquals(sst1.getCount(), sst2.getCount());
+ assertEquals(sst1.getUniqueCount(), sst2.getUniqueCount());
+
+ List<CTRst> items1 = sst1.getItems();
+ List<CTRst> items2 = sst2.getItems();
+ assertEquals(items1.size(), items2.size());
+ for (int i = 0; i < items1.size(); i++) {
+ CTRst st1 = items1.get(i);
+ CTRst st2 = items2.get(i);
+ assertEquals(st1.toString(), st2.toString());
+ }
+ }
+}
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-package org.apache.poi.xssf.usermodel;\r
-\r
-import junit.framework.TestCase;\r
-import org.apache.poi.xssf.XSSFTestDataSamples;\r
-\r
-/**\r
- * @author Yegor Kozlov\r
- */\r
-public class TestSheetHiding extends TestCase {\r
- private XSSFWorkbook wbH;\r
- private XSSFWorkbook wbU;\r
-\r
- protected void setUp() {\r
- wbH = XSSFTestDataSamples.openSampleWorkbook("TwoSheetsOneHidden.xlsx");\r
- wbU = XSSFTestDataSamples.openSampleWorkbook("TwoSheetsNoneHidden.xlsx");\r
- }\r
-\r
- /**\r
- * Test that we get the right number of sheets,\r
- * with the right text on them, no matter what\r
- * the hidden flags are\r
- */\r
- public void testTextSheets() throws Exception {\r
- // Both should have two sheets\r
- assertEquals(2, wbH.getNumberOfSheets());\r
- assertEquals(2, wbU.getNumberOfSheets());\r
-\r
- // All sheets should have one row\r
- assertEquals(0, wbH.getSheetAt(0).getLastRowNum());\r
- assertEquals(0, wbH.getSheetAt(1).getLastRowNum());\r
- assertEquals(0, wbU.getSheetAt(0).getLastRowNum());\r
- assertEquals(0, wbU.getSheetAt(1).getLastRowNum());\r
-\r
- // All rows should have one column\r
- assertEquals(1, wbH.getSheetAt(0).getRow(0).getLastCellNum());\r
- assertEquals(1, wbH.getSheetAt(1).getRow(0).getLastCellNum());\r
- assertEquals(1, wbU.getSheetAt(0).getRow(0).getLastCellNum());\r
- assertEquals(1, wbU.getSheetAt(1).getRow(0).getLastCellNum());\r
-\r
- // Text should be sheet based\r
- assertEquals("Sheet1A1", wbH.getSheetAt(0).getRow(0).getCell(0).getRichStringCellValue().getString());\r
- assertEquals("Sheet2A1", wbH.getSheetAt(1).getRow(0).getCell(0).getRichStringCellValue().getString());\r
- assertEquals("Sheet1A1", wbU.getSheetAt(0).getRow(0).getCell(0).getRichStringCellValue().getString());\r
- assertEquals("Sheet2A1", wbU.getSheetAt(1).getRow(0).getCell(0).getRichStringCellValue().getString());\r
- }\r
-\r
- /**\r
- * Check that we can get and set the hidden flags\r
- * as expected\r
- */\r
- public void testHideUnHideFlags() throws Exception {\r
- assertTrue(wbH.isSheetHidden(0));\r
- assertFalse(wbH.isSheetHidden(1));\r
- assertFalse(wbU.isSheetHidden(0));\r
- assertFalse(wbU.isSheetHidden(1));\r
- }\r
-\r
- /**\r
- * Turn the sheet with none hidden into the one with\r
- * one hidden\r
- */\r
- public void testHide() throws Exception {\r
- wbU.setSheetHidden(0, true);\r
- assertTrue(wbU.isSheetHidden(0));\r
- assertFalse(wbU.isSheetHidden(1));\r
- XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wbU);\r
- assertTrue(wb2.isSheetHidden(0));\r
- assertFalse(wb2.isSheetHidden(1));\r
- }\r
-\r
- /**\r
- * Turn the sheet with one hidden into the one with\r
- * none hidden\r
- */\r
- public void testUnHide() throws Exception {\r
- wbH.setSheetHidden(0, false);\r
- assertFalse(wbH.isSheetHidden(0));\r
- assertFalse(wbH.isSheetHidden(1));\r
- XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wbH);\r
- assertFalse(wb2.isSheetHidden(0));\r
- assertFalse(wb2.isSheetHidden(1));\r
- }\r
-}\r
+/* ====================================================================
+ 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.xssf.usermodel;
+
+import junit.framework.TestCase;
+import org.apache.poi.xssf.XSSFTestDataSamples;
+
+/**
+ * @author Yegor Kozlov
+ */
+public final class TestSheetHiding extends TestCase {
+ private XSSFWorkbook wbH;
+ private XSSFWorkbook wbU;
+
+ protected void setUp() {
+ wbH = XSSFTestDataSamples.openSampleWorkbook("TwoSheetsOneHidden.xlsx");
+ wbU = XSSFTestDataSamples.openSampleWorkbook("TwoSheetsNoneHidden.xlsx");
+ }
+
+ /**
+ * Test that we get the right number of sheets,
+ * with the right text on them, no matter what
+ * the hidden flags are
+ */
+ public void testTextSheets() throws Exception {
+ // Both should have two sheets
+ assertEquals(2, wbH.getNumberOfSheets());
+ assertEquals(2, wbU.getNumberOfSheets());
+
+ // All sheets should have one row
+ assertEquals(0, wbH.getSheetAt(0).getLastRowNum());
+ assertEquals(0, wbH.getSheetAt(1).getLastRowNum());
+ assertEquals(0, wbU.getSheetAt(0).getLastRowNum());
+ assertEquals(0, wbU.getSheetAt(1).getLastRowNum());
+
+ // All rows should have one column
+ assertEquals(1, wbH.getSheetAt(0).getRow(0).getLastCellNum());
+ assertEquals(1, wbH.getSheetAt(1).getRow(0).getLastCellNum());
+ assertEquals(1, wbU.getSheetAt(0).getRow(0).getLastCellNum());
+ assertEquals(1, wbU.getSheetAt(1).getRow(0).getLastCellNum());
+
+ // Text should be sheet based
+ assertEquals("Sheet1A1", wbH.getSheetAt(0).getRow(0).getCell(0).getRichStringCellValue().getString());
+ assertEquals("Sheet2A1", wbH.getSheetAt(1).getRow(0).getCell(0).getRichStringCellValue().getString());
+ assertEquals("Sheet1A1", wbU.getSheetAt(0).getRow(0).getCell(0).getRichStringCellValue().getString());
+ assertEquals("Sheet2A1", wbU.getSheetAt(1).getRow(0).getCell(0).getRichStringCellValue().getString());
+ }
+
+ /**
+ * Check that we can get and set the hidden flags
+ * as expected
+ */
+ public void testHideUnHideFlags() throws Exception {
+ assertTrue(wbH.isSheetHidden(0));
+ assertFalse(wbH.isSheetHidden(1));
+ assertFalse(wbU.isSheetHidden(0));
+ assertFalse(wbU.isSheetHidden(1));
+ }
+
+ /**
+ * Turn the sheet with none hidden into the one with
+ * one hidden
+ */
+ public void testHide() throws Exception {
+ wbU.setSheetHidden(0, true);
+ assertTrue(wbU.isSheetHidden(0));
+ assertFalse(wbU.isSheetHidden(1));
+ XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wbU);
+ assertTrue(wb2.isSheetHidden(0));
+ assertFalse(wb2.isSheetHidden(1));
+ }
+
+ /**
+ * Turn the sheet with one hidden into the one with
+ * none hidden
+ */
+ public void testUnHide() throws Exception {
+ wbH.setSheetHidden(0, false);
+ assertFalse(wbH.isSheetHidden(0));
+ assertFalse(wbH.isSheetHidden(1));
+ XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wbH);
+ assertFalse(wb2.isSheetHidden(0));
+ assertFalse(wb2.isSheetHidden(1));
+ }
+}
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-package org.apache.poi.xssf.usermodel;\r
-\r
-import org.apache.poi.ss.usermodel.BaseTestSheetShiftRows;\r
-import org.apache.poi.ss.ITestDataProvider;\r
-import org.apache.poi.xssf.XSSFITestDataProvider;\r
-\r
-/**\r
- * @author Yegor Kozlov\r
- */\r
-public class TestSheetShiftRows extends BaseTestSheetShiftRows {\r
-\r
- @Override\r
- protected ITestDataProvider getTestDataProvider(){\r
- return XSSFITestDataProvider.getInstance();\r
- }\r
-\r
- public void testShiftRows() {\r
- baseTestShiftRows("SimpleMultiCell.xlsx");\r
- }\r
-\r
- public void testShiftRow() {\r
- baseTestShiftRow();\r
- }\r
-\r
- public void testShiftNames() {\r
- baseTestShiftWithNames();\r
- }\r
-\r
- //TODO support shifting of page breaks\r
- public void $testShiftRowBreaks() {\r
- baseTestShiftRowBreaks();\r
- }\r
-\r
- //TODO support shifting of comments. \r
- public void $testShiftWithComments() {\r
- baseTestShiftWithComments("comments.xlsx");\r
- }\r
-\r
- public void testShiftWithFormulas() {\r
- baseTestShiftWithFormulas("ForShifting.xlsx");\r
- }\r
-\r
- public void testShiftWithMergedRegions() {\r
- baseTestShiftWithMergedRegions();\r
- }\r
-}\r
+/* ====================================================================
+ 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.xssf.usermodel;
+
+import org.apache.poi.ss.usermodel.BaseTestSheetShiftRows;
+import org.apache.poi.ss.ITestDataProvider;
+import org.apache.poi.xssf.XSSFITestDataProvider;
+
+/**
+ * @author Yegor Kozlov
+ */
+public final class TestSheetShiftRows extends BaseTestSheetShiftRows {
+
+ @Override
+ protected ITestDataProvider getTestDataProvider(){
+ return XSSFITestDataProvider.getInstance();
+ }
+
+ public void testShiftRows() {
+ baseTestShiftRows("SimpleMultiCell.xlsx");
+ }
+
+ public void testShiftRow() {
+ baseTestShiftRow();
+ }
+
+ public void testShiftNames() {
+ baseTestShiftWithNames();
+ }
+
+ //TODO support shifting of page breaks
+ public void $testShiftRowBreaks() {
+ baseTestShiftRowBreaks();
+ }
+
+ //TODO support shifting of comments.
+ public void $testShiftWithComments() {
+ baseTestShiftWithComments("comments.xlsx");
+ }
+
+ public void testShiftWithFormulas() {
+ baseTestShiftWithFormulas("ForShifting.xlsx");
+ }
+
+ public void testShiftWithMergedRegions() {
+ baseTestShiftWithMergedRegions();
+ }
+}
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-package org.apache.poi.xssf.usermodel;\r
-\r
-import junit.framework.TestCase;\r
-import org.apache.poi.xssf.XSSFTestDataSamples;\r
-import org.apache.poi.xssf.XSSFITestDataProvider;\r
-import org.apache.poi.ss.usermodel.BaseTestNamedRange;\r
-\r
-/**\r
- * @author Yegor Kozlov\r
- */\r
-public class TestXSSFName extends BaseTestNamedRange {\r
-\r
- @Override\r
- protected XSSFITestDataProvider getTestDataProvider(){\r
- return XSSFITestDataProvider.getInstance();\r
- }\r
-\r
- //TODO combine testRepeatingRowsAndColums() for HSSF and XSSF\r
- public void testRepeatingRowsAndColums() {\r
- // First test that setting RR&C for same sheet more than once only creates a\r
- // single Print_Titles built-in record\r
- XSSFWorkbook wb = getTestDataProvider().createWorkbook();\r
- XSSFSheet sheet = wb.createSheet("FirstSheet");\r
-\r
- // set repeating rows and columns twice for the first sheet\r
- for (int i = 0; i < 2; i++) {\r
- wb.setRepeatingRowsAndColumns(0, 0, 0, 0, 3);\r
- //sheet.createFreezePane(0, 3);\r
- }\r
- assertEquals(1, wb.getNumberOfNames());\r
- XSSFName nr1 = wb.getNameAt(0);\r
-\r
- assertEquals(XSSFName.BUILTIN_PRINT_TITLE, nr1.getNameName());\r
- assertEquals("'FirstSheet'!$A:$A,'FirstSheet'!$1:$4", nr1.getRefersToFormula());\r
-\r
- // Save and re-open\r
- XSSFWorkbook nwb = XSSFTestDataSamples.writeOutAndReadBack(wb);\r
-\r
- assertEquals(1, nwb.getNumberOfNames());\r
- nr1 = nwb.getNameAt(0);\r
-\r
- assertEquals(XSSFName.BUILTIN_PRINT_TITLE, nr1.getNameName());\r
- assertEquals("'FirstSheet'!$A:$A,'FirstSheet'!$1:$4", nr1.getRefersToFormula());\r
-\r
- // check that setting RR&C on a second sheet causes a new Print_Titles built-in\r
- // name to be created\r
- sheet = nwb.createSheet("SecondSheet");\r
- nwb.setRepeatingRowsAndColumns(1, 1, 2, 0, 0);\r
-\r
- assertEquals(2, nwb.getNumberOfNames());\r
- XSSFName nr2 = nwb.getNameAt(1);\r
-\r
- assertEquals(XSSFName.BUILTIN_PRINT_TITLE, nr2.getNameName());\r
- assertEquals("'SecondSheet'!$B:$C,'SecondSheet'!$1:$1", nr2.getRefersToFormula());\r
-\r
- nwb.setRepeatingRowsAndColumns(1, -1, -1, -1, -1);\r
- }\r
-\r
-\r
-}\r
+/* ====================================================================
+ 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.xssf.usermodel;
+
+import junit.framework.TestCase;
+import org.apache.poi.xssf.XSSFTestDataSamples;
+import org.apache.poi.xssf.XSSFITestDataProvider;
+import org.apache.poi.ss.usermodel.BaseTestNamedRange;
+
+/**
+ * @author Yegor Kozlov
+ */
+public final class TestXSSFName extends BaseTestNamedRange {
+
+ @Override
+ protected XSSFITestDataProvider getTestDataProvider(){
+ return XSSFITestDataProvider.getInstance();
+ }
+
+ //TODO combine testRepeatingRowsAndColums() for HSSF and XSSF
+ public void testRepeatingRowsAndColums() {
+ // First test that setting RR&C for same sheet more than once only creates a
+ // single Print_Titles built-in record
+ XSSFWorkbook wb = getTestDataProvider().createWorkbook();
+ XSSFSheet sheet = wb.createSheet("FirstSheet");
+
+ // set repeating rows and columns twice for the first sheet
+ for (int i = 0; i < 2; i++) {
+ wb.setRepeatingRowsAndColumns(0, 0, 0, 0, 3);
+ //sheet.createFreezePane(0, 3);
+ }
+ assertEquals(1, wb.getNumberOfNames());
+ XSSFName nr1 = wb.getNameAt(0);
+
+ assertEquals(XSSFName.BUILTIN_PRINT_TITLE, nr1.getNameName());
+ assertEquals("'FirstSheet'!$A:$A,'FirstSheet'!$1:$4", nr1.getRefersToFormula());
+
+ // Save and re-open
+ XSSFWorkbook nwb = XSSFTestDataSamples.writeOutAndReadBack(wb);
+
+ assertEquals(1, nwb.getNumberOfNames());
+ nr1 = nwb.getNameAt(0);
+
+ assertEquals(XSSFName.BUILTIN_PRINT_TITLE, nr1.getNameName());
+ assertEquals("'FirstSheet'!$A:$A,'FirstSheet'!$1:$4", nr1.getRefersToFormula());
+
+ // check that setting RR&C on a second sheet causes a new Print_Titles built-in
+ // name to be created
+ sheet = nwb.createSheet("SecondSheet");
+ nwb.setRepeatingRowsAndColumns(1, 1, 2, 0, 0);
+
+ assertEquals(2, nwb.getNumberOfNames());
+ XSSFName nr2 = nwb.getNameAt(1);
+
+ assertEquals(XSSFName.BUILTIN_PRINT_TITLE, nr2.getNameName());
+ assertEquals("'SecondSheet'!$B:$C,'SecondSheet'!$1:$1", nr2.getRefersToFormula());
+
+ nwb.setRepeatingRowsAndColumns(1, -1, -1, -1, -1);
+ }
+
+
+}
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-package org.apache.poi.xssf.usermodel;\r
-\r
-import junit.framework.TestCase;\r
-import org.apache.poi.ss.usermodel.ClientAnchor;\r
-import org.apache.poi.ss.usermodel.BaseTestPicture;\r
-import org.apache.poi.xssf.XSSFITestDataProvider;\r
-import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTTwoCellAnchor;\r
-import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.STEditAs;\r
-\r
-import java.util.List;\r
-import java.util.Arrays;\r
-\r
-/**\r
- * @author Yegor Kozlov\r
- */\r
-public class TestXSSFPicture extends BaseTestPicture {\r
-\r
- @Override\r
- protected XSSFITestDataProvider getTestDataProvider(){\r
- return XSSFITestDataProvider.getInstance();\r
- }\r
-\r
- public void testResize() {\r
- baseTestResize(new XSSFClientAnchor(0, 0, 504825, 85725, (short)0, 0, (short)1, 8));\r
- }\r
-\r
-\r
- public void testCreate(){\r
- XSSFWorkbook wb = new XSSFWorkbook();\r
- XSSFSheet sheet = wb.createSheet();\r
- XSSFDrawing drawing = sheet.createDrawingPatriarch();\r
-\r
- byte[] jpegData = "test jpeg data".getBytes();\r
-\r
- List<XSSFPictureData> pictures = wb.getAllPictures();\r
- assertEquals(0, pictures.size());\r
-\r
- int jpegIdx = wb.addPicture(jpegData, XSSFWorkbook.PICTURE_TYPE_JPEG);\r
- assertEquals(1, pictures.size());\r
- assertEquals("jpeg", pictures.get(jpegIdx).suggestFileExtension());\r
- assertTrue(Arrays.equals(jpegData, pictures.get(jpegIdx).getData()));\r
-\r
- XSSFClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0, 1, 1, 10, 30);\r
- assertEquals(ClientAnchor.MOVE_AND_RESIZE, anchor.getAnchorType());\r
- anchor.setAnchorType(ClientAnchor.DONT_MOVE_AND_RESIZE);\r
- assertEquals(ClientAnchor.DONT_MOVE_AND_RESIZE, anchor.getAnchorType());\r
-\r
- XSSFPicture shape = drawing.createPicture(anchor, jpegIdx);\r
- assertTrue(anchor.equals(shape.getAnchor()));\r
- assertNotNull(shape.getPictureData());\r
- assertTrue(Arrays.equals(jpegData, shape.getPictureData().getData()));\r
-\r
- CTTwoCellAnchor ctShapeHolder = drawing.getCTDrawing().getTwoCellAnchorArray(0);\r
- // STEditAs.ABSOLUTE corresponds to ClientAnchor.DONT_MOVE_AND_RESIZE\r
- assertEquals(STEditAs.ABSOLUTE, ctShapeHolder.getEditAs());\r
- }\r
-}\r
+/* ====================================================================
+ 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.xssf.usermodel;
+
+import junit.framework.TestCase;
+import org.apache.poi.ss.usermodel.ClientAnchor;
+import org.apache.poi.ss.usermodel.BaseTestPicture;
+import org.apache.poi.xssf.XSSFITestDataProvider;
+import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTTwoCellAnchor;
+import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.STEditAs;
+
+import java.util.List;
+import java.util.Arrays;
+
+/**
+ * @author Yegor Kozlov
+ */
+public final class TestXSSFPicture extends BaseTestPicture {
+
+ @Override
+ protected XSSFITestDataProvider getTestDataProvider(){
+ return XSSFITestDataProvider.getInstance();
+ }
+
+ public void testResize() {
+ baseTestResize(new XSSFClientAnchor(0, 0, 504825, 85725, (short)0, 0, (short)1, 8));
+ }
+
+
+ public void testCreate(){
+ XSSFWorkbook wb = new XSSFWorkbook();
+ XSSFSheet sheet = wb.createSheet();
+ XSSFDrawing drawing = sheet.createDrawingPatriarch();
+
+ byte[] jpegData = "test jpeg data".getBytes();
+
+ List<XSSFPictureData> pictures = wb.getAllPictures();
+ assertEquals(0, pictures.size());
+
+ int jpegIdx = wb.addPicture(jpegData, XSSFWorkbook.PICTURE_TYPE_JPEG);
+ assertEquals(1, pictures.size());
+ assertEquals("jpeg", pictures.get(jpegIdx).suggestFileExtension());
+ assertTrue(Arrays.equals(jpegData, pictures.get(jpegIdx).getData()));
+
+ XSSFClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0, 1, 1, 10, 30);
+ assertEquals(ClientAnchor.MOVE_AND_RESIZE, anchor.getAnchorType());
+ anchor.setAnchorType(ClientAnchor.DONT_MOVE_AND_RESIZE);
+ assertEquals(ClientAnchor.DONT_MOVE_AND_RESIZE, anchor.getAnchorType());
+
+ XSSFPicture shape = drawing.createPicture(anchor, jpegIdx);
+ assertTrue(anchor.equals(shape.getAnchor()));
+ assertNotNull(shape.getPictureData());
+ assertTrue(Arrays.equals(jpegData, shape.getPictureData().getData()));
+
+ CTTwoCellAnchor ctShapeHolder = drawing.getCTDrawing().getTwoCellAnchorArray(0);
+ // STEditAs.ABSOLUTE corresponds to ClientAnchor.DONT_MOVE_AND_RESIZE
+ assertEquals(STEditAs.ABSOLUTE, ctShapeHolder.getEditAs());
+ }
+}
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-package org.apache.poi.xssf.usermodel;\r
-\r
-import junit.framework.TestCase;\r
-import org.apache.poi.xssf.XSSFTestDataSamples;\r
-import org.apache.poi.POIXMLDocumentPart;\r
-import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTDrawing;\r
-\r
-import java.util.List;\r
-import java.util.Arrays;\r
-import java.io.IOException;\r
-\r
-/**\r
- * @author Yegor Kozlov\r
- */\r
-public class TestXSSFPictureData extends TestCase {\r
- public void testRead(){\r
- XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("WithDrawing.xlsx");\r
- List<XSSFPictureData> pictures = wb.getAllPictures();\r
- //wb.getAllPictures() should return the same instance across multiple calls\r
- assertSame(pictures, wb.getAllPictures());\r
-\r
- assertEquals(5, pictures.size());\r
- String[] ext = {"jpeg", "emf", "png", "emf", "wmf"};\r
- for (int i = 0; i < pictures.size(); i++) {\r
- assertEquals(ext[i], pictures.get(i).suggestFileExtension());\r
- }\r
-\r
- int num = pictures.size();\r
-\r
- byte[] pictureData = {0xA, 0xB, 0XC, 0xD, 0xE, 0xF};\r
-\r
- int idx = wb.addPicture(pictureData, XSSFWorkbook.PICTURE_TYPE_JPEG);\r
- assertEquals(num + 1, pictures.size());\r
- //idx is 0-based index in the #pictures array\r
- assertEquals(pictures.size() - 1, idx);\r
- XSSFPictureData pict = pictures.get(idx);\r
- assertEquals("jpeg", pict.suggestFileExtension());\r
- assertTrue(Arrays.equals(pictureData, pict.getData()));\r
- }\r
-\r
- public void testNew(){\r
- XSSFWorkbook wb = new XSSFWorkbook();\r
- XSSFSheet sheet = wb.createSheet();\r
- XSSFDrawing drawing = sheet.createDrawingPatriarch();\r
-\r
- byte[] jpegData = "test jpeg data".getBytes();\r
- byte[] wmfData = "test wmf data".getBytes();\r
- byte[] pngData = "test png data".getBytes();\r
-\r
- List<XSSFPictureData> pictures = wb.getAllPictures();\r
- assertEquals(0, pictures.size());\r
-\r
- int jpegIdx = wb.addPicture(jpegData, XSSFWorkbook.PICTURE_TYPE_JPEG);\r
- assertEquals(1, pictures.size());\r
- assertEquals("jpeg", pictures.get(jpegIdx).suggestFileExtension());\r
- assertTrue(Arrays.equals(jpegData, pictures.get(jpegIdx).getData()));\r
-\r
- int wmfIdx = wb.addPicture(wmfData, XSSFWorkbook.PICTURE_TYPE_WMF);\r
- assertEquals(2, pictures.size());\r
- assertEquals("wmf", pictures.get(wmfIdx).suggestFileExtension());\r
- assertTrue(Arrays.equals(wmfData, pictures.get(wmfIdx).getData()));\r
-\r
- int pngIdx = wb.addPicture(pngData, XSSFWorkbook.PICTURE_TYPE_PNG);\r
- assertEquals(3, pictures.size());\r
- assertEquals("png", pictures.get(pngIdx).suggestFileExtension());\r
- assertTrue(Arrays.equals(pngData, pictures.get(pngIdx).getData()));\r
-\r
- //TODO finish usermodel API for XSSFPicture\r
- XSSFPicture p1 = drawing.createPicture(new XSSFClientAnchor(), jpegIdx);\r
- XSSFPicture p2 = drawing.createPicture(new XSSFClientAnchor(), wmfIdx);\r
- XSSFPicture p3 = drawing.createPicture(new XSSFClientAnchor(), pngIdx);\r
-\r
- //check that the added pictures are accessible after write\r
- wb = XSSFTestDataSamples.writeOutAndReadBack(wb);\r
- List<XSSFPictureData> pictures2 = wb.getAllPictures();\r
- assertEquals(3, pictures2.size());\r
-\r
- assertEquals("jpeg", pictures2.get(jpegIdx).suggestFileExtension());\r
- assertTrue(Arrays.equals(jpegData, pictures2.get(jpegIdx).getData()));\r
-\r
- assertEquals("wmf", pictures2.get(wmfIdx).suggestFileExtension());\r
- assertTrue(Arrays.equals(wmfData, pictures2.get(wmfIdx).getData()));\r
-\r
- assertEquals("png", pictures2.get(pngIdx).suggestFileExtension());\r
- assertTrue(Arrays.equals(pngData, pictures2.get(pngIdx).getData()));\r
-\r
- }\r
-}\r
+/* ====================================================================
+ 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.xssf.usermodel;
+
+import junit.framework.TestCase;
+import org.apache.poi.xssf.XSSFTestDataSamples;
+import org.apache.poi.POIXMLDocumentPart;
+import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTDrawing;
+
+import java.util.List;
+import java.util.Arrays;
+import java.io.IOException;
+
+/**
+ * @author Yegor Kozlov
+ */
+public final class TestXSSFPictureData extends TestCase {
+ public void testRead(){
+ XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("WithDrawing.xlsx");
+ List<XSSFPictureData> pictures = wb.getAllPictures();
+ //wb.getAllPictures() should return the same instance across multiple calls
+ assertSame(pictures, wb.getAllPictures());
+
+ assertEquals(5, pictures.size());
+ String[] ext = {"jpeg", "emf", "png", "emf", "wmf"};
+ for (int i = 0; i < pictures.size(); i++) {
+ assertEquals(ext[i], pictures.get(i).suggestFileExtension());
+ }
+
+ int num = pictures.size();
+
+ byte[] pictureData = {0xA, 0xB, 0XC, 0xD, 0xE, 0xF};
+
+ int idx = wb.addPicture(pictureData, XSSFWorkbook.PICTURE_TYPE_JPEG);
+ assertEquals(num + 1, pictures.size());
+ //idx is 0-based index in the #pictures array
+ assertEquals(pictures.size() - 1, idx);
+ XSSFPictureData pict = pictures.get(idx);
+ assertEquals("jpeg", pict.suggestFileExtension());
+ assertTrue(Arrays.equals(pictureData, pict.getData()));
+ }
+
+ public void testNew(){
+ XSSFWorkbook wb = new XSSFWorkbook();
+ XSSFSheet sheet = wb.createSheet();
+ XSSFDrawing drawing = sheet.createDrawingPatriarch();
+
+ byte[] jpegData = "test jpeg data".getBytes();
+ byte[] wmfData = "test wmf data".getBytes();
+ byte[] pngData = "test png data".getBytes();
+
+ List<XSSFPictureData> pictures = wb.getAllPictures();
+ assertEquals(0, pictures.size());
+
+ int jpegIdx = wb.addPicture(jpegData, XSSFWorkbook.PICTURE_TYPE_JPEG);
+ assertEquals(1, pictures.size());
+ assertEquals("jpeg", pictures.get(jpegIdx).suggestFileExtension());
+ assertTrue(Arrays.equals(jpegData, pictures.get(jpegIdx).getData()));
+
+ int wmfIdx = wb.addPicture(wmfData, XSSFWorkbook.PICTURE_TYPE_WMF);
+ assertEquals(2, pictures.size());
+ assertEquals("wmf", pictures.get(wmfIdx).suggestFileExtension());
+ assertTrue(Arrays.equals(wmfData, pictures.get(wmfIdx).getData()));
+
+ int pngIdx = wb.addPicture(pngData, XSSFWorkbook.PICTURE_TYPE_PNG);
+ assertEquals(3, pictures.size());
+ assertEquals("png", pictures.get(pngIdx).suggestFileExtension());
+ assertTrue(Arrays.equals(pngData, pictures.get(pngIdx).getData()));
+
+ //TODO finish usermodel API for XSSFPicture
+ XSSFPicture p1 = drawing.createPicture(new XSSFClientAnchor(), jpegIdx);
+ XSSFPicture p2 = drawing.createPicture(new XSSFClientAnchor(), wmfIdx);
+ XSSFPicture p3 = drawing.createPicture(new XSSFClientAnchor(), pngIdx);
+
+ //check that the added pictures are accessible after write
+ wb = XSSFTestDataSamples.writeOutAndReadBack(wb);
+ List<XSSFPictureData> pictures2 = wb.getAllPictures();
+ assertEquals(3, pictures2.size());
+
+ assertEquals("jpeg", pictures2.get(jpegIdx).suggestFileExtension());
+ assertTrue(Arrays.equals(jpegData, pictures2.get(jpegIdx).getData()));
+
+ assertEquals("wmf", pictures2.get(wmfIdx).suggestFileExtension());
+ assertTrue(Arrays.equals(wmfData, pictures2.get(wmfIdx).getData()));
+
+ assertEquals("png", pictures2.get(pngIdx).suggestFileExtension());
+ assertTrue(Arrays.equals(pngData, pictures2.get(pngIdx).getData()));
+
+ }
+}
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-\r
-package org.apache.poi.xssf.usermodel;\r
-\r
-import java.io.*;\r
-import java.util.ArrayList;\r
-import java.util.Calendar;\r
-import java.util.Date;\r
-\r
-import junit.framework.TestCase;\r
-\r
-import org.apache.poi.ss.usermodel.Cell;\r
-import org.apache.poi.ss.usermodel.CellStyle;\r
-import org.apache.poi.ss.usermodel.Comment;\r
-import org.apache.poi.ss.usermodel.CreationHelper;\r
-import org.apache.poi.ss.usermodel.Row;\r
-import org.apache.poi.ss.usermodel.Sheet;\r
-import org.apache.poi.ss.usermodel.Workbook;\r
-import org.apache.poi.xssf.model.CommentsTable;\r
-import org.apache.xmlbeans.XmlOptions;\r
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.*;\r
-\r
-/**\r
- * Tests functionality of the XSSFRichTextRun object\r
- *\r
- * @author Yegor Kozlov\r
- */\r
-public class TestXSSFRichTextString extends TestCase {\r
-\r
- public void testCreate() throws Exception {\r
-\r
- XSSFRichTextString rt = new XSSFRichTextString("Apache POI");\r
- assertEquals("Apache POI", rt.getString());\r
-\r
- CTRst st = rt.getCTRst();\r
- assertTrue(st.isSetT());\r
- assertEquals("Apache POI", st.getT());\r
-\r
- rt.append(" is cool stuff");\r
- assertEquals(2, st.sizeOfRArray());\r
- assertFalse(st.isSetT());\r
-\r
- assertEquals("Apache POI is cool stuff", rt.getString());\r
- }\r
-\r
-\r
- public void testApplyFont() throws Exception {\r
-\r
- XSSFRichTextString rt = new XSSFRichTextString();\r
- rt.append("123");\r
- rt.append("4567");\r
- rt.append("89");\r
-\r
- XSSFFont font1 = new XSSFFont();\r
- font1.setBold(true);\r
-\r
- rt.applyFont(2, 5, font1);\r
-\r
- assertEquals(5, rt.numFormattingRuns());\r
- assertEquals(0, rt.getIndexOfFormattingRun(0));\r
- assertEquals(2, rt.getLengthOfFormattingRun(0));\r
-\r
- assertEquals(2, rt.getIndexOfFormattingRun(1));\r
- assertEquals(3, rt.getLengthOfFormattingRun(1));\r
-\r
- assertEquals(5, rt.getIndexOfFormattingRun(2));\r
- assertEquals(3, rt.getLengthOfFormattingRun(2));\r
-\r
- assertEquals(8, rt.getIndexOfFormattingRun(3));\r
- assertEquals(1, rt.getLengthOfFormattingRun(3));\r
- }\r
-\r
- public void testClearFormatting() throws Exception {\r
-\r
- XSSFRichTextString rt = new XSSFRichTextString("Apache POI");\r
- assertEquals("Apache POI", rt.getString());\r
-\r
- rt.clearFormatting();\r
-\r
- CTRst st = rt.getCTRst();\r
- assertTrue(st.isSetT());\r
- assertEquals("Apache POI", rt.getString());\r
- assertEquals(0, rt.numFormattingRuns());\r
-\r
- XSSFFont font = new XSSFFont();\r
- font.setBold(true);\r
-\r
- rt.applyFont(7, 10, font);\r
- assertEquals(2, rt.numFormattingRuns());\r
- rt.clearFormatting();\r
- assertEquals("Apache POI", rt.getString());\r
- assertEquals(0, rt.numFormattingRuns());\r
-\r
- }\r
-\r
- public void testGetFonts() throws Exception {\r
-\r
- XSSFRichTextString rt = new XSSFRichTextString();\r
-\r
- XSSFFont font1 = new XSSFFont();\r
- font1.setFontName("Arial");\r
- font1.setItalic(true);\r
- rt.append("The quick", font1);\r
-\r
- XSSFFont font1$ = rt.getFontOfFormattingRun(0);\r
- assertEquals(font1.getItalic(), font1$.getItalic());\r
- assertEquals(font1.getFontName(), font1$.getFontName());\r
-\r
- XSSFFont font2 = new XSSFFont();\r
- font2.setFontName("Courier");\r
- font2.setBold(true);\r
- rt.append(" brown fox", font2);\r
-\r
- XSSFFont font2$ = rt.getFontOfFormattingRun(1);\r
- assertEquals(font2.getBold(), font2$.getBold());\r
- assertEquals(font2.getFontName(), font2$.getFontName());\r
-\r
- }\r
-}\r
+/* ====================================================================
+ 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.xssf.usermodel;
+
+import java.io.*;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+
+import junit.framework.TestCase;
+
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellStyle;
+import org.apache.poi.ss.usermodel.Comment;
+import org.apache.poi.ss.usermodel.CreationHelper;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.xssf.model.CommentsTable;
+import org.apache.xmlbeans.XmlOptions;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.*;
+
+/**
+ * Tests functionality of the XSSFRichTextRun object
+ *
+ * @author Yegor Kozlov
+ */
+public final class TestXSSFRichTextString extends TestCase {
+
+ public void testCreate() throws Exception {
+
+ XSSFRichTextString rt = new XSSFRichTextString("Apache POI");
+ assertEquals("Apache POI", rt.getString());
+
+ CTRst st = rt.getCTRst();
+ assertTrue(st.isSetT());
+ assertEquals("Apache POI", st.getT());
+
+ rt.append(" is cool stuff");
+ assertEquals(2, st.sizeOfRArray());
+ assertFalse(st.isSetT());
+
+ assertEquals("Apache POI is cool stuff", rt.getString());
+ }
+
+
+ public void testApplyFont() throws Exception {
+
+ XSSFRichTextString rt = new XSSFRichTextString();
+ rt.append("123");
+ rt.append("4567");
+ rt.append("89");
+
+ XSSFFont font1 = new XSSFFont();
+ font1.setBold(true);
+
+ rt.applyFont(2, 5, font1);
+
+ assertEquals(5, rt.numFormattingRuns());
+ assertEquals(0, rt.getIndexOfFormattingRun(0));
+ assertEquals(2, rt.getLengthOfFormattingRun(0));
+
+ assertEquals(2, rt.getIndexOfFormattingRun(1));
+ assertEquals(3, rt.getLengthOfFormattingRun(1));
+
+ assertEquals(5, rt.getIndexOfFormattingRun(2));
+ assertEquals(3, rt.getLengthOfFormattingRun(2));
+
+ assertEquals(8, rt.getIndexOfFormattingRun(3));
+ assertEquals(1, rt.getLengthOfFormattingRun(3));
+ }
+
+ public void testClearFormatting() throws Exception {
+
+ XSSFRichTextString rt = new XSSFRichTextString("Apache POI");
+ assertEquals("Apache POI", rt.getString());
+
+ rt.clearFormatting();
+
+ CTRst st = rt.getCTRst();
+ assertTrue(st.isSetT());
+ assertEquals("Apache POI", rt.getString());
+ assertEquals(0, rt.numFormattingRuns());
+
+ XSSFFont font = new XSSFFont();
+ font.setBold(true);
+
+ rt.applyFont(7, 10, font);
+ assertEquals(2, rt.numFormattingRuns());
+ rt.clearFormatting();
+ assertEquals("Apache POI", rt.getString());
+ assertEquals(0, rt.numFormattingRuns());
+
+ }
+
+ public void testGetFonts() throws Exception {
+
+ XSSFRichTextString rt = new XSSFRichTextString();
+
+ XSSFFont font1 = new XSSFFont();
+ font1.setFontName("Arial");
+ font1.setItalic(true);
+ rt.append("The quick", font1);
+
+ XSSFFont font1$ = rt.getFontOfFormattingRun(0);
+ assertEquals(font1.getItalic(), font1$.getItalic());
+ assertEquals(font1.getFontName(), font1$.getFontName());
+
+ XSSFFont font2 = new XSSFFont();
+ font2.setFontName("Courier");
+ font2.setBold(true);
+ rt.append(" brown fox", font2);
+
+ XSSFFont font2$ = rt.getFontOfFormattingRun(1);
+ assertEquals(font2.getBold(), font2$.getBold());
+ assertEquals(font2.getFontName(), font2$.getFontName());
+
+ }
+}