Changed CRLF to LF in ooxml/testcases. Minor fixes for compiler warnings and formatting

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@776905 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Josh Micich 2009-05-21 00:55:56 +00:00
parent 7b5b57423f
commit 5fb78707f7
15 changed files with 1175 additions and 1168 deletions

View File

@ -1,44 +1,44 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership. this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0 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 not use this file except in compliance with
the License. You may obtain a copy of the License at the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.openxml4j.opc; package org.apache.poi.openxml4j.opc;
import junit.framework.Test; import junit.framework.Test;
import junit.framework.TestSuite; import junit.framework.TestSuite;
import org.apache.poi.openxml4j.opc.compliance.AllOpenXML4JComplianceTests; import org.apache.poi.openxml4j.opc.compliance.AllOpenXML4JComplianceTests;
import org.apache.poi.openxml4j.opc.internal.AllOpenXML4JInternalTests; import org.apache.poi.openxml4j.opc.internal.AllOpenXML4JInternalTests;
public final class AllOpenXML4JTests { public final class AllOpenXML4JTests {
public static Test suite() { public static Test suite() {
TestSuite suite = new TestSuite(AllOpenXML4JTests.class.getName()); TestSuite suite = new TestSuite(AllOpenXML4JTests.class.getName());
suite.addTestSuite(TestContentType.class); suite.addTestSuite(TestContentType.class);
suite.addTestSuite(TestFileHelper.class); suite.addTestSuite(TestFileHelper.class);
suite.addTestSuite(TestListParts.class); suite.addTestSuite(TestListParts.class);
suite.addTestSuite(TestPackage.class); suite.addTestSuite(TestPackage.class);
suite.addTestSuite(TestPackageCoreProperties.class); suite.addTestSuite(TestPackageCoreProperties.class);
suite.addTestSuite(TestPackagePartName.class); suite.addTestSuite(TestPackagePartName.class);
suite.addTestSuite(TestPackageThumbnail.class); suite.addTestSuite(TestPackageThumbnail.class);
suite.addTestSuite(TestPackagingURIHelper.class); suite.addTestSuite(TestPackagingURIHelper.class);
suite.addTestSuite(TestRelationships.class); suite.addTestSuite(TestRelationships.class);
suite.addTest(AllOpenXML4JComplianceTests.suite()); suite.addTest(AllOpenXML4JComplianceTests.suite());
suite.addTest(AllOpenXML4JInternalTests.suite()); suite.addTest(AllOpenXML4JInternalTests.suite());
return suite; return suite;
} }
} }

View File

@ -1,117 +1,117 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership. this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0 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 not use this file except in compliance with
the License. You may obtain a copy of the License at the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.openxml4j.opc; package org.apache.poi.openxml4j.opc;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.opc.internal.ContentType; import org.apache.poi.openxml4j.opc.internal.ContentType;
/** /**
* Tests for content type (ContentType class). * Tests for content type (ContentType class).
* *
* @author Julien Chable * @author Julien Chable
*/ */
public class TestContentType extends TestCase { public final class TestContentType extends TestCase {
/** /**
* Check rule M1.13: Package implementers shall only create and only * Check rule M1.13: Package implementers shall only create and only
* recognize parts with a content type; format designers shall specify a * recognize parts with a content type; format designers shall specify a
* content type for each part included in the format. Content types for * content type for each part included in the format. Content types for
* package parts shall fit the definition and syntax for media types as * package parts shall fit the definition and syntax for media types as
* specified in RFC 2616, \u00A73.7. * specified in RFC 2616, \u00A73.7.
*/ */
public void testContentTypeValidation() throws InvalidFormatException { public void testContentTypeValidation() throws InvalidFormatException {
String[] contentTypesToTest = new String[] { "text/xml", String[] contentTypesToTest = new String[] { "text/xml",
"application/pgp-key", "application/vnd.hp-PCLXL", "application/pgp-key", "application/vnd.hp-PCLXL",
"application/vnd.lotus-1-2-3" }; "application/vnd.lotus-1-2-3" };
for (int i = 0; i < contentTypesToTest.length; ++i) { for (int i = 0; i < contentTypesToTest.length; ++i) {
new ContentType(contentTypesToTest[i]); new ContentType(contentTypesToTest[i]);
} }
} }
/** /**
* Check rule M1.13 : Package implementers shall only create and only * Check rule M1.13 : Package implementers shall only create and only
* recognize parts with a content type; format designers shall specify a * recognize parts with a content type; format designers shall specify a
* content type for each part included in the format. Content types for * content type for each part included in the format. Content types for
* package parts shall fit the definition and syntax for media types as * package parts shall fit the definition and syntax for media types as
* specified in RFC 2616, \u00A3.7. * specified in RFC 2616, \u00A3.7.
* *
* Check rule M1.14: Content types shall not use linear white space either * 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. * between the type and subtype or between an attribute and its value.
* Content types also shall not have leading or trailing white spaces. * Content types also shall not have leading or trailing white spaces.
* Package implementers shall create only such content types and shall * Package implementers shall create only such content types and shall
* require such content types when retrieving a part from a package; format * require such content types when retrieving a part from a package; format
* designers shall specify only such content types for inclusion in the * designers shall specify only such content types for inclusion in the
* format. * format.
*/ */
public void testContentTypeValidationFailure() { public void testContentTypeValidationFailure() {
String[] contentTypesToTest = new String[] { "text/xml/app", "", String[] contentTypesToTest = new String[] { "text/xml/app", "",
"test", "text(xml/xml", "text)xml/xml", "text<xml/xml", "test", "text(xml/xml", "text)xml/xml", "text<xml/xml",
"text>/xml", "text@/xml", "text,/xml", "text;/xml", "text>/xml", "text@/xml", "text,/xml", "text;/xml",
"text:/xml", "text\\/xml", "t/ext/xml", "t\"ext/xml", "text:/xml", "text\\/xml", "t/ext/xml", "t\"ext/xml",
"text[/xml", "text]/xml", "text?/xml", "tex=t/xml", "text[/xml", "text]/xml", "text?/xml", "tex=t/xml",
"te{xt/xml", "tex}t/xml", "te xt/xml", "te{xt/xml", "tex}t/xml", "te xt/xml",
"text" + (char) 9 + "/xml", "text xml", " text/xml " }; "text" + (char) 9 + "/xml", "text xml", " text/xml " };
for (int i = 0; i < contentTypesToTest.length; ++i) { for (int i = 0; i < contentTypesToTest.length; ++i) {
try { try {
new ContentType(contentTypesToTest[i]); new ContentType(contentTypesToTest[i]);
} catch (InvalidFormatException e) { } catch (InvalidFormatException e) {
continue; continue;
} }
fail("Must have fail for content type: '" + contentTypesToTest[i] fail("Must have fail for content type: '" + contentTypesToTest[i]
+ "' !"); + "' !");
} }
} }
/** /**
* Check rule [O1.2]: Format designers might restrict the usage of * Check rule [O1.2]: Format designers might restrict the usage of
* parameters for content types. * parameters for content types.
*/ */
public void testContentTypeParameterFailure() { public void testContentTypeParameterFailure() {
String[] contentTypesToTest = new String[] { "mail/toto;titi=tata", String[] contentTypesToTest = new String[] { "mail/toto;titi=tata",
"text/xml;a=b;c=d", "mail/toto;\"titi=tata\"" }; "text/xml;a=b;c=d", "mail/toto;\"titi=tata\"" };
for (int i = 0; i < contentTypesToTest.length; ++i) { for (int i = 0; i < contentTypesToTest.length; ++i) {
try { try {
new ContentType(contentTypesToTest[i]); new ContentType(contentTypesToTest[i]);
} catch (InvalidFormatException e) { } catch (InvalidFormatException e) {
continue; continue;
} }
fail("Must have fail for content type: '" + contentTypesToTest[i] fail("Must have fail for content type: '" + contentTypesToTest[i]
+ "' !"); + "' !");
} }
} }
/** /**
* Check rule M1.15: The package implementer shall require a content type * Check rule M1.15: The package implementer shall require a content type
* that does not include comments and the format designer shall specify such * that does not include comments and the format designer shall specify such
* a content type. * a content type.
*/ */
public void testContentTypeCommentFailure() { public void testContentTypeCommentFailure() {
String[] contentTypesToTest = new String[] { "text/xml(comment)" }; String[] contentTypesToTest = new String[] { "text/xml(comment)" };
for (int i = 0; i < contentTypesToTest.length; ++i) { for (int i = 0; i < contentTypesToTest.length; ++i) {
try { try {
new ContentType(contentTypesToTest[i]); new ContentType(contentTypesToTest[i]);
} catch (InvalidFormatException e) { } catch (InvalidFormatException e) {
continue; continue;
} }
fail("Must have fail for content type: '" + contentTypesToTest[i] fail("Must have fail for content type: '" + contentTypesToTest[i]
+ "' !"); + "' !");
} }
} }
} }

