Changed CRLF to LF in .java test files. Minor reformatting and compiler warning fixes
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@776056 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b924e3f4c8
commit
e6a53dc85b
@ -1,156 +1,155 @@
|
||||
|
||||
/* ====================================================================
|
||||
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.ddf;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.poi.util.HexRead;
|
||||
import org.apache.poi.util.HexDump;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.util.Iterator;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Test read/serialize of escher blip records
|
||||
*
|
||||
* @author Yegor Kozlov
|
||||
*/
|
||||
public class TestEscherBlipRecord extends TestCase
|
||||
{
|
||||
protected String cwd = System.getProperty("DDF.testdata.path");
|
||||
|
||||
//test reading/serializing of a PNG blip
|
||||
public void testReadPNG() throws IOException {
|
||||
//provided in bug-44886
|
||||
byte[] data = read(new File(cwd, "Container.dat"));
|
||||
|
||||
EscherContainerRecord record = new EscherContainerRecord();
|
||||
record.fillFields(data, 0, new DefaultEscherRecordFactory());
|
||||
EscherContainerRecord bstore = (EscherContainerRecord)record.getChild(1);
|
||||
EscherBSERecord bse1 = (EscherBSERecord)bstore.getChild(0);
|
||||
assertEquals(EscherBSERecord.BT_PNG, bse1.getBlipTypeWin32());
|
||||
assertEquals(EscherBSERecord.BT_PNG, bse1.getBlipTypeMacOS());
|
||||
assertTrue(Arrays.equals(new byte[]{
|
||||
0x65, 0x07, 0x4A, (byte)0x8D, 0x3E, 0x42, (byte)0x8B, (byte)0xAC,
|
||||
0x1D, (byte)0x89, 0x35, 0x4F, 0x48, (byte)0xFA, 0x37, (byte)0xC2
|
||||
}, bse1.getUid()));
|
||||
assertEquals(255, bse1.getTag());
|
||||
assertEquals(32308, bse1.getSize());
|
||||
|
||||
EscherBitmapBlip blip1 = (EscherBitmapBlip)bse1.getBlipRecord();
|
||||
assertEquals(0x6E00, blip1.getOptions());
|
||||
assertEquals(EscherBitmapBlip.RECORD_ID_PNG, blip1.getRecordId());
|
||||
assertTrue(Arrays.equals(new byte[]{
|
||||
0x65, 0x07, 0x4A, (byte)0x8D, 0x3E, 0x42, (byte)0x8B, (byte)0xAC,
|
||||
0x1D, (byte)0x89, 0x35, 0x4F, 0x48, (byte)0xFA, 0x37, (byte)0xC2
|
||||
}, blip1.getUID()));
|
||||
|
||||
//serialize and read again
|
||||
byte[] ser = bse1.serialize();
|
||||
EscherBSERecord bse2 = new EscherBSERecord();
|
||||
bse2.fillFields(ser, 0, new DefaultEscherRecordFactory());
|
||||
assertEquals(bse1.getRecordId(), bse2.getRecordId());
|
||||
assertEquals(bse1.getBlipTypeWin32(), bse2.getBlipTypeWin32());
|
||||
assertEquals(bse1.getBlipTypeMacOS(), bse2.getBlipTypeMacOS());
|
||||
assertTrue(Arrays.equals(bse1.getUid(), bse2.getUid()));
|
||||
assertEquals(bse1.getTag(), bse2.getTag());
|
||||
assertEquals(bse1.getSize(), bse2.getSize());
|
||||
|
||||
EscherBitmapBlip blip2 = (EscherBitmapBlip)bse1.getBlipRecord();
|
||||
assertEquals(blip1.getOptions(), blip2.getOptions());
|
||||
assertEquals(blip1.getRecordId(), blip2.getRecordId());
|
||||
assertEquals(blip1.getUID(), blip2.getUID());
|
||||
|
||||
assertTrue(Arrays.equals(blip1.getPicturedata(), blip1.getPicturedata()));
|
||||
}
|
||||
|
||||
//test reading/serializing of a PICT metafile
|
||||
public void testReadPICT() throws IOException {
|
||||
//provided in bug-44886
|
||||
byte[] data = read(new File(cwd, "Container.dat"));
|
||||
|
||||
EscherContainerRecord record = new EscherContainerRecord();
|
||||
record.fillFields(data, 0, new DefaultEscherRecordFactory());
|
||||
EscherContainerRecord bstore = (EscherContainerRecord)record.getChild(1);
|
||||
EscherBSERecord bse1 = (EscherBSERecord)bstore.getChild(1);
|
||||
//System.out.println(bse1);
|
||||
assertEquals(EscherBSERecord.BT_WMF, bse1.getBlipTypeWin32());
|
||||
assertEquals(EscherBSERecord.BT_PICT, bse1.getBlipTypeMacOS());
|
||||
assertTrue(Arrays.equals(new byte[]{
|
||||
(byte)0xC7, 0x15, 0x69, 0x2D, (byte)0xE5, (byte)0x89, (byte)0xA3, 0x6F,
|
||||
0x66, 0x03, (byte)0xD6, 0x24, (byte)0xF7, (byte)0xDB, 0x1D, 0x13
|
||||
}, bse1.getUid()));
|
||||
assertEquals(255, bse1.getTag());
|
||||
assertEquals(1133, bse1.getSize());
|
||||
|
||||
EscherMetafileBlip blip1 = (EscherMetafileBlip)bse1.getBlipRecord();
|
||||
assertEquals(0x5430, blip1.getOptions());
|
||||
assertEquals(EscherMetafileBlip.RECORD_ID_PICT, blip1.getRecordId());
|
||||
assertTrue(Arrays.equals(new byte[]{
|
||||
0x57, 0x32, 0x7B, (byte)0x91, 0x23, 0x5D, (byte)0xDB, 0x36,
|
||||
0x7A, (byte)0xDB, (byte)0xFF, 0x17, (byte)0xFE, (byte)0xF3, (byte)0xA7, 0x05
|
||||
}, blip1.getUID()));
|
||||
assertTrue(Arrays.equals(new byte[]{
|
||||
(byte)0xC7, 0x15, 0x69, 0x2D, (byte)0xE5, (byte)0x89, (byte)0xA3, 0x6F,
|
||||
0x66, 0x03, (byte)0xD6, 0x24, (byte)0xF7, (byte)0xDB, 0x1D, 0x13
|
||||
}, blip1.getPrimaryUID()));
|
||||
|
||||
//serialize and read again
|
||||
byte[] ser = bse1.serialize();
|
||||
EscherBSERecord bse2 = new EscherBSERecord();
|
||||
bse2.fillFields(ser, 0, new DefaultEscherRecordFactory());
|
||||
assertEquals(bse1.getRecordId(), bse2.getRecordId());
|
||||
assertEquals(bse1.getOptions(), bse2.getOptions());
|
||||
assertEquals(bse1.getBlipTypeWin32(), bse2.getBlipTypeWin32());
|
||||
assertEquals(bse1.getBlipTypeMacOS(), bse2.getBlipTypeMacOS());
|
||||
assertTrue(Arrays.equals(bse1.getUid(), bse2.getUid()));
|
||||
assertEquals(bse1.getTag(), bse2.getTag());
|
||||
assertEquals(bse1.getSize(), bse2.getSize());
|
||||
|
||||
EscherMetafileBlip blip2 = (EscherMetafileBlip)bse1.getBlipRecord();
|
||||
assertEquals(blip1.getOptions(), blip2.getOptions());
|
||||
assertEquals(blip1.getRecordId(), blip2.getRecordId());
|
||||
assertEquals(blip1.getUID(), blip2.getUID());
|
||||
assertEquals(blip1.getPrimaryUID(), blip2.getPrimaryUID());
|
||||
|
||||
assertTrue(Arrays.equals(blip1.getPicturedata(), blip1.getPicturedata()));
|
||||
}
|
||||
|
||||
//integral test: check that the read-write-read round trip is consistent
|
||||
public void testContainer() throws IOException {
|
||||
byte[] data = read(new File(cwd, "Container.dat"));
|
||||
|
||||
EscherContainerRecord record = new EscherContainerRecord();
|
||||
record.fillFields(data, 0, new DefaultEscherRecordFactory());
|
||||
|
||||
byte[] ser = record.serialize();
|
||||
assertTrue(Arrays.equals(data, ser));
|
||||
}
|
||||
|
||||
private byte[] read(File file) throws IOException {
|
||||
byte[] data = new byte[(int)file.length()];
|
||||
FileInputStream is = new FileInputStream(file);
|
||||
is.read(data);
|
||||
is.close();
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
||||
/* ====================================================================
|
||||
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.ddf;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Test read/serialize of escher blip records
|
||||
*
|
||||
* @author Yegor Kozlov
|
||||
*/
|
||||
public final class TestEscherBlipRecord extends TestCase {
|
||||
protected String cwd = System.getProperty("DDF.testdata.path");
|
||||
|
||||
//test reading/serializing of a PNG blip
|
||||
public void testReadPNG() {
|
||||
//provided in bug-44886
|
||||
byte[] data = read(new File(cwd, "Container.dat"));
|
||||
|
||||
EscherContainerRecord record = new EscherContainerRecord();
|
||||
record.fillFields(data, 0, new DefaultEscherRecordFactory());
|
||||
EscherContainerRecord bstore = (EscherContainerRecord)record.getChild(1);
|
||||
EscherBSERecord bse1 = (EscherBSERecord)bstore.getChild(0);
|
||||
assertEquals(EscherBSERecord.BT_PNG, bse1.getBlipTypeWin32());
|
||||
assertEquals(EscherBSERecord.BT_PNG, bse1.getBlipTypeMacOS());
|
||||
assertTrue(Arrays.equals(new byte[]{
|
||||
0x65, 0x07, 0x4A, (byte)0x8D, 0x3E, 0x42, (byte)0x8B, (byte)0xAC,
|
||||
0x1D, (byte)0x89, 0x35, 0x4F, 0x48, (byte)0xFA, 0x37, (byte)0xC2
|
||||
}, bse1.getUid()));
|
||||
assertEquals(255, bse1.getTag());
|
||||
assertEquals(32308, bse1.getSize());
|
||||
|
||||
EscherBitmapBlip blip1 = (EscherBitmapBlip)bse1.getBlipRecord();
|
||||
assertEquals(0x6E00, blip1.getOptions());
|
||||
assertEquals(EscherBitmapBlip.RECORD_ID_PNG, blip1.getRecordId());
|
||||
assertTrue(Arrays.equals(new byte[]{
|
||||
0x65, 0x07, 0x4A, (byte)0x8D, 0x3E, 0x42, (byte)0x8B, (byte)0xAC,
|
||||
0x1D, (byte)0x89, 0x35, 0x4F, 0x48, (byte)0xFA, 0x37, (byte)0xC2
|
||||
}, blip1.getUID()));
|
||||
|
||||
//serialize and read again
|
||||
byte[] ser = bse1.serialize();
|
||||
EscherBSERecord bse2 = new EscherBSERecord();
|
||||
bse2.fillFields(ser, 0, new DefaultEscherRecordFactory());
|
||||
assertEquals(bse1.getRecordId(), bse2.getRecordId());
|
||||
assertEquals(bse1.getBlipTypeWin32(), bse2.getBlipTypeWin32());
|
||||
assertEquals(bse1.getBlipTypeMacOS(), bse2.getBlipTypeMacOS());
|
||||
assertTrue(Arrays.equals(bse1.getUid(), bse2.getUid()));
|
||||
assertEquals(bse1.getTag(), bse2.getTag());
|
||||
assertEquals(bse1.getSize(), bse2.getSize());
|
||||
|
||||
EscherBitmapBlip blip2 = (EscherBitmapBlip)bse1.getBlipRecord();
|
||||
assertEquals(blip1.getOptions(), blip2.getOptions());
|
||||
assertEquals(blip1.getRecordId(), blip2.getRecordId());
|
||||
assertEquals(blip1.getUID(), blip2.getUID());
|
||||
|
||||
assertTrue(Arrays.equals(blip1.getPicturedata(), blip1.getPicturedata()));
|
||||
}
|
||||
|
||||
//test reading/serializing of a PICT metafile
|
||||
public void testReadPICT() {
|
||||
//provided in bug-44886
|
||||
byte[] data = read(new File(cwd, "Container.dat"));
|
||||
|
||||
EscherContainerRecord record = new EscherContainerRecord();
|
||||
record.fillFields(data, 0, new DefaultEscherRecordFactory());
|
||||
EscherContainerRecord bstore = (EscherContainerRecord)record.getChild(1);
|
||||
EscherBSERecord bse1 = (EscherBSERecord)bstore.getChild(1);
|
||||
//System.out.println(bse1);
|
||||
assertEquals(EscherBSERecord.BT_WMF, bse1.getBlipTypeWin32());
|
||||
assertEquals(EscherBSERecord.BT_PICT, bse1.getBlipTypeMacOS());
|
||||
assertTrue(Arrays.equals(new byte[]{
|
||||
(byte)0xC7, 0x15, 0x69, 0x2D, (byte)0xE5, (byte)0x89, (byte)0xA3, 0x6F,
|
||||
0x66, 0x03, (byte)0xD6, 0x24, (byte)0xF7, (byte)0xDB, 0x1D, 0x13
|
||||
}, bse1.getUid()));
|
||||
assertEquals(255, bse1.getTag());
|
||||
assertEquals(1133, bse1.getSize());
|
||||
|
||||
EscherMetafileBlip blip1 = (EscherMetafileBlip)bse1.getBlipRecord();
|
||||
assertEquals(0x5430, blip1.getOptions());
|
||||
assertEquals(EscherMetafileBlip.RECORD_ID_PICT, blip1.getRecordId());
|
||||
assertTrue(Arrays.equals(new byte[]{
|
||||
0x57, 0x32, 0x7B, (byte)0x91, 0x23, 0x5D, (byte)0xDB, 0x36,
|
||||
0x7A, (byte)0xDB, (byte)0xFF, 0x17, (byte)0xFE, (byte)0xF3, (byte)0xA7, 0x05
|
||||
}, blip1.getUID()));
|
||||
assertTrue(Arrays.equals(new byte[]{
|
||||
(byte)0xC7, 0x15, 0x69, 0x2D, (byte)0xE5, (byte)0x89, (byte)0xA3, 0x6F,
|
||||
0x66, 0x03, (byte)0xD6, 0x24, (byte)0xF7, (byte)0xDB, 0x1D, 0x13
|
||||
}, blip1.getPrimaryUID()));
|
||||
|
||||
//serialize and read again
|
||||
byte[] ser = bse1.serialize();
|
||||
EscherBSERecord bse2 = new EscherBSERecord();
|
||||
bse2.fillFields(ser, 0, new DefaultEscherRecordFactory());
|
||||
assertEquals(bse1.getRecordId(), bse2.getRecordId());
|
||||
assertEquals(bse1.getOptions(), bse2.getOptions());
|
||||
assertEquals(bse1.getBlipTypeWin32(), bse2.getBlipTypeWin32());
|
||||
assertEquals(bse1.getBlipTypeMacOS(), bse2.getBlipTypeMacOS());
|
||||
assertTrue(Arrays.equals(bse1.getUid(), bse2.getUid()));
|
||||
assertEquals(bse1.getTag(), bse2.getTag());
|
||||
assertEquals(bse1.getSize(), bse2.getSize());
|
||||
|
||||
EscherMetafileBlip blip2 = (EscherMetafileBlip)bse1.getBlipRecord();
|
||||
assertEquals(blip1.getOptions(), blip2.getOptions());
|
||||
assertEquals(blip1.getRecordId(), blip2.getRecordId());
|
||||
assertEquals(blip1.getUID(), blip2.getUID());
|
||||
assertEquals(blip1.getPrimaryUID(), blip2.getPrimaryUID());
|
||||
|
||||
assertTrue(Arrays.equals(blip1.getPicturedata(), blip1.getPicturedata()));
|
||||
}
|
||||
|
||||
//integral test: check that the read-write-read round trip is consistent
|
||||
public void testContainer() {
|
||||
byte[] data = read(new File(cwd, "Container.dat"));
|
||||
|
||||
EscherContainerRecord record = new EscherContainerRecord();
|
||||
record.fillFields(data, 0, new DefaultEscherRecordFactory());
|
||||
|
||||
byte[] ser = record.serialize();
|
||||
assertTrue(Arrays.equals(data, ser));
|
||||
}
|
||||
|
||||
private byte[] read(File file) {
|
||||
byte[] data = new byte[(int)file.length()];
|
||||
try {
|
||||
FileInputStream is = new FileInputStream(file);
|
||||
is.read(data);
|
||||
is.close();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,59 +1,59 @@
|
||||
/* ====================================================================
|
||||
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.hssf;
|
||||
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.ss.ITestDataProvider;
|
||||
import org.apache.poi.ss.SpreadsheetVersion;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
|
||||
/**
|
||||
* @author Yegor Kozlov
|
||||
*/
|
||||
public final class HSSFITestDataProvider implements ITestDataProvider {
|
||||
|
||||
public HSSFWorkbook openSampleWorkbook(String sampleFileName) {
|
||||
return HSSFTestDataSamples.openSampleWorkbook(sampleFileName);
|
||||
}
|
||||
|
||||
public HSSFWorkbook writeOutAndReadBack(Workbook original) {
|
||||
if(!(original instanceof HSSFWorkbook)) {
|
||||
throw new IllegalArgumentException("Expected an instance of HSSFWorkbook");
|
||||
}
|
||||
|
||||
return HSSFTestDataSamples.writeOutAndReadBack((HSSFWorkbook)original);
|
||||
}
|
||||
|
||||
public HSSFWorkbook createWorkbook(){
|
||||
return new HSSFWorkbook();
|
||||
}
|
||||
|
||||
public byte[] getTestDataFileContent(String fileName) {
|
||||
return HSSFTestDataSamples.getTestDataFileContent(fileName);
|
||||
}
|
||||
|
||||
public SpreadsheetVersion getSpreadsheetVersion(){
|
||||
return SpreadsheetVersion.EXCEL97;
|
||||
}
|
||||
|
||||
private HSSFITestDataProvider(){}
|
||||
private static HSSFITestDataProvider inst = new HSSFITestDataProvider();
|
||||
public static HSSFITestDataProvider 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.hssf;
|
||||
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.ss.ITestDataProvider;
|
||||
import org.apache.poi.ss.SpreadsheetVersion;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
|
||||
/**
|
||||
* @author Yegor Kozlov
|
||||
*/
|
||||
public final class HSSFITestDataProvider implements ITestDataProvider {
|
||||
|
||||
public HSSFWorkbook openSampleWorkbook(String sampleFileName) {
|
||||
return HSSFTestDataSamples.openSampleWorkbook(sampleFileName);
|
||||
}
|
||||
|
||||
public HSSFWorkbook writeOutAndReadBack(Workbook original) {
|
||||
if(!(original instanceof HSSFWorkbook)) {
|
||||
throw new IllegalArgumentException("Expected an instance of HSSFWorkbook");
|
||||
}
|
||||
|
||||
return HSSFTestDataSamples.writeOutAndReadBack((HSSFWorkbook)original);
|
||||
}
|
||||
|
||||
public HSSFWorkbook createWorkbook(){
|
||||
return new HSSFWorkbook();
|
||||
}
|
||||
|
||||
public byte[] getTestDataFileContent(String fileName) {
|
||||
return HSSFTestDataSamples.getTestDataFileContent(fileName);
|
||||
}
|
||||
|
||||
public SpreadsheetVersion getSpreadsheetVersion(){
|
||||
return SpreadsheetVersion.EXCEL97;
|
||||
}
|
||||
|
||||
private HSSFITestDataProvider(){}
|
||||
private static HSSFITestDataProvider inst = new HSSFITestDataProvider();
|
||||
public static HSSFITestDataProvider getInstance(){
|
||||
return inst;
|
||||
}
|
||||
}
|
||||
|
@ -1,199 +1,198 @@
|
||||
/* ====================================================================
|
||||
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.hssf;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
|
||||
/**
|
||||
* Centralises logic for finding/opening sample files in the src/testcases/org/apache/poi/hssf/hssf/data folder.
|
||||
*
|
||||
* @author Josh Micich
|
||||
*/
|
||||
public final class HSSFTestDataSamples {
|
||||
|
||||
private static final String TEST_DATA_DIR_SYS_PROPERTY_NAME = "HSSF.testdata.path";
|
||||
|
||||
private static boolean _isInitialised;
|
||||
private static File _resolvedDataDir;
|
||||
/** <code>true</code> if standard system propery is not set,
|
||||
* but the data is available on the test runtime classpath */
|
||||
private static boolean _sampleDataIsAvaliableOnClassPath;
|
||||
|
||||
/**
|
||||
* Opens a sample file from the standard HSSF test data directory
|
||||
*
|
||||
* @return an open <tt>InputStream</tt> for the specified sample file
|
||||
*/
|
||||
public static InputStream openSampleFileStream(String sampleFileName) {
|
||||
|
||||
if(!_isInitialised) {
|
||||
try {
|
||||
initialise();
|
||||
} finally {
|
||||
_isInitialised = true;
|
||||
}
|
||||
}
|
||||
if (_sampleDataIsAvaliableOnClassPath) {
|
||||
InputStream result = openClasspathResource(sampleFileName);
|
||||
if(result == null) {
|
||||
throw new RuntimeException("specified test sample file '" + sampleFileName
|
||||
+ "' not found on the classpath");
|
||||
}
|
||||
// System.out.println("opening cp: " + sampleFileName);
|
||||
// wrap to avoid temp warning method about auto-closing input stream
|
||||
return new NonSeekableInputStream(result);
|
||||
}
|
||||
if (_resolvedDataDir == null) {
|
||||
throw new RuntimeException("Must set system property '"
|
||||
+ TEST_DATA_DIR_SYS_PROPERTY_NAME
|
||||
+ "' properly before running tests");
|
||||
}
|
||||
|
||||
File f = new File(_resolvedDataDir, sampleFileName);
|
||||
if (!f.exists()) {
|
||||
throw new RuntimeException("Sample file '" + sampleFileName
|
||||
+ "' not found in data dir '" + _resolvedDataDir.getAbsolutePath() + "'");
|
||||
}
|
||||
// System.out.println("opening " + f.getAbsolutePath());
|
||||
try {
|
||||
return new FileInputStream(f);
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static void initialise() {
|
||||
String dataDirName = System.getProperty(TEST_DATA_DIR_SYS_PROPERTY_NAME);
|
||||
if (dataDirName == null) {
|
||||
// check to see if we can just get the resources from the classpath
|
||||
InputStream is = openClasspathResource("SampleSS.xls");
|
||||
if(is != null) {
|
||||
try {
|
||||
is.close(); // be nice
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
_sampleDataIsAvaliableOnClassPath = true;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
throw new RuntimeException("Must set system property '"
|
||||
+ TEST_DATA_DIR_SYS_PROPERTY_NAME
|
||||
+ "' before running tests");
|
||||
}
|
||||
File dataDir = new File(dataDirName);
|
||||
if (!dataDir.exists()) {
|
||||
throw new RuntimeException("Data dir '" + dataDirName
|
||||
+ "' specified by system property '"
|
||||
+ TEST_DATA_DIR_SYS_PROPERTY_NAME + "' does not exist");
|
||||
}
|
||||
// convert to canonical file, to make any subsequent error messages clearer.
|
||||
try {
|
||||
_resolvedDataDir = dataDir.getCanonicalFile();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens a test sample file from the 'data' sub-package of this class's package.
|
||||
* @return <code>null</code> if the sample file is not deployed on the classpath.
|
||||
*/
|
||||
private static InputStream openClasspathResource(String sampleFileName) {
|
||||
return HSSFTestDataSamples.class.getResourceAsStream("data/" + sampleFileName);
|
||||
}
|
||||
|
||||
private static final class NonSeekableInputStream extends InputStream {
|
||||
|
||||
private final InputStream _is;
|
||||
|
||||
public NonSeekableInputStream(InputStream is) {
|
||||
_is = is;
|
||||
}
|
||||
|
||||
public int read() throws IOException {
|
||||
return _is.read();
|
||||
}
|
||||
public int read(byte[] b, int off, int len) throws IOException {
|
||||
return _is.read(b, off, len);
|
||||
}
|
||||
public boolean markSupported() {
|
||||
return false;
|
||||
}
|
||||
public void close() throws IOException {
|
||||
_is.close();
|
||||
}
|
||||
}
|
||||
|
||||
public static HSSFWorkbook openSampleWorkbook(String sampleFileName) {
|
||||
try {
|
||||
return new HSSFWorkbook(openSampleFileStream(sampleFileName));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Writes a spreadsheet to a <tt>ByteArrayOutputStream</tt> and reads it back
|
||||
* from a <tt>ByteArrayInputStream</tt>.<p/>
|
||||
* Useful for verifying that the serialisation round trip
|
||||
*/
|
||||
public static HSSFWorkbook writeOutAndReadBack(HSSFWorkbook original) {
|
||||
|
||||
try {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
|
||||
original.write(baos);
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
|
||||
return new HSSFWorkbook(bais);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return byte array of sample file content from file found in standard hssf test data dir
|
||||
*/
|
||||
public static byte[] getTestDataFileContent(String fileName) {
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
|
||||
try {
|
||||
InputStream fis = HSSFTestDataSamples.openSampleFileStream(fileName);
|
||||
|
||||
byte[] buf = new byte[512];
|
||||
while (true) {
|
||||
int bytesRead = fis.read(buf);
|
||||
if (bytesRead < 1) {
|
||||
break;
|
||||
}
|
||||
bos.write(buf, 0, bytesRead);
|
||||
}
|
||||
fis.close();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return bos.toByteArray();
|
||||
}
|
||||
}
|
||||
/* ====================================================================
|
||||
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.hssf;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
|
||||
/**
|
||||
* Centralises logic for finding/opening sample files in the src/testcases/org/apache/poi/hssf/hssf/data folder.
|
||||
*
|
||||
* @author Josh Micich
|
||||
*/
|
||||
public final class HSSFTestDataSamples {
|
||||
|
||||
private static final String TEST_DATA_DIR_SYS_PROPERTY_NAME = "HSSF.testdata.path";
|
||||
|
||||
private static boolean _isInitialised;
|
||||
private static File _resolvedDataDir;
|
||||
/** <code>true</code> if standard system propery is not set,
|
||||
* but the data is available on the test runtime classpath */
|
||||
private static boolean _sampleDataIsAvaliableOnClassPath;
|
||||
|
||||
/**
|
||||
* Opens a sample file from the standard HSSF test data directory
|
||||
*
|
||||
* @return an open <tt>InputStream</tt> for the specified sample file
|
||||
*/
|
||||
public static InputStream openSampleFileStream(String sampleFileName) {
|
||||
|
||||
if(!_isInitialised) {
|
||||
try {
|
||||
initialise();
|
||||
} finally {
|
||||
_isInitialised = true;
|
||||
}
|
||||
}
|
||||
if (_sampleDataIsAvaliableOnClassPath) {
|
||||
InputStream result = openClasspathResource(sampleFileName);
|
||||
if(result == null) {
|
||||
throw new RuntimeException("specified test sample file '" + sampleFileName
|
||||
+ "' not found on the classpath");
|
||||
}
|
||||
// System.out.println("opening cp: " + sampleFileName);
|
||||
// wrap to avoid temp warning method about auto-closing input stream
|
||||
return new NonSeekableInputStream(result);
|
||||
}
|
||||
if (_resolvedDataDir == null) {
|
||||
throw new RuntimeException("Must set system property '"
|
||||
+ TEST_DATA_DIR_SYS_PROPERTY_NAME
|
||||
+ "' properly before running tests");
|
||||
}
|
||||
|
||||
File f = new File(_resolvedDataDir, sampleFileName);
|
||||
if (!f.exists()) {
|
||||
throw new RuntimeException("Sample file '" + sampleFileName
|
||||
+ "' not found in data dir '" + _resolvedDataDir.getAbsolutePath() + "'");
|
||||
}
|
||||
// System.out.println("opening " + f.getAbsolutePath());
|
||||
try {
|
||||
return new FileInputStream(f);
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static void initialise() {
|
||||
String dataDirName = System.getProperty(TEST_DATA_DIR_SYS_PROPERTY_NAME);
|
||||
if (dataDirName == null) {
|
||||
// check to see if we can just get the resources from the classpath
|
||||
InputStream is = openClasspathResource("SampleSS.xls");
|
||||
if (is != null) {
|
||||
try {
|
||||
is.close(); // be nice
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
_sampleDataIsAvaliableOnClassPath = true;
|
||||
return;
|
||||
}
|
||||
|
||||
throw new RuntimeException("Must set system property '"
|
||||
+ TEST_DATA_DIR_SYS_PROPERTY_NAME + "' before running tests");
|
||||
}
|
||||
File dataDir = new File(dataDirName);
|
||||
if (!dataDir.exists()) {
|
||||
throw new RuntimeException("Data dir '" + dataDirName
|
||||
+ "' specified by system property '" + TEST_DATA_DIR_SYS_PROPERTY_NAME
|
||||
+ "' does not exist");
|
||||
}
|
||||
// convert to canonical file, to make any subsequent error messages
|
||||
// clearer.
|
||||
try {
|
||||
_resolvedDataDir = dataDir.getCanonicalFile();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens a test sample file from the 'data' sub-package of this class's package.
|
||||
* @return <code>null</code> if the sample file is not deployed on the classpath.
|
||||
*/
|
||||
private static InputStream openClasspathResource(String sampleFileName) {
|
||||
return HSSFTestDataSamples.class.getResourceAsStream("data/" + sampleFileName);
|
||||
}
|
||||
|
||||
private static final class NonSeekableInputStream extends InputStream {
|
||||
|
||||
private final InputStream _is;
|
||||
|
||||
public NonSeekableInputStream(InputStream is) {
|
||||
_is = is;
|
||||
}
|
||||
|
||||
public int read() throws IOException {
|
||||
return _is.read();
|
||||
}
|
||||
public int read(byte[] b, int off, int len) throws IOException {
|
||||
return _is.read(b, off, len);
|
||||
}
|
||||
public boolean markSupported() {
|
||||
return false;
|
||||
}
|
||||
public void close() throws IOException {
|
||||
_is.close();
|
||||
}
|
||||
}
|
||||
|
||||
public static HSSFWorkbook openSampleWorkbook(String sampleFileName) {
|
||||
try {
|
||||
return new HSSFWorkbook(openSampleFileStream(sampleFileName));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Writes a spreadsheet to a <tt>ByteArrayOutputStream</tt> and reads it back
|
||||
* from a <tt>ByteArrayInputStream</tt>.<p/>
|
||||
* Useful for verifying that the serialisation round trip
|
||||
*/
|
||||
public static HSSFWorkbook writeOutAndReadBack(HSSFWorkbook original) {
|
||||
|
||||
try {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
|
||||
original.write(baos);
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
|
||||
return new HSSFWorkbook(bais);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return byte array of sample file content from file found in standard hssf test data dir
|
||||
*/
|
||||
public static byte[] getTestDataFileContent(String fileName) {
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
|
||||
try {
|
||||
InputStream fis = HSSFTestDataSamples.openSampleFileStream(fileName);
|
||||
|
||||
byte[] buf = new byte[512];
|
||||
while (true) {
|
||||
int bytesRead = fis.read(buf);
|
||||
if (bytesRead < 1) {
|
||||
break;
|
||||
}
|
||||
bos.write(buf, 0, bytesRead);
|
||||
}
|
||||
fis.close();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return bos.toByteArray();
|
||||
}
|
||||
}
|
||||
|
@ -1,60 +1,61 @@
|
||||
/* ====================================================================
|
||||
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.hssf.model;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import junit.framework.AssertionFailedError;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.poi.hssf.record.NumberRecord;
|
||||
import org.apache.poi.hssf.record.Record;
|
||||
import org.apache.poi.hssf.record.RowRecord;
|
||||
import org.apache.poi.hssf.record.UnknownRecord;
|
||||
import org.apache.poi.hssf.record.WindowTwoRecord;
|
||||
|
||||
/**
|
||||
* Tests for {@link RowBlocksReader}
|
||||
*
|
||||
* @author Josh Micich
|
||||
*/
|
||||
public final class TestRowBlocksReader extends TestCase {
|
||||
public void testAbnormalPivotTableRecords_bug46280() {
|
||||
int SXVIEW_SID = 0x00B0;
|
||||
Record[] inRecs = {
|
||||
new RowRecord(0),
|
||||
new NumberRecord(),
|
||||
// normally MSODRAWING(0x00EC) would come here before SXVIEW
|
||||
new UnknownRecord(SXVIEW_SID, "dummydata (SXVIEW: View Definition)".getBytes()),
|
||||
new WindowTwoRecord(),
|
||||
};
|
||||
RecordStream rs = new RecordStream(Arrays.asList(inRecs), 0);
|
||||
RowBlocksReader rbr = new RowBlocksReader(rs);
|
||||
if (rs.peekNextClass() == WindowTwoRecord.class) {
|
||||
// Should have stopped at the SXVIEW record
|
||||
throw new AssertionFailedError("Identified bug 46280b");
|
||||
}
|
||||
RecordStream rbStream = rbr.getPlainRecordStream();
|
||||
assertEquals(inRecs[0], rbStream.getNext());
|
||||
assertEquals(inRecs[1], rbStream.getNext());
|
||||
assertFalse(rbStream.hasNext());
|
||||
assertTrue(rs.hasNext());
|
||||
assertEquals(inRecs[2], rs.getNext());
|
||||
assertEquals(inRecs[3], rs.getNext());
|
||||
}
|
||||
}
|
||||
/* ====================================================================
|
||||
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.hssf.model;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import junit.framework.AssertionFailedError;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.poi.hssf.record.NumberRecord;
|
||||
import org.apache.poi.hssf.record.Record;
|
||||
import org.apache.poi.hssf.record.RowRecord;
|
||||
import org.apache.poi.hssf.record.UnknownRecord;
|
||||
import org.apache.poi.hssf.record.WindowTwoRecord;
|
||||
import org.apache.poi.hssf.record.pivottable.ViewDefinitionRecord;
|
||||
|
||||
/**
|
||||
* Tests for {@link RowBlocksReader}
|
||||
*
|
||||
* @author Josh Micich
|
||||
*/
|
||||
public final class TestRowBlocksReader extends TestCase {
|
||||
public void testAbnormalPivotTableRecords_bug46280() {
|
||||
int SXVIEW_SID = ViewDefinitionRecord.sid;
|
||||
Record[] inRecs = {
|
||||
new RowRecord(0),
|
||||
new NumberRecord(),
|
||||
// normally MSODRAWING(0x00EC) would come here before SXVIEW
|
||||
new UnknownRecord(SXVIEW_SID, "dummydata (SXVIEW: View Definition)".getBytes()),
|
||||
new WindowTwoRecord(),
|
||||
};
|
||||
RecordStream rs = new RecordStream(Arrays.asList(inRecs), 0);
|
||||
RowBlocksReader rbr = new RowBlocksReader(rs);
|
||||
if (rs.peekNextClass() == WindowTwoRecord.class) {
|
||||
// Should have stopped at the SXVIEW record
|
||||
throw new AssertionFailedError("Identified bug 46280b");
|
||||
}
|
||||
RecordStream rbStream = rbr.getPlainRecordStream();
|
||||
assertEquals(inRecs[0], rbStream.getNext());
|
||||
assertEquals(inRecs[1], rbStream.getNext());
|
||||
assertFalse(rbStream.hasNext());
|
||||
assertTrue(rs.hasNext());
|
||||
assertEquals(inRecs[2], rs.getNext());
|
||||
assertEquals(inRecs[3], rs.getNext());
|
||||
}
|
||||
}
|
||||
|
@ -1,171 +1,171 @@
|
||||
/* ====================================================================
|
||||
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.hssf.record;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import junit.framework.AssertionFailedError;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.poi.util.HexRead;
|
||||
|
||||
/**
|
||||
* Tests the serialization and deserialization of the TestEmbeddedObjectRefSubRecord
|
||||
* class works correctly. Test data taken directly from a real
|
||||
* Excel file.
|
||||
*
|
||||
* @author Yegor Kozlov
|
||||
*/
|
||||
public final class TestEmbeddedObjectRefSubRecord extends TestCase {
|
||||
|
||||
private static final short EORSR_SID = EmbeddedObjectRefSubRecord.sid;
|
||||
|
||||
public void testStore() {
|
||||
String data1
|
||||
= "20 00 05 00 FC 10 76 01 02 24 14 DF 00 03 10 00 "
|
||||
+ "00 46 6F 72 6D 73 2E 43 68 65 63 6B 42 6F 78 2E "
|
||||
+ "31 00 00 00 00 00 70 00 00 00 00 00 00 00 00 00 "
|
||||
+ "00 00";
|
||||
|
||||
byte[] src = hr(data1);
|
||||
|
||||
RecordInputStream in = TestcaseRecordInputStream.create(EORSR_SID, src);
|
||||
|
||||
EmbeddedObjectRefSubRecord record1 = new EmbeddedObjectRefSubRecord(in, src.length);
|
||||
|
||||
byte[] ser = record1.serialize();
|
||||
|
||||
RecordInputStream in2 = TestcaseRecordInputStream.create(ser);
|
||||
EmbeddedObjectRefSubRecord record2 = new EmbeddedObjectRefSubRecord(in2, ser.length-4);
|
||||
|
||||
confirmData(src, ser);
|
||||
assertEquals(record1.getOLEClassName(), record2.getOLEClassName());
|
||||
|
||||
byte[] ser2 = record1.serialize();
|
||||
assertTrue(Arrays.equals(ser, ser2));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param expectedData does not include sid & size
|
||||
* @param actualFullRecordData includes sid & size
|
||||
*/
|
||||
private static void confirmData(byte[] expectedData, byte[] actualFullRecordData) {
|
||||
assertEquals(expectedData.length, actualFullRecordData.length-4);
|
||||
for (int i = 0; i < expectedData.length; i++) {
|
||||
if(expectedData[i] != actualFullRecordData[i+4]) {
|
||||
throw new AssertionFailedError("Difference at offset (" + i + ")");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void testCreate() {
|
||||
|
||||
EmbeddedObjectRefSubRecord record1 = new EmbeddedObjectRefSubRecord();
|
||||
|
||||
byte[] ser = record1.serialize();
|
||||
RecordInputStream in2 = TestcaseRecordInputStream.create(ser);
|
||||
EmbeddedObjectRefSubRecord record2 = new EmbeddedObjectRefSubRecord(in2, ser.length-4);
|
||||
|
||||
assertEquals(record1.getOLEClassName(), record2.getOLEClassName());
|
||||
assertEquals(record1.getStreamId(), record2.getStreamId());
|
||||
|
||||
byte[] ser2 = record1.serialize();
|
||||
assertTrue(Arrays.equals(ser, ser2));
|
||||
}
|
||||
|
||||
public void testCameraTool_bug45912() {
|
||||
/**
|
||||
* taken from ftPictFmla sub-record in attachment 22645 (offset 0x40AB).
|
||||
*/
|
||||
byte[] data45912 = hr(
|
||||
"12 00 0B 00 F8 02 88 04 3B 00 " +
|
||||
"00 00 00 01 00 00 00 01 " +
|
||||
"00 00");
|
||||
RecordInputStream in = TestcaseRecordInputStream.create(EORSR_SID, data45912);
|
||||
|
||||
EmbeddedObjectRefSubRecord rec = new EmbeddedObjectRefSubRecord(in, data45912.length);
|
||||
byte[] ser2 = rec.serialize();
|
||||
confirmData(data45912, ser2);
|
||||
}
|
||||
|
||||
private static byte[] hr(String string) {
|
||||
return HexRead.readFromString(string);
|
||||
}
|
||||
|
||||
/**
|
||||
* tests various examples of OLE controls
|
||||
*/
|
||||
public void testVarious() {
|
||||
String[] rawData = {
|
||||
"12 00 0B 00 70 95 0B 05 3B 01 00 36 00 40 00 18 00 19 00 18",
|
||||
"12 00 0B 00 B0 4D 3E 03 3B 00 00 00 00 01 00 00 80 01 C0 00",
|
||||
"0C 00 05 00 60 AF 3B 03 24 FD FF FE C0 FE",
|
||||
"24 00 05 00 40 42 3E 03 02 80 CD B4 04 03 15 00 00 46 6F 72 6D 73 2E 43 6F 6D 6D 61 6E 64 42 75 74 74 6F 6E 2E 31 00 00 00 00 54 00 00 00 00 00 00 00 00 00 00 00",
|
||||
"22 00 05 00 10 4E 3E 03 02 00 4C CC 04 03 12 00 00 46 6F 72 6D 73 2E 53 70 69 6E 42 75 74 74 6F 6E 2E 31 00 54 00 00 00 20 00 00 00 00 00 00 00 00 00 00 00",
|
||||
"20 00 05 00 E0 41 3E 03 02 00 FC 0B 05 03 10 00 00 46 6F 72 6D 73 2E 43 6F 6D 62 6F 42 6F 78 2E 31 00 74 00 00 00 4C 00 00 00 00 00 00 00 00 00 00 00",
|
||||
"24 00 05 00 00 4C AF 03 02 80 E1 93 05 03 14 00 00 46 6F 72 6D 73 2E 4F 70 74 69 6F 6E 42 75 74 74 6F 6E 2E 31 00 C0 00 00 00 70 00 00 00 00 00 00 00 00 00 00 00",
|
||||
"20 00 05 00 E0 A4 28 04 02 80 EA 93 05 03 10 00 00 46 6F 72 6D 73 2E 43 68 65 63 6B 42 6F 78 2E 31 00 30 01 00 00 6C 00 00 00 00 00 00 00 00 00 00 00",
|
||||
"1C 00 05 00 30 40 3E 03 02 00 CC B4 04 03 0D 00 00 46 6F 72 6D 73 2E 4C 61 62 65 6C 2E 31 9C 01 00 00 54 00 00 00 00 00 00 00 00 00 00 00",
|
||||
"1E 00 05 00 B0 A4 28 04 02 00 D0 0A 05 03 0F 00 00 46 6F 72 6D 73 2E 4C 69 73 74 42 6F 78 2E 31 F0 01 00 00 48 00 00 00 00 00 00 00 00 00 00 00",
|
||||
"24 00 05 00 C0 AF 3B 03 02 80 D1 0A 05 03 14 00 00 46 6F 72 6D 73 2E 54 6F 67 67 6C 65 42 75 74 74 6F 6E 2E 31 00 38 02 00 00 6C 00 00 00 00 00 00 00 00 00 00 00",
|
||||
"1E 00 05 00 90 AF 3B 03 02 80 D4 0A 05 03 0F 00 00 46 6F 72 6D 73 2E 54 65 78 74 42 6F 78 2E 31 A4 02 00 00 48 00 00 00 00 00 00 00 00 00 00 00",
|
||||
"24 00 05 00 60 40 3E 03 02 00 D6 0A 05 03 14 00 00 46 6F 72 6D 73 2E 54 6F 67 67 6C 65 42 75 74 74 6F 6E 2E 31 00 EC 02 00 00 6C 00 00 00 00 00 00 00 00 00 00 00",
|
||||
"20 00 05 00 20 4D 3E 03 02 00 D9 0A 05 03 11 00 00 46 6F 72 6D 73 2E 53 63 72 6F 6C 6C 42 61 72 2E 31 58 03 00 00 20 00 00 00 00 00 00 00 00 00 00 00",
|
||||
"20 00 05 00 00 AF 28 04 02 80 31 AC 04 03 10 00 00 53 68 65 6C 6C 2E 45 78 70 6C 6F 72 65 72 2E 32 00 78 03 00 00 AC 00 00 00 00 00 00 00 00 00 00 00",
|
||||
};
|
||||
|
||||
for (int i = 0; i < rawData.length; i++) {
|
||||
confirmRead(hr(rawData[i]), i);
|
||||
}
|
||||
}
|
||||
|
||||
private static void confirmRead(byte[] data, int i) {
|
||||
RecordInputStream in = TestcaseRecordInputStream.create(EORSR_SID, data);
|
||||
|
||||
EmbeddedObjectRefSubRecord rec = new EmbeddedObjectRefSubRecord(in, data.length);
|
||||
byte[] ser2 = rec.serialize();
|
||||
TestcaseRecordInputStream.confirmRecordEncoding("Test record " + i, EORSR_SID, data, ser2);
|
||||
}
|
||||
|
||||
public void testVisioDrawing_bug46199() {
|
||||
/**
|
||||
* taken from ftPictFmla sub-record in attachment 22860 (stream offset 0x768F).<br/>
|
||||
* Note that the since the string length is zero, there is no unicode flag byte
|
||||
*/
|
||||
byte[] data46199 = hr(
|
||||
"0E 00 "
|
||||
+ "05 00 "
|
||||
+ "28 25 A3 01 "
|
||||
+ "02 6C D1 34 02 "
|
||||
+ "03 00 00 "
|
||||
+ "0F CB E8 00");
|
||||
RecordInputStream in = TestcaseRecordInputStream.create(EORSR_SID, data46199);
|
||||
|
||||
EmbeddedObjectRefSubRecord rec;
|
||||
try {
|
||||
rec = new EmbeddedObjectRefSubRecord(in, data46199.length);
|
||||
} catch (RecordFormatException e) {
|
||||
if (e.getMessage().equals("Not enough data (3) to read requested (4) bytes")) {
|
||||
throw new AssertionFailedError("Identified bug 22860");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
byte[] ser2 = rec.serialize();
|
||||
TestcaseRecordInputStream.confirmRecordEncoding(EORSR_SID, data46199, ser2);
|
||||
}
|
||||
}
|
||||
/* ====================================================================
|
||||
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.hssf.record;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import junit.framework.AssertionFailedError;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.poi.util.HexRead;
|
||||
|
||||
/**
|
||||
* Tests the serialization and deserialization of the TestEmbeddedObjectRefSubRecord
|
||||
* class works correctly. Test data taken directly from a real
|
||||
* Excel file.
|
||||
*
|
||||
* @author Yegor Kozlov
|
||||
*/
|
||||
public final class TestEmbeddedObjectRefSubRecord extends TestCase {
|
||||
|
||||
private static final short EORSR_SID = EmbeddedObjectRefSubRecord.sid;
|
||||
|
||||
public void testStore() {
|
||||
String data1
|
||||
= "20 00 05 00 FC 10 76 01 02 24 14 DF 00 03 10 00 "
|
||||
+ "00 46 6F 72 6D 73 2E 43 68 65 63 6B 42 6F 78 2E "
|
||||
+ "31 00 00 00 00 00 70 00 00 00 00 00 00 00 00 00 "
|
||||
+ "00 00";
|
||||
|
||||
byte[] src = hr(data1);
|
||||
|
||||
RecordInputStream in = TestcaseRecordInputStream.create(EORSR_SID, src);
|
||||
|
||||
EmbeddedObjectRefSubRecord record1 = new EmbeddedObjectRefSubRecord(in, src.length);
|
||||
|
||||
byte[] ser = record1.serialize();
|
||||
|
||||
RecordInputStream in2 = TestcaseRecordInputStream.create(ser);
|
||||
EmbeddedObjectRefSubRecord record2 = new EmbeddedObjectRefSubRecord(in2, ser.length-4);
|
||||
|
||||
confirmData(src, ser);
|
||||
assertEquals(record1.getOLEClassName(), record2.getOLEClassName());
|
||||
|
||||
byte[] ser2 = record1.serialize();
|
||||
assertTrue(Arrays.equals(ser, ser2));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param expectedData does not include sid & size
|
||||
* @param actualFullRecordData includes sid & size
|
||||
*/
|
||||
private static void confirmData(byte[] expectedData, byte[] actualFullRecordData) {
|
||||
assertEquals(expectedData.length, actualFullRecordData.length-4);
|
||||
for (int i = 0; i < expectedData.length; i++) {
|
||||
if(expectedData[i] != actualFullRecordData[i+4]) {
|
||||
throw new AssertionFailedError("Difference at offset (" + i + ")");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void testCreate() {
|
||||
|
||||
EmbeddedObjectRefSubRecord record1 = new EmbeddedObjectRefSubRecord();
|
||||
|
||||
byte[] ser = record1.serialize();
|
||||
RecordInputStream in2 = TestcaseRecordInputStream.create(ser);
|
||||
EmbeddedObjectRefSubRecord record2 = new EmbeddedObjectRefSubRecord(in2, ser.length-4);
|
||||
|
||||
assertEquals(record1.getOLEClassName(), record2.getOLEClassName());
|
||||
assertEquals(record1.getStreamId(), record2.getStreamId());
|
||||
|
||||
byte[] ser2 = record1.serialize();
|
||||
assertTrue(Arrays.equals(ser, ser2));
|
||||
}
|
||||
|
||||
public void testCameraTool_bug45912() {
|
||||
/**
|
||||
* taken from ftPictFmla sub-record in attachment 22645 (offset 0x40AB).
|
||||
*/
|
||||
byte[] data45912 = hr(
|
||||
"12 00 0B 00 F8 02 88 04 3B 00 " +
|
||||
"00 00 00 01 00 00 00 01 " +
|
||||
"00 00");
|
||||
RecordInputStream in = TestcaseRecordInputStream.create(EORSR_SID, data45912);
|
||||
|
||||
EmbeddedObjectRefSubRecord rec = new EmbeddedObjectRefSubRecord(in, data45912.length);
|
||||
byte[] ser2 = rec.serialize();
|
||||
confirmData(data45912, ser2);
|
||||
}
|
||||
|
||||
private static byte[] hr(String string) {
|
||||
return HexRead.readFromString(string);
|
||||
}
|
||||
|
||||
/**
|
||||
* tests various examples of OLE controls
|
||||
*/
|
||||
public void testVarious() {
|
||||
String[] rawData = {
|
||||
"12 00 0B 00 70 95 0B 05 3B 01 00 36 00 40 00 18 00 19 00 18",
|
||||
"12 00 0B 00 B0 4D 3E 03 3B 00 00 00 00 01 00 00 80 01 C0 00",
|
||||
"0C 00 05 00 60 AF 3B 03 24 FD FF FE C0 FE",
|
||||
"24 00 05 00 40 42 3E 03 02 80 CD B4 04 03 15 00 00 46 6F 72 6D 73 2E 43 6F 6D 6D 61 6E 64 42 75 74 74 6F 6E 2E 31 00 00 00 00 54 00 00 00 00 00 00 00 00 00 00 00",
|
||||
"22 00 05 00 10 4E 3E 03 02 00 4C CC 04 03 12 00 00 46 6F 72 6D 73 2E 53 70 69 6E 42 75 74 74 6F 6E 2E 31 00 54 00 00 00 20 00 00 00 00 00 00 00 00 00 00 00",
|
||||
"20 00 05 00 E0 41 3E 03 02 00 FC 0B 05 03 10 00 00 46 6F 72 6D 73 2E 43 6F 6D 62 6F 42 6F 78 2E 31 00 74 00 00 00 4C 00 00 00 00 00 00 00 00 00 00 00",
|
||||
"24 00 05 00 00 4C AF 03 02 80 E1 93 05 03 14 00 00 46 6F 72 6D 73 2E 4F 70 74 69 6F 6E 42 75 74 74 6F 6E 2E 31 00 C0 00 00 00 70 00 00 00 00 00 00 00 00 00 00 00",
|
||||
"20 00 05 00 E0 A4 28 04 02 80 EA 93 05 03 10 00 00 46 6F 72 6D 73 2E 43 68 65 63 6B 42 6F 78 2E 31 00 30 01 00 00 6C 00 00 00 00 00 00 00 00 00 00 00",
|
||||
"1C 00 05 00 30 40 3E 03 02 00 CC B4 04 03 0D 00 00 46 6F 72 6D 73 2E 4C 61 62 65 6C 2E 31 9C 01 00 00 54 00 00 00 00 00 00 00 00 00 00 00",
|
||||
"1E 00 05 00 B0 A4 28 04 02 00 D0 0A 05 03 0F 00 00 46 6F 72 6D 73 2E 4C 69 73 74 42 6F 78 2E 31 F0 01 00 00 48 00 00 00 00 00 00 00 00 00 00 00",
|
||||
"24 00 05 00 C0 AF 3B 03 02 80 D1 0A 05 03 14 00 00 46 6F 72 6D 73 2E 54 6F 67 67 6C 65 42 75 74 74 6F 6E 2E 31 00 38 02 00 00 6C 00 00 00 00 00 00 00 00 00 00 00",
|
||||
"1E 00 05 00 90 AF 3B 03 02 80 D4 0A 05 03 0F 00 00 46 6F 72 6D 73 2E 54 65 78 74 42 6F 78 2E 31 A4 02 00 00 48 00 00 00 00 00 00 00 00 00 00 00",
|
||||
"24 00 05 00 60 40 3E 03 02 00 D6 0A 05 03 14 00 00 46 6F 72 6D 73 2E 54 6F 67 67 6C 65 42 75 74 74 6F 6E 2E 31 00 EC 02 00 00 6C 00 00 00 00 00 00 00 00 00 00 00",
|
||||
"20 00 05 00 20 4D 3E 03 02 00 D9 0A 05 03 11 00 00 46 6F 72 6D 73 2E 53 63 72 6F 6C 6C 42 61 72 2E 31 58 03 00 00 20 00 00 00 00 00 00 00 00 00 00 00",
|
||||
"20 00 05 00 00 AF 28 04 02 80 31 AC 04 03 10 00 00 53 68 65 6C 6C 2E 45 78 70 6C 6F 72 65 72 2E 32 00 78 03 00 00 AC 00 00 00 00 00 00 00 00 00 00 00",
|
||||
};
|
||||
|
||||
for (int i = 0; i < rawData.length; i++) {
|
||||
confirmRead(hr(rawData[i]), i);
|
||||
}
|
||||
}
|
||||
|
||||
private static void confirmRead(byte[] data, int i) {
|
||||
RecordInputStream in = TestcaseRecordInputStream.create(EORSR_SID, data);
|
||||
|
||||
EmbeddedObjectRefSubRecord rec = new EmbeddedObjectRefSubRecord(in, data.length);
|
||||
byte[] ser2 = rec.serialize();
|
||||
TestcaseRecordInputStream.confirmRecordEncoding("Test record " + i, EORSR_SID, data, ser2);
|
||||
}
|
||||
|
||||
public void testVisioDrawing_bug46199() {
|
||||
/**
|
||||
* taken from ftPictFmla sub-record in attachment 22860 (stream offset 0x768F).<br/>
|
||||
* Note that the since the string length is zero, there is no unicode flag byte
|
||||
*/
|
||||
byte[] data46199 = hr(
|
||||
"0E 00 "
|
||||
+ "05 00 "
|
||||
+ "28 25 A3 01 "
|
||||
+ "02 6C D1 34 02 "
|
||||
+ "03 00 00 "
|
||||
+ "0F CB E8 00");
|
||||
RecordInputStream in = TestcaseRecordInputStream.create(EORSR_SID, data46199);
|
||||
|
||||
EmbeddedObjectRefSubRecord rec;
|
||||
try {
|
||||
rec = new EmbeddedObjectRefSubRecord(in, data46199.length);
|
||||
} catch (RecordFormatException e) {
|
||||
if (e.getMessage().equals("Not enough data (3) to read requested (4) bytes")) {
|
||||
throw new AssertionFailedError("Identified bug 22860");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
byte[] ser2 = rec.serialize();
|
||||
TestcaseRecordInputStream.confirmRecordEncoding(EORSR_SID, data46199, ser2);
|
||||
}
|
||||
}
|
||||
|
@ -1,105 +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.hssf.record;
|
||||
|
||||
import junit.framework.AssertionFailedError;
|
||||
import junit.framework.TestCase;
|
||||
/**
|
||||
*
|
||||
* @author Josh Micich
|
||||
*/
|
||||
public final class TestExternalNameRecord extends TestCase {
|
||||
|
||||
private static final byte[] dataFDS = {
|
||||
0, 0, 0, 0, 0, 0, 3, 0, 70, 68, 83, 0, 0,
|
||||
};
|
||||
|
||||
// data taken from bugzilla 44774 att 21790
|
||||
private static final byte[] dataAutoDocName = {
|
||||
-22, 127, 0, 0, 0, 0, 29, 0, 39, 49, 57, 49, 50, 49, 57, 65, 87, 52, 32, 67, 111, 114,
|
||||
112, 44, 91, 87, 79, 82, 75, 79, 85, 84, 95, 80, 88, 93, 39,
|
||||
};
|
||||
|
||||
// data taken from bugzilla 44774 att 21790
|
||||
private static final byte[] dataPlainName = {
|
||||
0, 0, 0, 0, 0, 0, 9, 0, 82, 97, 116, 101, 95, 68, 97, 116, 101, 9, 0, 58, 0, 0, 0, 0, 4, 0, 8, 0
|
||||
// TODO - the last 2 bytes of formula data (8,0) seem weird. They encode to ConcatPtg, UnknownPtg
|
||||
// UnknownPtg is otherwise not created by any other test cases
|
||||
};
|
||||
|
||||
private static ExternalNameRecord createSimpleENR(byte[] data) {
|
||||
return new ExternalNameRecord(TestcaseRecordInputStream.create(0x0023, data));
|
||||
}
|
||||
public void testBasicDeserializeReserialize() {
|
||||
|
||||
ExternalNameRecord enr = createSimpleENR(dataFDS);
|
||||
assertEquals("FDS", enr.getText());
|
||||
|
||||
try {
|
||||
TestcaseRecordInputStream.confirmRecordEncoding(0x0023, dataFDS, enr.serialize());
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
if(e.getMessage().equals("15")) {
|
||||
throw new AssertionFailedError("Identified bug 44695");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void testBasicSize() {
|
||||
ExternalNameRecord enr = createSimpleENR(dataFDS);
|
||||
if(enr.getRecordSize() == 13) {
|
||||
throw new AssertionFailedError("Identified bug 44695");
|
||||
}
|
||||
assertEquals(17, enr.getRecordSize());
|
||||
}
|
||||
|
||||
public void testAutoStdDocName() {
|
||||
|
||||
ExternalNameRecord enr;
|
||||
try {
|
||||
enr = createSimpleENR(dataAutoDocName);
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
if(e.getMessage() == null) {
|
||||
throw new AssertionFailedError("Identified bug XXXX");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
assertEquals("'191219AW4 Corp,[WORKOUT_PX]'", enr.getText());
|
||||
assertTrue(enr.isAutomaticLink());
|
||||
assertFalse(enr.isBuiltInName());
|
||||
assertFalse(enr.isIconifiedPictureLink());
|
||||
assertFalse(enr.isOLELink());
|
||||
assertFalse(enr.isPicureLink());
|
||||
assertTrue(enr.isStdDocumentNameIdentifier());
|
||||
|
||||
TestcaseRecordInputStream.confirmRecordEncoding(0x0023, dataAutoDocName, enr.serialize());
|
||||
}
|
||||
|
||||
public void testPlainName() {
|
||||
|
||||
ExternalNameRecord enr = createSimpleENR(dataPlainName);
|
||||
assertEquals("Rate_Date", enr.getText());
|
||||
assertFalse(enr.isAutomaticLink());
|
||||
assertFalse(enr.isBuiltInName());
|
||||
assertFalse(enr.isIconifiedPictureLink());
|
||||
assertFalse(enr.isOLELink());
|
||||
assertFalse(enr.isPicureLink());
|
||||
assertFalse(enr.isStdDocumentNameIdentifier());
|
||||
|
||||
TestcaseRecordInputStream.confirmRecordEncoding(0x0023, dataPlainName, enr.serialize());
|
||||
}
|
||||
}
|
||||
/* ====================================================================
|
||||
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.hssf.record;
|
||||
|
||||
import junit.framework.AssertionFailedError;
|
||||
import junit.framework.TestCase;
|
||||
/**
|
||||
*
|
||||
* @author Josh Micich
|
||||
*/
|
||||
public final class TestExternalNameRecord extends TestCase {
|
||||
|
||||
private static final byte[] dataFDS = {
|
||||
0, 0, 0, 0, 0, 0, 3, 0, 70, 68, 83, 0, 0,
|
||||
};
|
||||
|
||||
// data taken from bugzilla 44774 att 21790
|
||||
private static final byte[] dataAutoDocName = {
|
||||
-22, 127, 0, 0, 0, 0, 29, 0, 39, 49, 57, 49, 50, 49, 57, 65, 87, 52, 32, 67, 111, 114,
|
||||
112, 44, 91, 87, 79, 82, 75, 79, 85, 84, 95, 80, 88, 93, 39,
|
||||
};
|
||||
|
||||
// data taken from bugzilla 44774 att 21790
|
||||
private static final byte[] dataPlainName = {
|
||||
0, 0, 0, 0, 0, 0, 9, 0, 82, 97, 116, 101, 95, 68, 97, 116, 101, 9, 0, 58, 0, 0, 0, 0, 4, 0, 8, 0
|
||||
// TODO - the last 2 bytes of formula data (8,0) seem weird. They encode to ConcatPtg, UnknownPtg
|
||||
// UnknownPtg is otherwise not created by any other test cases
|
||||
};
|
||||
|
||||
private static ExternalNameRecord createSimpleENR(byte[] data) {
|
||||
return new ExternalNameRecord(TestcaseRecordInputStream.create(0x0023, data));
|
||||
}
|
||||
public void testBasicDeserializeReserialize() {
|
||||
|
||||
ExternalNameRecord enr = createSimpleENR(dataFDS);
|
||||
assertEquals("FDS", enr.getText());
|
||||
|
||||
try {
|
||||
TestcaseRecordInputStream.confirmRecordEncoding(0x0023, dataFDS, enr.serialize());
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
if(e.getMessage().equals("15")) {
|
||||
throw new AssertionFailedError("Identified bug 44695");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void testBasicSize() {
|
||||
ExternalNameRecord enr = createSimpleENR(dataFDS);
|
||||
if(enr.getRecordSize() == 13) {
|
||||
throw new AssertionFailedError("Identified bug 44695");
|
||||
}
|
||||
assertEquals(17, enr.getRecordSize());
|
||||
}
|
||||
|
||||
public void testAutoStdDocName() {
|
||||
|
||||
ExternalNameRecord enr;
|
||||
try {
|
||||
enr = createSimpleENR(dataAutoDocName);
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
if(e.getMessage() == null) {
|
||||
throw new AssertionFailedError("Identified bug XXXX");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
assertEquals("'191219AW4 Corp,[WORKOUT_PX]'", enr.getText());
|
||||
assertTrue(enr.isAutomaticLink());
|
||||
assertFalse(enr.isBuiltInName());
|
||||
assertFalse(enr.isIconifiedPictureLink());
|
||||
assertFalse(enr.isOLELink());
|
||||
assertFalse(enr.isPicureLink());
|
||||
assertTrue(enr.isStdDocumentNameIdentifier());
|
||||
|
||||
TestcaseRecordInputStream.confirmRecordEncoding(0x0023, dataAutoDocName, enr.serialize());
|
||||
}
|
||||
|
||||
public void testPlainName() {
|
||||
|
||||
ExternalNameRecord enr = createSimpleENR(dataPlainName);
|
||||
assertEquals("Rate_Date", enr.getText());
|
||||
assertFalse(enr.isAutomaticLink());
|
||||
assertFalse(enr.isBuiltInName());
|
||||
assertFalse(enr.isIconifiedPictureLink());
|
||||
assertFalse(enr.isOLELink());
|
||||
assertFalse(enr.isPicureLink());
|
||||
assertFalse(enr.isStdDocumentNameIdentifier());
|
||||
|
||||
TestcaseRecordInputStream.confirmRecordEncoding(0x0023, dataPlainName, enr.serialize());
|
||||
}
|
||||
}
|
||||
|
@ -1,46 +1,46 @@
|
||||
/* ====================================================================
|
||||
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.hssf.record;
|
||||
|
||||
import junit.framework.AssertionFailedError;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.poi.util.HexRead;
|
||||
|
||||
/**
|
||||
* Tests for {@link StyleRecord}
|
||||
*/
|
||||
public final class TestStyleRecord extends TestCase {
|
||||
public void testUnicodeReadName() {
|
||||
byte[] data = HexRead.readFromString(
|
||||
"11 00 09 00 01 38 5E C4 89 5F 00 53 00 68 00 65 00 65 00 74 00 31 00");
|
||||
RecordInputStream in = TestcaseRecordInputStream.create(StyleRecord.sid, data);
|
||||
StyleRecord sr = new StyleRecord(in);
|
||||
assertEquals("\u5E38\u89C4_Sheet1", sr.getName()); // "<Conventional>_Sheet1"
|
||||
byte[] ser;
|
||||
try {
|
||||
ser = sr.serialize();
|
||||
} catch (IllegalStateException e) {
|
||||
if (e.getMessage().equals("Incorrect number of bytes written - expected 27 but got 18")) {
|
||||
throw new AssertionFailedError("Identified bug 46385");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
TestcaseRecordInputStream.confirmRecordEncoding(StyleRecord.sid, data, ser);
|
||||
}
|
||||
}
|
||||
/* ====================================================================
|
||||
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.hssf.record;
|
||||
|
||||
import junit.framework.AssertionFailedError;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.poi.util.HexRead;
|
||||
|
||||
/**
|
||||
* Tests for {@link StyleRecord}
|
||||
*/
|
||||
public final class TestStyleRecord extends TestCase {
|
||||
public void testUnicodeReadName() {
|
||||
byte[] data = HexRead.readFromString(
|
||||
"11 00 09 00 01 38 5E C4 89 5F 00 53 00 68 00 65 00 65 00 74 00 31 00");
|
||||
RecordInputStream in = TestcaseRecordInputStream.create(StyleRecord.sid, data);
|
||||
StyleRecord sr = new StyleRecord(in);
|
||||
assertEquals("\u5E38\u89C4_Sheet1", sr.getName()); // "<Conventional>_Sheet1"
|
||||
byte[] ser;
|
||||
try {
|
||||
ser = sr.serialize();
|
||||
} catch (IllegalStateException e) {
|
||||
if (e.getMessage().equals("Incorrect number of bytes written - expected 27 but got 18")) {
|
||||
throw new AssertionFailedError("Identified bug 46385");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
TestcaseRecordInputStream.confirmRecordEncoding(StyleRecord.sid, data, ser);
|
||||
}
|
||||
}
|
||||
|
@ -1,196 +1,194 @@
|
||||
/* ====================================================================
|
||||
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.hssf.record;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.util.Arrays;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.poi.hssf.record.formula.Ptg;
|
||||
import org.apache.poi.hssf.record.formula.RefPtg;
|
||||
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
|
||||
import org.apache.poi.util.HexRead;
|
||||
import org.apache.poi.util.LittleEndian;
|
||||
|
||||
/**
|
||||
* Tests that serialization and deserialization of the TextObjectRecord .
|
||||
* Test data taken directly from a real Excel file.
|
||||
*
|
||||
* @author Yegor Kozlov
|
||||
*/
|
||||
public final class TestTextObjectRecord extends TestCase {
|
||||
|
||||
private static final byte[] simpleData = HexRead.readFromString(
|
||||
"B6 01 12 00 " +
|
||||
"12 02 00 00 00 00 00 00" +
|
||||
"00 00 0D 00 08 00 00 00" +
|
||||
"00 00 " +
|
||||
"3C 00 0E 00 " +
|
||||
"00 48 65 6C 6C 6F 2C 20 57 6F 72 6C 64 21 " +
|
||||
"3C 00 08 " +
|
||||
"00 0D 00 00 00 00 00 00 00"
|
||||
);
|
||||
|
||||
|
||||
public void testRead() {
|
||||
|
||||
RecordInputStream is =TestcaseRecordInputStream.create(simpleData);
|
||||
TextObjectRecord record = new TextObjectRecord(is);
|
||||
|
||||
assertEquals(TextObjectRecord.sid, record.getSid());
|
||||
assertEquals(TextObjectRecord.HORIZONTAL_TEXT_ALIGNMENT_LEFT_ALIGNED, record.getHorizontalTextAlignment());
|
||||
assertEquals(TextObjectRecord.VERTICAL_TEXT_ALIGNMENT_TOP, record.getVerticalTextAlignment());
|
||||
assertEquals(TextObjectRecord.TEXT_ORIENTATION_NONE, record.getTextOrientation());
|
||||
assertEquals("Hello, World!", record.getStr().getString());
|
||||
}
|
||||
|
||||
public void testWrite() {
|
||||
HSSFRichTextString str = new HSSFRichTextString("Hello, World!");
|
||||
|
||||
TextObjectRecord record = new TextObjectRecord();
|
||||
record.setStr(str);
|
||||
record.setHorizontalTextAlignment( TextObjectRecord.HORIZONTAL_TEXT_ALIGNMENT_LEFT_ALIGNED );
|
||||
record.setVerticalTextAlignment( TextObjectRecord.VERTICAL_TEXT_ALIGNMENT_TOP );
|
||||
record.setTextLocked( true );
|
||||
record.setTextOrientation( TextObjectRecord.TEXT_ORIENTATION_NONE );
|
||||
|
||||
byte [] ser = record.serialize();
|
||||
assertEquals(ser.length , simpleData.length);
|
||||
|
||||
assertTrue(Arrays.equals(simpleData, ser));
|
||||
|
||||
//read again
|
||||
RecordInputStream is = TestcaseRecordInputStream.create(simpleData);
|
||||
record = new TextObjectRecord(is);
|
||||
}
|
||||
|
||||
/**
|
||||
* Zero {@link ContinueRecord}s follow a {@link TextObjectRecord} if the text is empty
|
||||
*/
|
||||
public void testWriteEmpty() {
|
||||
HSSFRichTextString str = new HSSFRichTextString("");
|
||||
|
||||
TextObjectRecord record = new TextObjectRecord();
|
||||
record.setStr(str);
|
||||
|
||||
byte [] ser = record.serialize();
|
||||
|
||||
int formatDataLen = LittleEndian.getUShort(ser, 16);
|
||||
assertEquals("formatDataLength", 0, formatDataLen);
|
||||
|
||||
assertEquals(22, ser.length); // just the TXO record
|
||||
|
||||
//read again
|
||||
RecordInputStream is = TestcaseRecordInputStream.create(ser);
|
||||
record = new TextObjectRecord(is);
|
||||
assertEquals(0, record.getStr().length());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that TextObjectRecord serializes logs records properly.
|
||||
*/
|
||||
public void testLongRecords() {
|
||||
int[] length = {1024, 2048, 4096, 8192, 16384}; //test against strings of different length
|
||||
for (int i = 0; i < length.length; i++) {
|
||||
StringBuffer buff = new StringBuffer(length[i]);
|
||||
for (int j = 0; j < length[i]; j++) {
|
||||
buff.append("x");
|
||||
}
|
||||
HSSFRichTextString str = new HSSFRichTextString(buff.toString());
|
||||
|
||||
TextObjectRecord obj = new TextObjectRecord();
|
||||
obj.setStr(str);
|
||||
|
||||
byte [] data = obj.serialize();
|
||||
RecordInputStream is = new RecordInputStream(new ByteArrayInputStream(data));
|
||||
is.nextRecord();
|
||||
TextObjectRecord record = new TextObjectRecord(is);
|
||||
str = record.getStr();
|
||||
|
||||
assertEquals(buff.length(), str.length());
|
||||
assertEquals(buff.toString(), str.getString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test cloning
|
||||
*/
|
||||
public void testClone() {
|
||||
String text = "Hello, World";
|
||||
HSSFRichTextString str = new HSSFRichTextString(text);
|
||||
|
||||
TextObjectRecord obj = new TextObjectRecord();
|
||||
obj.setStr( str );
|
||||
|
||||
|
||||
TextObjectRecord cloned = (TextObjectRecord)obj.clone();
|
||||
assertEquals(obj.getRecordSize(), cloned.getRecordSize());
|
||||
assertEquals(obj.getHorizontalTextAlignment(), cloned.getHorizontalTextAlignment());
|
||||
assertEquals(obj.getStr().getString(), cloned.getStr().getString());
|
||||
|
||||
//finally check that the serialized data is the same
|
||||
byte[] src = obj.serialize();
|
||||
byte[] cln = cloned.serialize();
|
||||
assertTrue(Arrays.equals(src, cln));
|
||||
}
|
||||
|
||||
/** similar to {@link #simpleData} but with link formula at end of TXO rec*/
|
||||
private static final byte[] linkData = HexRead.readFromString(
|
||||
"B6 01 " + // TextObjectRecord.sid
|
||||
"1E 00 " + // size 18
|
||||
"44 02 02 00 00 00 00 00" +
|
||||
"00 00 " +
|
||||
"02 00 " + // strLen 2
|
||||
"10 00 " + // 16 bytes for 2 format runs
|
||||
"00 00 00 00 " +
|
||||
|
||||
"05 00 " + // formula size
|
||||
"D4 F0 8A 03 " + // unknownInt
|
||||
"24 01 00 13 C0 " + //tRef(T2)
|
||||
"13 " + // ??
|
||||
|
||||
"3C 00 " + // ContinueRecord.sid
|
||||
"03 00 " + // size 3
|
||||
"00 " + // unicode compressed
|
||||
"41 42 " + // 'AB'
|
||||
"3C 00 " + // ContinueRecord.sid
|
||||
"10 00 " + // size 16
|
||||
"00 00 18 00 00 00 00 00 " +
|
||||
"02 00 00 00 00 00 00 00 "
|
||||
);
|
||||
|
||||
|
||||
public void testLinkFormula() {
|
||||
RecordInputStream is = new RecordInputStream(new ByteArrayInputStream(linkData));
|
||||
is.nextRecord();
|
||||
TextObjectRecord rec = new TextObjectRecord(is);
|
||||
|
||||
Ptg ptg = rec.getLinkRefPtg();
|
||||
assertNotNull(ptg);
|
||||
assertEquals(RefPtg.class, ptg.getClass());
|
||||
RefPtg rptg = (RefPtg) ptg;
|
||||
assertEquals("T2", rptg.toFormulaString());
|
||||
|
||||
byte [] data2 = rec.serialize();
|
||||
assertEquals(linkData.length, data2.length);
|
||||
assertTrue(Arrays.equals(linkData, data2));
|
||||
}
|
||||
|
||||
}
|
||||
/* ====================================================================
|
||||
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.hssf.record;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.util.Arrays;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.poi.hssf.record.formula.Ptg;
|
||||
import org.apache.poi.hssf.record.formula.RefPtg;
|
||||
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
|
||||
import org.apache.poi.util.HexRead;
|
||||
import org.apache.poi.util.LittleEndian;
|
||||
|
||||
/**
|
||||
* Tests that serialization and deserialization of the TextObjectRecord .
|
||||
* Test data taken directly from a real Excel file.
|
||||
*
|
||||
* @author Yegor Kozlov
|
||||
*/
|
||||
public final class TestTextObjectRecord extends TestCase {
|
||||
|
||||
private static final byte[] simpleData = HexRead.readFromString(
|
||||
"B6 01 12 00 " +
|
||||
"12 02 00 00 00 00 00 00" +
|
||||
"00 00 0D 00 08 00 00 00" +
|
||||
"00 00 " +
|
||||
"3C 00 0E 00 " +
|
||||
"00 48 65 6C 6C 6F 2C 20 57 6F 72 6C 64 21 " +
|
||||
"3C 00 08 " +
|
||||
"00 0D 00 00 00 00 00 00 00"
|
||||
);
|
||||
|
||||
|
||||
public void testRead() {
|
||||
|
||||
RecordInputStream is =TestcaseRecordInputStream.create(simpleData);
|
||||
TextObjectRecord record = new TextObjectRecord(is);
|
||||
|
||||
assertEquals(TextObjectRecord.sid, record.getSid());
|
||||
assertEquals(TextObjectRecord.HORIZONTAL_TEXT_ALIGNMENT_LEFT_ALIGNED, record.getHorizontalTextAlignment());
|
||||
assertEquals(TextObjectRecord.VERTICAL_TEXT_ALIGNMENT_TOP, record.getVerticalTextAlignment());
|
||||
assertEquals(TextObjectRecord.TEXT_ORIENTATION_NONE, record.getTextOrientation());
|
||||
assertEquals("Hello, World!", record.getStr().getString());
|
||||
}
|
||||
|
||||
public void testWrite() {
|
||||
HSSFRichTextString str = new HSSFRichTextString("Hello, World!");
|
||||
|
||||
TextObjectRecord record = new TextObjectRecord();
|
||||
record.setStr(str);
|
||||
record.setHorizontalTextAlignment( TextObjectRecord.HORIZONTAL_TEXT_ALIGNMENT_LEFT_ALIGNED );
|
||||
record.setVerticalTextAlignment( TextObjectRecord.VERTICAL_TEXT_ALIGNMENT_TOP );
|
||||
record.setTextLocked( true );
|
||||
record.setTextOrientation( TextObjectRecord.TEXT_ORIENTATION_NONE );
|
||||
|
||||
byte [] ser = record.serialize();
|
||||
assertEquals(ser.length , simpleData.length);
|
||||
|
||||
assertTrue(Arrays.equals(simpleData, ser));
|
||||
|
||||
//read again
|
||||
RecordInputStream is = TestcaseRecordInputStream.create(simpleData);
|
||||
record = new TextObjectRecord(is);
|
||||
}
|
||||
|
||||
/**
|
||||
* Zero {@link ContinueRecord}s follow a {@link TextObjectRecord} if the text is empty
|
||||
*/
|
||||
public void testWriteEmpty() {
|
||||
HSSFRichTextString str = new HSSFRichTextString("");
|
||||
|
||||
TextObjectRecord record = new TextObjectRecord();
|
||||
record.setStr(str);
|
||||
|
||||
byte [] ser = record.serialize();
|
||||
|
||||
int formatDataLen = LittleEndian.getUShort(ser, 16);
|
||||
assertEquals("formatDataLength", 0, formatDataLen);
|
||||
|
||||
assertEquals(22, ser.length); // just the TXO record
|
||||
|
||||
//read again
|
||||
RecordInputStream is = TestcaseRecordInputStream.create(ser);
|
||||
record = new TextObjectRecord(is);
|
||||
assertEquals(0, record.getStr().length());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that TextObjectRecord serializes logs records properly.
|
||||
*/
|
||||
public void testLongRecords() {
|
||||
int[] length = {1024, 2048, 4096, 8192, 16384}; //test against strings of different length
|
||||
for (int i = 0; i < length.length; i++) {
|
||||
StringBuffer buff = new StringBuffer(length[i]);
|
||||
for (int j = 0; j < length[i]; j++) {
|
||||
buff.append("x");
|
||||
}
|
||||
HSSFRichTextString str = new HSSFRichTextString(buff.toString());
|
||||
|
||||
TextObjectRecord obj = new TextObjectRecord();
|
||||
obj.setStr(str);
|
||||
|
||||
byte [] data = obj.serialize();
|
||||
RecordInputStream is = new RecordInputStream(new ByteArrayInputStream(data));
|
||||
is.nextRecord();
|
||||
TextObjectRecord record = new TextObjectRecord(is);
|
||||
str = record.getStr();
|
||||
|
||||
assertEquals(buff.length(), str.length());
|
||||
assertEquals(buff.toString(), str.getString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test cloning
|
||||
*/
|
||||
public void testClone() {
|
||||
String text = "Hello, World";
|
||||
HSSFRichTextString str = new HSSFRichTextString(text);
|
||||
|
||||
TextObjectRecord obj = new TextObjectRecord();
|
||||
obj.setStr( str );
|
||||
|
||||
|
||||
TextObjectRecord cloned = (TextObjectRecord)obj.clone();
|
||||
assertEquals(obj.getRecordSize(), cloned.getRecordSize());
|
||||
assertEquals(obj.getHorizontalTextAlignment(), cloned.getHorizontalTextAlignment());
|
||||
assertEquals(obj.getStr().getString(), cloned.getStr().getString());
|
||||
|
||||
//finally check that the serialized data is the same
|
||||
byte[] src = obj.serialize();
|
||||
byte[] cln = cloned.serialize();
|
||||
assertTrue(Arrays.equals(src, cln));
|
||||
}
|
||||
|
||||
/** similar to {@link #simpleData} but with link formula at end of TXO rec*/
|
||||
private static final byte[] linkData = HexRead.readFromString(
|
||||
"B6 01 " + // TextObjectRecord.sid
|
||||
"1E 00 " + // size 18
|
||||
"44 02 02 00 00 00 00 00" +
|
||||
"00 00 " +
|
||||
"02 00 " + // strLen 2
|
||||
"10 00 " + // 16 bytes for 2 format runs
|
||||
"00 00 00 00 " +
|
||||
|
||||
"05 00 " + // formula size
|
||||
"D4 F0 8A 03 " + // unknownInt
|
||||
"24 01 00 13 C0 " + //tRef(T2)
|
||||
"13 " + // ??
|
||||
|
||||
"3C 00 " + // ContinueRecord.sid
|
||||
"03 00 " + // size 3
|
||||
"00 " + // unicode compressed
|
||||
"41 42 " + // 'AB'
|
||||
"3C 00 " + // ContinueRecord.sid
|
||||
"10 00 " + // size 16
|
||||
"00 00 18 00 00 00 00 00 " +
|
||||
"02 00 00 00 00 00 00 00 "
|
||||
);
|
||||
|
||||
|
||||
public void testLinkFormula() {
|
||||
RecordInputStream is = new RecordInputStream(new ByteArrayInputStream(linkData));
|
||||
is.nextRecord();
|
||||
TextObjectRecord rec = new TextObjectRecord(is);
|
||||
|
||||
Ptg ptg = rec.getLinkRefPtg();
|
||||
assertNotNull(ptg);
|
||||
assertEquals(RefPtg.class, ptg.getClass());
|
||||
RefPtg rptg = (RefPtg) ptg;
|
||||
assertEquals("T2", rptg.toFormulaString());
|
||||
|
||||
byte [] data2 = rec.serialize();
|
||||
assertEquals(linkData.length, data2.length);
|
||||
assertTrue(Arrays.equals(linkData, data2));
|
||||
}
|
||||
}
|
||||
|
@ -1,103 +1,103 @@
|
||||
/* ====================================================================
|
||||
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.hssf.record;
|
||||
|
||||
import junit.framework.AssertionFailedError;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.poi.util.HexRead;
|
||||
|
||||
/**
|
||||
* Tests for {@link WriteAccessRecord}
|
||||
*
|
||||
* @author Josh Micich
|
||||
*/
|
||||
public final class TestWriteAccessRecord extends TestCase {
|
||||
|
||||
private static final String HEX_SIXTYFOUR_SPACES = ""
|
||||
+ "20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 "
|
||||
+ "20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 "
|
||||
+ "20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 "
|
||||
+ "20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20";
|
||||
|
||||
|
||||
public void testMissingStringHeader_bug47001a() {
|
||||
/*
|
||||
* Data taken from offset 0x0224 in
|
||||
* attachment 23468 from bugzilla 47001
|
||||
*/
|
||||
byte[] data = HexRead.readFromString(""
|
||||
+ "5C 00 70 00 "
|
||||
+ "4A 61 76 61 20 45 78 63 65 6C 20 41 50 49 20 76 "
|
||||
+ "32 2E 36 2E 34"
|
||||
+ "20 20 20 20 20 20 20 20 20 20 20 "
|
||||
+ "20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 "
|
||||
+ HEX_SIXTYFOUR_SPACES);
|
||||
|
||||
RecordInputStream in = TestcaseRecordInputStream.create(data);
|
||||
|
||||
WriteAccessRecord rec;
|
||||
try {
|
||||
rec = new WriteAccessRecord(in);
|
||||
} catch (RecordFormatException e) {
|
||||
if (e.getMessage().equals("Not enough data (0) to read requested (1) bytes")) {
|
||||
throw new AssertionFailedError("Identified bug 47001a");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
assertEquals("Java Excel API v2.6.4", rec.getUsername());
|
||||
|
||||
|
||||
byte[] expectedEncoding = HexRead.readFromString(""
|
||||
+ "15 00 00 4A 61 76 61 20 45 78 63 65 6C 20 41 50 "
|
||||
+ "49 20 76 32 2E 36 2E 34"
|
||||
+ "20 20 20 20 20 20 20 20 "
|
||||
+ "20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 "
|
||||
+ HEX_SIXTYFOUR_SPACES);
|
||||
|
||||
TestcaseRecordInputStream.confirmRecordEncoding(WriteAccessRecord.sid, expectedEncoding, rec.serialize());
|
||||
}
|
||||
|
||||
public void testShortRecordWrittenByMSAccess() {
|
||||
/*
|
||||
* Data taken from two example files
|
||||
* ex42564-21435.xls
|
||||
* bug_42794.xls (from bug 42794 attachment 20429)
|
||||
* In both cases, this data is found at offset 0x0C1C.
|
||||
*/
|
||||
byte[] data = HexRead.readFromString(""
|
||||
+ "5C 00 39 00 "
|
||||
+ "36 00 00 41 20 73 61 74 69 73 66 69 65 64 20 4D "
|
||||
+ "69 63 72 6F 73 6F 66 74 20 4F 66 66 69 63 65 39 "
|
||||
+ "20 55 73 65 72"
|
||||
+ "20 20 20 20 20 20 20 20 20 20 20 "
|
||||
+ "20 20 20 20 20 20 20 20 20");
|
||||
|
||||
RecordInputStream in = TestcaseRecordInputStream.create(data);
|
||||
WriteAccessRecord rec = new WriteAccessRecord(in);
|
||||
assertEquals("A satisfied Microsoft Office9 User", rec.getUsername());
|
||||
byte[] expectedEncoding = HexRead.readFromString(""
|
||||
+ "22 00 00 41 20 73 61 74 69 73 66 69 65 64 20 4D "
|
||||
+ "69 63 72 6F 73 6F 66 74 20 4F 66 66 69 63 65 39 "
|
||||
+ "20 55 73 65 72"
|
||||
+ "20 20 20 20 20 20 20 20 20 20 20 "
|
||||
+ HEX_SIXTYFOUR_SPACES);
|
||||
|
||||
TestcaseRecordInputStream.confirmRecordEncoding(WriteAccessRecord.sid, expectedEncoding, rec.serialize());
|
||||
}
|
||||
}
|
||||
/* ====================================================================
|
||||
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.hssf.record;
|
||||
|
||||
import junit.framework.AssertionFailedError;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.poi.util.HexRead;
|
||||
|
||||
/**
|
||||
* Tests for {@link WriteAccessRecord}
|
||||
*
|
||||
* @author Josh Micich
|
||||
*/
|
||||
public final class TestWriteAccessRecord extends TestCase {
|
||||
|
||||
private static final String HEX_SIXTYFOUR_SPACES = ""
|
||||
+ "20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 "
|
||||
+ "20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 "
|
||||
+ "20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 "
|
||||
+ "20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20";
|
||||
|
||||
|
||||
public void testMissingStringHeader_bug47001a() {
|
||||
/*
|
||||
* Data taken from offset 0x0224 in
|
||||
* attachment 23468 from bugzilla 47001
|
||||
*/
|
||||
byte[] data = HexRead.readFromString(""
|
||||
+ "5C 00 70 00 "
|
||||
+ "4A 61 76 61 20 45 78 63 65 6C 20 41 50 49 20 76 "
|
||||
+ "32 2E 36 2E 34"
|
||||
+ "20 20 20 20 20 20 20 20 20 20 20 "
|
||||
+ "20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 "
|
||||
+ HEX_SIXTYFOUR_SPACES);
|
||||
|
||||
RecordInputStream in = TestcaseRecordInputStream.create(data);
|
||||
|
||||
WriteAccessRecord rec;
|
||||
try {
|
||||
rec = new WriteAccessRecord(in);
|
||||
} catch (RecordFormatException e) {
|
||||
if (e.getMessage().equals("Not enough data (0) to read requested (1) bytes")) {
|
||||
throw new AssertionFailedError("Identified bug 47001a");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
assertEquals("Java Excel API v2.6.4", rec.getUsername());
|
||||
|
||||
|
||||
byte[] expectedEncoding = HexRead.readFromString(""
|
||||
+ "15 00 00 4A 61 76 61 20 45 78 63 65 6C 20 41 50 "
|
||||
+ "49 20 76 32 2E 36 2E 34"
|
||||
+ "20 20 20 20 20 20 20 20 "
|
||||
+ "20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 "
|
||||
+ HEX_SIXTYFOUR_SPACES);
|
||||
|
||||
TestcaseRecordInputStream.confirmRecordEncoding(WriteAccessRecord.sid, expectedEncoding, rec.serialize());
|
||||
}
|
||||
|
||||
public void testShortRecordWrittenByMSAccess() {
|
||||
/*
|
||||
* Data taken from two example files
|
||||
* ex42564-21435.xls
|
||||
* bug_42794.xls (from bug 42794 attachment 20429)
|
||||
* In both cases, this data is found at offset 0x0C1C.
|
||||
*/
|
||||
byte[] data = HexRead.readFromString(""
|
||||
+ "5C 00 39 00 "
|
||||
+ "36 00 00 41 20 73 61 74 69 73 66 69 65 64 20 4D "
|
||||
+ "69 63 72 6F 73 6F 66 74 20 4F 66 66 69 63 65 39 "
|
||||
+ "20 55 73 65 72"
|
||||
+ "20 20 20 20 20 20 20 20 20 20 20 "
|
||||
+ "20 20 20 20 20 20 20 20 20");
|
||||
|
||||
RecordInputStream in = TestcaseRecordInputStream.create(data);
|
||||
WriteAccessRecord rec = new WriteAccessRecord(in);
|
||||
assertEquals("A satisfied Microsoft Office9 User", rec.getUsername());
|
||||
byte[] expectedEncoding = HexRead.readFromString(""
|
||||
+ "22 00 00 41 20 73 61 74 69 73 66 69 65 64 20 4D "
|
||||
+ "69 63 72 6F 73 6F 66 74 20 4F 66 66 69 63 65 39 "
|
||||
+ "20 55 73 65 72"
|
||||
+ "20 20 20 20 20 20 20 20 20 20 20 "
|
||||
+ HEX_SIXTYFOUR_SPACES);
|
||||
|
||||
TestcaseRecordInputStream.confirmRecordEncoding(WriteAccessRecord.sid, expectedEncoding, rec.serialize());
|
||||
}
|
||||
}
|
||||
|
@ -1,61 +1,61 @@
|
||||
/* ====================================================================
|
||||
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.hssf.record.chart;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.apache.poi.hssf.record.RecordInputStream;
|
||||
import org.apache.poi.hssf.record.TestcaseRecordInputStream;
|
||||
import org.apache.poi.util.HexRead;
|
||||
|
||||
import junit.framework.AssertionFailedError;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Tests for {@link ChartFormatRecord} Test data taken directly from a real
|
||||
* Excel file.
|
||||
*
|
||||
* @author Josh Micich
|
||||
*/
|
||||
public final class TestChartFormatRecord extends TestCase {
|
||||
/**
|
||||
* This rather uninteresting data came from attachment 23347 of bug 46693 at
|
||||
* offsets 0x6BB2 and 0x7BAF
|
||||
*/
|
||||
private static final byte[] data = HexRead.readFromString(
|
||||
"14 10 14 00 " // BIFF header
|
||||
+ "00 00 00 00 00 00 00 00 "
|
||||
+ "00 00 00 00 00 00 00 00 "
|
||||
+ "00 00 00 00");
|
||||
|
||||
/**
|
||||
* The correct size of a {@link ChartFormatRecord} is 20 bytes (not including header).
|
||||
*/
|
||||
public void testLoad() {
|
||||
RecordInputStream in = TestcaseRecordInputStream.create(data);
|
||||
ChartFormatRecord record = new ChartFormatRecord(in);
|
||||
if (in.remaining() == 2) {
|
||||
throw new AssertionFailedError("Identified bug 44693d");
|
||||
}
|
||||
assertEquals(0, in.remaining());
|
||||
assertEquals(24, record.getRecordSize());
|
||||
|
||||
byte[] data2 = record.serialize();
|
||||
assertTrue(Arrays.equals(data, data2));
|
||||
}
|
||||
}
|
||||
/* ====================================================================
|
||||
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.hssf.record.chart;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.apache.poi.hssf.record.RecordInputStream;
|
||||
import org.apache.poi.hssf.record.TestcaseRecordInputStream;
|
||||
import org.apache.poi.util.HexRead;
|
||||
|
||||
import junit.framework.AssertionFailedError;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Tests for {@link ChartFormatRecord} Test data taken directly from a real
|
||||
* Excel file.
|
||||
*
|
||||
* @author Josh Micich
|
||||
*/
|
||||
public final class TestChartFormatRecord extends TestCase {
|
||||
/**
|
||||
* This rather uninteresting data came from attachment 23347 of bug 46693 at
|
||||
* offsets 0x6BB2 and 0x7BAF
|
||||
*/
|
||||
private static final byte[] data = HexRead.readFromString(
|
||||
"14 10 14 00 " // BIFF header
|
||||
+ "00 00 00 00 00 00 00 00 "
|
||||
+ "00 00 00 00 00 00 00 00 "
|
||||
+ "00 00 00 00");
|
||||
|
||||
/**
|
||||
* The correct size of a {@link ChartFormatRecord} is 20 bytes (not including header).
|
||||
*/
|
||||
public void testLoad() {
|
||||
RecordInputStream in = TestcaseRecordInputStream.create(data);
|
||||
ChartFormatRecord record = new ChartFormatRecord(in);
|
||||
if (in.remaining() == 2) {
|
||||
throw new AssertionFailedError("Identified bug 44693d");
|
||||
}
|
||||
assertEquals(0, in.remaining());
|
||||
assertEquals(24, record.getRecordSize());
|
||||
|
||||
byte[] data2 = record.serialize();
|
||||
assertTrue(Arrays.equals(data, data2));
|
||||
}
|
||||
}
|
||||
|
@ -1,94 +1,94 @@
|
||||
/* ====================================================================
|
||||
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.hssf.record.formula.eval;
|
||||
|
||||
import junit.framework.AssertionFailedError;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.poi.hssf.record.formula.functions.EvalFactory;
|
||||
|
||||
/**
|
||||
* Test for {@link EqualEval}
|
||||
*
|
||||
* @author Josh Micich
|
||||
*/
|
||||
public final class TestEqualEval extends TestCase {
|
||||
|
||||
/**
|
||||
* Test for bug observable at svn revision 692218 (Sep 2008)<br/>
|
||||
* The value from a 1x1 area should be taken immediately, regardless of srcRow and srcCol
|
||||
*/
|
||||
public void test1x1AreaOperand() {
|
||||
|
||||
ValueEval[] values = { BoolEval.FALSE, };
|
||||
Eval[] args = {
|
||||
EvalFactory.createAreaEval("B1:B1", values),
|
||||
BoolEval.FALSE,
|
||||
};
|
||||
Eval result = EqualEval.instance.evaluate(args, 10, (short)20);
|
||||
if (result instanceof ErrorEval) {
|
||||
if (result == ErrorEval.VALUE_INVALID) {
|
||||
throw new AssertionFailedError("Identified bug in evaluation of 1x1 area");
|
||||
}
|
||||
}
|
||||
assertEquals(BoolEval.class, result.getClass());
|
||||
assertTrue(((BoolEval)result).getBooleanValue());
|
||||
}
|
||||
/**
|
||||
* Empty string is equal to blank
|
||||
*/
|
||||
public void testBlankEqualToEmptyString() {
|
||||
|
||||
Eval[] args = {
|
||||
new StringEval(""),
|
||||
BlankEval.INSTANCE,
|
||||
};
|
||||
Eval result = EqualEval.instance.evaluate(args, 10, (short)20);
|
||||
assertEquals(BoolEval.class, result.getClass());
|
||||
BoolEval be = (BoolEval) result;
|
||||
if (!be.getBooleanValue()) {
|
||||
throw new AssertionFailedError("Identified bug blank/empty string equality");
|
||||
}
|
||||
assertTrue(be.getBooleanValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for bug 46613 (observable at svn r737248)
|
||||
*/
|
||||
public void testStringInsensitive_bug46613() {
|
||||
if (!evalStringCmp("abc", "aBc", EqualEval.instance)) {
|
||||
throw new AssertionFailedError("Identified bug 46613");
|
||||
}
|
||||
assertTrue(evalStringCmp("abc", "aBc", EqualEval.instance));
|
||||
assertTrue(evalStringCmp("ABC", "azz", LessThanEval.instance));
|
||||
assertTrue(evalStringCmp("abc", "AZZ", LessThanEval.instance));
|
||||
assertTrue(evalStringCmp("ABC", "aaa", GreaterThanEval.instance));
|
||||
assertTrue(evalStringCmp("abc", "AAA", GreaterThanEval.instance));
|
||||
}
|
||||
|
||||
private static boolean evalStringCmp(String a, String b, OperationEval cmpOp) {
|
||||
Eval[] args = {
|
||||
new StringEval(a),
|
||||
new StringEval(b),
|
||||
};
|
||||
Eval result = cmpOp.evaluate(args, 10, (short)20);
|
||||
assertEquals(BoolEval.class, result.getClass());
|
||||
BoolEval be = (BoolEval) result;
|
||||
return be.getBooleanValue();
|
||||
}
|
||||
}
|
||||
/* ====================================================================
|
||||
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.hssf.record.formula.eval;
|
||||
|
||||
import junit.framework.AssertionFailedError;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.poi.hssf.record.formula.functions.EvalFactory;
|
||||
|
||||
/**
|
||||
* Test for {@link EqualEval}
|
||||
*
|
||||
* @author Josh Micich
|
||||
*/
|
||||
public final class TestEqualEval extends TestCase {
|
||||
|
||||
/**
|
||||
* Test for bug observable at svn revision 692218 (Sep 2008)<br/>
|
||||
* The value from a 1x1 area should be taken immediately, regardless of srcRow and srcCol
|
||||
*/
|
||||
public void test1x1AreaOperand() {
|
||||
|
||||
ValueEval[] values = { BoolEval.FALSE, };
|
||||
Eval[] args = {
|
||||
EvalFactory.createAreaEval("B1:B1", values),
|
||||
BoolEval.FALSE,
|
||||
};
|
||||
Eval result = EqualEval.instance.evaluate(args, 10, (short)20);
|
||||
if (result instanceof ErrorEval) {
|
||||
if (result == ErrorEval.VALUE_INVALID) {
|
||||
throw new AssertionFailedError("Identified bug in evaluation of 1x1 area");
|
||||
}
|
||||
}
|
||||
assertEquals(BoolEval.class, result.getClass());
|
||||
assertTrue(((BoolEval)result).getBooleanValue());
|
||||
}
|
||||
/**
|
||||
* Empty string is equal to blank
|
||||
*/
|
||||
public void testBlankEqualToEmptyString() {
|
||||
|
||||
Eval[] args = {
|
||||
new StringEval(""),
|
||||
BlankEval.INSTANCE,
|
||||
};
|
||||
Eval result = EqualEval.instance.evaluate(args, 10, (short)20);
|
||||
assertEquals(BoolEval.class, result.getClass());
|
||||
BoolEval be = (BoolEval) result;
|
||||
if (!be.getBooleanValue()) {
|
||||
throw new AssertionFailedError("Identified bug blank/empty string equality");
|
||||
}
|
||||
assertTrue(be.getBooleanValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for bug 46613 (observable at svn r737248)
|
||||
*/
|
||||
public void testStringInsensitive_bug46613() {
|
||||
if (!evalStringCmp("abc", "aBc", EqualEval.instance)) {
|
||||
throw new AssertionFailedError("Identified bug 46613");
|
||||
}
|
||||
assertTrue(evalStringCmp("abc", "aBc", EqualEval.instance));
|
||||
assertTrue(evalStringCmp("ABC", "azz", LessThanEval.instance));
|
||||
assertTrue(evalStringCmp("abc", "AZZ", LessThanEval.instance));
|
||||
assertTrue(evalStringCmp("ABC", "aaa", GreaterThanEval.instance));
|
||||
assertTrue(evalStringCmp("abc", "AAA", GreaterThanEval.instance));
|
||||
}
|
||||
|
||||
private static boolean evalStringCmp(String a, String b, OperationEval cmpOp) {
|
||||
Eval[] args = {
|
||||
new StringEval(a),
|
||||
new StringEval(b),
|
||||
};
|
||||
Eval result = cmpOp.evaluate(args, 10, (short)20);
|
||||
assertEquals(BoolEval.class, result.getClass());
|
||||
BoolEval be = (BoolEval) result;
|
||||
return be.getBooleanValue();
|
||||
}
|
||||
}
|
||||
|
@ -1,232 +1,232 @@
|
||||
/* ====================================================================
|
||||
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.hssf.usermodel;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import org.apache.poi.hssf.HSSFTestDataSamples;
|
||||
|
||||
/**
|
||||
* Tests HSSFHyperlink.
|
||||
*
|
||||
* @author Yegor Kozlov
|
||||
*/
|
||||
public final class TestHSSFHyperlink extends TestCase {
|
||||
|
||||
/**
|
||||
* Test that we can read hyperlinks.
|
||||
*/
|
||||
public void testRead() {
|
||||
|
||||
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("HyperlinksOnManySheets.xls");
|
||||
|
||||
HSSFSheet sheet;
|
||||
HSSFCell cell;
|
||||
HSSFHyperlink link;
|
||||
|
||||
sheet = wb.getSheet("WebLinks");
|
||||
cell = sheet.getRow(4).getCell(0);
|
||||
link = cell.getHyperlink();
|
||||
assertNotNull(link);
|
||||
assertEquals("POI", link.getLabel());
|
||||
assertEquals("POI", cell.getRichStringCellValue().getString());
|
||||
assertEquals("http://poi.apache.org/", link.getAddress());
|
||||
|
||||
cell = sheet.getRow(8).getCell(0);
|
||||
link = cell.getHyperlink();
|
||||
assertNotNull(link);
|
||||
assertEquals("HSSF", link.getLabel());
|
||||
assertEquals("HSSF", cell.getRichStringCellValue().getString());
|
||||
assertEquals("http://poi.apache.org/hssf/", link.getAddress());
|
||||
|
||||
sheet = wb.getSheet("Emails");
|
||||
cell = sheet.getRow(4).getCell(0);
|
||||
link = cell.getHyperlink();
|
||||
assertNotNull(link);
|
||||
assertEquals("dev", link.getLabel());
|
||||
assertEquals("dev", cell.getRichStringCellValue().getString());
|
||||
assertEquals("mailto:dev@poi.apache.org", link.getAddress());
|
||||
|
||||
sheet = wb.getSheet("Internal");
|
||||
cell = sheet.getRow(4).getCell(0);
|
||||
link = cell.getHyperlink();
|
||||
assertNotNull(link);
|
||||
assertEquals("Link To First Sheet", link.getLabel());
|
||||
assertEquals("Link To First Sheet", cell.getRichStringCellValue().getString());
|
||||
assertEquals("WebLinks!A1", link.getTextMark());
|
||||
}
|
||||
|
||||
public void testModify() throws Exception {
|
||||
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("HyperlinksOnManySheets.xls");
|
||||
|
||||
HSSFSheet sheet;
|
||||
HSSFCell cell;
|
||||
HSSFHyperlink link;
|
||||
|
||||
sheet = wb.getSheet("WebLinks");
|
||||
cell = sheet.getRow(4).getCell(0);
|
||||
link = cell.getHyperlink();
|
||||
//modify the link
|
||||
link.setAddress("www.apache.org");
|
||||
|
||||
//serialize and read again
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
wb.write(out);
|
||||
|
||||
wb = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
|
||||
sheet = wb.getSheet("WebLinks");
|
||||
cell = sheet.getRow(4).getCell(0);
|
||||
link = cell.getHyperlink();
|
||||
assertNotNull(link);
|
||||
assertEquals("www.apache.org", link.getAddress());
|
||||
|
||||
}
|
||||
|
||||
public void testCreate() throws Exception {
|
||||
HSSFWorkbook wb = new HSSFWorkbook();
|
||||
|
||||
HSSFCell cell;
|
||||
HSSFSheet sheet = wb.createSheet("Hyperlinks");
|
||||
|
||||
//URL
|
||||
cell = sheet.createRow(0).createCell(0);
|
||||
cell.setCellValue("URL Link");
|
||||
HSSFHyperlink link = new HSSFHyperlink(HSSFHyperlink.LINK_URL);
|
||||
link.setAddress("http://poi.apache.org/");
|
||||
cell.setHyperlink(link);
|
||||
|
||||
//link to a file in the current directory
|
||||
cell = sheet.createRow(1).createCell(0);
|
||||
cell.setCellValue("File Link");
|
||||
link = new HSSFHyperlink(HSSFHyperlink.LINK_FILE);
|
||||
link.setAddress("link1.xls");
|
||||
cell.setHyperlink(link);
|
||||
|
||||
//e-mail link
|
||||
cell = sheet.createRow(2).createCell(0);
|
||||
cell.setCellValue("Email Link");
|
||||
link = new HSSFHyperlink(HSSFHyperlink.LINK_EMAIL);
|
||||
//note, if subject contains white spaces, make sure they are url-encoded
|
||||
link.setAddress("mailto:poi@apache.org?subject=Hyperlinks");
|
||||
cell.setHyperlink(link);
|
||||
|
||||
//link to a place in this workbook
|
||||
|
||||
//create a target sheet and cell
|
||||
HSSFSheet sheet2 = wb.createSheet("Target Sheet");
|
||||
sheet2.createRow(0).createCell(0).setCellValue("Target Cell");
|
||||
|
||||
cell = sheet.createRow(3).createCell(0);
|
||||
cell.setCellValue("Worksheet Link");
|
||||
link = new HSSFHyperlink(HSSFHyperlink.LINK_DOCUMENT);
|
||||
link.setTextMark("'Target Sheet'!A1");
|
||||
cell.setHyperlink(link);
|
||||
|
||||
//serialize and read again
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
wb.write(out);
|
||||
|
||||
wb = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
|
||||
sheet = wb.getSheet("Hyperlinks");
|
||||
cell = sheet.getRow(0).getCell(0);
|
||||
link = cell.getHyperlink();
|
||||
assertNotNull(link);
|
||||
assertEquals("http://poi.apache.org/", link.getAddress());
|
||||
|
||||
cell = sheet.getRow(1).getCell(0);
|
||||
link = cell.getHyperlink();
|
||||
assertNotNull(link);
|
||||
assertEquals("link1.xls", link.getAddress());
|
||||
|
||||
cell = sheet.getRow(2).getCell(0);
|
||||
link = cell.getHyperlink();
|
||||
assertNotNull(link);
|
||||
assertEquals("mailto:poi@apache.org?subject=Hyperlinks", link.getAddress());
|
||||
|
||||
cell = sheet.getRow(3).getCell(0);
|
||||
link = cell.getHyperlink();
|
||||
assertNotNull(link);
|
||||
assertEquals("'Target Sheet'!A1", link.getTextMark());
|
||||
}
|
||||
|
||||
public void testCloneSheet() {
|
||||
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("HyperlinksOnManySheets.xls");
|
||||
|
||||
HSSFCell cell;
|
||||
HSSFHyperlink link;
|
||||
|
||||
HSSFSheet sheet = wb.cloneSheet(0);
|
||||
|
||||
cell = sheet.getRow(4).getCell(0);
|
||||
link = cell.getHyperlink();
|
||||
assertNotNull(link);
|
||||
assertEquals("http://poi.apache.org/", link.getAddress());
|
||||
|
||||
cell = sheet.getRow(8).getCell(0);
|
||||
link = cell.getHyperlink();
|
||||
assertNotNull(link);
|
||||
assertEquals("http://poi.apache.org/hssf/", link.getAddress());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that HSSFSheet#shiftRows moves hyperlinks,
|
||||
* see bugs #46445 and #29957
|
||||
*/
|
||||
public void testShiftRows(){
|
||||
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("46445.xls");
|
||||
|
||||
|
||||
HSSFSheet sheet = wb.getSheetAt(0);
|
||||
|
||||
//verify existing hyperlink in A3
|
||||
HSSFCell cell1 = sheet.getRow(2).getCell(0);
|
||||
HSSFHyperlink link1 = cell1.getHyperlink();
|
||||
assertNotNull(link1);
|
||||
assertEquals(2, link1.getFirstRow());
|
||||
assertEquals(2, link1.getLastRow());
|
||||
|
||||
//assign a hyperlink to A4
|
||||
HSSFHyperlink link2 = new HSSFHyperlink(HSSFHyperlink.LINK_DOCUMENT);
|
||||
link2.setAddress("Sheet2!A2");
|
||||
HSSFCell cell2 = sheet.getRow(3).getCell(0);
|
||||
cell2.setHyperlink(link2);
|
||||
assertEquals(3, link2.getFirstRow());
|
||||
assertEquals(3, link2.getLastRow());
|
||||
|
||||
//move the 3rd row two rows down
|
||||
sheet.shiftRows(sheet.getFirstRowNum(), sheet.getLastRowNum(), 2);
|
||||
|
||||
//cells A3 and A4 don't contain hyperlinks anymore
|
||||
assertNull(sheet.getRow(2).getCell(0).getHyperlink());
|
||||
assertNull(sheet.getRow(3).getCell(0).getHyperlink());
|
||||
|
||||
//the first hypelink now belongs to A5
|
||||
HSSFHyperlink link1_shifted = sheet.getRow(2+2).getCell(0).getHyperlink();
|
||||
assertNotNull(link1_shifted);
|
||||
assertEquals(4, link1_shifted.getFirstRow());
|
||||
assertEquals(4, link1_shifted.getLastRow());
|
||||
|
||||
//the second hypelink now belongs to A6
|
||||
HSSFHyperlink link2_shifted = sheet.getRow(3+2).getCell(0).getHyperlink();
|
||||
assertNotNull(link2_shifted);
|
||||
assertEquals(5, link2_shifted.getFirstRow());
|
||||
assertEquals(5, link2_shifted.getLastRow());
|
||||
}
|
||||
}
|
||||
/* ====================================================================
|
||||
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.hssf.usermodel;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import org.apache.poi.hssf.HSSFTestDataSamples;
|
||||
|
||||
/**
|
||||
* Tests HSSFHyperlink.
|
||||
*
|
||||
* @author Yegor Kozlov
|
||||
*/
|
||||
public final class TestHSSFHyperlink extends TestCase {
|
||||
|
||||
/**
|
||||
* Test that we can read hyperlinks.
|
||||
*/
|
||||
public void testRead() {
|
||||
|
||||
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("HyperlinksOnManySheets.xls");
|
||||
|
||||
HSSFSheet sheet;
|
||||
HSSFCell cell;
|
||||
HSSFHyperlink link;
|
||||
|
||||
sheet = wb.getSheet("WebLinks");
|
||||
cell = sheet.getRow(4).getCell(0);
|
||||
link = cell.getHyperlink();
|
||||
assertNotNull(link);
|
||||
assertEquals("POI", link.getLabel());
|
||||
assertEquals("POI", cell.getRichStringCellValue().getString());
|
||||
assertEquals("http://poi.apache.org/", link.getAddress());
|
||||
|
||||
cell = sheet.getRow(8).getCell(0);
|
||||
link = cell.getHyperlink();
|
||||
assertNotNull(link);
|
||||
assertEquals("HSSF", link.getLabel());
|
||||
assertEquals("HSSF", cell.getRichStringCellValue().getString());
|
||||
assertEquals("http://poi.apache.org/hssf/", link.getAddress());
|
||||
|
||||
sheet = wb.getSheet("Emails");
|
||||
cell = sheet.getRow(4).getCell(0);
|
||||
link = cell.getHyperlink();
|
||||
assertNotNull(link);
|
||||
assertEquals("dev", link.getLabel());
|
||||
assertEquals("dev", cell.getRichStringCellValue().getString());
|
||||
assertEquals("mailto:dev@poi.apache.org", link.getAddress());
|
||||
|
||||
sheet = wb.getSheet("Internal");
|
||||
cell = sheet.getRow(4).getCell(0);
|
||||
link = cell.getHyperlink();
|
||||
assertNotNull(link);
|
||||
assertEquals("Link To First Sheet", link.getLabel());
|
||||
assertEquals("Link To First Sheet", cell.getRichStringCellValue().getString());
|
||||
assertEquals("WebLinks!A1", link.getTextMark());
|
||||
}
|
||||
|
||||
public void testModify() throws Exception {
|
||||
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("HyperlinksOnManySheets.xls");
|
||||
|
||||
HSSFSheet sheet;
|
||||
HSSFCell cell;
|
||||
HSSFHyperlink link;
|
||||
|
||||
sheet = wb.getSheet("WebLinks");
|
||||
cell = sheet.getRow(4).getCell(0);
|
||||
link = cell.getHyperlink();
|
||||
//modify the link
|
||||
link.setAddress("www.apache.org");
|
||||
|
||||
//serialize and read again
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
wb.write(out);
|
||||
|
||||
wb = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
|
||||
sheet = wb.getSheet("WebLinks");
|
||||
cell = sheet.getRow(4).getCell(0);
|
||||
link = cell.getHyperlink();
|
||||
assertNotNull(link);
|
||||
assertEquals("www.apache.org", link.getAddress());
|
||||
|
||||
}
|
||||
|
||||
public void testCreate() throws Exception {
|
||||
HSSFWorkbook wb = new HSSFWorkbook();
|
||||
|
||||
HSSFCell cell;
|
||||
HSSFSheet sheet = wb.createSheet("Hyperlinks");
|
||||
|
||||
//URL
|
||||
cell = sheet.createRow(0).createCell(0);
|
||||
cell.setCellValue("URL Link");
|
||||
HSSFHyperlink link = new HSSFHyperlink(HSSFHyperlink.LINK_URL);
|
||||
link.setAddress("http://poi.apache.org/");
|
||||
cell.setHyperlink(link);
|
||||
|
||||
//link to a file in the current directory
|
||||
cell = sheet.createRow(1).createCell(0);
|
||||
cell.setCellValue("File Link");
|
||||
link = new HSSFHyperlink(HSSFHyperlink.LINK_FILE);
|
||||
link.setAddress("link1.xls");
|
||||
cell.setHyperlink(link);
|
||||
|
||||
//e-mail link
|
||||
cell = sheet.createRow(2).createCell(0);
|
||||
cell.setCellValue("Email Link");
|
||||
link = new HSSFHyperlink(HSSFHyperlink.LINK_EMAIL);
|
||||
//note, if subject contains white spaces, make sure they are url-encoded
|
||||
link.setAddress("mailto:poi@apache.org?subject=Hyperlinks");
|
||||
cell.setHyperlink(link);
|
||||
|
||||
//link to a place in this workbook
|
||||
|
||||
//create a target sheet and cell
|
||||
HSSFSheet sheet2 = wb.createSheet("Target Sheet");
|
||||
sheet2.createRow(0).createCell(0).setCellValue("Target Cell");
|
||||
|
||||
cell = sheet.createRow(3).createCell(0);
|
||||
cell.setCellValue("Worksheet Link");
|
||||
link = new HSSFHyperlink(HSSFHyperlink.LINK_DOCUMENT);
|
||||
link.setTextMark("'Target Sheet'!A1");
|
||||
cell.setHyperlink(link);
|
||||
|
||||
//serialize and read again
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
wb.write(out);
|
||||
|
||||
wb = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
|
||||
sheet = wb.getSheet("Hyperlinks");
|
||||
cell = sheet.getRow(0).getCell(0);
|
||||
link = cell.getHyperlink();
|
||||
assertNotNull(link);
|
||||
assertEquals("http://poi.apache.org/", link.getAddress());
|
||||
|
||||
cell = sheet.getRow(1).getCell(0);
|
||||
link = cell.getHyperlink();
|
||||
assertNotNull(link);
|
||||
assertEquals("link1.xls", link.getAddress());
|
||||
|
||||
cell = sheet.getRow(2).getCell(0);
|
||||
link = cell.getHyperlink();
|
||||
assertNotNull(link);
|
||||
assertEquals("mailto:poi@apache.org?subject=Hyperlinks", link.getAddress());
|
||||
|
||||
cell = sheet.getRow(3).getCell(0);
|
||||
link = cell.getHyperlink();
|
||||
assertNotNull(link);
|
||||
assertEquals("'Target Sheet'!A1", link.getTextMark());
|
||||
}
|
||||
|
||||
public void testCloneSheet() {
|
||||
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("HyperlinksOnManySheets.xls");
|
||||
|
||||
HSSFCell cell;
|
||||
HSSFHyperlink link;
|
||||
|
||||
HSSFSheet sheet = wb.cloneSheet(0);
|
||||
|
||||
cell = sheet.getRow(4).getCell(0);
|
||||
link = cell.getHyperlink();
|
||||
assertNotNull(link);
|
||||
assertEquals("http://poi.apache.org/", link.getAddress());
|
||||
|
||||
cell = sheet.getRow(8).getCell(0);
|
||||
link = cell.getHyperlink();
|
||||
assertNotNull(link);
|
||||
assertEquals("http://poi.apache.org/hssf/", link.getAddress());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that HSSFSheet#shiftRows moves hyperlinks,
|
||||
* see bugs #46445 and #29957
|
||||
*/
|
||||
public void testShiftRows(){
|
||||
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("46445.xls");
|
||||
|
||||
|
||||
HSSFSheet sheet = wb.getSheetAt(0);
|
||||
|
||||
//verify existing hyperlink in A3
|
||||
HSSFCell cell1 = sheet.getRow(2).getCell(0);
|
||||
HSSFHyperlink link1 = cell1.getHyperlink();
|
||||
assertNotNull(link1);
|
||||
assertEquals(2, link1.getFirstRow());
|
||||
assertEquals(2, link1.getLastRow());
|
||||
|
||||
//assign a hyperlink to A4
|
||||
HSSFHyperlink link2 = new HSSFHyperlink(HSSFHyperlink.LINK_DOCUMENT);
|
||||
link2.setAddress("Sheet2!A2");
|
||||
HSSFCell cell2 = sheet.getRow(3).getCell(0);
|
||||
cell2.setHyperlink(link2);
|
||||
assertEquals(3, link2.getFirstRow());
|
||||
assertEquals(3, link2.getLastRow());
|
||||
|
||||
//move the 3rd row two rows down
|
||||
sheet.shiftRows(sheet.getFirstRowNum(), sheet.getLastRowNum(), 2);
|
||||
|
||||
//cells A3 and A4 don't contain hyperlinks anymore
|
||||
assertNull(sheet.getRow(2).getCell(0).getHyperlink());
|
||||
assertNull(sheet.getRow(3).getCell(0).getHyperlink());
|
||||
|
||||
//the first hypelink now belongs to A5
|
||||
HSSFHyperlink link1_shifted = sheet.getRow(2+2).getCell(0).getHyperlink();
|
||||
assertNotNull(link1_shifted);
|
||||
assertEquals(4, link1_shifted.getFirstRow());
|
||||
assertEquals(4, link1_shifted.getLastRow());
|
||||
|
||||
//the second hypelink now belongs to A6
|
||||
HSSFHyperlink link2_shifted = sheet.getRow(3+2).getCell(0).getHyperlink();
|
||||
assertNotNull(link2_shifted);
|
||||
assertEquals(5, link2_shifted.getFirstRow());
|
||||
assertEquals(5, link2_shifted.getLastRow());
|
||||
}
|
||||
}
|
||||
|
@ -1,71 +1,69 @@
|
||||
/* ====================================================================
|
||||
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.hssf.usermodel;
|
||||
|
||||
import org.apache.poi.hssf.HSSFTestDataSamples;
|
||||
|
||||
import junit.framework.AssertionFailedError;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* @author Josh Micich
|
||||
*/
|
||||
public final class TestHSSFPatriarch extends TestCase {
|
||||
|
||||
public void testBasic() {
|
||||
|
||||
HSSFWorkbook wb = new HSSFWorkbook();
|
||||
HSSFSheet sheet = wb.createSheet();
|
||||
|
||||
HSSFPatriarch patr = sheet.createDrawingPatriarch();
|
||||
|
||||
assertNotNull(patr);
|
||||
|
||||
// assert something more interesting
|
||||
}
|
||||
|
||||
// TODO - fix bug 44916 (1-May-2008)
|
||||
public void DISABLED_test44916() {
|
||||
|
||||
HSSFWorkbook wb = new HSSFWorkbook();
|
||||
HSSFSheet sheet = wb.createSheet();
|
||||
|
||||
// 1. Create drawing patriarch
|
||||
HSSFPatriarch patr = sheet.createDrawingPatriarch();
|
||||
|
||||
// 2. Try to re-get the patriarch
|
||||
HSSFPatriarch existingPatr;
|
||||
try {
|
||||
existingPatr = sheet.getDrawingPatriarch();
|
||||
} catch (NullPointerException e) {
|
||||
throw new AssertionFailedError("Identified bug 44916");
|
||||
}
|
||||
|
||||
// 3. Use patriarch
|
||||
HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 600, 245, (short) 1, 1, (short) 1, 2);
|
||||
anchor.setAnchorType(3);
|
||||
byte[] pictureData = HSSFTestDataSamples.getTestDataFileContent("logoKarmokar4.png");
|
||||
int idx1 = wb.addPicture(pictureData, HSSFWorkbook.PICTURE_TYPE_PNG);
|
||||
patr.createPicture(anchor, idx1);
|
||||
|
||||
// 4. Try to re-use patriarch later
|
||||
existingPatr = sheet.getDrawingPatriarch();
|
||||
assertNotNull(existingPatr);
|
||||
}
|
||||
|
||||
}
|
||||
/* ====================================================================
|
||||
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.hssf.usermodel;
|
||||
|
||||
import org.apache.poi.hssf.HSSFTestDataSamples;
|
||||
|
||||
import junit.framework.AssertionFailedError;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* @author Josh Micich
|
||||
*/
|
||||
public final class TestHSSFPatriarch extends TestCase {
|
||||
|
||||
public void testBasic() {
|
||||
|
||||
HSSFWorkbook wb = new HSSFWorkbook();
|
||||
HSSFSheet sheet = wb.createSheet();
|
||||
|
||||
HSSFPatriarch patr = sheet.createDrawingPatriarch();
|
||||
assertNotNull(patr);
|
||||
|
||||
// assert something more interesting
|
||||
}
|
||||
|
||||
// TODO - fix bug 44916 (1-May-2008)
|
||||
public void DISABLED_test44916() {
|
||||
|
||||
HSSFWorkbook wb = new HSSFWorkbook();
|
||||
HSSFSheet sheet = wb.createSheet();
|
||||
|
||||
// 1. Create drawing patriarch
|
||||
HSSFPatriarch patr = sheet.createDrawingPatriarch();
|
||||
|
||||
// 2. Try to re-get the patriarch
|
||||
HSSFPatriarch existingPatr;
|
||||
try {
|
||||
existingPatr = sheet.getDrawingPatriarch();
|
||||
} catch (NullPointerException e) {
|
||||
throw new AssertionFailedError("Identified bug 44916");
|
||||
}
|
||||
|
||||
// 3. Use patriarch
|
||||
HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 600, 245, (short) 1, 1, (short) 1, 2);
|
||||
anchor.setAnchorType(3);
|
||||
byte[] pictureData = HSSFTestDataSamples.getTestDataFileContent("logoKarmokar4.png");
|
||||
int idx1 = wb.addPicture(pictureData, HSSFWorkbook.PICTURE_TYPE_PNG);
|
||||
patr.createPicture(anchor, idx1);
|
||||
|
||||
// 4. Try to re-use patriarch later
|
||||
existingPatr = sheet.getDrawingPatriarch();
|
||||
assertNotNull(existingPatr);
|
||||
}
|
||||
}
|
||||
|
@ -1,54 +1,54 @@
|
||||
/*
|
||||
* 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.hssf.usermodel;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.poi.hssf.HSSFTestDataSamples;
|
||||
import org.apache.poi.hssf.HSSFITestDataProvider;
|
||||
import org.apache.poi.ss.usermodel.BaseTestPicture;
|
||||
|
||||
/**
|
||||
* Test <code>HSSFPicture</code>.
|
||||
*
|
||||
* @author Yegor Kozlov (yegor at apache.org)
|
||||
*/
|
||||
public final class TestHSSFPicture extends BaseTestPicture {
|
||||
|
||||
@Override
|
||||
protected HSSFITestDataProvider getTestDataProvider(){
|
||||
return HSSFITestDataProvider.getInstance();
|
||||
}
|
||||
|
||||
public void testResize() {
|
||||
baseTestResize(new HSSFClientAnchor(0, 0, 848, 240, (short)0, 0, (short)1, 9));
|
||||
}
|
||||
|
||||
/**
|
||||
* Bug # 45829 reported ArithmeticException (/ by zero) when resizing png with zero DPI.
|
||||
*/
|
||||
public void test45829() {
|
||||
HSSFWorkbook wb = new HSSFWorkbook();
|
||||
HSSFSheet sh1 = wb.createSheet();
|
||||
HSSFPatriarch p1 = sh1.createDrawingPatriarch();
|
||||
|
||||
byte[] pictureData = HSSFTestDataSamples.getTestDataFileContent("45829.png");
|
||||
int idx1 = wb.addPicture( pictureData, HSSFWorkbook.PICTURE_TYPE_PNG );
|
||||
HSSFPicture pic = p1.createPicture(new HSSFClientAnchor(), idx1);
|
||||
pic.resize();
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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.hssf.usermodel;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.poi.hssf.HSSFTestDataSamples;
|
||||
import org.apache.poi.hssf.HSSFITestDataProvider;
|
||||
import org.apache.poi.ss.usermodel.BaseTestPicture;
|
||||
|
||||
/**
|
||||
* Test <code>HSSFPicture</code>.
|
||||
*
|
||||
* @author Yegor Kozlov (yegor at apache.org)
|
||||
*/
|
||||
public final class TestHSSFPicture extends BaseTestPicture {
|
||||
|
||||
@Override
|
||||
protected HSSFITestDataProvider getTestDataProvider(){
|
||||
return HSSFITestDataProvider.getInstance();
|
||||
}
|
||||
|
||||
public void testResize() {
|
||||
baseTestResize(new HSSFClientAnchor(0, 0, 848, 240, (short)0, 0, (short)1, 9));
|
||||
}
|
||||
|
||||
/**
|
||||
* Bug # 45829 reported ArithmeticException (/ by zero) when resizing png with zero DPI.
|
||||
*/
|
||||
public void test45829() {
|
||||
HSSFWorkbook wb = new HSSFWorkbook();
|
||||
HSSFSheet sh1 = wb.createSheet();
|
||||
HSSFPatriarch p1 = sh1.createDrawingPatriarch();
|
||||
|
||||
byte[] pictureData = HSSFTestDataSamples.getTestDataFileContent("45829.png");
|
||||
int idx1 = wb.addPicture( pictureData, HSSFWorkbook.PICTURE_TYPE_PNG );
|
||||
HSSFPicture pic = p1.createPicture(new HSSFClientAnchor(), idx1);
|
||||
pic.resize();
|
||||
}
|
||||
}
|
||||
|
@ -1,71 +1,72 @@
|
||||
/* ====================================================================
|
||||
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.hssf.usermodel;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.poi.hssf.HSSFTestDataSamples;
|
||||
|
||||
/**
|
||||
* Test <code>HSSFPictureData</code>.
|
||||
* The code to retrieve images from a workbook provided by Trejkaz (trejkaz at trypticon dot org) in Bug 41223.
|
||||
*
|
||||
* @author Yegor Kozlov (yegor at apache dot org)
|
||||
* @author Trejkaz (trejkaz at trypticon dot org)
|
||||
*/
|
||||
public final class TestHSSFPictureData extends TestCase{
|
||||
|
||||
|
||||
public void testPictures() throws IOException {
|
||||
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("SimpleWithImages.xls");
|
||||
|
||||
List lst = wb.getAllPictures();
|
||||
//assertEquals(2, lst.size());
|
||||
|
||||
for (Iterator it = lst.iterator(); it.hasNext(); ) {
|
||||
HSSFPictureData pict = (HSSFPictureData)it.next();
|
||||
String ext = pict.suggestFileExtension();
|
||||
byte[] data = pict.getData();
|
||||
if (ext.equals("jpeg")){
|
||||
//try to read image data using javax.imageio.* (JDK 1.4+)
|
||||
BufferedImage jpg = ImageIO.read(new ByteArrayInputStream(data));
|
||||
assertNotNull(jpg);
|
||||
assertEquals(192, jpg.getWidth());
|
||||
assertEquals(176, jpg.getHeight());
|
||||
assertEquals(HSSFWorkbook.PICTURE_TYPE_JPEG, pict.getFormat());
|
||||
} else if (ext.equals("png")){
|
||||
//try to read image data using javax.imageio.* (JDK 1.4+)
|
||||
BufferedImage png = ImageIO.read(new ByteArrayInputStream(data));
|
||||
assertNotNull(png);
|
||||
assertEquals(300, png.getWidth());
|
||||
assertEquals(300, png.getHeight());
|
||||
assertEquals(HSSFWorkbook.PICTURE_TYPE_PNG, pict.getFormat());
|
||||
} else {
|
||||
//TODO: test code for PICT, WMF and EMF
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/* ====================================================================
|
||||
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.hssf.usermodel;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.poi.hssf.HSSFTestDataSamples;
|
||||
|
||||
/**
|
||||
* Test <code>HSSFPictureData</code>.
|
||||
* The code to retrieve images from a workbook provided by Trejkaz (trejkaz at trypticon dot org) in Bug 41223.
|
||||
*
|
||||
* @author Yegor Kozlov (yegor at apache dot org)
|
||||
* @author Trejkaz (trejkaz at trypticon dot org)
|
||||
*/
|
||||
public final class TestHSSFPictureData extends TestCase{
|
||||
|
||||
|
||||
public void testPictures() throws IOException {
|
||||
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("SimpleWithImages.xls");
|
||||
|
||||
@SuppressWarnings("unchecked") // TODO - add getFormat() to interface PictureData and genericise wb.getAllPictures()
|
||||
List<HSSFPictureData> lst = (List<HSSFPictureData>)(List<?>)wb.getAllPictures();
|
||||
//assertEquals(2, lst.size());
|
||||
|
||||
for (Iterator it = lst.iterator(); it.hasNext(); ) {
|
||||
HSSFPictureData pict = (HSSFPictureData)it.next();
|
||||
String ext = pict.suggestFileExtension();
|
||||
byte[] data = pict.getData();
|
||||
if (ext.equals("jpeg")){
|
||||
//try to read image data using javax.imageio.* (JDK 1.4+)
|
||||
BufferedImage jpg = ImageIO.read(new ByteArrayInputStream(data));
|
||||
assertNotNull(jpg);
|
||||
assertEquals(192, jpg.getWidth());
|
||||
assertEquals(176, jpg.getHeight());
|
||||
assertEquals(HSSFWorkbook.PICTURE_TYPE_JPEG, pict.getFormat());
|
||||
} else if (ext.equals("png")){
|
||||
//try to read image data using javax.imageio.* (JDK 1.4+)
|
||||
BufferedImage png = ImageIO.read(new ByteArrayInputStream(data));
|
||||
assertNotNull(png);
|
||||
assertEquals(300, png.getWidth());
|
||||
assertEquals(300, png.getHeight());
|
||||
assertEquals(HSSFWorkbook.PICTURE_TYPE_PNG, pict.getFormat());
|
||||
} else {
|
||||
//TODO: test code for PICT, WMF and EMF
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,71 +1,65 @@
|
||||
/*
|
||||
* 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.hssf.usermodel;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Test <code>HSSFTextbox</code>.
|
||||
*
|
||||
* @author Yegor Kozlov (yegor at apache.org)
|
||||
*/
|
||||
public final class TestHSSFTextbox extends TestCase{
|
||||
|
||||
/**
|
||||
* Test that accessors to horizontal and vertical alignment work properly
|
||||
*/
|
||||
public void testAlignment() {
|
||||
HSSFWorkbook wb = new HSSFWorkbook();
|
||||
HSSFSheet sh1 = wb.createSheet();
|
||||
HSSFPatriarch patriarch = sh1.createDrawingPatriarch();
|
||||
|
||||
HSSFTextbox textbox = patriarch.createTextbox(new HSSFClientAnchor(0, 0, 0, 0, (short) 1, 1, (short) 6, 4));
|
||||
HSSFRichTextString str = new HSSFRichTextString("Hello, World");
|
||||
textbox.setString(str);
|
||||
textbox.setHorizontalAlignment(HSSFTextbox.HORIZONTAL_ALIGNMENT_CENTERED);
|
||||
textbox.setVerticalAlignment(HSSFTextbox.VERTICAL_ALIGNMENT_CENTER);
|
||||
|
||||
assertEquals(HSSFTextbox.HORIZONTAL_ALIGNMENT_CENTERED, textbox.getHorizontalAlignment());
|
||||
assertEquals(HSSFTextbox.VERTICAL_ALIGNMENT_CENTER, textbox.getVerticalAlignment());
|
||||
}
|
||||
|
||||
/**
|
||||
* Excel requires at least one format run in HSSFTextbox.
|
||||
* When inserting text make sure that if font is not set we must set the default one.
|
||||
*/
|
||||
public void testSetDeafultTextFormat() {
|
||||
HSSFWorkbook wb = new HSSFWorkbook();
|
||||
HSSFSheet sheet = wb.createSheet();
|
||||
HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
|
||||
|
||||
HSSFTextbox textbox1 = patriarch.createTextbox(new HSSFClientAnchor(0,0,0,0,(short)1,1,(short)3,3));
|
||||
HSSFRichTextString rt1 = new HSSFRichTextString("Hello, World!");
|
||||
assertEquals(0, rt1.numFormattingRuns());
|
||||
textbox1.setString(rt1);
|
||||
|
||||
HSSFRichTextString rt2 = textbox1.getString();
|
||||
assertEquals(1, rt2.numFormattingRuns());
|
||||
assertEquals(HSSFRichTextString.NO_FONT, rt2.getFontOfFormattingRun(0));
|
||||
}
|
||||
|
||||
}
|
||||
/* ====================================================================
|
||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
contributor license agreements. See the NOTICE file distributed with
|
||||
this work for additional information regarding copyright ownership.
|
||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
(the "License"); you may not use this file except in compliance with
|
||||
the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==================================================================== */
|
||||
|
||||
package org.apache.poi.hssf.usermodel;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Test <code>HSSFTextbox</code>.
|
||||
*
|
||||
* @author Yegor Kozlov (yegor at apache.org)
|
||||
*/
|
||||
public final class TestHSSFTextbox extends TestCase{
|
||||
|
||||
/**
|
||||
* Test that accessors to horizontal and vertical alignment work properly
|
||||
*/
|
||||
public void testAlignment() {
|
||||
HSSFWorkbook wb = new HSSFWorkbook();
|
||||
HSSFSheet sh1 = wb.createSheet();
|
||||
HSSFPatriarch patriarch = sh1.createDrawingPatriarch();
|
||||
|
||||
HSSFTextbox textbox = patriarch.createTextbox(new HSSFClientAnchor(0, 0, 0, 0, (short) 1, 1, (short) 6, 4));
|
||||
HSSFRichTextString str = new HSSFRichTextString("Hello, World");
|
||||
textbox.setString(str);
|
||||
textbox.setHorizontalAlignment(HSSFTextbox.HORIZONTAL_ALIGNMENT_CENTERED);
|
||||
textbox.setVerticalAlignment(HSSFTextbox.VERTICAL_ALIGNMENT_CENTER);
|
||||
|
||||
assertEquals(HSSFTextbox.HORIZONTAL_ALIGNMENT_CENTERED, textbox.getHorizontalAlignment());
|
||||
assertEquals(HSSFTextbox.VERTICAL_ALIGNMENT_CENTER, textbox.getVerticalAlignment());
|
||||
}
|
||||
|
||||
/**
|
||||
* Excel requires at least one format run in HSSFTextbox.
|
||||
* When inserting text make sure that if font is not set we must set the default one.
|
||||
*/
|
||||
public void testSetDeafultTextFormat() {
|
||||
HSSFWorkbook wb = new HSSFWorkbook();
|
||||
HSSFSheet sheet = wb.createSheet();
|
||||
HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
|
||||
|
||||
HSSFTextbox textbox1 = patriarch.createTextbox(new HSSFClientAnchor(0,0,0,0,(short)1,1,(short)3,3));
|
||||
HSSFRichTextString rt1 = new HSSFRichTextString("Hello, World!");
|
||||
assertEquals(0, rt1.numFormattingRuns());
|
||||
textbox1.setString(rt1);
|
||||
|
||||
HSSFRichTextString rt2 = textbox1.getString();
|
||||
assertEquals(1, rt2.numFormattingRuns());
|
||||
assertEquals(HSSFRichTextString.NO_FONT, rt2.getFontOfFormattingRun(0));
|
||||
}
|
||||
}
|
||||
|
@ -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.ss;
|
||||
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
|
||||
/**
|
||||
* Incapsulates a provider of test data for common HSSF / XSSF tests.
|
||||
*/
|
||||
public interface ITestDataProvider {
|
||||
/**
|
||||
* Override to provide HSSF / XSSF specific way for re-serialising a workbook
|
||||
*
|
||||
* @param wb the workbook to re-serialize
|
||||
* @return the re-serialized workbook
|
||||
*/
|
||||
Workbook writeOutAndReadBack(Workbook wb);
|
||||
|
||||
/**
|
||||
* Override to provide way of loading HSSF / XSSF sample workbooks
|
||||
*
|
||||
* @param sampleFileName the file name to load
|
||||
* @return an instance of Workbook loaded from the supplied file name
|
||||
*/
|
||||
Workbook openSampleWorkbook(String sampleFileName);
|
||||
|
||||
/**
|
||||
* Override to provide way of creating HSSF / XSSF workbooks
|
||||
* @return an instance of Workbook
|
||||
*/
|
||||
Workbook createWorkbook();
|
||||
|
||||
/**
|
||||
* Opens a sample file from the standard HSSF test data directory
|
||||
*
|
||||
* @return an open <tt>InputStream</tt> for the specified sample file
|
||||
*/
|
||||
byte[] getTestDataFileContent(String fileName);
|
||||
|
||||
SpreadsheetVersion getSpreadsheetVersion();
|
||||
}
|
||||
/* ====================================================================
|
||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
contributor license agreements. See the NOTICE file distributed with
|
||||
this work for additional information regarding copyright ownership.
|
||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
(the "License"); you may not use this file except in compliance with
|
||||
the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==================================================================== */
|
||||
|
||||
package org.apache.poi.ss;
|
||||
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
|
||||
/**
|
||||
* Encapsulates a provider of test data for common HSSF / XSSF tests.
|
||||
*/
|
||||
public interface ITestDataProvider {
|
||||
/**
|
||||
* Override to provide HSSF / XSSF specific way for re-serialising a workbook
|
||||
*
|
||||
* @param wb the workbook to re-serialize
|
||||
* @return the re-serialized workbook
|
||||
*/
|
||||
Workbook writeOutAndReadBack(Workbook wb);
|
||||
|
||||
/**
|
||||
* Override to provide way of loading HSSF / XSSF sample workbooks
|
||||
*
|
||||
* @param sampleFileName the file name to load
|
||||
* @return an instance of Workbook loaded from the supplied file name
|
||||
*/
|
||||
Workbook openSampleWorkbook(String sampleFileName);
|
||||
|
||||
/**
|
||||
* Override to provide way of creating HSSF / XSSF workbooks
|
||||
* @return an instance of Workbook
|
||||
*/
|
||||
Workbook createWorkbook();
|
||||
|
||||
/**
|
||||
* Opens a sample file from the standard HSSF test data directory
|
||||
*
|
||||
* @return an open <tt>InputStream</tt> for the specified sample file
|
||||
*/
|
||||
byte[] getTestDataFileContent(String fileName);
|
||||
|
||||
SpreadsheetVersion getSpreadsheetVersion();
|
||||
}
|
||||
|
@ -1,49 +1,50 @@
|
||||
/* ====================================================================
|
||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
contributor license agreements. See the NOTICE file distributed with
|
||||
this work for additional information regarding copyright ownership.
|
||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
(the "License"); you may not use this file except in compliance with
|
||||
the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==================================================================== */
|
||||
package org.apache.poi.ss;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Check that all enum values are properly set
|
||||
*
|
||||
* @author Yegor Kozlov
|
||||
*/
|
||||
public class TestSpreadsheetVersion extends TestCase {
|
||||
|
||||
public void testExcel97(){
|
||||
SpreadsheetVersion v = SpreadsheetVersion.EXCEL97;
|
||||
assertEquals(1 << 8, v.getMaxColumns());
|
||||
assertEquals(v.getMaxColumns() - 1, v.getLastColumnIndex());
|
||||
assertEquals(1 << 16, v.getMaxRows());
|
||||
assertEquals(v.getMaxRows() - 1, v.getLastRowIndex());
|
||||
assertEquals(30, v.getMaxFunctionArgs());
|
||||
assertEquals(3, v.getMaxConditionalFormats());
|
||||
assertEquals("IV", v.getLastColumnName());
|
||||
}
|
||||
|
||||
public void testExcel2007(){
|
||||
SpreadsheetVersion v = SpreadsheetVersion.EXCEL2007;
|
||||
assertEquals(1 << 14, v.getMaxColumns());
|
||||
assertEquals(v.getMaxColumns() - 1, v.getLastColumnIndex());
|
||||
assertEquals(1 << 20, v.getMaxRows());
|
||||
assertEquals(v.getMaxRows() - 1, v.getLastRowIndex());
|
||||
assertEquals(255, v.getMaxFunctionArgs());
|
||||
assertEquals(Integer.MAX_VALUE, v.getMaxConditionalFormats());
|
||||
assertEquals("XFD", v.getLastColumnName());
|
||||
}
|
||||
}
|
||||
/* ====================================================================
|
||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
contributor license agreements. See the NOTICE file distributed with
|
||||
this work for additional information regarding copyright ownership.
|
||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
(the "License"); you may not use this file except in compliance with
|
||||
the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==================================================================== */
|
||||
|
||||
package org.apache.poi.ss;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Check that all enum values are properly set
|
||||
*
|
||||
* @author Yegor Kozlov
|
||||
*/
|
||||
public final class TestSpreadsheetVersion extends TestCase {
|
||||
|
||||
public void testExcel97(){
|
||||
SpreadsheetVersion v = SpreadsheetVersion.EXCEL97;
|
||||
assertEquals(1 << 8, v.getMaxColumns());
|
||||
assertEquals(v.getMaxColumns() - 1, v.getLastColumnIndex());
|
||||
assertEquals(1 << 16, v.getMaxRows());
|
||||
assertEquals(v.getMaxRows() - 1, v.getLastRowIndex());
|
||||
assertEquals(30, v.getMaxFunctionArgs());
|
||||
assertEquals(3, v.getMaxConditionalFormats());
|
||||
assertEquals("IV", v.getLastColumnName());
|
||||
}
|
||||
|
||||
public void testExcel2007(){
|
||||
SpreadsheetVersion v = SpreadsheetVersion.EXCEL2007;
|
||||
assertEquals(1 << 14, v.getMaxColumns());
|
||||
assertEquals(v.getMaxColumns() - 1, v.getLastColumnIndex());
|
||||
assertEquals(1 << 20, v.getMaxRows());
|
||||
assertEquals(v.getMaxRows() - 1, v.getLastRowIndex());
|
||||
assertEquals(255, v.getMaxFunctionArgs());
|
||||
assertEquals(Integer.MAX_VALUE, v.getMaxConditionalFormats());
|
||||
assertEquals("XFD", v.getLastColumnName());
|
||||
}
|
||||
}
|
||||
|
@ -1,55 +1,55 @@
|
||||
/* ====================================================================
|
||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
contributor license agreements. See the NOTICE file distributed with
|
||||
this work for additional information regarding copyright ownership.
|
||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
(the "License"); you may not use this file except in compliance with
|
||||
the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==================================================================== */
|
||||
|
||||
package org.apache.poi.ss.formula;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.AssertionFailedError;
|
||||
|
||||
import org.apache.poi.ss.formula.FormulaParser.FormulaParseException;
|
||||
/**
|
||||
* Avoids making {@link FormulaParseException} public
|
||||
*
|
||||
* @author Josh Micich
|
||||
*/
|
||||
public class FormulaParserTestHelper {
|
||||
/**
|
||||
* @throws AssertionFailedError if <tt>e</tt> is not a formula parser exception
|
||||
* or if the exception message doesn't match.
|
||||
*/
|
||||
public static void confirmParseException(RuntimeException e, String expectedMessage) {
|
||||
checkType(e);
|
||||
Assert.assertEquals(expectedMessage, e.getMessage());
|
||||
}
|
||||
/**
|
||||
* @throws AssertionFailedError if <tt>e</tt> is not a formula parser exception
|
||||
* or if <tt>e</tt> has no message.
|
||||
*/
|
||||
public static void confirmParseException(RuntimeException e) {
|
||||
checkType(e);
|
||||
Assert.assertNotNull(e.getMessage());
|
||||
}
|
||||
private static void checkType(RuntimeException e) throws AssertionFailedError {
|
||||
if (!(e instanceof FormulaParseException)) {
|
||||
String failMsg = "Expected FormulaParseException, but got ("
|
||||
+ e.getClass().getName() + "):";
|
||||
System.err.println(failMsg);
|
||||
e.printStackTrace();
|
||||
throw new AssertionFailedError(failMsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
/* ====================================================================
|
||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
contributor license agreements. See the NOTICE file distributed with
|
||||
this work for additional information regarding copyright ownership.
|
||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
(the "License"); you may not use this file except in compliance with
|
||||
the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==================================================================== */
|
||||
|
||||
package org.apache.poi.ss.formula;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.AssertionFailedError;
|
||||
|
||||
import org.apache.poi.ss.formula.FormulaParser.FormulaParseException;
|
||||
/**
|
||||
* Avoids making {@link FormulaParseException} public
|
||||
*
|
||||
* @author Josh Micich
|
||||
*/
|
||||
public class FormulaParserTestHelper {
|
||||
/**
|
||||
* @throws AssertionFailedError if <tt>e</tt> is not a formula parser exception
|
||||
* or if the exception message doesn't match.
|
||||
*/
|
||||
public static void confirmParseException(RuntimeException e, String expectedMessage) {
|
||||
checkType(e);
|
||||
Assert.assertEquals(expectedMessage, e.getMessage());
|
||||
}
|
||||
/**
|
||||
* @throws AssertionFailedError if <tt>e</tt> is not a formula parser exception
|
||||
* or if <tt>e</tt> has no message.
|
||||
*/
|
||||
public static void confirmParseException(RuntimeException e) {
|
||||
checkType(e);
|
||||
Assert.assertNotNull(e.getMessage());
|
||||
}
|
||||
private static void checkType(RuntimeException e) throws AssertionFailedError {
|
||||
if (!(e instanceof FormulaParseException)) {
|
||||
String failMsg = "Expected FormulaParseException, but got ("
|
||||
+ e.getClass().getName() + "):";
|
||||
System.err.println(failMsg);
|
||||
e.printStackTrace();
|
||||
throw new AssertionFailedError(failMsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,336 +1,337 @@
|
||||
/* ====================================================================
|
||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
contributor license agreements. See the NOTICE file distributed with
|
||||
this work for additional information regarding copyright ownership.
|
||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
(the "License"); you may not use this file except in compliance with
|
||||
the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==================================================================== */
|
||||
package org.apache.poi.ss.usermodel;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.poi.ss.ITestDataProvider;
|
||||
import org.apache.poi.ss.SpreadsheetVersion;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
|
||||
/**
|
||||
* A base class for bugzilla issues that can be described in terms of common ss interfaces.
|
||||
*
|
||||
* @author Yegor Kozlov
|
||||
*/
|
||||
public abstract class BaseTestBugzillaIssues extends TestCase {
|
||||
|
||||
protected abstract ITestDataProvider getTestDataProvider();
|
||||
|
||||
/**
|
||||
*
|
||||
* Test writing a hyperlink
|
||||
* Open resulting sheet in Excel and check that A1 contains a hyperlink
|
||||
*
|
||||
* Also tests bug 15353 (problems with hyperlinks to Google)
|
||||
*/
|
||||
public void test23094() {
|
||||
Workbook wb = getTestDataProvider().createWorkbook();
|
||||
Sheet s = wb.createSheet();
|
||||
Row r = s.createRow(0);
|
||||
r.createCell(0).setCellFormula("HYPERLINK(\"http://jakarta.apache.org\",\"Jakarta\")");
|
||||
r.createCell(1).setCellFormula("HYPERLINK(\"http://google.com\",\"Google\")");
|
||||
|
||||
wb = getTestDataProvider().writeOutAndReadBack(wb);
|
||||
r = wb.getSheetAt(0).getRow(0);
|
||||
|
||||
Cell cell_0 = r.getCell(0);
|
||||
assertEquals("HYPERLINK(\"http://jakarta.apache.org\",\"Jakarta\")", cell_0.getCellFormula());
|
||||
Cell cell_1 = r.getCell(1);
|
||||
assertEquals("HYPERLINK(\"http://google.com\",\"Google\")", cell_1.getCellFormula());
|
||||
}
|
||||
|
||||
/**
|
||||
* test writing a file with large number of unique strings,
|
||||
* open resulting file in Excel to check results!
|
||||
* @param num the number of strings to generate
|
||||
*/
|
||||
public void baseTest15375(int num) {
|
||||
Workbook wb = getTestDataProvider().createWorkbook();
|
||||
Sheet sheet = wb.createSheet();
|
||||
CreationHelper factory = wb.getCreationHelper();
|
||||
|
||||
String tmp1 = null;
|
||||
String tmp2 = null;
|
||||
String tmp3 = null;
|
||||
|
||||
for (int i = 0; i < num; i++) {
|
||||
tmp1 = "Test1" + i;
|
||||
tmp2 = "Test2" + i;
|
||||
tmp3 = "Test3" + i;
|
||||
|
||||
Row row = sheet.createRow(i);
|
||||
|
||||
Cell cell = row.createCell(0);
|
||||
cell.setCellValue(factory.createRichTextString(tmp1));
|
||||
cell = row.createCell(1);
|
||||
cell.setCellValue(factory.createRichTextString(tmp2));
|
||||
cell = row.createCell(2);
|
||||
cell.setCellValue(factory.createRichTextString(tmp3));
|
||||
}
|
||||
wb = getTestDataProvider().writeOutAndReadBack(wb);
|
||||
for (int i = 0; i < num; i++) {
|
||||
tmp1 = "Test1" + i;
|
||||
tmp2 = "Test2" + i;
|
||||
tmp3 = "Test3" + i;
|
||||
|
||||
Row row = sheet.getRow(i);
|
||||
|
||||
assertEquals(tmp1, row.getCell(0).getStringCellValue());
|
||||
assertEquals(tmp2, row.getCell(1).getStringCellValue());
|
||||
assertEquals(tmp3, row.getCell(2).getStringCellValue());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Merged regions were being removed from the parent in cloned sheets
|
||||
*/
|
||||
public void test22720() {
|
||||
Workbook workBook = getTestDataProvider().createWorkbook();
|
||||
workBook.createSheet("TEST");
|
||||
Sheet template = workBook.getSheetAt(0);
|
||||
|
||||
template.addMergedRegion(new CellRangeAddress(0, 1, 0, 2));
|
||||
template.addMergedRegion(new CellRangeAddress(1, 2, 0, 2));
|
||||
|
||||
Sheet clone = workBook.cloneSheet(0);
|
||||
int originalMerged = template.getNumMergedRegions();
|
||||
assertEquals("2 merged regions", 2, originalMerged);
|
||||
|
||||
//remove merged regions from clone
|
||||
for (int i=template.getNumMergedRegions()-1; i>=0; i--) {
|
||||
clone.removeMergedRegion(i);
|
||||
}
|
||||
|
||||
assertEquals("Original Sheet's Merged Regions were removed", originalMerged, template.getNumMergedRegions());
|
||||
//check if template's merged regions are OK
|
||||
if (template.getNumMergedRegions()>0) {
|
||||
// fetch the first merged region...EXCEPTION OCCURS HERE
|
||||
template.getMergedRegion(0);
|
||||
}
|
||||
//make sure we dont exception
|
||||
|
||||
}
|
||||
|
||||
public void test28031() {
|
||||
Workbook wb = getTestDataProvider().createWorkbook();
|
||||
Sheet sheet = wb.createSheet();
|
||||
wb.setSheetName(0, "Sheet1");
|
||||
|
||||
Row row = sheet.createRow(0);
|
||||
Cell cell = row.createCell(0);
|
||||
String formulaText =
|
||||
"IF(ROUND(A2*B2*C2,2)>ROUND(B2*D2,2),ROUND(A2*B2*C2,2),ROUND(B2*D2,2))";
|
||||
cell.setCellFormula(formulaText);
|
||||
|
||||
assertEquals(formulaText, cell.getCellFormula());
|
||||
wb = getTestDataProvider().writeOutAndReadBack(wb);
|
||||
cell = wb.getSheetAt(0).getRow(0).getCell(0);
|
||||
assertEquals("IF(ROUND(A2*B2*C2,2)>ROUND(B2*D2,2),ROUND(A2*B2*C2,2),ROUND(B2*D2,2))", cell.getCellFormula());
|
||||
}
|
||||
|
||||
/**
|
||||
* Bug 21334: "File error: data may have been lost" with a file
|
||||
* that contains macros and this formula:
|
||||
* {=SUM(IF(FREQUENCY(IF(LEN(V4:V220)>0,MATCH(V4:V220,V4:V220,0),""),IF(LEN(V4:V220)>0,MATCH(V4:V220,V4:V220,0),""))>0,1))}
|
||||
*/
|
||||
public void test21334() {
|
||||
Workbook wb = getTestDataProvider().createWorkbook();
|
||||
Sheet sh = wb.createSheet();
|
||||
Cell cell = sh.createRow(0).createCell(0);
|
||||
String formula = "SUM(IF(FREQUENCY(IF(LEN(V4:V220)>0,MATCH(V4:V220,V4:V220,0),\"\"),IF(LEN(V4:V220)>0,MATCH(V4:V220,V4:V220,0),\"\"))>0,1))";
|
||||
cell.setCellFormula(formula);
|
||||
|
||||
Workbook wb_sv = getTestDataProvider().writeOutAndReadBack(wb);
|
||||
Cell cell_sv = wb_sv.getSheetAt(0).getRow(0).getCell(0);
|
||||
assertEquals(formula, cell_sv.getCellFormula());
|
||||
}
|
||||
|
||||
/** another test for the number of unique strings issue
|
||||
*test opening the resulting file in Excel*/
|
||||
public void test22568() {
|
||||
int r=2000;int c=3;
|
||||
|
||||
Workbook wb = getTestDataProvider().createWorkbook();
|
||||
Sheet sheet = wb.createSheet("ExcelTest") ;
|
||||
|
||||
int col_cnt=0, rw_cnt=0 ;
|
||||
|
||||
col_cnt = c;
|
||||
rw_cnt = r;
|
||||
|
||||
Row rw ;
|
||||
rw = sheet.createRow(0) ;
|
||||
//Header row
|
||||
for(int j=0; j<col_cnt; j++){
|
||||
Cell cell = rw.createCell(j) ;
|
||||
cell.setCellValue("Col " + (j+1));
|
||||
}
|
||||
|
||||
for(int i=1; i<rw_cnt; i++){
|
||||
rw = sheet.createRow(i) ;
|
||||
for(int j=0; j<col_cnt; j++){
|
||||
Cell cell = rw.createCell(j) ;
|
||||
cell.setCellValue("Row:" + (i+1) + ",Column:" + (j+1));
|
||||
}
|
||||
}
|
||||
|
||||
sheet.setDefaultColumnWidth(18) ;
|
||||
|
||||
wb = getTestDataProvider().writeOutAndReadBack(wb);
|
||||
sheet = wb.getSheetAt(0);
|
||||
rw = sheet.getRow(0);
|
||||
//Header row
|
||||
for(int j=0; j<col_cnt; j++){
|
||||
Cell cell = rw.getCell(j) ;
|
||||
assertEquals("Col " + (j+1), cell.getStringCellValue());
|
||||
}
|
||||
for(int i=1; i<rw_cnt; i++){
|
||||
rw = sheet.getRow(i) ;
|
||||
for(int j=0; j<col_cnt; j++){
|
||||
Cell cell = rw.getCell(j) ;
|
||||
assertEquals("Row:" + (i+1) + ",Column:" + (j+1), cell.getStringCellValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Bug 42448: Can't parse SUMPRODUCT(A!C7:A!C67, B8:B68) / B69
|
||||
*/
|
||||
public void test42448(){
|
||||
Workbook wb = getTestDataProvider().createWorkbook();
|
||||
Cell cell = wb.createSheet().createRow(0).createCell(0);
|
||||
cell.setCellFormula("SUMPRODUCT(A!C7:A!C67, B8:B68) / B69");
|
||||
assertTrue("no errors parsing formula", true);
|
||||
}
|
||||
|
||||
/**
|
||||
* HSSFRichTextString.length() returns negative for really
|
||||
* long strings
|
||||
*/
|
||||
public void test46368() {
|
||||
Workbook wb = getTestDataProvider().createWorkbook();
|
||||
Sheet s = wb.createSheet();
|
||||
Row r = s.createRow(0);
|
||||
for(int i=0; i<15; i++) {
|
||||
int len = 32760 + i;
|
||||
Cell c = r.createCell(i);
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for(int j=0; j<len; j++) {
|
||||
sb.append("x");
|
||||
}
|
||||
RichTextString rtr = wb.getCreationHelper().createRichTextString(sb.toString());
|
||||
assertEquals(len, rtr.length());
|
||||
c.setCellValue(rtr);
|
||||
}
|
||||
|
||||
// Save and reload
|
||||
wb = getTestDataProvider().writeOutAndReadBack(wb);
|
||||
s = wb.getSheetAt(0);
|
||||
r = s.getRow(0);
|
||||
for(int i=0; i<15; i++) {
|
||||
int len = 32760 + i;
|
||||
Cell c = r.getCell(i);
|
||||
assertEquals(len, c.getRichStringCellValue().length());
|
||||
}
|
||||
}
|
||||
|
||||
public void test18800() {
|
||||
Workbook book = getTestDataProvider().createWorkbook();
|
||||
book.createSheet("TEST");
|
||||
Sheet sheet = book.cloneSheet(0);
|
||||
book.setSheetName(1,"CLONE");
|
||||
sheet.createRow(0).createCell(0).setCellValue("Test");
|
||||
|
||||
book = getTestDataProvider().writeOutAndReadBack(book);
|
||||
sheet = book.getSheet("CLONE");
|
||||
Row row = sheet.getRow(0);
|
||||
Cell cell = row.getCell(0);
|
||||
assertEquals("Test", cell.getRichStringCellValue().getString());
|
||||
}
|
||||
|
||||
private static void addNewSheetWithCellsA1toD4(Workbook book, int sheet) {
|
||||
|
||||
Sheet sht = book .createSheet("s" + sheet);
|
||||
for (int r=0; r < 4; r++) {
|
||||
|
||||
Row row = sht.createRow (r);
|
||||
for (int c=0; c < 4; c++) {
|
||||
|
||||
Cell cel = row.createCell(c);
|
||||
cel.setCellValue(sheet*100 + r*10 + c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void testBug43093() {
|
||||
Workbook xlw = getTestDataProvider().createWorkbook();
|
||||
|
||||
addNewSheetWithCellsA1toD4(xlw, 1);
|
||||
addNewSheetWithCellsA1toD4(xlw, 2);
|
||||
addNewSheetWithCellsA1toD4(xlw, 3);
|
||||
addNewSheetWithCellsA1toD4(xlw, 4);
|
||||
|
||||
Sheet s2 = xlw.getSheet("s2");
|
||||
Row s2r3 = s2.getRow(3);
|
||||
Cell s2E4 = s2r3.createCell(4);
|
||||
s2E4.setCellFormula("SUM(s3!B2:C3)");
|
||||
|
||||
FormulaEvaluator eva = xlw.getCreationHelper().createFormulaEvaluator();
|
||||
double d = eva.evaluate(s2E4).getNumberValue();
|
||||
|
||||
assertEquals(d, (311+312+321+322), 0.0000001);
|
||||
}
|
||||
|
||||
public void testMaxFunctionArguments_bug46729(){
|
||||
String[] func = {"COUNT", "AVERAGE", "MAX", "MIN", "OR", "SUBTOTAL", "SKEW"};
|
||||
|
||||
SpreadsheetVersion ssVersion = getTestDataProvider().getSpreadsheetVersion();
|
||||
Workbook wb = getTestDataProvider().createWorkbook();
|
||||
Cell cell = wb.createSheet().createRow(0).createCell(0);
|
||||
|
||||
String fmla;
|
||||
for (String name : func) {
|
||||
|
||||
fmla = createFunction(name, 5);
|
||||
cell.setCellFormula(fmla);
|
||||
|
||||
fmla = createFunction(name, ssVersion.getMaxFunctionArgs());
|
||||
cell.setCellFormula(fmla);
|
||||
|
||||
try {
|
||||
fmla = createFunction(name, ssVersion.getMaxFunctionArgs() + 1);
|
||||
cell.setCellFormula(fmla);
|
||||
fail("Expected FormulaParseException");
|
||||
} catch (RuntimeException e){
|
||||
assertTrue(e.getMessage().startsWith("Too many arguments to function '"+name+"'"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String createFunction(String name, int maxArgs){
|
||||
StringBuffer fmla = new StringBuffer();
|
||||
fmla.append(name);
|
||||
fmla.append("(");
|
||||
for(int i=0; i < maxArgs; i++){
|
||||
if(i > 0) fmla.append(',');
|
||||
fmla.append("A1");
|
||||
}
|
||||
fmla.append(")");
|
||||
return fmla.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.ss.usermodel;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.poi.ss.ITestDataProvider;
|
||||
import org.apache.poi.ss.SpreadsheetVersion;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
|
||||
/**
|
||||
* A base class for bugzilla issues that can be described in terms of common ss interfaces.
|
||||
*
|
||||
* @author Yegor Kozlov
|
||||
*/
|
||||
public abstract class BaseTestBugzillaIssues extends TestCase {
|
||||
|
||||
protected abstract ITestDataProvider getTestDataProvider();
|
||||
|
||||
/**
|
||||
*
|
||||
* Test writing a hyperlink
|
||||
* Open resulting sheet in Excel and check that A1 contains a hyperlink
|
||||
*
|
||||
* Also tests bug 15353 (problems with hyperlinks to Google)
|
||||
*/
|
||||
public void test23094() {
|
||||
Workbook wb = getTestDataProvider().createWorkbook();
|
||||
Sheet s = wb.createSheet();
|
||||
Row r = s.createRow(0);
|
||||
r.createCell(0).setCellFormula("HYPERLINK(\"http://jakarta.apache.org\",\"Jakarta\")");
|
||||
r.createCell(1).setCellFormula("HYPERLINK(\"http://google.com\",\"Google\")");
|
||||
|
||||
wb = getTestDataProvider().writeOutAndReadBack(wb);
|
||||
r = wb.getSheetAt(0).getRow(0);
|
||||
|
||||
Cell cell_0 = r.getCell(0);
|
||||
assertEquals("HYPERLINK(\"http://jakarta.apache.org\",\"Jakarta\")", cell_0.getCellFormula());
|
||||
Cell cell_1 = r.getCell(1);
|
||||
assertEquals("HYPERLINK(\"http://google.com\",\"Google\")", cell_1.getCellFormula());
|
||||
}
|
||||
|
||||
/**
|
||||
* test writing a file with large number of unique strings,
|
||||
* open resulting file in Excel to check results!
|
||||
* @param num the number of strings to generate
|
||||
*/
|
||||
public void baseTest15375(int num) {
|
||||
Workbook wb = getTestDataProvider().createWorkbook();
|
||||
Sheet sheet = wb.createSheet();
|
||||
CreationHelper factory = wb.getCreationHelper();
|
||||
|
||||
String tmp1 = null;
|
||||
String tmp2 = null;
|
||||
String tmp3 = null;
|
||||
|
||||
for (int i = 0; i < num; i++) {
|
||||
tmp1 = "Test1" + i;
|
||||
tmp2 = "Test2" + i;
|
||||
tmp3 = "Test3" + i;
|
||||
|
||||
Row row = sheet.createRow(i);
|
||||
|
||||
Cell cell = row.createCell(0);
|
||||
cell.setCellValue(factory.createRichTextString(tmp1));
|
||||
cell = row.createCell(1);
|
||||
cell.setCellValue(factory.createRichTextString(tmp2));
|
||||
cell = row.createCell(2);
|
||||
cell.setCellValue(factory.createRichTextString(tmp3));
|
||||
}
|
||||
wb = getTestDataProvider().writeOutAndReadBack(wb);
|
||||
for (int i = 0; i < num; i++) {
|
||||
tmp1 = "Test1" + i;
|
||||
tmp2 = "Test2" + i;
|
||||
tmp3 = "Test3" + i;
|
||||
|
||||
Row row = sheet.getRow(i);
|
||||
|
||||
assertEquals(tmp1, row.getCell(0).getStringCellValue());
|
||||
assertEquals(tmp2, row.getCell(1).getStringCellValue());
|
||||
assertEquals(tmp3, row.getCell(2).getStringCellValue());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Merged regions were being removed from the parent in cloned sheets
|
||||
*/
|
||||
public void test22720() {
|
||||
Workbook workBook = getTestDataProvider().createWorkbook();
|
||||
workBook.createSheet("TEST");
|
||||
Sheet template = workBook.getSheetAt(0);
|
||||
|
||||
template.addMergedRegion(new CellRangeAddress(0, 1, 0, 2));
|
||||
template.addMergedRegion(new CellRangeAddress(1, 2, 0, 2));
|
||||
|
||||
Sheet clone = workBook.cloneSheet(0);
|
||||
int originalMerged = template.getNumMergedRegions();
|
||||
assertEquals("2 merged regions", 2, originalMerged);
|
||||
|
||||
//remove merged regions from clone
|
||||
for (int i=template.getNumMergedRegions()-1; i>=0; i--) {
|
||||
clone.removeMergedRegion(i);
|
||||
}
|
||||
|
||||
assertEquals("Original Sheet's Merged Regions were removed", originalMerged, template.getNumMergedRegions());
|
||||
//check if template's merged regions are OK
|
||||
if (template.getNumMergedRegions()>0) {
|
||||
// fetch the first merged region...EXCEPTION OCCURS HERE
|
||||
template.getMergedRegion(0);
|
||||
}
|
||||
//make sure we dont exception
|
||||
|
||||
}
|
||||
|
||||
public void test28031() {
|
||||
Workbook wb = getTestDataProvider().createWorkbook();
|
||||
Sheet sheet = wb.createSheet();
|
||||
wb.setSheetName(0, "Sheet1");
|
||||
|
||||
Row row = sheet.createRow(0);
|
||||
Cell cell = row.createCell(0);
|
||||
String formulaText =
|
||||
"IF(ROUND(A2*B2*C2,2)>ROUND(B2*D2,2),ROUND(A2*B2*C2,2),ROUND(B2*D2,2))";
|
||||
cell.setCellFormula(formulaText);
|
||||
|
||||
assertEquals(formulaText, cell.getCellFormula());
|
||||
wb = getTestDataProvider().writeOutAndReadBack(wb);
|
||||
cell = wb.getSheetAt(0).getRow(0).getCell(0);
|
||||
assertEquals("IF(ROUND(A2*B2*C2,2)>ROUND(B2*D2,2),ROUND(A2*B2*C2,2),ROUND(B2*D2,2))", cell.getCellFormula());
|
||||
}
|
||||
|
||||
/**
|
||||
* Bug 21334: "File error: data may have been lost" with a file
|
||||
* that contains macros and this formula:
|
||||
* {=SUM(IF(FREQUENCY(IF(LEN(V4:V220)>0,MATCH(V4:V220,V4:V220,0),""),IF(LEN(V4:V220)>0,MATCH(V4:V220,V4:V220,0),""))>0,1))}
|
||||
*/
|
||||
public void test21334() {
|
||||
Workbook wb = getTestDataProvider().createWorkbook();
|
||||
Sheet sh = wb.createSheet();
|
||||
Cell cell = sh.createRow(0).createCell(0);
|
||||
String formula = "SUM(IF(FREQUENCY(IF(LEN(V4:V220)>0,MATCH(V4:V220,V4:V220,0),\"\"),IF(LEN(V4:V220)>0,MATCH(V4:V220,V4:V220,0),\"\"))>0,1))";
|
||||
cell.setCellFormula(formula);
|
||||
|
||||
Workbook wb_sv = getTestDataProvider().writeOutAndReadBack(wb);
|
||||
Cell cell_sv = wb_sv.getSheetAt(0).getRow(0).getCell(0);
|
||||
assertEquals(formula, cell_sv.getCellFormula());
|
||||
}
|
||||
|
||||
/** another test for the number of unique strings issue
|
||||
*test opening the resulting file in Excel*/
|
||||
public void test22568() {
|
||||
int r=2000;int c=3;
|
||||
|
||||
Workbook wb = getTestDataProvider().createWorkbook();
|
||||
Sheet sheet = wb.createSheet("ExcelTest") ;
|
||||
|
||||
int col_cnt=0, rw_cnt=0 ;
|
||||
|
||||
col_cnt = c;
|
||||
rw_cnt = r;
|
||||
|
||||
Row rw ;
|
||||
rw = sheet.createRow(0) ;
|
||||
//Header row
|
||||
for(int j=0; j<col_cnt; j++){
|
||||
Cell cell = rw.createCell(j) ;
|
||||
cell.setCellValue("Col " + (j+1));
|
||||
}
|
||||
|
||||
for(int i=1; i<rw_cnt; i++){
|
||||
rw = sheet.createRow(i) ;
|
||||
for(int j=0; j<col_cnt; j++){
|
||||
Cell cell = rw.createCell(j) ;
|
||||
cell.setCellValue("Row:" + (i+1) + ",Column:" + (j+1));
|
||||
}
|
||||
}
|
||||
|
||||
sheet.setDefaultColumnWidth(18) ;
|
||||
|
||||
wb = getTestDataProvider().writeOutAndReadBack(wb);
|
||||
sheet = wb.getSheetAt(0);
|
||||
rw = sheet.getRow(0);
|
||||
//Header row
|
||||
for(int j=0; j<col_cnt; j++){
|
||||
Cell cell = rw.getCell(j) ;
|
||||
assertEquals("Col " + (j+1), cell.getStringCellValue());
|
||||
}
|
||||
for(int i=1; i<rw_cnt; i++){
|
||||
rw = sheet.getRow(i) ;
|
||||
for(int j=0; j<col_cnt; j++){
|
||||
Cell cell = rw.getCell(j) ;
|
||||
assertEquals("Row:" + (i+1) + ",Column:" + (j+1), cell.getStringCellValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Bug 42448: Can't parse SUMPRODUCT(A!C7:A!C67, B8:B68) / B69
|
||||
*/
|
||||
public void test42448(){
|
||||
Workbook wb = getTestDataProvider().createWorkbook();
|
||||
Cell cell = wb.createSheet().createRow(0).createCell(0);
|
||||
cell.setCellFormula("SUMPRODUCT(A!C7:A!C67, B8:B68) / B69");
|
||||
assertTrue("no errors parsing formula", true);
|
||||
}
|
||||
|
||||
/**
|
||||
* HSSFRichTextString.length() returns negative for really
|
||||
* long strings
|
||||
*/
|
||||
public void test46368() {
|
||||
Workbook wb = getTestDataProvider().createWorkbook();
|
||||
Sheet s = wb.createSheet();
|
||||
Row r = s.createRow(0);
|
||||
for(int i=0; i<15; i++) {
|
||||
int len = 32760 + i;
|
||||
Cell c = r.createCell(i);
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for(int j=0; j<len; j++) {
|
||||
sb.append("x");
|
||||
}
|
||||
RichTextString rtr = wb.getCreationHelper().createRichTextString(sb.toString());
|
||||
assertEquals(len, rtr.length());
|
||||
c.setCellValue(rtr);
|
||||
}
|
||||
|
||||
// Save and reload
|
||||
wb = getTestDataProvider().writeOutAndReadBack(wb);
|
||||
s = wb.getSheetAt(0);
|
||||
r = s.getRow(0);
|
||||
for(int i=0; i<15; i++) {
|
||||
int len = 32760 + i;
|
||||
Cell c = r.getCell(i);
|
||||
assertEquals(len, c.getRichStringCellValue().length());
|
||||
}
|
||||
}
|
||||
|
||||
public void test18800() {
|
||||
Workbook book = getTestDataProvider().createWorkbook();
|
||||
book.createSheet("TEST");
|
||||
Sheet sheet = book.cloneSheet(0);
|
||||
book.setSheetName(1,"CLONE");
|
||||
sheet.createRow(0).createCell(0).setCellValue("Test");
|
||||
|
||||
book = getTestDataProvider().writeOutAndReadBack(book);
|
||||
sheet = book.getSheet("CLONE");
|
||||
Row row = sheet.getRow(0);
|
||||
Cell cell = row.getCell(0);
|
||||
assertEquals("Test", cell.getRichStringCellValue().getString());
|
||||
}
|
||||
|
||||
private static void addNewSheetWithCellsA1toD4(Workbook book, int sheet) {
|
||||
|
||||
Sheet sht = book .createSheet("s" + sheet);
|
||||
for (int r=0; r < 4; r++) {
|
||||
|
||||
Row row = sht.createRow (r);
|
||||
for (int c=0; c < 4; c++) {
|
||||
|
||||
Cell cel = row.createCell(c);
|
||||
cel.setCellValue(sheet*100 + r*10 + c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void testBug43093() {
|
||||
Workbook xlw = getTestDataProvider().createWorkbook();
|
||||
|
||||
addNewSheetWithCellsA1toD4(xlw, 1);
|
||||
addNewSheetWithCellsA1toD4(xlw, 2);
|
||||
addNewSheetWithCellsA1toD4(xlw, 3);
|
||||
addNewSheetWithCellsA1toD4(xlw, 4);
|
||||
|
||||
Sheet s2 = xlw.getSheet("s2");
|
||||
Row s2r3 = s2.getRow(3);
|
||||
Cell s2E4 = s2r3.createCell(4);
|
||||
s2E4.setCellFormula("SUM(s3!B2:C3)");
|
||||
|
||||
FormulaEvaluator eva = xlw.getCreationHelper().createFormulaEvaluator();
|
||||
double d = eva.evaluate(s2E4).getNumberValue();
|
||||
|
||||
assertEquals(d, (311+312+321+322), 0.0000001);
|
||||
}
|
||||
|
||||
public void testMaxFunctionArguments_bug46729(){
|
||||
String[] func = {"COUNT", "AVERAGE", "MAX", "MIN", "OR", "SUBTOTAL", "SKEW"};
|
||||
|
||||
SpreadsheetVersion ssVersion = getTestDataProvider().getSpreadsheetVersion();
|
||||
Workbook wb = getTestDataProvider().createWorkbook();
|
||||
Cell cell = wb.createSheet().createRow(0).createCell(0);
|
||||
|
||||
String fmla;
|
||||
for (String name : func) {
|
||||
|
||||
fmla = createFunction(name, 5);
|
||||
cell.setCellFormula(fmla);
|
||||
|
||||
fmla = createFunction(name, ssVersion.getMaxFunctionArgs());
|
||||
cell.setCellFormula(fmla);
|
||||
|
||||
try {
|
||||
fmla = createFunction(name, ssVersion.getMaxFunctionArgs() + 1);
|
||||
cell.setCellFormula(fmla);
|
||||
fail("Expected FormulaParseException");
|
||||
} catch (RuntimeException e){
|
||||
assertTrue(e.getMessage().startsWith("Too many arguments to function '"+name+"'"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String createFunction(String name, int maxArgs){
|
||||
StringBuffer fmla = new StringBuffer();
|
||||
fmla.append(name);
|
||||
fmla.append("(");
|
||||
for(int i=0; i < maxArgs; i++){
|
||||
if(i > 0) fmla.append(',');
|
||||
fmla.append("A1");
|
||||
}
|
||||
fmla.append(")");
|
||||
return fmla.toString();
|
||||
}
|
||||
}
|
||||
|
@ -1,204 +1,200 @@
|
||||
/* ====================================================================
|
||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
contributor license agreements. See the NOTICE file distributed with
|
||||
this work for additional information regarding copyright ownership.
|
||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
(the "License"); you may not use this file except in compliance with
|
||||
the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==================================================================== */
|
||||
package org.apache.poi.ss.usermodel;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.AssertionFailedError;
|
||||
import org.apache.poi.ss.ITestDataProvider;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
|
||||
/**
|
||||
* @author Yegor Kozlov
|
||||
*/
|
||||
public abstract class BaseTestFont extends TestCase {
|
||||
|
||||
protected abstract ITestDataProvider getTestDataProvider();
|
||||
|
||||
public void baseTestDefaultFont(String defaultName, short defaultSize, short defaultColor){
|
||||
//get default font and check against default value
|
||||
Workbook workbook = getTestDataProvider().createWorkbook();
|
||||
Font fontFind=workbook.findFont(Font.BOLDWEIGHT_NORMAL, defaultColor, defaultSize, defaultName, false, false, Font.SS_NONE, Font.U_NONE);
|
||||
assertNotNull(fontFind);
|
||||
|
||||
//get default font, then change 2 values and check against different values (height changes)
|
||||
Font font=workbook.createFont();
|
||||
font.setBoldweight(Font.BOLDWEIGHT_BOLD);
|
||||
assertEquals(Font.BOLDWEIGHT_BOLD, font.getBoldweight());
|
||||
font.setUnderline(Font.U_DOUBLE);
|
||||
assertEquals(Font.U_DOUBLE, font.getUnderline());
|
||||
font.setFontHeightInPoints((short)15);
|
||||
assertEquals(15*20, font.getFontHeight());
|
||||
assertEquals(15, font.getFontHeightInPoints());
|
||||
fontFind=workbook.findFont(Font.BOLDWEIGHT_BOLD, defaultColor, (short)(15*20), defaultName, false, false, Font.SS_NONE, Font.U_DOUBLE);
|
||||
assertNotNull(fontFind);
|
||||
}
|
||||
|
||||
public void testGetNumberOfFonts(){
|
||||
Workbook wb = getTestDataProvider().createWorkbook();
|
||||
int num0 = wb.getNumberOfFonts();
|
||||
|
||||
Font f1=wb.createFont();
|
||||
f1.setBoldweight(Font.BOLDWEIGHT_BOLD);
|
||||
short idx1 = f1.getIndex();
|
||||
wb.createCellStyle().setFont(f1);
|
||||
|
||||
Font f2=wb.createFont();
|
||||
f2.setUnderline(Font.U_DOUBLE);
|
||||
short idx2 = f2.getIndex();
|
||||
wb.createCellStyle().setFont(f2);
|
||||
|
||||
Font f3=wb.createFont();
|
||||
f3.setFontHeightInPoints((short)23);
|
||||
short idx3 = f3.getIndex();
|
||||
wb.createCellStyle().setFont(f3);
|
||||
|
||||
assertEquals(num0 + 3,wb.getNumberOfFonts());
|
||||
assertEquals(Font.BOLDWEIGHT_BOLD,wb.getFontAt(idx1).getBoldweight());
|
||||
assertEquals(Font.U_DOUBLE,wb.getFontAt(idx2).getUnderline());
|
||||
assertEquals(23,wb.getFontAt(idx3).getFontHeightInPoints());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that we can define fonts to a new
|
||||
* file, save, load, and still see them
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testCreateSave() {
|
||||
Workbook wb = getTestDataProvider().createWorkbook();
|
||||
Sheet s1 = wb.createSheet();
|
||||
Row r1 = s1.createRow(0);
|
||||
Cell r1c1 = r1.createCell(0);
|
||||
r1c1.setCellValue(2.2);
|
||||
|
||||
int num0 = wb.getNumberOfFonts();
|
||||
|
||||
Font font=wb.createFont();
|
||||
font.setBoldweight(Font.BOLDWEIGHT_BOLD);
|
||||
font.setStrikeout(true);
|
||||
font.setColor(IndexedColors.YELLOW.getIndex());
|
||||
font.setFontName("Courier");
|
||||
short font1Idx = font.getIndex();
|
||||
wb.createCellStyle().setFont(font);
|
||||
assertEquals(num0 + 1, wb.getNumberOfFonts());
|
||||
|
||||
CellStyle cellStyleTitle=wb.createCellStyle();
|
||||
cellStyleTitle.setFont(font);
|
||||
r1c1.setCellStyle(cellStyleTitle);
|
||||
|
||||
// Save and re-load
|
||||
wb = getTestDataProvider().writeOutAndReadBack(wb);
|
||||
s1 = wb.getSheetAt(0);
|
||||
|
||||
assertEquals(num0 + 1, wb.getNumberOfFonts());
|
||||
short idx = s1.getRow(0).getCell(0).getCellStyle().getFontIndex();
|
||||
Font fnt = wb.getFontAt(idx);
|
||||
assertNotNull(fnt);
|
||||
assertEquals(IndexedColors.YELLOW.getIndex(), fnt.getColor());
|
||||
assertEquals("Courier", fnt.getFontName());
|
||||
|
||||
// Now add an orphaned one
|
||||
Font font2 = wb.createFont();
|
||||
font2.setItalic(true);
|
||||
font2.setFontHeightInPoints((short)15);
|
||||
short font2Idx = font2.getIndex();
|
||||
wb.createCellStyle().setFont(font2);
|
||||
assertEquals(num0 + 2, wb.getNumberOfFonts());
|
||||
|
||||
// Save and re-load
|
||||
wb = getTestDataProvider().writeOutAndReadBack(wb);
|
||||
s1 = wb.getSheetAt(0);
|
||||
|
||||
assertEquals(num0 + 2, wb.getNumberOfFonts());
|
||||
assertNotNull(wb.getFontAt(font1Idx));
|
||||
assertNotNull(wb.getFontAt(font2Idx));
|
||||
|
||||
assertEquals(15, wb.getFontAt(font2Idx).getFontHeightInPoints());
|
||||
assertEquals(true, wb.getFontAt(font2Idx).getItalic());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Test that fonts get added properly
|
||||
*
|
||||
* @see org.apache.poi.hssf.usermodel.TestBugs#test45338()
|
||||
*/
|
||||
public void test45338() {
|
||||
Workbook wb = getTestDataProvider().createWorkbook();
|
||||
int num0 = wb.getNumberOfFonts();
|
||||
|
||||
Sheet s = wb.createSheet();
|
||||
s.createRow(0);
|
||||
s.createRow(1);
|
||||
s.getRow(0).createCell(0);
|
||||
s.getRow(1).createCell(0);
|
||||
|
||||
//default font
|
||||
Font f1 = wb.getFontAt((short)0);
|
||||
assertEquals(Font.BOLDWEIGHT_NORMAL, f1.getBoldweight());
|
||||
|
||||
// Check that asking for the same font
|
||||
// multiple times gives you the same thing.
|
||||
// Otherwise, our tests wouldn't work!
|
||||
assertSame(wb.getFontAt((short)0), wb.getFontAt((short)0));
|
||||
|
||||
// Look for a new font we have
|
||||
// yet to add
|
||||
assertNull(
|
||||
wb.findFont(
|
||||
Font.BOLDWEIGHT_BOLD, (short)123, (short)(22*20),
|
||||
"Thingy", false, true, (short)2, (byte)2
|
||||
)
|
||||
);
|
||||
|
||||
Font nf = wb.createFont();
|
||||
short nfIdx = nf.getIndex();
|
||||
assertEquals(num0 + 1, wb.getNumberOfFonts());
|
||||
|
||||
assertSame(nf, wb.getFontAt(nfIdx));
|
||||
|
||||
nf.setBoldweight(Font.BOLDWEIGHT_BOLD);
|
||||
nf.setColor((short)123);
|
||||
nf.setFontHeightInPoints((short)22);
|
||||
nf.setFontName("Thingy");
|
||||
nf.setItalic(false);
|
||||
nf.setStrikeout(true);
|
||||
nf.setTypeOffset((short)2);
|
||||
nf.setUnderline((byte)2);
|
||||
|
||||
assertEquals(num0 + 1, wb.getNumberOfFonts());
|
||||
assertEquals(nf, wb.getFontAt(nfIdx));
|
||||
|
||||
assertEquals(wb.getFontAt(nfIdx), wb.getFontAt(nfIdx));
|
||||
assertTrue(wb.getFontAt((short)0) != wb.getFontAt(nfIdx));
|
||||
|
||||
// Find it now
|
||||
assertNotNull(
|
||||
wb.findFont(
|
||||
Font.BOLDWEIGHT_BOLD, (short)123, (short)(22*20),
|
||||
"Thingy", false, true, (short)2, (byte)2
|
||||
)
|
||||
);
|
||||
assertSame(nf,
|
||||
wb.findFont(
|
||||
Font.BOLDWEIGHT_BOLD, (short)123, (short)(22*20),
|
||||
"Thingy", false, true, (short)2, (byte)2
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
/* ====================================================================
|
||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
contributor license agreements. See the NOTICE file distributed with
|
||||
this work for additional information regarding copyright ownership.
|
||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
(the "License"); you may not use this file except in compliance with
|
||||
the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==================================================================== */
|
||||
|
||||
package org.apache.poi.ss.usermodel;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.poi.ss.ITestDataProvider;
|
||||
|
||||
/**
|
||||
* @author Yegor Kozlov
|
||||
*/
|
||||
public abstract class BaseTestFont extends TestCase {
|
||||
|
||||
protected abstract ITestDataProvider getTestDataProvider();
|
||||
|
||||
public void baseTestDefaultFont(String defaultName, short defaultSize, short defaultColor){
|
||||
//get default font and check against default value
|
||||
Workbook workbook = getTestDataProvider().createWorkbook();
|
||||
Font fontFind=workbook.findFont(Font.BOLDWEIGHT_NORMAL, defaultColor, defaultSize, defaultName, false, false, Font.SS_NONE, Font.U_NONE);
|
||||
assertNotNull(fontFind);
|
||||
|
||||
//get default font, then change 2 values and check against different values (height changes)
|
||||
Font font=workbook.createFont();
|
||||
font.setBoldweight(Font.BOLDWEIGHT_BOLD);
|
||||
assertEquals(Font.BOLDWEIGHT_BOLD, font.getBoldweight());
|
||||
font.setUnderline(Font.U_DOUBLE);
|
||||
assertEquals(Font.U_DOUBLE, font.getUnderline());
|
||||
font.setFontHeightInPoints((short)15);
|
||||
assertEquals(15*20, font.getFontHeight());
|
||||
assertEquals(15, font.getFontHeightInPoints());
|
||||
fontFind=workbook.findFont(Font.BOLDWEIGHT_BOLD, defaultColor, (short)(15*20), defaultName, false, false, Font.SS_NONE, Font.U_DOUBLE);
|
||||
assertNotNull(fontFind);
|
||||
}
|
||||
|
||||
public void testGetNumberOfFonts(){
|
||||
Workbook wb = getTestDataProvider().createWorkbook();
|
||||
int num0 = wb.getNumberOfFonts();
|
||||
|
||||
Font f1=wb.createFont();
|
||||
f1.setBoldweight(Font.BOLDWEIGHT_BOLD);
|
||||
short idx1 = f1.getIndex();
|
||||
wb.createCellStyle().setFont(f1);
|
||||
|
||||
Font f2=wb.createFont();
|
||||
f2.setUnderline(Font.U_DOUBLE);
|
||||
short idx2 = f2.getIndex();
|
||||
wb.createCellStyle().setFont(f2);
|
||||
|
||||
Font f3=wb.createFont();
|
||||
f3.setFontHeightInPoints((short)23);
|
||||
short idx3 = f3.getIndex();
|
||||
wb.createCellStyle().setFont(f3);
|
||||
|
||||
assertEquals(num0 + 3,wb.getNumberOfFonts());
|
||||
assertEquals(Font.BOLDWEIGHT_BOLD,wb.getFontAt(idx1).getBoldweight());
|
||||
assertEquals(Font.U_DOUBLE,wb.getFontAt(idx2).getUnderline());
|
||||
assertEquals(23,wb.getFontAt(idx3).getFontHeightInPoints());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that we can define fonts to a new
|
||||
* file, save, load, and still see them
|
||||
*/
|
||||
public void testCreateSave() {
|
||||
Workbook wb = getTestDataProvider().createWorkbook();
|
||||
Sheet s1 = wb.createSheet();
|
||||
Row r1 = s1.createRow(0);
|
||||
Cell r1c1 = r1.createCell(0);
|
||||
r1c1.setCellValue(2.2);
|
||||
|
||||
int num0 = wb.getNumberOfFonts();
|
||||
|
||||
Font font=wb.createFont();
|
||||
font.setBoldweight(Font.BOLDWEIGHT_BOLD);
|
||||
font.setStrikeout(true);
|
||||
font.setColor(IndexedColors.YELLOW.getIndex());
|
||||
font.setFontName("Courier");
|
||||
short font1Idx = font.getIndex();
|
||||
wb.createCellStyle().setFont(font);
|
||||
assertEquals(num0 + 1, wb.getNumberOfFonts());
|
||||
|
||||
CellStyle cellStyleTitle=wb.createCellStyle();
|
||||
cellStyleTitle.setFont(font);
|
||||
r1c1.setCellStyle(cellStyleTitle);
|
||||
|
||||
// Save and re-load
|
||||
wb = getTestDataProvider().writeOutAndReadBack(wb);
|
||||
s1 = wb.getSheetAt(0);
|
||||
|
||||
assertEquals(num0 + 1, wb.getNumberOfFonts());
|
||||
short idx = s1.getRow(0).getCell(0).getCellStyle().getFontIndex();
|
||||
Font fnt = wb.getFontAt(idx);
|
||||
assertNotNull(fnt);
|
||||
assertEquals(IndexedColors.YELLOW.getIndex(), fnt.getColor());
|
||||
assertEquals("Courier", fnt.getFontName());
|
||||
|
||||
// Now add an orphaned one
|
||||
Font font2 = wb.createFont();
|
||||
font2.setItalic(true);
|
||||
font2.setFontHeightInPoints((short)15);
|
||||
short font2Idx = font2.getIndex();
|
||||
wb.createCellStyle().setFont(font2);
|
||||
assertEquals(num0 + 2, wb.getNumberOfFonts());
|
||||
|
||||
// Save and re-load
|
||||
wb = getTestDataProvider().writeOutAndReadBack(wb);
|
||||
s1 = wb.getSheetAt(0);
|
||||
|
||||
assertEquals(num0 + 2, wb.getNumberOfFonts());
|
||||
assertNotNull(wb.getFontAt(font1Idx));
|
||||
assertNotNull(wb.getFontAt(font2Idx));
|
||||
|
||||
assertEquals(15, wb.getFontAt(font2Idx).getFontHeightInPoints());
|
||||
assertEquals(true, wb.getFontAt(font2Idx).getItalic());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that fonts get added properly
|
||||
*
|
||||
* @see org.apache.poi.hssf.usermodel.TestBugs#test45338()
|
||||
*/
|
||||
public void test45338() {
|
||||
Workbook wb = getTestDataProvider().createWorkbook();
|
||||
int num0 = wb.getNumberOfFonts();
|
||||
|
||||
Sheet s = wb.createSheet();
|
||||
s.createRow(0);
|
||||
s.createRow(1);
|
||||
s.getRow(0).createCell(0);
|
||||
s.getRow(1).createCell(0);
|
||||
|
||||
//default font
|
||||
Font f1 = wb.getFontAt((short)0);
|
||||
assertEquals(Font.BOLDWEIGHT_NORMAL, f1.getBoldweight());
|
||||
|
||||
// Check that asking for the same font
|
||||
// multiple times gives you the same thing.
|
||||
// Otherwise, our tests wouldn't work!
|
||||
assertSame(wb.getFontAt((short)0), wb.getFontAt((short)0));
|
||||
|
||||
// Look for a new font we have
|
||||
// yet to add
|
||||
assertNull(
|
||||
wb.findFont(
|
||||
Font.BOLDWEIGHT_BOLD, (short)123, (short)(22*20),
|
||||
"Thingy", false, true, (short)2, (byte)2
|
||||
)
|
||||
);
|
||||
|
||||
Font nf = wb.createFont();
|
||||
short nfIdx = nf.getIndex();
|
||||
assertEquals(num0 + 1, wb.getNumberOfFonts());
|
||||
|
||||
assertSame(nf, wb.getFontAt(nfIdx));
|
||||
|
||||
nf.setBoldweight(Font.BOLDWEIGHT_BOLD);
|
||||
nf.setColor((short)123);
|
||||
nf.setFontHeightInPoints((short)22);
|
||||
nf.setFontName("Thingy");
|
||||
nf.setItalic(false);
|
||||
nf.setStrikeout(true);
|
||||
nf.setTypeOffset((short)2);
|
||||
nf.setUnderline((byte)2);
|
||||
|
||||
assertEquals(num0 + 1, wb.getNumberOfFonts());
|
||||
assertEquals(nf, wb.getFontAt(nfIdx));
|
||||
|
||||
assertEquals(wb.getFontAt(nfIdx), wb.getFontAt(nfIdx));
|
||||
assertTrue(wb.getFontAt((short)0) != wb.getFontAt(nfIdx));
|
||||
|
||||
// Find it now
|
||||
assertNotNull(
|
||||
wb.findFont(
|
||||
Font.BOLDWEIGHT_BOLD, (short)123, (short)(22*20),
|
||||
"Thingy", false, true, (short)2, (byte)2
|
||||
)
|
||||
);
|
||||
assertSame(nf,
|
||||
wb.findFont(
|
||||
Font.BOLDWEIGHT_BOLD, (short)123, (short)(22*20),
|
||||
"Thingy", false, true, (short)2, (byte)2
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1,53 +1,52 @@
|
||||
/* ====================================================================
|
||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
contributor license agreements. See the NOTICE file distributed with
|
||||
this work for additional information regarding copyright ownership.
|
||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
(the "License"); you may not use this file except in compliance with
|
||||
the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==================================================================== */
|
||||
package org.apache.poi.ss.usermodel;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.poi.ss.ITestDataProvider;
|
||||
|
||||
/**
|
||||
* @author Yegor Kozlov
|
||||
*/
|
||||
public abstract class BaseTestPicture extends TestCase {
|
||||
|
||||
protected abstract ITestDataProvider getTestDataProvider();
|
||||
|
||||
public void baseTestResize(ClientAnchor referenceAnchor) {
|
||||
Workbook wb = getTestDataProvider().createWorkbook();
|
||||
Sheet sh1 = wb.createSheet();
|
||||
Drawing p1 = sh1.createDrawingPatriarch();
|
||||
CreationHelper factory = wb.getCreationHelper();
|
||||
|
||||
byte[] pictureData = getTestDataProvider().getTestDataFileContent("logoKarmokar4.png");
|
||||
int idx1 = wb.addPicture( pictureData, Workbook.PICTURE_TYPE_PNG );
|
||||
Picture picture = p1.createPicture(factory.createClientAnchor(), idx1);
|
||||
picture.resize();
|
||||
ClientAnchor anchor1 = picture.getPreferredSize();
|
||||
|
||||
//assert against what would BiffViewer print if we insert the image in xls and dump the file
|
||||
assertEquals(referenceAnchor.getCol1(), anchor1.getCol1());
|
||||
assertEquals(referenceAnchor.getRow1(), anchor1.getRow1());
|
||||
assertEquals(referenceAnchor.getCol2(), anchor1.getCol2());
|
||||
assertEquals(referenceAnchor.getRow2(), anchor1.getRow2());
|
||||
assertEquals(referenceAnchor.getDx1(), anchor1.getDx1());
|
||||
assertEquals(referenceAnchor.getDy1(), anchor1.getDy1());
|
||||
assertEquals(referenceAnchor.getDx2(), anchor1.getDx2());
|
||||
assertEquals(referenceAnchor.getDy2(), anchor1.getDy2());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
/* ====================================================================
|
||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
contributor license agreements. See the NOTICE file distributed with
|
||||
this work for additional information regarding copyright ownership.
|
||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
(the "License"); you may not use this file except in compliance with
|
||||
the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==================================================================== */
|
||||
|
||||
package org.apache.poi.ss.usermodel;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.poi.ss.ITestDataProvider;
|
||||
|
||||
/**
|
||||
* @author Yegor Kozlov
|
||||
*/
|
||||
public abstract class BaseTestPicture extends TestCase {
|
||||
|
||||
protected abstract ITestDataProvider getTestDataProvider();
|
||||
|
||||
public void baseTestResize(ClientAnchor referenceAnchor) {
|
||||
Workbook wb = getTestDataProvider().createWorkbook();
|
||||
Sheet sh1 = wb.createSheet();
|
||||
Drawing p1 = sh1.createDrawingPatriarch();
|
||||
CreationHelper factory = wb.getCreationHelper();
|
||||
|
||||
byte[] pictureData = getTestDataProvider().getTestDataFileContent("logoKarmokar4.png");
|
||||
int idx1 = wb.addPicture( pictureData, Workbook.PICTURE_TYPE_PNG );
|
||||
Picture picture = p1.createPicture(factory.createClientAnchor(), idx1);
|
||||
picture.resize();
|
||||
ClientAnchor anchor1 = picture.getPreferredSize();
|
||||
|
||||
//assert against what would BiffViewer print if we insert the image in xls and dump the file
|
||||
assertEquals(referenceAnchor.getCol1(), anchor1.getCol1());
|
||||
assertEquals(referenceAnchor.getRow1(), anchor1.getRow1());
|
||||
assertEquals(referenceAnchor.getCol2(), anchor1.getCol2());
|
||||
assertEquals(referenceAnchor.getRow2(), anchor1.getRow2());
|
||||
assertEquals(referenceAnchor.getDx1(), anchor1.getDx1());
|
||||
assertEquals(referenceAnchor.getDy1(), anchor1.getDy1());
|
||||
assertEquals(referenceAnchor.getDx2(), anchor1.getDx2());
|
||||
assertEquals(referenceAnchor.getDy2(), anchor1.getDy2());
|
||||
}
|
||||
}
|
||||
|
@ -1,327 +1,327 @@
|
||||
/* ====================================================================
|
||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
contributor license agreements. See the NOTICE file distributed with
|
||||
this work for additional information regarding copyright ownership.
|
||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
(the "License"); you may not use this file except in compliance with
|
||||
the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==================================================================== */
|
||||
|
||||
package org.apache.poi.ss.usermodel;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.poi.ss.ITestDataProvider;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
|
||||
/**
|
||||
* Tests row shifting capabilities.
|
||||
*
|
||||
* @author Shawn Laubach (slaubach at apache dot com)
|
||||
* @author Toshiaki Kamoshida (kamoshida.toshiaki at future dot co dot jp)
|
||||
*/
|
||||
public abstract class BaseTestSheetShiftRows extends TestCase {
|
||||
|
||||
/**
|
||||
* @return an object that provides test data in HSSF / XSSF specific way
|
||||
*/
|
||||
protected abstract ITestDataProvider getTestDataProvider();
|
||||
|
||||
/**
|
||||
* Tests the shiftRows function. Does three different shifts.
|
||||
* After each shift, writes the workbook to file and reads back to
|
||||
* check. This ensures that if some changes code that breaks
|
||||
* writing or what not, they realize it.
|
||||
*
|
||||
* @param sampleName the sample file to test against
|
||||
*/
|
||||
public final void baseTestShiftRows(String sampleName){
|
||||
// Read initial file in
|
||||
Workbook wb = getTestDataProvider().openSampleWorkbook(sampleName);
|
||||
Sheet s = wb.getSheetAt( 0 );
|
||||
|
||||
// Shift the second row down 1 and write to temp file
|
||||
s.shiftRows( 1, 1, 1 );
|
||||
|
||||
wb = getTestDataProvider().writeOutAndReadBack(wb);
|
||||
|
||||
// Read from temp file and check the number of cells in each
|
||||
// row (in original file each row was unique)
|
||||
s = wb.getSheetAt( 0 );
|
||||
|
||||
assertEquals(s.getRow(0).getPhysicalNumberOfCells(), 1);
|
||||
confirmEmptyRow(s, 1);
|
||||
assertEquals(s.getRow(2).getPhysicalNumberOfCells(), 2);
|
||||
assertEquals(s.getRow(3).getPhysicalNumberOfCells(), 4);
|
||||
assertEquals(s.getRow(4).getPhysicalNumberOfCells(), 5);
|
||||
|
||||
// Shift rows 1-3 down 3 in the current one. This tests when
|
||||
// 1 row is blank. Write to a another temp file
|
||||
s.shiftRows( 0, 2, 3 );
|
||||
wb = getTestDataProvider().writeOutAndReadBack(wb);
|
||||
|
||||
// Read and ensure things are where they should be
|
||||
s = wb.getSheetAt(0);
|
||||
confirmEmptyRow(s, 0);
|
||||
confirmEmptyRow(s, 1);
|
||||
confirmEmptyRow(s, 2);
|
||||
assertEquals(s.getRow(3).getPhysicalNumberOfCells(), 1);
|
||||
confirmEmptyRow(s, 4);
|
||||
assertEquals(s.getRow(5).getPhysicalNumberOfCells(), 2);
|
||||
|
||||
// Read the first file again
|
||||
wb = getTestDataProvider().openSampleWorkbook(sampleName);
|
||||
s = wb.getSheetAt( 0 );
|
||||
|
||||
// Shift rows 3 and 4 up and write to temp file
|
||||
s.shiftRows( 2, 3, -2 );
|
||||
wb = getTestDataProvider().writeOutAndReadBack(wb);
|
||||
s = wb.getSheetAt( 0 );
|
||||
assertEquals(s.getRow(0).getPhysicalNumberOfCells(), 3);
|
||||
assertEquals(s.getRow(1).getPhysicalNumberOfCells(), 4);
|
||||
confirmEmptyRow(s, 2);
|
||||
confirmEmptyRow(s, 3);
|
||||
assertEquals(s.getRow(4).getPhysicalNumberOfCells(), 5);
|
||||
}
|
||||
private static void confirmEmptyRow(Sheet s, int rowIx) {
|
||||
Row row = s.getRow(rowIx);
|
||||
assertTrue(row == null || row.getPhysicalNumberOfCells() == 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests when rows are null.
|
||||
*/
|
||||
public final void baseTestShiftRow() {
|
||||
Workbook b = getTestDataProvider().createWorkbook();
|
||||
Sheet s = b.createSheet();
|
||||
s.createRow(0).createCell(0).setCellValue("TEST1");
|
||||
s.createRow(3).createCell(0).setCellValue("TEST2");
|
||||
s.shiftRows(0,4,1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests when shifting the first row.
|
||||
*/
|
||||
public final void baseTestActiveCell() {
|
||||
Workbook b = getTestDataProvider().createWorkbook();
|
||||
Sheet s = b.createSheet();
|
||||
|
||||
s.createRow(0).createCell(0).setCellValue("TEST1");
|
||||
s.createRow(3).createCell(0).setCellValue("TEST2");
|
||||
s.shiftRows(0,4,1);
|
||||
}
|
||||
|
||||
/**
|
||||
* When shifting rows, the page breaks should go with it
|
||||
*
|
||||
*/
|
||||
public final void baseTestShiftRowBreaks() {
|
||||
Workbook b = getTestDataProvider().createWorkbook();
|
||||
Sheet s = b.createSheet();
|
||||
Row row = s.createRow(4);
|
||||
row.createCell(0).setCellValue("test");
|
||||
s.setRowBreak(4);
|
||||
|
||||
s.shiftRows(4, 4, 2);
|
||||
assertTrue("Row number 6 should have a pagebreak", s.isRowBroken(6));
|
||||
}
|
||||
|
||||
|
||||
public final void baseTestShiftWithComments(String sampleName) {
|
||||
Workbook wb = getTestDataProvider().openSampleWorkbook(sampleName);
|
||||
|
||||
Sheet sheet = wb.getSheet("Sheet1");
|
||||
assertEquals(3, sheet.getLastRowNum());
|
||||
|
||||
// Verify comments are in the position expected
|
||||
assertNotNull(sheet.getCellComment(0,0));
|
||||
assertNull(sheet.getCellComment(1,0));
|
||||
assertNotNull(sheet.getCellComment(2,0));
|
||||
assertNotNull(sheet.getCellComment(3,0));
|
||||
|
||||
String comment1 = sheet.getCellComment(0,0).getString().getString();
|
||||
assertEquals(comment1,"comment top row1 (index0)\n");
|
||||
String comment3 = sheet.getCellComment(2,0).getString().getString();
|
||||
assertEquals(comment3,"comment top row3 (index2)\n");
|
||||
String comment4 = sheet.getCellComment(3,0).getString().getString();
|
||||
assertEquals(comment4,"comment top row4 (index3)\n");
|
||||
|
||||
// Shifting all but first line down to test comments shifting
|
||||
sheet.shiftRows(1, sheet.getLastRowNum(), 1, true, true);
|
||||
|
||||
// Test that comments were shifted as expected
|
||||
assertEquals(4, sheet.getLastRowNum());
|
||||
assertNotNull(sheet.getCellComment(0,0));
|
||||
assertNull(sheet.getCellComment(1,0));
|
||||
assertNull(sheet.getCellComment(2,0));
|
||||
assertNotNull(sheet.getCellComment(3,0));
|
||||
assertNotNull(sheet.getCellComment(4,0));
|
||||
|
||||
String comment1_shifted = sheet.getCellComment(0,0).getString().getString();
|
||||
assertEquals(comment1,comment1_shifted);
|
||||
String comment3_shifted = sheet.getCellComment(3,0).getString().getString();
|
||||
assertEquals(comment3,comment3_shifted);
|
||||
String comment4_shifted = sheet.getCellComment(4,0).getString().getString();
|
||||
assertEquals(comment4,comment4_shifted);
|
||||
|
||||
// Write out and read back in again
|
||||
// Ensure that the changes were persisted
|
||||
wb = getTestDataProvider().writeOutAndReadBack(wb);
|
||||
sheet = wb.getSheet("Sheet1");
|
||||
assertEquals(4, sheet.getLastRowNum());
|
||||
|
||||
// Verify comments are in the position expected after the shift
|
||||
assertNotNull(sheet.getCellComment(0,0));
|
||||
assertNull(sheet.getCellComment(1,0));
|
||||
assertNull(sheet.getCellComment(2,0));
|
||||
assertNotNull(sheet.getCellComment(3,0));
|
||||
assertNotNull(sheet.getCellComment(4,0));
|
||||
|
||||
comment1_shifted = sheet.getCellComment(0,0).getString().getString();
|
||||
assertEquals(comment1,comment1_shifted);
|
||||
comment3_shifted = sheet.getCellComment(3,0).getString().getString();
|
||||
assertEquals(comment3,comment3_shifted);
|
||||
comment4_shifted = sheet.getCellComment(4,0).getString().getString();
|
||||
assertEquals(comment4,comment4_shifted);
|
||||
}
|
||||
|
||||
public final void baseTestShiftWithNames() {
|
||||
Workbook wb = getTestDataProvider().createWorkbook();
|
||||
Sheet sheet1 = wb.createSheet("Sheet1");
|
||||
Sheet sheet2 = wb.createSheet("Sheet2");
|
||||
Row row = sheet1.createRow(0);
|
||||
row.createCell(0).setCellValue(1.1);
|
||||
row.createCell(1).setCellValue(2.2);
|
||||
|
||||
Name name1 = wb.createName();
|
||||
name1.setNameName("name1");
|
||||
name1.setRefersToFormula("Sheet1!$A$1+Sheet1!$B$1");
|
||||
|
||||
Name name2 = wb.createName();
|
||||
name2.setNameName("name2");
|
||||
name2.setRefersToFormula("Sheet1!$A$1");
|
||||
|
||||
//refers to A1 but on Sheet2. Should stay unaffected.
|
||||
Name name3 = wb.createName();
|
||||
name3.setNameName("name3");
|
||||
name3.setRefersToFormula("Sheet2!$A$1");
|
||||
|
||||
//The scope of this one is Sheet2. Should stay unaffected.
|
||||
Name name4 = wb.createName();
|
||||
name4.setNameName("name4");
|
||||
name4.setRefersToFormula("A1");
|
||||
name4.setSheetIndex(1);
|
||||
|
||||
sheet1.shiftRows(0, 1, 2); //shift down the top row on Sheet1.
|
||||
name1 = wb.getNameAt(0);
|
||||
assertEquals("Sheet1!$A$3+Sheet1!$B$3", name1.getRefersToFormula());
|
||||
|
||||
name2 = wb.getNameAt(1);
|
||||
assertEquals("Sheet1!$A$3", name2.getRefersToFormula());
|
||||
|
||||
//name3 and name4 refer to Sheet2 and should not be affected
|
||||
name3 = wb.getNameAt(2);
|
||||
assertEquals("Sheet2!$A$1", name3.getRefersToFormula());
|
||||
|
||||
name4 = wb.getNameAt(3);
|
||||
assertEquals("A1", name4.getRefersToFormula());
|
||||
}
|
||||
|
||||
public final void baseTestShiftWithMergedRegions() {
|
||||
Workbook wb = getTestDataProvider().createWorkbook();
|
||||
Sheet sheet = wb.createSheet();
|
||||
Row row = sheet.createRow(0);
|
||||
row.createCell(0).setCellValue(1.1);
|
||||
row.createCell(1).setCellValue(2.2);
|
||||
CellRangeAddress region = new CellRangeAddress(0, 0, 0, 2);
|
||||
assertEquals("A1:C1", region.formatAsString());
|
||||
|
||||
sheet.addMergedRegion(region);
|
||||
|
||||
sheet.shiftRows(0, 1, 2);
|
||||
region = sheet.getMergedRegion(0);
|
||||
assertEquals("A3:C3", region.formatAsString());
|
||||
}
|
||||
|
||||
/**
|
||||
* See bug #34023
|
||||
*
|
||||
* @param sampleName the sample file to test against
|
||||
*/
|
||||
public void baseTestShiftWithFormulas(String sampleName) {
|
||||
Workbook wb = getTestDataProvider().openSampleWorkbook(sampleName);
|
||||
|
||||
Sheet sheet = wb.getSheet("Sheet1");
|
||||
assertEquals(20, sheet.getLastRowNum());
|
||||
|
||||
confirmRow(sheet, 0, 1, 171, 1, "ROW(D1)", "100+B1", "COUNT(D1:E1)");
|
||||
confirmRow(sheet, 1, 2, 172, 1, "ROW(D2)", "100+B2", "COUNT(D2:E2)");
|
||||
confirmRow(sheet, 2, 3, 173, 1, "ROW(D3)", "100+B3", "COUNT(D3:E3)");
|
||||
|
||||
confirmCell(sheet, 6, 1, 271, "200+B1");
|
||||
confirmCell(sheet, 7, 1, 272, "200+B2");
|
||||
confirmCell(sheet, 8, 1, 273, "200+B3");
|
||||
|
||||
confirmCell(sheet, 14, 0, 0.0, "A12"); // the cell referred to by this formula will be replaced
|
||||
|
||||
// -----------
|
||||
// Row index 1 -> 11 (row "2" -> row "12")
|
||||
sheet.shiftRows(1, 1, 10);
|
||||
|
||||
// Now check what sheet looks like after move
|
||||
|
||||
// no changes on row "1"
|
||||
confirmRow(sheet, 0, 1, 171, 1, "ROW(D1)", "100+B1", "COUNT(D1:E1)");
|
||||
|
||||
// row "2" is now empty
|
||||
confirmEmptyRow(sheet, 1);
|
||||
|
||||
// Row "2" moved to row "12", and the formula has been updated.
|
||||
// note however that the cached formula result (2) has not been updated. (POI differs from Excel here)
|
||||
confirmRow(sheet, 11, 2, 172, 1, "ROW(D12)", "100+B12", "COUNT(D12:E12)");
|
||||
|
||||
// no changes on row "3"
|
||||
confirmRow(sheet, 2, 3, 173, 1, "ROW(D3)", "100+B3", "COUNT(D3:E3)");
|
||||
|
||||
|
||||
confirmCell(sheet, 14, 0, 0.0, "#REF!");
|
||||
|
||||
|
||||
// Formulas on rows that weren't shifted:
|
||||
confirmCell(sheet, 6, 1, 271, "200+B1");
|
||||
confirmCell(sheet, 7, 1, 272, "200+B12"); // this one moved
|
||||
confirmCell(sheet, 8, 1, 273, "200+B3");
|
||||
|
||||
// check formulas on other sheets
|
||||
Sheet sheet2 = wb.getSheet("Sheet2");
|
||||
confirmCell(sheet2, 0, 0, 371, "300+Sheet1!B1");
|
||||
confirmCell(sheet2, 1, 0, 372, "300+Sheet1!B12");
|
||||
confirmCell(sheet2, 2, 0, 373, "300+Sheet1!B3");
|
||||
|
||||
confirmCell(sheet2, 11, 0, 300, "300+Sheet1!#REF!");
|
||||
|
||||
|
||||
// Note - named ranges formulas have not been updated
|
||||
}
|
||||
|
||||
private static void confirmRow(Sheet sheet, int rowIx, double valA, double valB, double valC,
|
||||
String formulaA, String formulaB, String formulaC) {
|
||||
confirmCell(sheet, rowIx, 4, valA, formulaA);
|
||||
confirmCell(sheet, rowIx, 5, valB, formulaB);
|
||||
confirmCell(sheet, rowIx, 6, valC, formulaC);
|
||||
}
|
||||
|
||||
private static void confirmCell(Sheet sheet, int rowIx, int colIx,
|
||||
double expectedValue, String expectedFormula) {
|
||||
Cell cell = sheet.getRow(rowIx).getCell(colIx);
|
||||
assertEquals(expectedValue, cell.getNumericCellValue(), 0.0);
|
||||
assertEquals(expectedFormula, cell.getCellFormula());
|
||||
}
|
||||
}
|
||||
/* ====================================================================
|
||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
contributor license agreements. See the NOTICE file distributed with
|
||||
this work for additional information regarding copyright ownership.
|
||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
(the "License"); you may not use this file except in compliance with
|
||||
the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==================================================================== */
|
||||
|
||||
package org.apache.poi.ss.usermodel;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.poi.ss.ITestDataProvider;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
|
||||
/**
|
||||
* Tests row shifting capabilities.
|
||||
*
|
||||
* @author Shawn Laubach (slaubach at apache dot com)
|
||||
* @author Toshiaki Kamoshida (kamoshida.toshiaki at future dot co dot jp)
|
||||
*/
|
||||
public abstract class BaseTestSheetShiftRows extends TestCase {
|
||||
|
||||
/**
|
||||
* @return an object that provides test data in HSSF / XSSF specific way
|
||||
*/
|
||||
protected abstract ITestDataProvider getTestDataProvider();
|
||||
|
||||
/**
|
||||
* Tests the shiftRows function. Does three different shifts.
|
||||
* After each shift, writes the workbook to file and reads back to
|
||||
* check. This ensures that if some changes code that breaks
|
||||
* writing or what not, they realize it.
|
||||
*
|
||||
* @param sampleName the sample file to test against
|
||||
*/
|
||||
public final void baseTestShiftRows(String sampleName){
|
||||
// Read initial file in
|
||||
Workbook wb = getTestDataProvider().openSampleWorkbook(sampleName);
|
||||
Sheet s = wb.getSheetAt( 0 );
|
||||
|
||||
// Shift the second row down 1 and write to temp file
|
||||
s.shiftRows( 1, 1, 1 );
|
||||
|
||||
wb = getTestDataProvider().writeOutAndReadBack(wb);
|
||||
|
||||
// Read from temp file and check the number of cells in each
|
||||
// row (in original file each row was unique)
|
||||
s = wb.getSheetAt( 0 );
|
||||
|
||||
assertEquals(s.getRow(0).getPhysicalNumberOfCells(), 1);
|
||||
confirmEmptyRow(s, 1);
|
||||
assertEquals(s.getRow(2).getPhysicalNumberOfCells(), 2);
|
||||
assertEquals(s.getRow(3).getPhysicalNumberOfCells(), 4);
|
||||
assertEquals(s.getRow(4).getPhysicalNumberOfCells(), 5);
|
||||
|
||||
// Shift rows 1-3 down 3 in the current one. This tests when
|
||||
// 1 row is blank. Write to a another temp file
|
||||
s.shiftRows( 0, 2, 3 );
|
||||
wb = getTestDataProvider().writeOutAndReadBack(wb);
|
||||
|
||||
// Read and ensure things are where they should be
|
||||
s = wb.getSheetAt(0);
|
||||
confirmEmptyRow(s, 0);
|
||||
confirmEmptyRow(s, 1);
|
||||
confirmEmptyRow(s, 2);
|
||||
assertEquals(s.getRow(3).getPhysicalNumberOfCells(), 1);
|
||||
confirmEmptyRow(s, 4);
|
||||
assertEquals(s.getRow(5).getPhysicalNumberOfCells(), 2);
|
||||
|
||||
// Read the first file again
|
||||
wb = getTestDataProvider().openSampleWorkbook(sampleName);
|
||||
s = wb.getSheetAt( 0 );
|
||||
|
||||
// Shift rows 3 and 4 up and write to temp file
|
||||
s.shiftRows( 2, 3, -2 );
|
||||
wb = getTestDataProvider().writeOutAndReadBack(wb);
|
||||
s = wb.getSheetAt( 0 );
|
||||
assertEquals(s.getRow(0).getPhysicalNumberOfCells(), 3);
|
||||
assertEquals(s.getRow(1).getPhysicalNumberOfCells(), 4);
|
||||
confirmEmptyRow(s, 2);
|
||||
confirmEmptyRow(s, 3);
|
||||
assertEquals(s.getRow(4).getPhysicalNumberOfCells(), 5);
|
||||
}
|
||||
private static void confirmEmptyRow(Sheet s, int rowIx) {
|
||||
Row row = s.getRow(rowIx);
|
||||
assertTrue(row == null || row.getPhysicalNumberOfCells() == 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests when rows are null.
|
||||
*/
|
||||
public final void baseTestShiftRow() {
|
||||
Workbook b = getTestDataProvider().createWorkbook();
|
||||
Sheet s = b.createSheet();
|
||||
s.createRow(0).createCell(0).setCellValue("TEST1");
|
||||
s.createRow(3).createCell(0).setCellValue("TEST2");
|
||||
s.shiftRows(0,4,1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests when shifting the first row.
|
||||
*/
|
||||
public final void baseTestActiveCell() {
|
||||
Workbook b = getTestDataProvider().createWorkbook();
|
||||
Sheet s = b.createSheet();
|
||||
|
||||
s.createRow(0).createCell(0).setCellValue("TEST1");
|
||||
s.createRow(3).createCell(0).setCellValue("TEST2");
|
||||
s.shiftRows(0,4,1);
|
||||
}
|
||||
|
||||
/**
|
||||
* When shifting rows, the page breaks should go with it
|
||||
*
|
||||
*/
|
||||
public final void baseTestShiftRowBreaks() {
|
||||
Workbook b = getTestDataProvider().createWorkbook();
|
||||
Sheet s = b.createSheet();
|
||||
Row row = s.createRow(4);
|
||||
row.createCell(0).setCellValue("test");
|
||||
s.setRowBreak(4);
|
||||
|
||||
s.shiftRows(4, 4, 2);
|
||||
assertTrue("Row number 6 should have a pagebreak", s.isRowBroken(6));
|
||||
}
|
||||
|
||||
|
||||
public final void baseTestShiftWithComments(String sampleName) {
|
||||
Workbook wb = getTestDataProvider().openSampleWorkbook(sampleName);
|
||||
|
||||
Sheet sheet = wb.getSheet("Sheet1");
|
||||
assertEquals(3, sheet.getLastRowNum());
|
||||
|
||||
// Verify comments are in the position expected
|
||||
assertNotNull(sheet.getCellComment(0,0));
|
||||
assertNull(sheet.getCellComment(1,0));
|
||||
assertNotNull(sheet.getCellComment(2,0));
|
||||
assertNotNull(sheet.getCellComment(3,0));
|
||||
|
||||
String comment1 = sheet.getCellComment(0,0).getString().getString();
|
||||
assertEquals(comment1,"comment top row1 (index0)\n");
|
||||
String comment3 = sheet.getCellComment(2,0).getString().getString();
|
||||
assertEquals(comment3,"comment top row3 (index2)\n");
|
||||
String comment4 = sheet.getCellComment(3,0).getString().getString();
|
||||
assertEquals(comment4,"comment top row4 (index3)\n");
|
||||
|
||||
// Shifting all but first line down to test comments shifting
|
||||
sheet.shiftRows(1, sheet.getLastRowNum(), 1, true, true);
|
||||
|
||||
// Test that comments were shifted as expected
|
||||
assertEquals(4, sheet.getLastRowNum());
|
||||
assertNotNull(sheet.getCellComment(0,0));
|
||||
assertNull(sheet.getCellComment(1,0));
|
||||
assertNull(sheet.getCellComment(2,0));
|
||||
assertNotNull(sheet.getCellComment(3,0));
|
||||
assertNotNull(sheet.getCellComment(4,0));
|
||||
|
||||
String comment1_shifted = sheet.getCellComment(0,0).getString().getString();
|
||||
assertEquals(comment1,comment1_shifted);
|
||||
String comment3_shifted = sheet.getCellComment(3,0).getString().getString();
|
||||
assertEquals(comment3,comment3_shifted);
|
||||
String comment4_shifted = sheet.getCellComment(4,0).getString().getString();
|
||||
assertEquals(comment4,comment4_shifted);
|
||||
|
||||
// Write out and read back in again
|
||||
// Ensure that the changes were persisted
|
||||
wb = getTestDataProvider().writeOutAndReadBack(wb);
|
||||
sheet = wb.getSheet("Sheet1");
|
||||
assertEquals(4, sheet.getLastRowNum());
|
||||
|
||||
// Verify comments are in the position expected after the shift
|
||||
assertNotNull(sheet.getCellComment(0,0));
|
||||
assertNull(sheet.getCellComment(1,0));
|
||||
assertNull(sheet.getCellComment(2,0));
|
||||
assertNotNull(sheet.getCellComment(3,0));
|
||||
assertNotNull(sheet.getCellComment(4,0));
|
||||
|
||||
comment1_shifted = sheet.getCellComment(0,0).getString().getString();
|
||||
assertEquals(comment1,comment1_shifted);
|
||||
comment3_shifted = sheet.getCellComment(3,0).getString().getString();
|
||||
assertEquals(comment3,comment3_shifted);
|
||||
comment4_shifted = sheet.getCellComment(4,0).getString().getString();
|
||||
assertEquals(comment4,comment4_shifted);
|
||||
}
|
||||
|
||||
public final void baseTestShiftWithNames() {
|
||||
Workbook wb = getTestDataProvider().createWorkbook();
|
||||
Sheet sheet1 = wb.createSheet("Sheet1");
|
||||
wb.createSheet("Sheet2");
|
||||
Row row = sheet1.createRow(0);
|
||||
row.createCell(0).setCellValue(1.1);
|
||||
row.createCell(1).setCellValue(2.2);
|
||||
|
||||
Name name1 = wb.createName();
|
||||
name1.setNameName("name1");
|
||||
name1.setRefersToFormula("Sheet1!$A$1+Sheet1!$B$1");
|
||||
|
||||
Name name2 = wb.createName();
|
||||
name2.setNameName("name2");
|
||||
name2.setRefersToFormula("Sheet1!$A$1");
|
||||
|
||||
//refers to A1 but on Sheet2. Should stay unaffected.
|
||||
Name name3 = wb.createName();
|
||||
name3.setNameName("name3");
|
||||
name3.setRefersToFormula("Sheet2!$A$1");
|
||||
|
||||
//The scope of this one is Sheet2. Should stay unaffected.
|
||||
Name name4 = wb.createName();
|
||||
name4.setNameName("name4");
|
||||
name4.setRefersToFormula("A1");
|
||||
name4.setSheetIndex(1);
|
||||
|
||||
sheet1.shiftRows(0, 1, 2); //shift down the top row on Sheet1.
|
||||
name1 = wb.getNameAt(0);
|
||||
assertEquals("Sheet1!$A$3+Sheet1!$B$3", name1.getRefersToFormula());
|
||||
|
||||
name2 = wb.getNameAt(1);
|
||||
assertEquals("Sheet1!$A$3", name2.getRefersToFormula());
|
||||
|
||||
//name3 and name4 refer to Sheet2 and should not be affected
|
||||
name3 = wb.getNameAt(2);
|
||||
assertEquals("Sheet2!$A$1", name3.getRefersToFormula());
|
||||
|
||||
name4 = wb.getNameAt(3);
|
||||
assertEquals("A1", name4.getRefersToFormula());
|
||||
}
|
||||
|
||||
public final void baseTestShiftWithMergedRegions() {
|
||||
Workbook wb = getTestDataProvider().createWorkbook();
|
||||
Sheet sheet = wb.createSheet();
|
||||
Row row = sheet.createRow(0);
|
||||
row.createCell(0).setCellValue(1.1);
|
||||
row.createCell(1).setCellValue(2.2);
|
||||
CellRangeAddress region = new CellRangeAddress(0, 0, 0, 2);
|
||||
assertEquals("A1:C1", region.formatAsString());
|
||||
|
||||
sheet.addMergedRegion(region);
|
||||
|
||||
sheet.shiftRows(0, 1, 2);
|
||||
region = sheet.getMergedRegion(0);
|
||||
assertEquals("A3:C3", region.formatAsString());
|
||||
}
|
||||
|
||||
/**
|
||||
* See bug #34023
|
||||
*
|
||||
* @param sampleName the sample file to test against
|
||||
*/
|
||||
public void baseTestShiftWithFormulas(String sampleName) {
|
||||
Workbook wb = getTestDataProvider().openSampleWorkbook(sampleName);
|
||||
|
||||
Sheet sheet = wb.getSheet("Sheet1");
|
||||
assertEquals(20, sheet.getLastRowNum());
|
||||
|
||||
confirmRow(sheet, 0, 1, 171, 1, "ROW(D1)", "100+B1", "COUNT(D1:E1)");
|
||||
confirmRow(sheet, 1, 2, 172, 1, "ROW(D2)", "100+B2", "COUNT(D2:E2)");
|
||||
confirmRow(sheet, 2, 3, 173, 1, "ROW(D3)", "100+B3", "COUNT(D3:E3)");
|
||||
|
||||
confirmCell(sheet, 6, 1, 271, "200+B1");
|
||||
confirmCell(sheet, 7, 1, 272, "200+B2");
|
||||
confirmCell(sheet, 8, 1, 273, "200+B3");
|
||||
|
||||
confirmCell(sheet, 14, 0, 0.0, "A12"); // the cell referred to by this formula will be replaced
|
||||
|
||||
// -----------
|
||||
// Row index 1 -> 11 (row "2" -> row "12")
|
||||
sheet.shiftRows(1, 1, 10);
|
||||
|
||||
// Now check what sheet looks like after move
|
||||
|
||||
// no changes on row "1"
|
||||
confirmRow(sheet, 0, 1, 171, 1, "ROW(D1)", "100+B1", "COUNT(D1:E1)");
|
||||
|
||||
// row "2" is now empty
|
||||
confirmEmptyRow(sheet, 1);
|
||||
|
||||
// Row "2" moved to row "12", and the formula has been updated.
|
||||
// note however that the cached formula result (2) has not been updated. (POI differs from Excel here)
|
||||
confirmRow(sheet, 11, 2, 172, 1, "ROW(D12)", "100+B12", "COUNT(D12:E12)");
|
||||
|
||||
// no changes on row "3"
|
||||
confirmRow(sheet, 2, 3, 173, 1, "ROW(D3)", "100+B3", "COUNT(D3:E3)");
|
||||
|
||||
|
||||
confirmCell(sheet, 14, 0, 0.0, "#REF!");
|
||||
|
||||
|
||||
// Formulas on rows that weren't shifted:
|
||||
confirmCell(sheet, 6, 1, 271, "200+B1");
|
||||
confirmCell(sheet, 7, 1, 272, "200+B12"); // this one moved
|
||||
confirmCell(sheet, 8, 1, 273, "200+B3");
|
||||
|
||||
// check formulas on other sheets
|
||||
Sheet sheet2 = wb.getSheet("Sheet2");
|
||||
confirmCell(sheet2, 0, 0, 371, "300+Sheet1!B1");
|
||||
confirmCell(sheet2, 1, 0, 372, "300+Sheet1!B12");
|
||||
confirmCell(sheet2, 2, 0, 373, "300+Sheet1!B3");
|
||||
|
||||
confirmCell(sheet2, 11, 0, 300, "300+Sheet1!#REF!");
|
||||
|
||||
|
||||
// Note - named ranges formulas have not been updated
|
||||
}
|
||||
|
||||
private static void confirmRow(Sheet sheet, int rowIx, double valA, double valB, double valC,
|
||||
String formulaA, String formulaB, String formulaC) {
|
||||
confirmCell(sheet, rowIx, 4, valA, formulaA);
|
||||
confirmCell(sheet, rowIx, 5, valB, formulaB);
|
||||
confirmCell(sheet, rowIx, 6, valC, formulaC);
|
||||
}
|
||||
|
||||
private static void confirmCell(Sheet sheet, int rowIx, int colIx,
|
||||
double expectedValue, String expectedFormula) {
|
||||
Cell cell = sheet.getRow(rowIx).getCell(colIx);
|
||||
assertEquals(expectedValue, cell.getNumericCellValue(), 0.0);
|
||||
assertEquals(expectedFormula, cell.getCellFormula());
|
||||
}
|
||||
}
|
||||
|
@ -1,355 +1,366 @@
|
||||
package org.apache.poi.ss.usermodel;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.AssertionFailedError;
|
||||
import org.apache.poi.ss.ITestDataProvider;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
|
||||
/**
|
||||
* @author Yegor Kozlov
|
||||
*/
|
||||
public abstract class BaseTestWorkbook extends TestCase {
|
||||
|
||||
protected abstract ITestDataProvider getTestDataProvider();
|
||||
|
||||
public void testCreateSheet() {
|
||||
Workbook wb = getTestDataProvider().createWorkbook();
|
||||
assertEquals(0, wb.getNumberOfSheets());
|
||||
|
||||
//getting a sheet by invalid index or non-existing name
|
||||
assertNull(wb.getSheet("Sheet1"));
|
||||
try {
|
||||
wb.getSheetAt(0);
|
||||
fail("should have thrown exceptiuon due to invalid sheet index");
|
||||
} catch (IllegalArgumentException e) {
|
||||
// expected during successful test
|
||||
;
|
||||
}
|
||||
|
||||
Sheet sheet0 = wb.createSheet();
|
||||
Sheet sheet1 = wb.createSheet();
|
||||
assertEquals("Sheet0", sheet0.getSheetName());
|
||||
assertEquals("Sheet1", sheet1.getSheetName());
|
||||
assertEquals(2, wb.getNumberOfSheets());
|
||||
|
||||
//fetching sheets by name is case-insensitive
|
||||
Sheet originalSheet = wb.createSheet("Sheet3");
|
||||
Sheet fetchedSheet = wb.getSheet("sheet3");
|
||||
if (fetchedSheet == null) {
|
||||
throw new AssertionFailedError("Identified bug 44892");
|
||||
}
|
||||
assertEquals("Sheet3", fetchedSheet.getSheetName());
|
||||
assertEquals(3, wb.getNumberOfSheets());
|
||||
assertSame(originalSheet, fetchedSheet);
|
||||
try {
|
||||
wb.createSheet("sHeeT3");
|
||||
fail("should have thrown exceptiuon due to duplicate sheet name");
|
||||
} catch (IllegalArgumentException e) {
|
||||
// expected during successful test
|
||||
assertEquals("The workbook already contains a sheet of this name", e.getMessage());
|
||||
}
|
||||
|
||||
//names cannot be blank or contain any of /\*?[]
|
||||
String[] invalidNames = {"", "Sheet/", "Sheet\\",
|
||||
"Sheet?", "Sheet*", "Sheet[", "Sheet]"};
|
||||
for (String sheetName : invalidNames) {
|
||||
try {
|
||||
wb.createSheet(sheetName);
|
||||
fail("should have thrown exceptiuon due to invalid sheet name: " + sheetName);
|
||||
} catch (IllegalArgumentException e) {
|
||||
// expected during successful test
|
||||
;
|
||||
}
|
||||
}
|
||||
//still have 3 sheets
|
||||
assertEquals(3, wb.getNumberOfSheets());
|
||||
|
||||
//change the name of the 3rd sheet
|
||||
wb.setSheetName(2, "I changed!");
|
||||
|
||||
//try to assign an invalid name to the 2nd sheet
|
||||
try {
|
||||
wb.setSheetName(1, "[I'm invalid]");
|
||||
fail("should have thrown exceptiuon due to invalid sheet name");
|
||||
} catch (IllegalArgumentException e) {
|
||||
; // expected during successful test
|
||||
}
|
||||
|
||||
//check
|
||||
assertEquals(0, wb.getSheetIndex("sheet0"));
|
||||
assertEquals(1, wb.getSheetIndex("sheet1"));
|
||||
assertEquals(2, wb.getSheetIndex("I changed!"));
|
||||
|
||||
assertSame(sheet0, wb.getSheet("sheet0"));
|
||||
assertSame(sheet1, wb.getSheet("sheet1"));
|
||||
assertSame(originalSheet, wb.getSheet("I changed!"));
|
||||
assertNull(wb.getSheet("unknown"));
|
||||
|
||||
//serialize and read again
|
||||
wb = getTestDataProvider().writeOutAndReadBack(wb);
|
||||
assertEquals(3, wb.getNumberOfSheets());
|
||||
assertEquals(0, wb.getSheetIndex("sheet0"));
|
||||
assertEquals(1, wb.getSheetIndex("sheet1"));
|
||||
assertEquals(2, wb.getSheetIndex("I changed!"));
|
||||
|
||||
}
|
||||
|
||||
public void testRemoveSheetAt() {
|
||||
Workbook workbook = getTestDataProvider().createWorkbook();
|
||||
workbook.createSheet("sheet1");
|
||||
workbook.createSheet("sheet2");
|
||||
workbook.createSheet("sheet3");
|
||||
assertEquals(3, workbook.getNumberOfSheets());
|
||||
workbook.removeSheetAt(1);
|
||||
assertEquals(2, workbook.getNumberOfSheets());
|
||||
assertEquals("sheet3", workbook.getSheetName(1));
|
||||
workbook.removeSheetAt(0);
|
||||
assertEquals(1, workbook.getNumberOfSheets());
|
||||
assertEquals("sheet3", workbook.getSheetName(0));
|
||||
workbook.removeSheetAt(0);
|
||||
assertEquals(0, workbook.getNumberOfSheets());
|
||||
|
||||
//re-create the sheets
|
||||
workbook.createSheet("sheet1");
|
||||
workbook.createSheet("sheet2");
|
||||
workbook.createSheet("sheet3");
|
||||
assertEquals(3, workbook.getNumberOfSheets());
|
||||
}
|
||||
|
||||
public void testDefaultValues() {
|
||||
Workbook b = getTestDataProvider().createWorkbook();
|
||||
assertEquals(0, b.getActiveSheetIndex());
|
||||
assertEquals(0, b.getFirstVisibleTab());
|
||||
assertEquals(0, b.getNumberOfNames());
|
||||
assertEquals(0, b.getNumberOfSheets());
|
||||
}
|
||||
|
||||
|
||||
public void testSheetSelection() {
|
||||
Workbook b = getTestDataProvider().createWorkbook();
|
||||
b.createSheet("Sheet One");
|
||||
b.createSheet("Sheet Two");
|
||||
b.setActiveSheet(1);
|
||||
b.setSelectedTab(1);
|
||||
b.setFirstVisibleTab(1);
|
||||
assertEquals(1, b.getActiveSheetIndex());
|
||||
assertEquals(1, b.getFirstVisibleTab());
|
||||
}
|
||||
|
||||
public void testPrintArea() {
|
||||
Workbook workbook = getTestDataProvider().createWorkbook();
|
||||
Sheet sheet1 = workbook.createSheet("Test Print Area");
|
||||
String sheetName1 = sheet1.getSheetName();
|
||||
|
||||
// workbook.setPrintArea(0, reference);
|
||||
workbook.setPrintArea(0, 1, 5, 4, 9);
|
||||
String retrievedPrintArea = workbook.getPrintArea(0);
|
||||
assertEquals("'" + sheetName1 + "'!$B$5:$F$10", retrievedPrintArea);
|
||||
|
||||
String reference = "$A$1:$B$1";
|
||||
workbook.setPrintArea(0, reference);
|
||||
retrievedPrintArea = workbook.getPrintArea(0);
|
||||
assertEquals("'" + sheetName1 + "'!" + reference, retrievedPrintArea);
|
||||
|
||||
workbook.removePrintArea(0);
|
||||
assertNull(workbook.getPrintArea(0));
|
||||
}
|
||||
|
||||
public void testGetSetActiveSheet(){
|
||||
Workbook workbook = getTestDataProvider().createWorkbook();
|
||||
assertEquals(0, workbook.getActiveSheetIndex());
|
||||
|
||||
workbook.createSheet("sheet1");
|
||||
workbook.createSheet("sheet2");
|
||||
workbook.createSheet("sheet3");
|
||||
// set second sheet
|
||||
workbook.setActiveSheet(1);
|
||||
// test if second sheet is set up
|
||||
assertEquals(1, workbook.getActiveSheetIndex());
|
||||
|
||||
workbook.setActiveSheet(0);
|
||||
// test if second sheet is set up
|
||||
assertEquals(0, workbook.getActiveSheetIndex());
|
||||
}
|
||||
|
||||
public void testSetSheetOrder() {
|
||||
Workbook wb = getTestDataProvider().createWorkbook();
|
||||
|
||||
for (int i=0; i < 10; i++) {
|
||||
Sheet sh = wb.createSheet("Sheet " + i);
|
||||
}
|
||||
|
||||
// Check the initial order
|
||||
assertEquals(0, wb.getSheetIndex("Sheet 0"));
|
||||
assertEquals(1, wb.getSheetIndex("Sheet 1"));
|
||||
assertEquals(2, wb.getSheetIndex("Sheet 2"));
|
||||
assertEquals(3, wb.getSheetIndex("Sheet 3"));
|
||||
assertEquals(4, wb.getSheetIndex("Sheet 4"));
|
||||
assertEquals(5, wb.getSheetIndex("Sheet 5"));
|
||||
assertEquals(6, wb.getSheetIndex("Sheet 6"));
|
||||
assertEquals(7, wb.getSheetIndex("Sheet 7"));
|
||||
assertEquals(8, wb.getSheetIndex("Sheet 8"));
|
||||
assertEquals(9, wb.getSheetIndex("Sheet 9"));
|
||||
|
||||
// Change
|
||||
wb.setSheetOrder("Sheet 6", 0);
|
||||
wb.setSheetOrder("Sheet 3", 7);
|
||||
wb.setSheetOrder("Sheet 1", 9);
|
||||
|
||||
// Check they're currently right
|
||||
assertEquals(0, wb.getSheetIndex("Sheet 6"));
|
||||
assertEquals(1, wb.getSheetIndex("Sheet 0"));
|
||||
assertEquals(2, wb.getSheetIndex("Sheet 2"));
|
||||
assertEquals(3, wb.getSheetIndex("Sheet 4"));
|
||||
assertEquals(4, wb.getSheetIndex("Sheet 5"));
|
||||
assertEquals(5, wb.getSheetIndex("Sheet 7"));
|
||||
assertEquals(6, wb.getSheetIndex("Sheet 3"));
|
||||
assertEquals(7, wb.getSheetIndex("Sheet 8"));
|
||||
assertEquals(8, wb.getSheetIndex("Sheet 9"));
|
||||
assertEquals(9, wb.getSheetIndex("Sheet 1"));
|
||||
|
||||
Workbook wbr = getTestDataProvider().writeOutAndReadBack(wb);
|
||||
|
||||
assertEquals(0, wbr.getSheetIndex("Sheet 6"));
|
||||
assertEquals(1, wbr.getSheetIndex("Sheet 0"));
|
||||
assertEquals(2, wbr.getSheetIndex("Sheet 2"));
|
||||
assertEquals(3, wbr.getSheetIndex("Sheet 4"));
|
||||
assertEquals(4, wbr.getSheetIndex("Sheet 5"));
|
||||
assertEquals(5, wbr.getSheetIndex("Sheet 7"));
|
||||
assertEquals(6, wbr.getSheetIndex("Sheet 3"));
|
||||
assertEquals(7, wbr.getSheetIndex("Sheet 8"));
|
||||
assertEquals(8, wbr.getSheetIndex("Sheet 9"));
|
||||
assertEquals(9, wbr.getSheetIndex("Sheet 1"));
|
||||
|
||||
// Now get the index by the sheet, not the name
|
||||
for(int i=0; i<10; i++) {
|
||||
Sheet s = wbr.getSheetAt(i);
|
||||
assertEquals(i, wbr.getSheetIndex(s));
|
||||
}
|
||||
}
|
||||
|
||||
public void testCloneSheet() {
|
||||
Workbook book = getTestDataProvider().createWorkbook();
|
||||
Sheet sheet = book.createSheet("TEST");
|
||||
sheet.createRow(0).createCell(0).setCellValue("Test");
|
||||
sheet.createRow(1).createCell(0).setCellValue(36.6);
|
||||
sheet.addMergedRegion(new CellRangeAddress(0, 1, 0, 2));
|
||||
sheet.addMergedRegion(new CellRangeAddress(1, 2, 0, 2));
|
||||
assertTrue(sheet.isSelected());
|
||||
|
||||
Sheet clonedSheet = book.cloneSheet(0);
|
||||
assertEquals("TEST (2)", clonedSheet.getSheetName());
|
||||
assertEquals(2, clonedSheet.getPhysicalNumberOfRows());
|
||||
assertEquals(2, clonedSheet.getNumMergedRegions());
|
||||
assertFalse(clonedSheet.isSelected());
|
||||
|
||||
//cloned sheet is a deep copy, adding rows in the original does not affect the clone
|
||||
sheet.createRow(2).createCell(0).setCellValue(1);
|
||||
sheet.addMergedRegion(new CellRangeAddress(0, 2, 0, 2));
|
||||
assertEquals(2, clonedSheet.getPhysicalNumberOfRows());
|
||||
assertEquals(2, clonedSheet.getPhysicalNumberOfRows());
|
||||
|
||||
clonedSheet.createRow(2).createCell(0).setCellValue(1);
|
||||
clonedSheet.addMergedRegion(new CellRangeAddress(0, 2, 0, 2));
|
||||
assertEquals(3, clonedSheet.getPhysicalNumberOfRows());
|
||||
assertEquals(3, clonedSheet.getPhysicalNumberOfRows());
|
||||
|
||||
}
|
||||
|
||||
public void testParentReferences(){
|
||||
Workbook workbook = getTestDataProvider().createWorkbook();
|
||||
Sheet sheet = workbook.createSheet();
|
||||
assertSame(workbook, sheet.getWorkbook());
|
||||
|
||||
Row row = sheet.createRow(0);
|
||||
assertSame(sheet, row.getSheet());
|
||||
|
||||
Cell cell = row.createCell(1);
|
||||
assertSame(sheet, cell.getSheet());
|
||||
assertSame(row, cell.getRow());
|
||||
|
||||
workbook = getTestDataProvider().writeOutAndReadBack(workbook);
|
||||
sheet = workbook.getSheetAt(0);
|
||||
assertSame(workbook, sheet.getWorkbook());
|
||||
|
||||
row = sheet.getRow(0);
|
||||
assertSame(sheet, row.getSheet());
|
||||
|
||||
cell = row.getCell(1);
|
||||
assertSame(sheet, cell.getSheet());
|
||||
assertSame(row, cell.getRow());
|
||||
}
|
||||
|
||||
/** Tests that all of the unicode capable string fields can be set, written and then read back
|
||||
*
|
||||
*
|
||||
*/
|
||||
public void testUnicodeInAll() throws Exception {
|
||||
Workbook wb = getTestDataProvider().createWorkbook();
|
||||
CreationHelper factory = wb.getCreationHelper();
|
||||
//Create a unicode dataformat (contains euro symbol)
|
||||
DataFormat df = wb.createDataFormat();
|
||||
final String formatStr = "_([$\u20ac-2]\\\\\\ * #,##0.00_);_([$\u20ac-2]\\\\\\ * \\\\\\(#,##0.00\\\\\\);_([$\u20ac-2]\\\\\\ *\\\"\\-\\\\\"??_);_(@_)";
|
||||
short fmt = df.getFormat(formatStr);
|
||||
|
||||
//Create a unicode sheet name (euro symbol)
|
||||
Sheet s = wb.createSheet("\u20ac");
|
||||
|
||||
//Set a unicode header (you guessed it the euro symbol)
|
||||
Header h = s.getHeader();
|
||||
h.setCenter("\u20ac");
|
||||
h.setLeft("\u20ac");
|
||||
h.setRight("\u20ac");
|
||||
|
||||
//Set a unicode footer
|
||||
Footer f = s.getFooter();
|
||||
f.setCenter("\u20ac");
|
||||
f.setLeft("\u20ac");
|
||||
f.setRight("\u20ac");
|
||||
|
||||
Row r = s.createRow(0);
|
||||
Cell c = r.createCell(1);
|
||||
c.setCellValue(12.34);
|
||||
c.getCellStyle().setDataFormat(fmt);
|
||||
|
||||
Cell c2 = r.createCell(2);
|
||||
c.setCellValue(factory.createRichTextString("\u20ac"));
|
||||
|
||||
Cell c3 = r.createCell(3);
|
||||
String formulaString = "TEXT(12.34,\"\u20ac###,##\")";
|
||||
c3.setCellFormula(formulaString);
|
||||
|
||||
wb = getTestDataProvider().writeOutAndReadBack(wb);
|
||||
|
||||
//Test the sheetname
|
||||
s = wb.getSheet("\u20ac");
|
||||
assertNotNull(s);
|
||||
|
||||
//Test the header
|
||||
h = s.getHeader();
|
||||
assertEquals(h.getCenter(), "\u20ac");
|
||||
assertEquals(h.getLeft(), "\u20ac");
|
||||
assertEquals(h.getRight(), "\u20ac");
|
||||
|
||||
//Test the footer
|
||||
f = s.getFooter();
|
||||
assertEquals(f.getCenter(), "\u20ac");
|
||||
assertEquals(f.getLeft(), "\u20ac");
|
||||
assertEquals(f.getRight(), "\u20ac");
|
||||
|
||||
//Test the dataformat
|
||||
r = s.getRow(0);
|
||||
c = r.getCell(1);
|
||||
df = wb.createDataFormat();
|
||||
assertEquals(formatStr, df.getFormat(c.getCellStyle().getDataFormat()));
|
||||
|
||||
//Test the cell string value
|
||||
c2 = r.getCell(2);
|
||||
assertEquals(c.getRichStringCellValue().getString(), "\u20ac");
|
||||
|
||||
//Test the cell formula
|
||||
c3 = r.getCell(3);
|
||||
assertEquals(c3.getCellFormula(), formulaString);
|
||||
}
|
||||
|
||||
}
|
||||
/* ====================================================================
|
||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
contributor license agreements. See the NOTICE file distributed with
|
||||
this work for additional information regarding copyright ownership.
|
||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
(the "License"); you may not use this file except in compliance with
|
||||
the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==================================================================== */
|
||||
|
||||
package org.apache.poi.ss.usermodel;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.AssertionFailedError;
|
||||
import org.apache.poi.ss.ITestDataProvider;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
|
||||
/**
|
||||
* @author Yegor Kozlov
|
||||
*/
|
||||
public abstract class BaseTestWorkbook extends TestCase {
|
||||
|
||||
protected abstract ITestDataProvider getTestDataProvider();
|
||||
|
||||
public void testCreateSheet() {
|
||||
Workbook wb = getTestDataProvider().createWorkbook();
|
||||
assertEquals(0, wb.getNumberOfSheets());
|
||||
|
||||
//getting a sheet by invalid index or non-existing name
|
||||
assertNull(wb.getSheet("Sheet1"));
|
||||
try {
|
||||
wb.getSheetAt(0);
|
||||
fail("should have thrown exceptiuon due to invalid sheet index");
|
||||
} catch (IllegalArgumentException e) {
|
||||
// expected during successful test
|
||||
}
|
||||
|
||||
Sheet sheet0 = wb.createSheet();
|
||||
Sheet sheet1 = wb.createSheet();
|
||||
assertEquals("Sheet0", sheet0.getSheetName());
|
||||
assertEquals("Sheet1", sheet1.getSheetName());
|
||||
assertEquals(2, wb.getNumberOfSheets());
|
||||
|
||||
//fetching sheets by name is case-insensitive
|
||||
Sheet originalSheet = wb.createSheet("Sheet3");
|
||||
Sheet fetchedSheet = wb.getSheet("sheet3");
|
||||
if (fetchedSheet == null) {
|
||||
throw new AssertionFailedError("Identified bug 44892");
|
||||
}
|
||||
assertEquals("Sheet3", fetchedSheet.getSheetName());
|
||||
assertEquals(3, wb.getNumberOfSheets());
|
||||
assertSame(originalSheet, fetchedSheet);
|
||||
try {
|
||||
wb.createSheet("sHeeT3");
|
||||
fail("should have thrown exceptiuon due to duplicate sheet name");
|
||||
} catch (IllegalArgumentException e) {
|
||||
// expected during successful test
|
||||
assertEquals("The workbook already contains a sheet of this name", e.getMessage());
|
||||
}
|
||||
|
||||
//names cannot be blank or contain any of /\*?[]
|
||||
String[] invalidNames = {"", "Sheet/", "Sheet\\",
|
||||
"Sheet?", "Sheet*", "Sheet[", "Sheet]"};
|
||||
for (String sheetName : invalidNames) {
|
||||
try {
|
||||
wb.createSheet(sheetName);
|
||||
fail("should have thrown exception due to invalid sheet name: " + sheetName);
|
||||
} catch (IllegalArgumentException e) {
|
||||
// expected during successful test
|
||||
}
|
||||
}
|
||||
//still have 3 sheets
|
||||
assertEquals(3, wb.getNumberOfSheets());
|
||||
|
||||
//change the name of the 3rd sheet
|
||||
wb.setSheetName(2, "I changed!");
|
||||
|
||||
//try to assign an invalid name to the 2nd sheet
|
||||
try {
|
||||
wb.setSheetName(1, "[I'm invalid]");
|
||||
fail("should have thrown exceptiuon due to invalid sheet name");
|
||||
} catch (IllegalArgumentException e) {
|
||||
; // expected during successful test
|
||||
}
|
||||
|
||||
//check
|
||||
assertEquals(0, wb.getSheetIndex("sheet0"));
|
||||
assertEquals(1, wb.getSheetIndex("sheet1"));
|
||||
assertEquals(2, wb.getSheetIndex("I changed!"));
|
||||
|
||||
assertSame(sheet0, wb.getSheet("sheet0"));
|
||||
assertSame(sheet1, wb.getSheet("sheet1"));
|
||||
assertSame(originalSheet, wb.getSheet("I changed!"));
|
||||
assertNull(wb.getSheet("unknown"));
|
||||
|
||||
//serialize and read again
|
||||
wb = getTestDataProvider().writeOutAndReadBack(wb);
|
||||
assertEquals(3, wb.getNumberOfSheets());
|
||||
assertEquals(0, wb.getSheetIndex("sheet0"));
|
||||
assertEquals(1, wb.getSheetIndex("sheet1"));
|
||||
assertEquals(2, wb.getSheetIndex("I changed!"));
|
||||
}
|
||||
|
||||
public void testRemoveSheetAt() {
|
||||
Workbook workbook = getTestDataProvider().createWorkbook();
|
||||
workbook.createSheet("sheet1");
|
||||
workbook.createSheet("sheet2");
|
||||
workbook.createSheet("sheet3");
|
||||
assertEquals(3, workbook.getNumberOfSheets());
|
||||
workbook.removeSheetAt(1);
|
||||
assertEquals(2, workbook.getNumberOfSheets());
|
||||
assertEquals("sheet3", workbook.getSheetName(1));
|
||||
workbook.removeSheetAt(0);
|
||||
assertEquals(1, workbook.getNumberOfSheets());
|
||||
assertEquals("sheet3", workbook.getSheetName(0));
|
||||
workbook.removeSheetAt(0);
|
||||
assertEquals(0, workbook.getNumberOfSheets());
|
||||
|
||||
//re-create the sheets
|
||||
workbook.createSheet("sheet1");
|
||||
workbook.createSheet("sheet2");
|
||||
workbook.createSheet("sheet3");
|
||||
assertEquals(3, workbook.getNumberOfSheets());
|
||||
}
|
||||
|
||||
public void testDefaultValues() {
|
||||
Workbook b = getTestDataProvider().createWorkbook();
|
||||
assertEquals(0, b.getActiveSheetIndex());
|
||||
assertEquals(0, b.getFirstVisibleTab());
|
||||
assertEquals(0, b.getNumberOfNames());
|
||||
assertEquals(0, b.getNumberOfSheets());
|
||||
}
|
||||
|
||||
public void testSheetSelection() {
|
||||
Workbook b = getTestDataProvider().createWorkbook();
|
||||
b.createSheet("Sheet One");
|
||||
b.createSheet("Sheet Two");
|
||||
b.setActiveSheet(1);
|
||||
b.setSelectedTab(1);
|
||||
b.setFirstVisibleTab(1);
|
||||
assertEquals(1, b.getActiveSheetIndex());
|
||||
assertEquals(1, b.getFirstVisibleTab());
|
||||
}
|
||||
|
||||
public void testPrintArea() {
|
||||
Workbook workbook = getTestDataProvider().createWorkbook();
|
||||
Sheet sheet1 = workbook.createSheet("Test Print Area");
|
||||
String sheetName1 = sheet1.getSheetName();
|
||||
|
||||
// workbook.setPrintArea(0, reference);
|
||||
workbook.setPrintArea(0, 1, 5, 4, 9);
|
||||
String retrievedPrintArea = workbook.getPrintArea(0);
|
||||
assertEquals("'" + sheetName1 + "'!$B$5:$F$10", retrievedPrintArea);
|
||||
|
||||
String reference = "$A$1:$B$1";
|
||||
workbook.setPrintArea(0, reference);
|
||||
retrievedPrintArea = workbook.getPrintArea(0);
|
||||
assertEquals("'" + sheetName1 + "'!" + reference, retrievedPrintArea);
|
||||
|
||||
workbook.removePrintArea(0);
|
||||
assertNull(workbook.getPrintArea(0));
|
||||
}
|
||||
|
||||
public void testGetSetActiveSheet(){
|
||||
Workbook workbook = getTestDataProvider().createWorkbook();
|
||||
assertEquals(0, workbook.getActiveSheetIndex());
|
||||
|
||||
workbook.createSheet("sheet1");
|
||||
workbook.createSheet("sheet2");
|
||||
workbook.createSheet("sheet3");
|
||||
// set second sheet
|
||||
workbook.setActiveSheet(1);
|
||||
// test if second sheet is set up
|
||||
assertEquals(1, workbook.getActiveSheetIndex());
|
||||
|
||||
workbook.setActiveSheet(0);
|
||||
// test if second sheet is set up
|
||||
assertEquals(0, workbook.getActiveSheetIndex());
|
||||
}
|
||||
|
||||
public void testSetSheetOrder() {
|
||||
Workbook wb = getTestDataProvider().createWorkbook();
|
||||
|
||||
for (int i=0; i < 10; i++) {
|
||||
wb.createSheet("Sheet " + i);
|
||||
}
|
||||
|
||||
// Check the initial order
|
||||
assertEquals(0, wb.getSheetIndex("Sheet 0"));
|
||||
assertEquals(1, wb.getSheetIndex("Sheet 1"));
|
||||
assertEquals(2, wb.getSheetIndex("Sheet 2"));
|
||||
assertEquals(3, wb.getSheetIndex("Sheet 3"));
|
||||
assertEquals(4, wb.getSheetIndex("Sheet 4"));
|
||||
assertEquals(5, wb.getSheetIndex("Sheet 5"));
|
||||
assertEquals(6, wb.getSheetIndex("Sheet 6"));
|
||||
assertEquals(7, wb.getSheetIndex("Sheet 7"));
|
||||
assertEquals(8, wb.getSheetIndex("Sheet 8"));
|
||||
assertEquals(9, wb.getSheetIndex("Sheet 9"));
|
||||
|
||||
// Change
|
||||
wb.setSheetOrder("Sheet 6", 0);
|
||||
wb.setSheetOrder("Sheet 3", 7);
|
||||
wb.setSheetOrder("Sheet 1", 9);
|
||||
|
||||
// Check they're currently right
|
||||
assertEquals(0, wb.getSheetIndex("Sheet 6"));
|
||||
assertEquals(1, wb.getSheetIndex("Sheet 0"));
|
||||
assertEquals(2, wb.getSheetIndex("Sheet 2"));
|
||||
assertEquals(3, wb.getSheetIndex("Sheet 4"));
|
||||
assertEquals(4, wb.getSheetIndex("Sheet 5"));
|
||||
assertEquals(5, wb.getSheetIndex("Sheet 7"));
|
||||
assertEquals(6, wb.getSheetIndex("Sheet 3"));
|
||||
assertEquals(7, wb.getSheetIndex("Sheet 8"));
|
||||
assertEquals(8, wb.getSheetIndex("Sheet 9"));
|
||||
assertEquals(9, wb.getSheetIndex("Sheet 1"));
|
||||
|
||||
Workbook wbr = getTestDataProvider().writeOutAndReadBack(wb);
|
||||
|
||||
assertEquals(0, wbr.getSheetIndex("Sheet 6"));
|
||||
assertEquals(1, wbr.getSheetIndex("Sheet 0"));
|
||||
assertEquals(2, wbr.getSheetIndex("Sheet 2"));
|
||||
assertEquals(3, wbr.getSheetIndex("Sheet 4"));
|
||||
assertEquals(4, wbr.getSheetIndex("Sheet 5"));
|
||||
assertEquals(5, wbr.getSheetIndex("Sheet 7"));
|
||||
assertEquals(6, wbr.getSheetIndex("Sheet 3"));
|
||||
assertEquals(7, wbr.getSheetIndex("Sheet 8"));
|
||||
assertEquals(8, wbr.getSheetIndex("Sheet 9"));
|
||||
assertEquals(9, wbr.getSheetIndex("Sheet 1"));
|
||||
|
||||
// Now get the index by the sheet, not the name
|
||||
for(int i=0; i<10; i++) {
|
||||
Sheet s = wbr.getSheetAt(i);
|
||||
assertEquals(i, wbr.getSheetIndex(s));
|
||||
}
|
||||
}
|
||||
|
||||
public void testCloneSheet() {
|
||||
Workbook book = getTestDataProvider().createWorkbook();
|
||||
Sheet sheet = book.createSheet("TEST");
|
||||
sheet.createRow(0).createCell(0).setCellValue("Test");
|
||||
sheet.createRow(1).createCell(0).setCellValue(36.6);
|
||||
sheet.addMergedRegion(new CellRangeAddress(0, 1, 0, 2));
|
||||
sheet.addMergedRegion(new CellRangeAddress(1, 2, 0, 2));
|
||||
assertTrue(sheet.isSelected());
|
||||
|
||||
Sheet clonedSheet = book.cloneSheet(0);
|
||||
assertEquals("TEST (2)", clonedSheet.getSheetName());
|
||||
assertEquals(2, clonedSheet.getPhysicalNumberOfRows());
|
||||
assertEquals(2, clonedSheet.getNumMergedRegions());
|
||||
assertFalse(clonedSheet.isSelected());
|
||||
|
||||
//cloned sheet is a deep copy, adding rows in the original does not affect the clone
|
||||
sheet.createRow(2).createCell(0).setCellValue(1);
|
||||
sheet.addMergedRegion(new CellRangeAddress(0, 2, 0, 2));
|
||||
assertEquals(2, clonedSheet.getPhysicalNumberOfRows());
|
||||
assertEquals(2, clonedSheet.getPhysicalNumberOfRows());
|
||||
|
||||
clonedSheet.createRow(2).createCell(0).setCellValue(1);
|
||||
clonedSheet.addMergedRegion(new CellRangeAddress(0, 2, 0, 2));
|
||||
assertEquals(3, clonedSheet.getPhysicalNumberOfRows());
|
||||
assertEquals(3, clonedSheet.getPhysicalNumberOfRows());
|
||||
|
||||
}
|
||||
|
||||
public void testParentReferences(){
|
||||
Workbook workbook = getTestDataProvider().createWorkbook();
|
||||
Sheet sheet = workbook.createSheet();
|
||||
assertSame(workbook, sheet.getWorkbook());
|
||||
|
||||
Row row = sheet.createRow(0);
|
||||
assertSame(sheet, row.getSheet());
|
||||
|
||||
Cell cell = row.createCell(1);
|
||||
assertSame(sheet, cell.getSheet());
|
||||
assertSame(row, cell.getRow());
|
||||
|
||||
workbook = getTestDataProvider().writeOutAndReadBack(workbook);
|
||||
sheet = workbook.getSheetAt(0);
|
||||
assertSame(workbook, sheet.getWorkbook());
|
||||
|
||||
row = sheet.getRow(0);
|
||||
assertSame(sheet, row.getSheet());
|
||||
|
||||
cell = row.getCell(1);
|
||||
assertSame(sheet, cell.getSheet());
|
||||
assertSame(row, cell.getRow());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that all of the unicode capable string fields can be set, written and then read back
|
||||
*/
|
||||
public void testUnicodeInAll() {
|
||||
Workbook wb = getTestDataProvider().createWorkbook();
|
||||
CreationHelper factory = wb.getCreationHelper();
|
||||
//Create a unicode dataformat (contains euro symbol)
|
||||
DataFormat df = wb.createDataFormat();
|
||||
final String formatStr = "_([$\u20ac-2]\\\\\\ * #,##0.00_);_([$\u20ac-2]\\\\\\ * \\\\\\(#,##0.00\\\\\\);_([$\u20ac-2]\\\\\\ *\\\"\\-\\\\\"??_);_(@_)";
|
||||
short fmt = df.getFormat(formatStr);
|
||||
|
||||
//Create a unicode sheet name (euro symbol)
|
||||
Sheet s = wb.createSheet("\u20ac");
|
||||
|
||||
//Set a unicode header (you guessed it the euro symbol)
|
||||
Header h = s.getHeader();
|
||||
h.setCenter("\u20ac");
|
||||
h.setLeft("\u20ac");
|
||||
h.setRight("\u20ac");
|
||||
|
||||
//Set a unicode footer
|
||||
Footer f = s.getFooter();
|
||||
f.setCenter("\u20ac");
|
||||
f.setLeft("\u20ac");
|
||||
f.setRight("\u20ac");
|
||||
|
||||
Row r = s.createRow(0);
|
||||
Cell c = r.createCell(1);
|
||||
c.setCellValue(12.34);
|
||||
c.getCellStyle().setDataFormat(fmt);
|
||||
|
||||
Cell c2 = r.createCell(2); // TODO - c2 unused but changing next line ('c'->'c2') causes test to fail
|
||||
c.setCellValue(factory.createRichTextString("\u20ac"));
|
||||
|
||||
Cell c3 = r.createCell(3);
|
||||
String formulaString = "TEXT(12.34,\"\u20ac###,##\")";
|
||||
c3.setCellFormula(formulaString);
|
||||
|
||||
wb = getTestDataProvider().writeOutAndReadBack(wb);
|
||||
|
||||
//Test the sheetname
|
||||
s = wb.getSheet("\u20ac");
|
||||
assertNotNull(s);
|
||||
|
||||
//Test the header
|
||||
h = s.getHeader();
|
||||
assertEquals(h.getCenter(), "\u20ac");
|
||||
assertEquals(h.getLeft(), "\u20ac");
|
||||
assertEquals(h.getRight(), "\u20ac");
|
||||
|
||||
//Test the footer
|
||||
f = s.getFooter();
|
||||
assertEquals(f.getCenter(), "\u20ac");
|
||||
assertEquals(f.getLeft(), "\u20ac");
|
||||
assertEquals(f.getRight(), "\u20ac");
|
||||
|
||||
//Test the dataformat
|
||||
r = s.getRow(0);
|
||||
c = r.getCell(1);
|
||||
df = wb.createDataFormat();
|
||||
assertEquals(formatStr, df.getFormat(c.getCellStyle().getDataFormat()));
|
||||
|
||||
//Test the cell string value
|
||||
c2 = r.getCell(2);
|
||||
assertEquals(c.getRichStringCellValue().getString(), "\u20ac");
|
||||
|
||||
//Test the cell formula
|
||||
c3 = r.getCell(3);
|
||||
assertEquals(c3.getCellFormula(), formulaString);
|
||||
}
|
||||
}
|
||||
|
@ -1,55 +1,55 @@
|
||||
/* ====================================================================
|
||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
contributor license agreements. See the NOTICE file distributed with
|
||||
this work for additional information regarding copyright ownership.
|
||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
(the "License"); you may not use this file except in compliance with
|
||||
the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==================================================================== */
|
||||
|
||||
package org.apache.poi.ss.util;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
|
||||
/**
|
||||
* Tests that the common CellReference works as we need it to
|
||||
*/
|
||||
public class TestRegion extends TestCase {
|
||||
|
||||
public void testGetRegionRef() {
|
||||
int rowFrom = 3;
|
||||
short colFrom = 3;
|
||||
int rowTo = 9;
|
||||
short colTo = 9;
|
||||
Region region = new Region(rowFrom, colFrom, rowTo, colTo);
|
||||
assertEquals("D4:J10", region.getRegionRef());
|
||||
}
|
||||
|
||||
public void testContains() {
|
||||
int rowFrom = 3;
|
||||
short colFrom = 3;
|
||||
int rowTo = 9;
|
||||
short colTo = 9;
|
||||
Region region = new Region(rowFrom, colFrom, rowTo, colTo);
|
||||
assertEquals("D4:J10", region.getRegionRef());
|
||||
assertTrue(region.contains(5, (short) 7));
|
||||
assertTrue(region.contains(9, (short) 9));
|
||||
assertFalse(region.contains(9, (short) 10));
|
||||
}
|
||||
|
||||
public void testConstructors() {
|
||||
Region region_1 = new Region("A1:E7");
|
||||
assertEquals(0, region_1.getColumnFrom());
|
||||
assertEquals((short)4, region_1.getColumnTo());
|
||||
}
|
||||
|
||||
}
|
||||
/* ====================================================================
|
||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
contributor license agreements. See the NOTICE file distributed with
|
||||
this work for additional information regarding copyright ownership.
|
||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
(the "License"); you may not use this file except in compliance with
|
||||
the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==================================================================== */
|
||||
|
||||
package org.apache.poi.ss.util;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
|
||||
/**
|
||||
* Tests that the common CellReference works as we need it to
|
||||
*/
|
||||
@SuppressWarnings("deprecation") // the Region class is deprecated in the public API, but still needs to be tested
|
||||
public final class TestRegion extends TestCase {
|
||||
|
||||
public void testGetRegionRef() {
|
||||
int rowFrom = 3;
|
||||
short colFrom = 3;
|
||||
int rowTo = 9;
|
||||
short colTo = 9;
|
||||
Region region = new Region(rowFrom, colFrom, rowTo, colTo);
|
||||
assertEquals("D4:J10", region.getRegionRef());
|
||||
}
|
||||
|
||||
public void testContains() {
|
||||
int rowFrom = 3;
|
||||
short colFrom = 3;
|
||||
int rowTo = 9;
|
||||
short colTo = 9;
|
||||
Region region = new Region(rowFrom, colFrom, rowTo, colTo);
|
||||
assertEquals("D4:J10", region.getRegionRef());
|
||||
assertTrue(region.contains(5, (short) 7));
|
||||
assertTrue(region.contains(9, (short) 9));
|
||||
assertFalse(region.contains(9, (short) 10));
|
||||
}
|
||||
|
||||
public void testConstructors() {
|
||||
Region region_1 = new Region("A1:E7");
|
||||
assertEquals(0, region_1.getColumnFrom());
|
||||
assertEquals((short)4, region_1.getColumnTo());
|
||||
}
|
||||
}
|
||||
|
@ -1,53 +1,53 @@
|
||||
/* ====================================================================
|
||||
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.util;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Class to test {@link LittleEndianInputStream} and {@link LittleEndianOutputStream}
|
||||
*
|
||||
* @author Josh Micich
|
||||
*/
|
||||
public final class TestLittleEndianStreams extends TestCase {
|
||||
|
||||
public void testRead() {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
LittleEndianOutput leo = new LittleEndianOutputStream(baos);
|
||||
leo.writeInt(12345678);
|
||||
leo.writeShort(12345);
|
||||
leo.writeByte(123);
|
||||
leo.writeShort(40000);
|
||||
leo.writeByte(200);
|
||||
leo.writeLong(1234567890123456789L);
|
||||
leo.writeDouble(123.456);
|
||||
|
||||
LittleEndianInput lei = new LittleEndianInputStream(new ByteArrayInputStream(baos.toByteArray()));
|
||||
|
||||
assertEquals(12345678, lei.readInt());
|
||||
assertEquals(12345, lei.readShort());
|
||||
assertEquals(123, lei.readByte());
|
||||
assertEquals(40000, lei.readUShort());
|
||||
assertEquals(200, lei.readUByte());
|
||||
assertEquals(1234567890123456789L, lei.readLong());
|
||||
assertEquals(123.456, lei.readDouble(), 0.0);
|
||||
}
|
||||
}
|
||||
/* ====================================================================
|
||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
contributor license agreements. See the NOTICE file distributed with
|
||||
this work for additional information regarding copyright ownership.
|
||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
(the "License"); you may not use this file except in compliance with
|
||||
the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==================================================================== */
|
||||
|
||||
package org.apache.poi.util;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Class to test {@link LittleEndianInputStream} and {@link LittleEndianOutputStream}
|
||||
*
|
||||
* @author Josh Micich
|
||||
*/
|
||||
public final class TestLittleEndianStreams extends TestCase {
|
||||
|
||||
public void testRead() {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
LittleEndianOutput leo = new LittleEndianOutputStream(baos);
|
||||
leo.writeInt(12345678);
|
||||
leo.writeShort(12345);
|
||||
leo.writeByte(123);
|
||||
leo.writeShort(40000);
|
||||
leo.writeByte(200);
|
||||
leo.writeLong(1234567890123456789L);
|
||||
leo.writeDouble(123.456);
|
||||
|
||||
LittleEndianInput lei = new LittleEndianInputStream(new ByteArrayInputStream(baos.toByteArray()));
|
||||
|
||||
assertEquals(12345678, lei.readInt());
|
||||
assertEquals(12345, lei.readShort());
|
||||
assertEquals(123, lei.readByte());
|
||||
assertEquals(40000, lei.readUShort());
|
||||
assertEquals(200, lei.readUByte());
|
||||
assertEquals(1234567890123456789L, lei.readLong());
|
||||
assertEquals(123.456, lei.readDouble(), 0.0);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user