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
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;
}
}
/* ====================================================================
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;
}
}

View File

@ -1,117 +1,117 @@
/* ====================================================================
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 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]
+ "' !");
}
}
}
/* ====================================================================
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]
+ "' !");
}
}
}

View File

@ -1,55 +1,56 @@
/* ====================================================================
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 class TestFileHelper extends TestCase {
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));
/*
* YK: The original version asserted expected values against File#getAbsolutePath():
* assertTrue(expectedValue.get(filename).equalsIgnoreCase(
* FileHelper.getDirectory(new File(filename))
* .getAbsolutePath()));
*
* This comparison is platform dependent and resulted in build errors in Gump since 21/02/2009.
* Assertion via File#equals(File otherFile) is a better approach.
*/
assertTrue(f1.equals(f2));
}
}
}
/* ====================================================================
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));
}
}
}

View File

@ -1,35 +1,36 @@
/* ====================================================================
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 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());
}
}
/* ====================================================================
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());
}
}

View File

@ -1,33 +1,33 @@
/* ====================================================================
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 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;
}
}
/* ====================================================================
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;
}
}

View File

@ -1,30 +1,30 @@
/* ====================================================================
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 class AllOpenXML4JInternalTests {
public static Test suite() {
TestSuite suite = new TestSuite(AllOpenXML4JInternalTests.class.getName());
suite.addTestSuite(TestContentTypeManager.class);
return suite;
}
}
/* ====================================================================
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;
}
}

View File

@ -1,116 +1,116 @@
/* ====================================================================
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 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
}
}
/* ====================================================================
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
}
}

View File

@ -1,59 +1,62 @@
/* ====================================================================
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(){}
private static XSSFITestDataProvider inst = new XSSFITestDataProvider();
public static XSSFITestDataProvider getInstance(){
return inst;
}
}
/* ====================================================================
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;
}
}

View File

@ -1,131 +1,128 @@
/* ====================================================================
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.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
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 egain
idx = sst.addEntry(st);
assertEquals(0, idx);
assertEquals(2, sst.getCount());
assertEquals(1, sst.getUniqueCount());
//and egain
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 egain
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());
}
}
}
/* ====================================================================
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());
}
}
}

View File

@ -1,99 +1,100 @@
/* ====================================================================
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 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));
}
}
/* ====================================================================
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));
}
}

View File

@ -1,62 +1,63 @@
/* ====================================================================
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 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();
}
}
/* ====================================================================
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();
}
}

View File

@ -1,76 +1,77 @@
/* ====================================================================
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 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);
}
}
/* ====================================================================
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);
}
}

View File

@ -1,73 +1,74 @@
/* ====================================================================
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 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());
}
}
/* ====================================================================
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());
}
}

View File

@ -1,104 +1,105 @@
/* ====================================================================
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 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()));
}
}
/* ====================================================================
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()));
}
}

View File

@ -1,134 +1,134 @@
/* ====================================================================
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 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());
}
}
/* ====================================================================
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());
}
}