You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by jo...@apache.org on 2009/05/18 21:11:47 UTC
svn commit: r776056 [1/4] - in /poi/trunk/src/testcases/org/apache/poi: ddf/
hssf/ hssf/model/ hssf/record/ hssf/record/chart/ hssf/record/formula/eval/
hssf/usermodel/ ss/ ss/formula/ ss/usermodel/ ss/util/ util/
Author: josh
Date: Mon May 18 19:11:45 2009
New Revision: 776056
URL: http://svn.apache.org/viewvc?rev=776056&view=rev
Log:
Changed CRLF to LF in .java test files. Minor reformatting and compiler warning fixes
Modified:
poi/trunk/src/testcases/org/apache/poi/ddf/TestEscherBlipRecord.java
poi/trunk/src/testcases/org/apache/poi/hssf/HSSFITestDataProvider.java
poi/trunk/src/testcases/org/apache/poi/hssf/HSSFTestDataSamples.java
poi/trunk/src/testcases/org/apache/poi/hssf/model/TestRowBlocksReader.java
poi/trunk/src/testcases/org/apache/poi/hssf/record/TestEmbeddedObjectRefSubRecord.java
poi/trunk/src/testcases/org/apache/poi/hssf/record/TestExternalNameRecord.java
poi/trunk/src/testcases/org/apache/poi/hssf/record/TestStyleRecord.java
poi/trunk/src/testcases/org/apache/poi/hssf/record/TestTextObjectRecord.java
poi/trunk/src/testcases/org/apache/poi/hssf/record/TestWriteAccessRecord.java
poi/trunk/src/testcases/org/apache/poi/hssf/record/chart/TestChartFormatRecord.java
poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/eval/TestEqualEval.java
poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFHyperlink.java
poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPatriarch.java
poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPicture.java
poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPictureData.java
poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFTextbox.java
poi/trunk/src/testcases/org/apache/poi/ss/ITestDataProvider.java
poi/trunk/src/testcases/org/apache/poi/ss/TestSpreadsheetVersion.java
poi/trunk/src/testcases/org/apache/poi/ss/formula/FormulaParserTestHelper.java
poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java
poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestFont.java
poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestPicture.java
poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetShiftRows.java
poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java
poi/trunk/src/testcases/org/apache/poi/ss/util/TestRegion.java
poi/trunk/src/testcases/org/apache/poi/util/TestLittleEndianStreams.java
Modified: poi/trunk/src/testcases/org/apache/poi/ddf/TestEscherBlipRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ddf/TestEscherBlipRecord.java?rev=776056&r1=776055&r2=776056&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ddf/TestEscherBlipRecord.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ddf/TestEscherBlipRecord.java Mon May 18 19:11:45 2009
@@ -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;
+ }
+
+}
Modified: poi/trunk/src/testcases/org/apache/poi/hssf/HSSFITestDataProvider.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/HSSFITestDataProvider.java?rev=776056&r1=776055&r2=776056&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/HSSFITestDataProvider.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/HSSFITestDataProvider.java Mon May 18 19:11:45 2009
@@ -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;
- }
-}
\ No newline at end of file
+/* ====================================================================
+ 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;
+ }
+}
Modified: poi/trunk/src/testcases/org/apache/poi/hssf/HSSFTestDataSamples.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/HSSFTestDataSamples.java?rev=776056&r1=776055&r2=776056&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/HSSFTestDataSamples.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/HSSFTestDataSamples.java Mon May 18 19:11:45 2009
@@ -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();
+ }
+}
Modified: poi/trunk/src/testcases/org/apache/poi/hssf/model/TestRowBlocksReader.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/model/TestRowBlocksReader.java?rev=776056&r1=776055&r2=776056&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/model/TestRowBlocksReader.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/model/TestRowBlocksReader.java Mon May 18 19:11:45 2009
@@ -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());
+ }
+}
Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/TestEmbeddedObjectRefSubRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/TestEmbeddedObjectRefSubRecord.java?rev=776056&r1=776055&r2=776056&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/TestEmbeddedObjectRefSubRecord.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/TestEmbeddedObjectRefSubRecord.java Mon May 18 19:11:45 2009
@@ -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);
+ }
+}
Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/TestExternalNameRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/TestExternalNameRecord.java?rev=776056&r1=776055&r2=776056&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/TestExternalNameRecord.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/TestExternalNameRecord.java Mon May 18 19:11:45 2009
@@ -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());
+ }
+}
Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/TestStyleRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/TestStyleRecord.java?rev=776056&r1=776055&r2=776056&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/TestStyleRecord.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/TestStyleRecord.java Mon May 18 19:11:45 2009
@@ -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);
+ }
+}
Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/TestTextObjectRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/TestTextObjectRecord.java?rev=776056&r1=776055&r2=776056&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/TestTextObjectRecord.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/TestTextObjectRecord.java Mon May 18 19:11:45 2009
@@ -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));
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org