View File

@ -1,55 +1,56 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership. this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0 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 not use this file except in compliance with
the License. You may obtain a copy of the License at the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.openxml4j.opc; package org.apache.poi.openxml4j.opc;
import java.io.File; import java.io.File;
import java.util.TreeMap; import java.util.TreeMap;
import org.apache.poi.openxml4j.opc.internal.FileHelper; import org.apache.poi.openxml4j.opc.internal.FileHelper;
import junit.framework.TestCase; import junit.framework.TestCase;
/** /**
* Test TestFileHelper class. * Test TestFileHelper class.
* *
* @author Julien Chable * @author Julien Chable
*/ */
public class TestFileHelper extends TestCase { public final class TestFileHelper extends TestCase {
public void testGetDirectory() { /**
TreeMap<String, String> expectedValue = new TreeMap<String, String>(); * TODO - use simple JDK methods on {@link File} instead:<br/>
expectedValue.put("/dir1/test.doc", "/dir1"); * {@link File#getParentFile()} instead of {@link FileHelper#getDirectory(File)
expectedValue.put("/dir1/dir2/test.doc.xml", "/dir1/dir2"); * {@link File#getName()} instead of {@link FileHelper#getFilename(File)
*/
for (String filename : expectedValue.keySet()) { public void testGetDirectory() {
File f1 = new File(expectedValue.get(filename)); TreeMap<String, String> expectedValue = new TreeMap<String, String>();
File f2 = FileHelper.getDirectory(new File(filename)); expectedValue.put("/dir1/test.doc", "/dir1");
expectedValue.put("/dir1/dir2/test.doc.xml", "/dir1/dir2");
/*
* YK: The original version asserted expected values against File#getAbsolutePath(): for (String filename : expectedValue.keySet()) {
* assertTrue(expectedValue.get(filename).equalsIgnoreCase( File f1 = new File(expectedValue.get(filename));
* FileHelper.getDirectory(new File(filename)) File f2 = FileHelper.getDirectory(new File(filename));
* .getAbsolutePath()));
* if (false) {
* This comparison is platform dependent and resulted in build errors in Gump since 21/02/2009. // YK: The original version asserted expected values against File#getAbsolutePath():
* Assertion via File#equals(File otherFile) is a better approach. assertTrue(expectedValue.get(filename).equalsIgnoreCase(f2.getAbsolutePath()));
*/ // This comparison is platform dependent. A better approach is below
assertTrue(f1.equals(f2)); }
} assertTrue(f1.equals(f2));
} }
} }
}

View File

@ -1,35 +1,36 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership. this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0 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 not use this file except in compliance with
the License. You may obtain a copy of the License at the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.openxml4j.opc;
package org.apache.poi.openxml4j.opc;
import org.apache.poi.openxml4j.opc.PackagePartName;
import org.apache.poi.openxml4j.opc.PackagingURIHelper; import org.apache.poi.openxml4j.opc.PackagePartName;
import org.apache.poi.openxml4j.opc.PackagingURIHelper;
import junit.framework.TestCase;
import junit.framework.TestCase;
public class TestPackagePartName extends TestCase {
public final class TestPackagePartName extends TestCase {
/**
* Test method getExtension(). /**
*/ * Test method getExtension().
public void testGetExtension() throws Exception{ */
PackagePartName name1 = PackagingURIHelper.createPartName("/doc/props/document.xml"); public void testGetExtension() throws Exception{
PackagePartName name2 = PackagingURIHelper.createPartName("/root/document"); PackagePartName name1 = PackagingURIHelper.createPartName("/doc/props/document.xml");
assertEquals("xml", name1.getExtension()); PackagePartName name2 = PackagingURIHelper.createPartName("/root/document");
assertEquals("", name2.getExtension()); assertEquals("xml", name1.getExtension());
} assertEquals("", name2.getExtension());
} }
}

View File

@ -1,33 +1,33 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership. this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0 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 not use this file except in compliance with
the License. You may obtain a copy of the License at the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.openxml4j.opc.compliance; package org.apache.poi.openxml4j.opc.compliance;
import junit.framework.Test; import junit.framework.Test;
import junit.framework.TestSuite; import junit.framework.TestSuite;
public class AllOpenXML4JComplianceTests { public final class AllOpenXML4JComplianceTests {
public static Test suite() { public static Test suite() {
TestSuite suite = new TestSuite(AllOpenXML4JComplianceTests.class.getName()); TestSuite suite = new TestSuite(AllOpenXML4JComplianceTests.class.getName());
suite.addTestSuite(TestOPCCompliancePartName.class); suite.addTestSuite(TestOPCCompliancePartName.class);
suite.addTestSuite(TestOPCComplianceCoreProperties.class); suite.addTestSuite(TestOPCComplianceCoreProperties.class);
suite.addTestSuite(TestOPCCompliancePackageModel.class); suite.addTestSuite(TestOPCCompliancePackageModel.class);
return suite; return suite;
} }
} }

View File

@ -1,30 +1,30 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership. this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0 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 not use this file except in compliance with
the License. You may obtain a copy of the License at the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.openxml4j.opc.internal; package org.apache.poi.openxml4j.opc.internal;
import junit.framework.Test; import junit.framework.Test;
import junit.framework.TestSuite; import junit.framework.TestSuite;
public class AllOpenXML4JInternalTests { public final class AllOpenXML4JInternalTests {
public static Test suite() { public static Test suite() {
TestSuite suite = new TestSuite(AllOpenXML4JInternalTests.class.getName()); TestSuite suite = new TestSuite(AllOpenXML4JInternalTests.class.getName());
suite.addTestSuite(TestContentTypeManager.class); suite.addTestSuite(TestContentTypeManager.class);
return suite; return suite;
} }
} }

View File

@ -1,116 +1,116 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership. this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0 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 not use this file except in compliance with
the License. You may obtain a copy of the License at the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.openxml4j.opc.internal; package org.apache.poi.openxml4j.opc.internal;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.poi.openxml4j.opc.PackagePartName; import org.apache.poi.openxml4j.opc.PackagePartName;
import org.apache.poi.openxml4j.opc.PackagingURIHelper; import org.apache.poi.openxml4j.opc.PackagingURIHelper;
public class TestContentTypeManager extends TestCase { public final class TestContentTypeManager extends TestCase {
/** /**
* Test the properties part content parsing. * Test the properties part content parsing.
*/ */
public void testContentType() throws Exception { public void testContentType() throws Exception {
// File originalFile = new File(testCore.getTestRootPath() + // File originalFile = new File(testCore.getTestRootPath() +
// File.separator + // File.separator +
// "sample.docx"); // "sample.docx");
// //
// // Retrieves core properties part // // Retrieves core properties part
// Package p = Package.open(originalFile.getAbsolutePath(), // Package p = Package.open(originalFile.getAbsolutePath(),
// PackageAccess.READ); // PackageAccess.READ);
// PackageRelationship corePropertiesRelationship = p // PackageRelationship corePropertiesRelationship = p
// .getRelationshipsByType( // .getRelationshipsByType(
// PackageRelationshipTypes.CORE_PROPERTIES) // PackageRelationshipTypes.CORE_PROPERTIES)
// .getRelationship(0); // .getRelationship(0);
// PackagePart coreDocument = p.getPart(corePropertiesRelationship); // PackagePart coreDocument = p.getPart(corePropertiesRelationship);
// //
// ContentTypeManager ctm = new ZipContentTypeManager(coreDocument // ContentTypeManager ctm = new ZipContentTypeManager(coreDocument
// .getInputStream()); // .getInputStream());
// //
// // TODO // // TODO
//fail(); //fail();
} }
/** /**
* Test the addition of several default and override content types. * Test the addition of several default and override content types.
*/ */
public void testContentTypeAddition() throws Exception { public void testContentTypeAddition() throws Exception {
ContentTypeManager ctm = new ZipContentTypeManager(null, null); ContentTypeManager ctm = new ZipContentTypeManager(null, null);
PackagePartName name1 = PackagingURIHelper PackagePartName name1 = PackagingURIHelper
.createPartName("/foo/foo.XML"); .createPartName("/foo/foo.XML");
PackagePartName name2 = PackagingURIHelper PackagePartName name2 = PackagingURIHelper
.createPartName("/foo/foo2.xml"); .createPartName("/foo/foo2.xml");
PackagePartName name3 = PackagingURIHelper PackagePartName name3 = PackagingURIHelper
.createPartName("/foo/doc.rels"); .createPartName("/foo/doc.rels");
PackagePartName name4 = PackagingURIHelper PackagePartName name4 = PackagingURIHelper
.createPartName("/foo/doc.RELS"); .createPartName("/foo/doc.RELS");
// Add content types // Add content types
ctm.addContentType(name1, "foo-type1"); ctm.addContentType(name1, "foo-type1");
ctm.addContentType(name2, "foo-type2"); ctm.addContentType(name2, "foo-type2");
ctm.addContentType(name3, "text/xml+rel"); ctm.addContentType(name3, "text/xml+rel");
ctm.addContentType(name4, "text/xml+rel"); ctm.addContentType(name4, "text/xml+rel");
assertEquals(ctm.getContentType(name1), "foo-type1"); assertEquals(ctm.getContentType(name1), "foo-type1");
assertEquals(ctm.getContentType(name2), "foo-type2"); assertEquals(ctm.getContentType(name2), "foo-type2");
assertEquals(ctm.getContentType(name3), "text/xml+rel"); assertEquals(ctm.getContentType(name3), "text/xml+rel");
assertEquals(ctm.getContentType(name3), "text/xml+rel"); assertEquals(ctm.getContentType(name3), "text/xml+rel");
} }
/** /**
* Test the addition then removal of content types. * Test the addition then removal of content types.
*/ */
public void testContentTypeRemoval() throws Exception { public void testContentTypeRemoval() throws Exception {
ContentTypeManager ctm = new ZipContentTypeManager(null, null); ContentTypeManager ctm = new ZipContentTypeManager(null, null);
PackagePartName name1 = PackagingURIHelper PackagePartName name1 = PackagingURIHelper
.createPartName("/foo/foo.xml"); .createPartName("/foo/foo.xml");
PackagePartName name2 = PackagingURIHelper PackagePartName name2 = PackagingURIHelper
.createPartName("/foo/foo2.xml"); .createPartName("/foo/foo2.xml");
PackagePartName name3 = PackagingURIHelper PackagePartName name3 = PackagingURIHelper
.createPartName("/foo/doc.rels"); .createPartName("/foo/doc.rels");
PackagePartName name4 = PackagingURIHelper PackagePartName name4 = PackagingURIHelper
.createPartName("/foo/doc.RELS"); .createPartName("/foo/doc.RELS");
// Add content types // Add content types
ctm.addContentType(name1, "foo-type1"); ctm.addContentType(name1, "foo-type1");
ctm.addContentType(name2, "foo-type2"); ctm.addContentType(name2, "foo-type2");
ctm.addContentType(name3, "text/xml+rel"); ctm.addContentType(name3, "text/xml+rel");
ctm.addContentType(name4, "text/xml+rel"); ctm.addContentType(name4, "text/xml+rel");
ctm.removeContentType(name2); ctm.removeContentType(name2);
ctm.removeContentType(name3); ctm.removeContentType(name3);
assertEquals(ctm.getContentType(name1), "foo-type1"); assertEquals(ctm.getContentType(name1), "foo-type1");
assertEquals(ctm.getContentType(name2), "foo-type1"); assertEquals(ctm.getContentType(name2), "foo-type1");
assertEquals(ctm.getContentType(name3), null); assertEquals(ctm.getContentType(name3), null);
ctm.removeContentType(name1); ctm.removeContentType(name1);
assertEquals(ctm.getContentType(name1), null); assertEquals(ctm.getContentType(name1), null);
assertEquals(ctm.getContentType(name2), null); assertEquals(ctm.getContentType(name2), null);
} }
/** /**
* Test the addition then removal of content types in a package. * Test the addition then removal of content types in a package.
*/ */
public void testContentTypeRemovalPackage() throws Exception { public void testContentTypeRemovalPackage() throws Exception {
// TODO // TODO
} }
} }

View File

@ -1,59 +1,62 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership. this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0 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 not use this file except in compliance with
the License. You may obtain a copy of the License at the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.xssf;
package org.apache.poi.xssf;
import org.apache.poi.ss.ITestDataProvider;
import org.apache.poi.ss.SpreadsheetVersion; import org.apache.poi.ss.ITestDataProvider;
import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.hssf.HSSFTestDataSamples;
/**
* @author Yegor Kozlov /**
*/ * @author Yegor Kozlov
public final class XSSFITestDataProvider implements ITestDataProvider { */
public final class XSSFITestDataProvider implements ITestDataProvider {
public XSSFWorkbook openSampleWorkbook(String sampleFileName) {
return XSSFTestDataSamples.openSampleWorkbook(sampleFileName); public XSSFWorkbook openSampleWorkbook(String sampleFileName) {
} return XSSFTestDataSamples.openSampleWorkbook(sampleFileName);
}
public XSSFWorkbook writeOutAndReadBack(Workbook original) {
if(!(original instanceof XSSFWorkbook)) { public XSSFWorkbook writeOutAndReadBack(Workbook original) {
throw new IllegalArgumentException("Expected an instance of XSSFWorkbook"); if(!(original instanceof XSSFWorkbook)) {
} throw new IllegalArgumentException("Expected an instance of XSSFWorkbook");
}
return XSSFTestDataSamples.writeOutAndReadBack((XSSFWorkbook)original);
} return XSSFTestDataSamples.writeOutAndReadBack((XSSFWorkbook)original);
}
public XSSFWorkbook createWorkbook(){
return new XSSFWorkbook(); public XSSFWorkbook createWorkbook(){
} return new XSSFWorkbook();
}
public byte[] getTestDataFileContent(String fileName) {
return HSSFTestDataSamples.getTestDataFileContent(fileName); public byte[] getTestDataFileContent(String fileName) {
} return HSSFTestDataSamples.getTestDataFileContent(fileName);
}
public SpreadsheetVersion getSpreadsheetVersion(){
return SpreadsheetVersion.EXCEL2007; public SpreadsheetVersion getSpreadsheetVersion(){
} return SpreadsheetVersion.EXCEL2007;
}
private XSSFITestDataProvider(){}
private static XSSFITestDataProvider inst = new XSSFITestDataProvider(); private XSSFITestDataProvider() {
public static XSSFITestDataProvider getInstance(){ // enforce singleton
return inst; }
} private static XSSFITestDataProvider inst = new XSSFITestDataProvider();
} public static XSSFITestDataProvider getInstance(){
return inst;
}
}

View File

@ -1,131 +1,128 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership. this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0 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 not use this file except in compliance with
the License. You may obtain a copy of the License at the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.xssf.model; package org.apache.poi.xssf.model;
import java.io.ByteArrayInputStream; import java.util.List;
import java.io.ByteArrayOutputStream;
import java.io.IOException; import junit.framework.TestCase;
import java.util.List;
import org.apache.poi.xssf.XSSFTestDataSamples;
import junit.framework.TestCase; import org.apache.poi.xssf.usermodel.XSSFRichTextString;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xssf.XSSFTestDataSamples; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRElt;
import org.apache.poi.xssf.usermodel.XSSFRichTextString; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRPrElt;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst;
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
* Test {@link SharedStringsTable}, the cache of strings in a workbook */
* public final class TestSharedStringsTable extends TestCase {
* @author Yegor Kozlov
*/ public void testCreateNew() {
public final class TestSharedStringsTable extends TestCase { SharedStringsTable sst = new SharedStringsTable();
public void testCreateNew() { CTRst st;
SharedStringsTable sst = new SharedStringsTable(); int idx;
CTRst st; // Check defaults
int idx; assertNotNull(sst.getItems());
assertEquals(0, sst.getItems().size());
// Check defaults assertEquals(0, sst.getCount());
assertNotNull(sst.getItems()); assertEquals(0, sst.getUniqueCount());
assertEquals(0, sst.getItems().size());
assertEquals(0, sst.getCount()); st = CTRst.Factory.newInstance();
assertEquals(0, sst.getUniqueCount()); st.setT("Hello, World!");
st = CTRst.Factory.newInstance(); idx = sst.addEntry(st);
st.setT("Hello, World!"); assertEquals(0, idx);
assertEquals(1, sst.getCount());
idx = sst.addEntry(st); assertEquals(1, sst.getUniqueCount());
assertEquals(0, idx);
assertEquals(1, sst.getCount()); //add the same entry again
assertEquals(1, sst.getUniqueCount()); idx = sst.addEntry(st);
assertEquals(0, idx);
//add the same entry egain assertEquals(2, sst.getCount());
idx = sst.addEntry(st); assertEquals(1, sst.getUniqueCount());
assertEquals(0, idx);
assertEquals(2, sst.getCount()); //and again
assertEquals(1, sst.getUniqueCount()); idx = sst.addEntry(st);
assertEquals(0, idx);
//and egain assertEquals(3, sst.getCount());
idx = sst.addEntry(st); assertEquals(1, sst.getUniqueCount());
assertEquals(0, idx);
assertEquals(3, sst.getCount()); st = CTRst.Factory.newInstance();
assertEquals(1, sst.getUniqueCount()); st.setT("Second string");
st = CTRst.Factory.newInstance(); idx = sst.addEntry(st);
st.setT("Second string"); assertEquals(1, idx);
assertEquals(4, sst.getCount());
idx = sst.addEntry(st); assertEquals(2, sst.getUniqueCount());
assertEquals(1, idx);
assertEquals(4, sst.getCount()); //add the same entry again
assertEquals(2, sst.getUniqueCount()); idx = sst.addEntry(st);
assertEquals(1, idx);
//add the same entry egain assertEquals(5, sst.getCount());
idx = sst.addEntry(st); assertEquals(2, sst.getUniqueCount());
assertEquals(1, idx);
assertEquals(5, sst.getCount()); st = CTRst.Factory.newInstance();
assertEquals(2, sst.getUniqueCount()); CTRElt r = st.addNewR();
CTRPrElt pr = r.addNewRPr();
st = CTRst.Factory.newInstance(); pr.addNewColor().setRgb(new byte[]{(byte)0xFF, 0, 0}); //red
CTRElt r = st.addNewR(); pr.addNewI().setVal(true); //bold
CTRPrElt pr = r.addNewRPr(); pr.addNewB().setVal(true); //italic
pr.addNewColor().setRgb(new byte[]{(byte)0xFF, 0, 0}); //red r.setT("Second string");
pr.addNewI().setVal(true); //bold
pr.addNewB().setVal(true); //italic idx = sst.addEntry(st);
r.setT("Second string"); assertEquals(2, idx);
assertEquals(6, sst.getCount());
idx = sst.addEntry(st); assertEquals(3, sst.getUniqueCount());
assertEquals(2, idx);
assertEquals(6, sst.getCount()); idx = sst.addEntry(st);
assertEquals(3, sst.getUniqueCount()); assertEquals(2, idx);
assertEquals(7, sst.getCount());
idx = sst.addEntry(st); assertEquals(3, sst.getUniqueCount());
assertEquals(2, idx);
assertEquals(7, sst.getCount()); //OK. the sst table is filled, check the contents
assertEquals(3, sst.getUniqueCount()); assertEquals(3, sst.getItems().size());
assertEquals("Hello, World!", new XSSFRichTextString(sst.getEntryAt(0)).toString());
//ok. the sst table is filled, check the contents assertEquals("Second string", new XSSFRichTextString(sst.getEntryAt(1)).toString());
assertEquals(3, sst.getItems().size()); assertEquals("Second string", new XSSFRichTextString(sst.getEntryAt(2)).toString());
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();
public void testReadWrite() {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("sample.xlsx"); //serialize, read back and compare with the original
SharedStringsTable sst1 = wb.getSharedStringSource(); SharedStringsTable sst2 = XSSFTestDataSamples.writeOutAndReadBack(wb).getSharedStringSource();
//serialize, read back and compare with the original assertEquals(sst1.getCount(), sst2.getCount());
SharedStringsTable sst2 = XSSFTestDataSamples.writeOutAndReadBack(wb).getSharedStringSource(); assertEquals(sst1.getUniqueCount(), sst2.getUniqueCount());
assertEquals(sst1.getCount(), sst2.getCount()); List<CTRst> items1 = sst1.getItems();
assertEquals(sst1.getUniqueCount(), sst2.getUniqueCount()); List<CTRst> items2 = sst2.getItems();
assertEquals(items1.size(), items2.size());
List<CTRst> items1 = sst1.getItems(); for (int i = 0; i < items1.size(); i++) {
List<CTRst> items2 = sst2.getItems(); CTRst st1 = items1.get(i);
assertEquals(items1.size(), items2.size()); CTRst st2 = items2.get(i);
for (int i = 0; i < items1.size(); i++) { assertEquals(st1.toString(), st2.toString());
CTRst st1 = items1.get(i); }
CTRst st2 = items2.get(i); }
assertEquals(st1.toString(), st2.toString()); }
}
}
}

View File

@ -1,99 +1,100 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership. this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0 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 not use this file except in compliance with
the License. You may obtain a copy of the License at the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.xssf.usermodel;
package org.apache.poi.xssf.usermodel;
import junit.framework.TestCase;
import org.apache.poi.xssf.XSSFTestDataSamples; import junit.framework.TestCase;
import org.apache.poi.xssf.XSSFTestDataSamples;
/**
* @author Yegor Kozlov /**
*/ * @author Yegor Kozlov
public class TestSheetHiding extends TestCase { */
private XSSFWorkbook wbH; public final class TestSheetHiding extends TestCase {
private XSSFWorkbook wbU; private XSSFWorkbook wbH;
private XSSFWorkbook wbU;
protected void setUp() {
wbH = XSSFTestDataSamples.openSampleWorkbook("TwoSheetsOneHidden.xlsx"); protected void setUp() {
wbU = XSSFTestDataSamples.openSampleWorkbook("TwoSheetsNoneHidden.xlsx"); 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 * Test that we get the right number of sheets,
* the hidden flags are * with the right text on them, no matter what
*/ * the hidden flags are
public void testTextSheets() throws Exception { */
// Both should have two sheets public void testTextSheets() throws Exception {
assertEquals(2, wbH.getNumberOfSheets()); // Both should have two sheets
assertEquals(2, wbU.getNumberOfSheets()); assertEquals(2, wbH.getNumberOfSheets());
assertEquals(2, wbU.getNumberOfSheets());
// All sheets should have one row
assertEquals(0, wbH.getSheetAt(0).getLastRowNum()); // All sheets should have one row
assertEquals(0, wbH.getSheetAt(1).getLastRowNum()); assertEquals(0, wbH.getSheetAt(0).getLastRowNum());
assertEquals(0, wbU.getSheetAt(0).getLastRowNum()); assertEquals(0, wbH.getSheetAt(1).getLastRowNum());
assertEquals(0, wbU.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()); // All rows should have one column
assertEquals(1, wbH.getSheetAt(1).getRow(0).getLastCellNum()); assertEquals(1, wbH.getSheetAt(0).getRow(0).getLastCellNum());
assertEquals(1, wbU.getSheetAt(0).getRow(0).getLastCellNum()); assertEquals(1, wbH.getSheetAt(1).getRow(0).getLastCellNum());
assertEquals(1, wbU.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()); // Text should be sheet based
assertEquals("Sheet2A1", wbH.getSheetAt(1).getRow(0).getCell(0).getRichStringCellValue().getString()); assertEquals("Sheet1A1", wbH.getSheetAt(0).getRow(0).getCell(0).getRichStringCellValue().getString());
assertEquals("Sheet1A1", wbU.getSheetAt(0).getRow(0).getCell(0).getRichStringCellValue().getString()); assertEquals("Sheet2A1", wbH.getSheetAt(1).getRow(0).getCell(0).getRichStringCellValue().getString());
assertEquals("Sheet2A1", wbU.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 * Check that we can get and set the hidden flags
*/ * as expected
public void testHideUnHideFlags() throws Exception { */
assertTrue(wbH.isSheetHidden(0)); public void testHideUnHideFlags() throws Exception {
assertFalse(wbH.isSheetHidden(1)); assertTrue(wbH.isSheetHidden(0));
assertFalse(wbU.isSheetHidden(0)); assertFalse(wbH.isSheetHidden(1));
assertFalse(wbU.isSheetHidden(1)); assertFalse(wbU.isSheetHidden(0));
} assertFalse(wbU.isSheetHidden(1));
}
/**
* Turn the sheet with none hidden into the one with /**
* one hidden * Turn the sheet with none hidden into the one with
*/ * one hidden
public void testHide() throws Exception { */
wbU.setSheetHidden(0, true); public void testHide() throws Exception {
assertTrue(wbU.isSheetHidden(0)); wbU.setSheetHidden(0, true);
assertFalse(wbU.isSheetHidden(1)); assertTrue(wbU.isSheetHidden(0));
XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wbU); assertFalse(wbU.isSheetHidden(1));
assertTrue(wb2.isSheetHidden(0)); XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wbU);
assertFalse(wb2.isSheetHidden(1)); assertTrue(wb2.isSheetHidden(0));
} assertFalse(wb2.isSheetHidden(1));
}
/**
* Turn the sheet with one hidden into the one with /**
* none hidden * Turn the sheet with one hidden into the one with
*/ * none hidden
public void testUnHide() throws Exception { */
wbH.setSheetHidden(0, false); public void testUnHide() throws Exception {
assertFalse(wbH.isSheetHidden(0)); wbH.setSheetHidden(0, false);
assertFalse(wbH.isSheetHidden(1)); assertFalse(wbH.isSheetHidden(0));
XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wbH); assertFalse(wbH.isSheetHidden(1));
assertFalse(wb2.isSheetHidden(0)); XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wbH);
assertFalse(wb2.isSheetHidden(1)); assertFalse(wb2.isSheetHidden(0));
} assertFalse(wb2.isSheetHidden(1));
} }
}

View File

@ -1,62 +1,63 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership. this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0 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 not use this file except in compliance with
the License. You may obtain a copy of the License at the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.xssf.usermodel;
package org.apache.poi.xssf.usermodel;
import org.apache.poi.ss.usermodel.BaseTestSheetShiftRows;
import org.apache.poi.ss.ITestDataProvider; import org.apache.poi.ss.usermodel.BaseTestSheetShiftRows;
import org.apache.poi.xssf.XSSFITestDataProvider; import org.apache.poi.ss.ITestDataProvider;
import org.apache.poi.xssf.XSSFITestDataProvider;
/**
* @author Yegor Kozlov /**
*/ * @author Yegor Kozlov
public class TestSheetShiftRows extends BaseTestSheetShiftRows { */
public final class TestSheetShiftRows extends BaseTestSheetShiftRows {
@Override
protected ITestDataProvider getTestDataProvider(){ @Override
return XSSFITestDataProvider.getInstance(); protected ITestDataProvider getTestDataProvider(){
} return XSSFITestDataProvider.getInstance();
}
public void testShiftRows() {
baseTestShiftRows("SimpleMultiCell.xlsx"); public void testShiftRows() {
} baseTestShiftRows("SimpleMultiCell.xlsx");
}
public void testShiftRow() {
baseTestShiftRow(); public void testShiftRow() {
} baseTestShiftRow();
}
public void testShiftNames() {
baseTestShiftWithNames(); public void testShiftNames() {
} baseTestShiftWithNames();
}
//TODO support shifting of page breaks
public void $testShiftRowBreaks() { //TODO support shifting of page breaks
baseTestShiftRowBreaks(); public void $testShiftRowBreaks() {
} baseTestShiftRowBreaks();
}
//TODO support shifting of comments.
public void $testShiftWithComments() { //TODO support shifting of comments.
baseTestShiftWithComments("comments.xlsx"); public void $testShiftWithComments() {
} baseTestShiftWithComments("comments.xlsx");
}
public void testShiftWithFormulas() {
baseTestShiftWithFormulas("ForShifting.xlsx"); public void testShiftWithFormulas() {
} baseTestShiftWithFormulas("ForShifting.xlsx");
}
public void testShiftWithMergedRegions() {
baseTestShiftWithMergedRegions(); public void testShiftWithMergedRegions() {
} baseTestShiftWithMergedRegions();
} }
}

View File

@ -1,76 +1,77 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership. this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0 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 not use this file except in compliance with
the License. You may obtain a copy of the License at the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.xssf.usermodel;
package org.apache.poi.xssf.usermodel;
import junit.framework.TestCase;
import org.apache.poi.xssf.XSSFTestDataSamples; import junit.framework.TestCase;
import org.apache.poi.xssf.XSSFITestDataProvider; import org.apache.poi.xssf.XSSFTestDataSamples;
import org.apache.poi.ss.usermodel.BaseTestNamedRange; import org.apache.poi.xssf.XSSFITestDataProvider;
import org.apache.poi.ss.usermodel.BaseTestNamedRange;
/**
* @author Yegor Kozlov /**
*/ * @author Yegor Kozlov
public class TestXSSFName extends BaseTestNamedRange { */
public final class TestXSSFName extends BaseTestNamedRange {
@Override
protected XSSFITestDataProvider getTestDataProvider(){ @Override
return XSSFITestDataProvider.getInstance(); protected XSSFITestDataProvider getTestDataProvider(){
} return XSSFITestDataProvider.getInstance();
}
//TODO combine testRepeatingRowsAndColums() for HSSF and XSSF
public void testRepeatingRowsAndColums() { //TODO combine testRepeatingRowsAndColums() for HSSF and XSSF
// First test that setting RR&C for same sheet more than once only creates a public void testRepeatingRowsAndColums() {
// single Print_Titles built-in record // First test that setting RR&C for same sheet more than once only creates a
XSSFWorkbook wb = getTestDataProvider().createWorkbook(); // single Print_Titles built-in record
XSSFSheet sheet = wb.createSheet("FirstSheet"); 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++) { // set repeating rows and columns twice for the first sheet
wb.setRepeatingRowsAndColumns(0, 0, 0, 0, 3); for (int i = 0; i < 2; i++) {
//sheet.createFreezePane(0, 3); wb.setRepeatingRowsAndColumns(0, 0, 0, 0, 3);
} //sheet.createFreezePane(0, 3);
assertEquals(1, wb.getNumberOfNames()); }
XSSFName nr1 = wb.getNameAt(0); 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()); 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); // Save and re-open
XSSFWorkbook nwb = XSSFTestDataSamples.writeOutAndReadBack(wb);
assertEquals(1, nwb.getNumberOfNames());
nr1 = nwb.getNameAt(0); assertEquals(1, nwb.getNumberOfNames());
nr1 = nwb.getNameAt(0);
assertEquals(XSSFName.BUILTIN_PRINT_TITLE, nr1.getNameName());
assertEquals("'FirstSheet'!$A:$A,'FirstSheet'!$1:$4", nr1.getRefersToFormula()); 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 // check that setting RR&C on a second sheet causes a new Print_Titles built-in
sheet = nwb.createSheet("SecondSheet"); // name to be created
nwb.setRepeatingRowsAndColumns(1, 1, 2, 0, 0); sheet = nwb.createSheet("SecondSheet");
nwb.setRepeatingRowsAndColumns(1, 1, 2, 0, 0);
assertEquals(2, nwb.getNumberOfNames());
XSSFName nr2 = nwb.getNameAt(1); 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()); assertEquals(XSSFName.BUILTIN_PRINT_TITLE, nr2.getNameName());
assertEquals("'SecondSheet'!$B:$C,'SecondSheet'!$1:$1", nr2.getRefersToFormula());
nwb.setRepeatingRowsAndColumns(1, -1, -1, -1, -1);
} nwb.setRepeatingRowsAndColumns(1, -1, -1, -1, -1);
}
}
}

View File

@ -1,73 +1,74 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership. this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0 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 not use this file except in compliance with
the License. You may obtain a copy of the License at the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.xssf.usermodel;
package org.apache.poi.xssf.usermodel;
import junit.framework.TestCase;
import org.apache.poi.ss.usermodel.ClientAnchor; import junit.framework.TestCase;
import org.apache.poi.ss.usermodel.BaseTestPicture; import org.apache.poi.ss.usermodel.ClientAnchor;
import org.apache.poi.xssf.XSSFITestDataProvider; import org.apache.poi.ss.usermodel.BaseTestPicture;
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTTwoCellAnchor; import org.apache.poi.xssf.XSSFITestDataProvider;
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.STEditAs; import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTTwoCellAnchor;
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.STEditAs;
import java.util.List;
import java.util.Arrays; import java.util.List;
import java.util.Arrays;
/**
* @author Yegor Kozlov /**
*/ * @author Yegor Kozlov
public class TestXSSFPicture extends BaseTestPicture { */
public final class TestXSSFPicture extends BaseTestPicture {
@Override
protected XSSFITestDataProvider getTestDataProvider(){ @Override
return XSSFITestDataProvider.getInstance(); protected XSSFITestDataProvider getTestDataProvider(){
} return XSSFITestDataProvider.getInstance();
}
public void testResize() {
baseTestResize(new XSSFClientAnchor(0, 0, 504825, 85725, (short)0, 0, (short)1, 8)); public void testResize() {
} baseTestResize(new XSSFClientAnchor(0, 0, 504825, 85725, (short)0, 0, (short)1, 8));
}
public void testCreate(){
XSSFWorkbook wb = new XSSFWorkbook(); public void testCreate(){
XSSFSheet sheet = wb.createSheet(); XSSFWorkbook wb = new XSSFWorkbook();
XSSFDrawing drawing = sheet.createDrawingPatriarch(); XSSFSheet sheet = wb.createSheet();
XSSFDrawing drawing = sheet.createDrawingPatriarch();
byte[] jpegData = "test jpeg data".getBytes();
byte[] jpegData = "test jpeg data".getBytes();
List<XSSFPictureData> pictures = wb.getAllPictures();
assertEquals(0, pictures.size()); List<XSSFPictureData> pictures = wb.getAllPictures();
assertEquals(0, pictures.size());
int jpegIdx = wb.addPicture(jpegData, XSSFWorkbook.PICTURE_TYPE_JPEG);
assertEquals(1, pictures.size()); int jpegIdx = wb.addPicture(jpegData, XSSFWorkbook.PICTURE_TYPE_JPEG);
assertEquals("jpeg", pictures.get(jpegIdx).suggestFileExtension()); assertEquals(1, pictures.size());
assertTrue(Arrays.equals(jpegData, pictures.get(jpegIdx).getData())); 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()); XSSFClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0, 1, 1, 10, 30);
anchor.setAnchorType(ClientAnchor.DONT_MOVE_AND_RESIZE); assertEquals(ClientAnchor.MOVE_AND_RESIZE, anchor.getAnchorType());
assertEquals(ClientAnchor.DONT_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())); XSSFPicture shape = drawing.createPicture(anchor, jpegIdx);
assertNotNull(shape.getPictureData()); assertTrue(anchor.equals(shape.getAnchor()));
assertTrue(Arrays.equals(jpegData, shape.getPictureData().getData())); 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 CTTwoCellAnchor ctShapeHolder = drawing.getCTDrawing().getTwoCellAnchorArray(0);
assertEquals(STEditAs.ABSOLUTE, ctShapeHolder.getEditAs()); // STEditAs.ABSOLUTE corresponds to ClientAnchor.DONT_MOVE_AND_RESIZE
} assertEquals(STEditAs.ABSOLUTE, ctShapeHolder.getEditAs());
} }
}

View File

@ -1,104 +1,105 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership. this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0 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 not use this file except in compliance with
the License. You may obtain a copy of the License at the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.xssf.usermodel;
package org.apache.poi.xssf.usermodel;
import junit.framework.TestCase;
import org.apache.poi.xssf.XSSFTestDataSamples; import junit.framework.TestCase;
import org.apache.poi.POIXMLDocumentPart; import org.apache.poi.xssf.XSSFTestDataSamples;
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTDrawing; import org.apache.poi.POIXMLDocumentPart;
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTDrawing;
import java.util.List;
import java.util.Arrays; import java.util.List;
import java.io.IOException; import java.util.Arrays;
import java.io.IOException;
/**
* @author Yegor Kozlov /**
*/ * @author Yegor Kozlov
public class TestXSSFPictureData extends TestCase { */
public void testRead(){ public final class TestXSSFPictureData extends TestCase {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("WithDrawing.xlsx"); public void testRead(){
List<XSSFPictureData> pictures = wb.getAllPictures(); XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("WithDrawing.xlsx");
//wb.getAllPictures() should return the same instance across multiple calls List<XSSFPictureData> pictures = wb.getAllPictures();
assertSame(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"}; assertEquals(5, pictures.size());
for (int i = 0; i < pictures.size(); i++) { String[] ext = {"jpeg", "emf", "png", "emf", "wmf"};
assertEquals(ext[i], pictures.get(i).suggestFileExtension()); for (int i = 0; i < pictures.size(); i++) {
} assertEquals(ext[i], pictures.get(i).suggestFileExtension());
}
int num = pictures.size();
int num = pictures.size();
byte[] pictureData = {0xA, 0xB, 0XC, 0xD, 0xE, 0xF};
byte[] pictureData = {0xA, 0xB, 0XC, 0xD, 0xE, 0xF};
int idx = wb.addPicture(pictureData, XSSFWorkbook.PICTURE_TYPE_JPEG);
assertEquals(num + 1, pictures.size()); int idx = wb.addPicture(pictureData, XSSFWorkbook.PICTURE_TYPE_JPEG);
//idx is 0-based index in the #pictures array assertEquals(num + 1, pictures.size());
assertEquals(pictures.size() - 1, idx); //idx is 0-based index in the #pictures array
XSSFPictureData pict = pictures.get(idx); assertEquals(pictures.size() - 1, idx);
assertEquals("jpeg", pict.suggestFileExtension()); XSSFPictureData pict = pictures.get(idx);
assertTrue(Arrays.equals(pictureData, pict.getData())); assertEquals("jpeg", pict.suggestFileExtension());
} assertTrue(Arrays.equals(pictureData, pict.getData()));
}
public void testNew(){
XSSFWorkbook wb = new XSSFWorkbook(); public void testNew(){
XSSFSheet sheet = wb.createSheet(); XSSFWorkbook wb = new XSSFWorkbook();
XSSFDrawing drawing = sheet.createDrawingPatriarch(); XSSFSheet sheet = wb.createSheet();
XSSFDrawing drawing = sheet.createDrawingPatriarch();
byte[] jpegData = "test jpeg data".getBytes();
byte[] wmfData = "test wmf data".getBytes(); byte[] jpegData = "test jpeg data".getBytes();
byte[] pngData = "test png data".getBytes(); byte[] wmfData = "test wmf data".getBytes();
byte[] pngData = "test png data".getBytes();
List<XSSFPictureData> pictures = wb.getAllPictures();
assertEquals(0, pictures.size()); List<XSSFPictureData> pictures = wb.getAllPictures();
assertEquals(0, pictures.size());
int jpegIdx = wb.addPicture(jpegData, XSSFWorkbook.PICTURE_TYPE_JPEG);
assertEquals(1, pictures.size()); int jpegIdx = wb.addPicture(jpegData, XSSFWorkbook.PICTURE_TYPE_JPEG);
assertEquals("jpeg", pictures.get(jpegIdx).suggestFileExtension()); assertEquals(1, pictures.size());
assertTrue(Arrays.equals(jpegData, pictures.get(jpegIdx).getData())); 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()); int wmfIdx = wb.addPicture(wmfData, XSSFWorkbook.PICTURE_TYPE_WMF);
assertEquals("wmf", pictures.get(wmfIdx).suggestFileExtension()); assertEquals(2, pictures.size());
assertTrue(Arrays.equals(wmfData, pictures.get(wmfIdx).getData())); 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()); int pngIdx = wb.addPicture(pngData, XSSFWorkbook.PICTURE_TYPE_PNG);
assertEquals("png", pictures.get(pngIdx).suggestFileExtension()); assertEquals(3, pictures.size());
assertTrue(Arrays.equals(pngData, pictures.get(pngIdx).getData())); 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); //TODO finish usermodel API for XSSFPicture
XSSFPicture p2 = drawing.createPicture(new XSSFClientAnchor(), wmfIdx); XSSFPicture p1 = drawing.createPicture(new XSSFClientAnchor(), jpegIdx);
XSSFPicture p3 = drawing.createPicture(new XSSFClientAnchor(), pngIdx); 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); //check that the added pictures are accessible after write
List<XSSFPictureData> pictures2 = wb.getAllPictures(); wb = XSSFTestDataSamples.writeOutAndReadBack(wb);
assertEquals(3, pictures2.size()); List<XSSFPictureData> pictures2 = wb.getAllPictures();
assertEquals(3, pictures2.size());
assertEquals("jpeg", pictures2.get(jpegIdx).suggestFileExtension());
assertTrue(Arrays.equals(jpegData, pictures2.get(jpegIdx).getData())); 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("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())); assertEquals("png", pictures2.get(pngIdx).suggestFileExtension());
assertTrue(Arrays.equals(pngData, pictures2.get(pngIdx).getData()));
}
} }
}

View File

@ -1,134 +1,134 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership. this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0 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 not use this file except in compliance with
the License. You may obtain a copy of the License at the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.xssf.usermodel; package org.apache.poi.xssf.usermodel;
import java.io.*; import java.io.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Comment; import org.apache.poi.ss.usermodel.Comment;
import org.apache.poi.ss.usermodel.CreationHelper; import org.apache.poi.ss.usermodel.CreationHelper;
import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.model.CommentsTable; import org.apache.poi.xssf.model.CommentsTable;
import org.apache.xmlbeans.XmlOptions; import org.apache.xmlbeans.XmlOptions;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.*; import org.openxmlformats.schemas.spreadsheetml.x2006.main.*;
/** /**
* Tests functionality of the XSSFRichTextRun object * Tests functionality of the XSSFRichTextRun object
* *
* @author Yegor Kozlov * @author Yegor Kozlov
*/ */
public class TestXSSFRichTextString extends TestCase { public final class TestXSSFRichTextString extends TestCase {
public void testCreate() throws Exception { public void testCreate() throws Exception {
XSSFRichTextString rt = new XSSFRichTextString("Apache POI"); XSSFRichTextString rt = new XSSFRichTextString("Apache POI");
assertEquals("Apache POI", rt.getString()); assertEquals("Apache POI", rt.getString());
CTRst st = rt.getCTRst(); CTRst st = rt.getCTRst();
assertTrue(st.isSetT()); assertTrue(st.isSetT());
assertEquals("Apache POI", st.getT()); assertEquals("Apache POI", st.getT());
rt.append(" is cool stuff"); rt.append(" is cool stuff");
assertEquals(2, st.sizeOfRArray()); assertEquals(2, st.sizeOfRArray());
assertFalse(st.isSetT()); assertFalse(st.isSetT());
assertEquals("Apache POI is cool stuff", rt.getString()); assertEquals("Apache POI is cool stuff", rt.getString());
} }
public void testApplyFont() throws Exception { public void testApplyFont() throws Exception {
XSSFRichTextString rt = new XSSFRichTextString(); XSSFRichTextString rt = new XSSFRichTextString();
rt.append("123"); rt.append("123");
rt.append("4567"); rt.append("4567");
rt.append("89"); rt.append("89");
XSSFFont font1 = new XSSFFont(); XSSFFont font1 = new XSSFFont();
font1.setBold(true); font1.setBold(true);
rt.applyFont(2, 5, font1); rt.applyFont(2, 5, font1);
assertEquals(5, rt.numFormattingRuns()); assertEquals(5, rt.numFormattingRuns());
assertEquals(0, rt.getIndexOfFormattingRun(0)); assertEquals(0, rt.getIndexOfFormattingRun(0));
assertEquals(2, rt.getLengthOfFormattingRun(0)); assertEquals(2, rt.getLengthOfFormattingRun(0));
assertEquals(2, rt.getIndexOfFormattingRun(1)); assertEquals(2, rt.getIndexOfFormattingRun(1));
assertEquals(3, rt.getLengthOfFormattingRun(1)); assertEquals(3, rt.getLengthOfFormattingRun(1));
assertEquals(5, rt.getIndexOfFormattingRun(2)); assertEquals(5, rt.getIndexOfFormattingRun(2));
assertEquals(3, rt.getLengthOfFormattingRun(2)); assertEquals(3, rt.getLengthOfFormattingRun(2));
assertEquals(8, rt.getIndexOfFormattingRun(3)); assertEquals(8, rt.getIndexOfFormattingRun(3));
assertEquals(1, rt.getLengthOfFormattingRun(3)); assertEquals(1, rt.getLengthOfFormattingRun(3));
} }
public void testClearFormatting() throws Exception { public void testClearFormatting() throws Exception {
XSSFRichTextString rt = new XSSFRichTextString("Apache POI"); XSSFRichTextString rt = new XSSFRichTextString("Apache POI");
assertEquals("Apache POI", rt.getString()); assertEquals("Apache POI", rt.getString());
rt.clearFormatting(); rt.clearFormatting();
CTRst st = rt.getCTRst(); CTRst st = rt.getCTRst();
assertTrue(st.isSetT()); assertTrue(st.isSetT());
assertEquals("Apache POI", rt.getString()); assertEquals("Apache POI", rt.getString());
assertEquals(0, rt.numFormattingRuns()); assertEquals(0, rt.numFormattingRuns());
XSSFFont font = new XSSFFont(); XSSFFont font = new XSSFFont();
font.setBold(true); font.setBold(true);
rt.applyFont(7, 10, font); rt.applyFont(7, 10, font);
assertEquals(2, rt.numFormattingRuns()); assertEquals(2, rt.numFormattingRuns());
rt.clearFormatting(); rt.clearFormatting();
assertEquals("Apache POI", rt.getString()); assertEquals("Apache POI", rt.getString());
assertEquals(0, rt.numFormattingRuns()); assertEquals(0, rt.numFormattingRuns());
} }
public void testGetFonts() throws Exception { public void testGetFonts() throws Exception {
XSSFRichTextString rt = new XSSFRichTextString(); XSSFRichTextString rt = new XSSFRichTextString();
XSSFFont font1 = new XSSFFont(); XSSFFont font1 = new XSSFFont();
font1.setFontName("Arial"); font1.setFontName("Arial");
font1.setItalic(true); font1.setItalic(true);
rt.append("The quick", font1); rt.append("The quick", font1);
XSSFFont font1$ = rt.getFontOfFormattingRun(0); XSSFFont font1$ = rt.getFontOfFormattingRun(0);
assertEquals(font1.getItalic(), font1$.getItalic()); assertEquals(font1.getItalic(), font1$.getItalic());
assertEquals(font1.getFontName(), font1$.getFontName()); assertEquals(font1.getFontName(), font1$.getFontName());
XSSFFont font2 = new XSSFFont(); XSSFFont font2 = new XSSFFont();
font2.setFontName("Courier"); font2.setFontName("Courier");
font2.setBold(true); font2.setBold(true);
rt.append(" brown fox", font2); rt.append(" brown fox", font2);
XSSFFont font2$ = rt.getFontOfFormattingRun(1); XSSFFont font2$ = rt.getFontOfFormattingRun(1);
assertEquals(font2.getBold(), font2$.getBold()); assertEquals(font2.getBold(), font2$.getBold());
assertEquals(font2.getFontName(), font2$.getFontName()); assertEquals(font2.getFontName(), font2$.getFontName());
} }
} }