mirror of https://github.com/apache/poi.git
Add tests for more classes
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@353712 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
04c2060ed8
commit
ca46ef0721
|
@ -0,0 +1,93 @@
|
|||
|
||||
/* ====================================================================
|
||||
Copyright 2002-2004 Apache Software Foundation
|
||||
|
||||
Licensed 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.hslf.extractor;
|
||||
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
* Tests that the QuickButCruddyTextExtractor works correctly
|
||||
*
|
||||
* @author Nick Burch (nick at torchbox dot com)
|
||||
*/
|
||||
public class TestCruddyExtractor extends TestCase {
|
||||
// Extractor primed on the test data
|
||||
private QuickButCruddyTextExtractor te;
|
||||
// All the text to be found in the file
|
||||
String[] allTheText = new String[] {
|
||||
"This is a test title",
|
||||
"This is a test subtitle\nThis is on page 1",
|
||||
"Click to edit Master title style",
|
||||
"Click to edit Master text styles\nSecond level\nThird level\nFourth level\nFifth level",
|
||||
"*",
|
||||
"*",
|
||||
"*",
|
||||
"*",
|
||||
"*",
|
||||
"Click to edit Master text styles\nSecond level\nThird level\nFourth level\nFifth level",
|
||||
"*",
|
||||
"*",
|
||||
"These are the notes for page 1",
|
||||
"This is a test title",
|
||||
"This is a test subtitle\nThis is on page 1",
|
||||
"This is the title on page 2",
|
||||
"This is page two\nIt has several blocks of text\nNone of them have formattingT",
|
||||
"These are the notes on page two, again lacking formatting",
|
||||
"This is a test title",
|
||||
"This is a test subtitle\nThis is on page 1",
|
||||
"This is the title on page 2",
|
||||
"This is page two\nIt has several blocks of text\nNone of them have formatting",
|
||||
};
|
||||
|
||||
public TestCruddyExtractor() throws Exception {
|
||||
String dirname = System.getProperty("HSLF.testdata.path");
|
||||
String filename = dirname + "/basic_test_ppt_file.ppt";
|
||||
te = new QuickButCruddyTextExtractor(filename);
|
||||
}
|
||||
|
||||
public void testReadAsVector() throws Exception {
|
||||
// Extract the text from the file as a vector
|
||||
Vector foundTextV = te.getTextAsVector();
|
||||
|
||||
// Ensure they match
|
||||
assertEquals(allTheText.length,foundTextV.size());
|
||||
for(int i=0; i<allTheText.length; i++) {
|
||||
String foundText = (String)foundTextV.get(i);
|
||||
assertEquals(allTheText[i],foundText);
|
||||
}
|
||||
}
|
||||
|
||||
public void testReadAsString() throws Exception {
|
||||
// Extract the text as a String
|
||||
String foundText = te.getTextAsString();
|
||||
|
||||
// Turn the string array into a single string
|
||||
StringBuffer expectTextSB = new StringBuffer();
|
||||
for(int i=0; i<allTheText.length; i++) {
|
||||
expectTextSB.append(allTheText[i]);
|
||||
expectTextSB.append('\n');
|
||||
}
|
||||
String expectText = expectTextSB.toString();
|
||||
|
||||
// Ensure they match
|
||||
assertEquals(expectText,foundText);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
|
||||
/* ====================================================================
|
||||
Copyright 2002-2004 Apache Software Foundation
|
||||
|
||||
Licensed 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.hslf.record;
|
||||
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
||||
/**
|
||||
* Tests that NotesAtom works properly
|
||||
*
|
||||
* @author Nick Burch (nick at torchbox dot com)
|
||||
*/
|
||||
public class TestNotesAtom extends TestCase {
|
||||
// From a real file
|
||||
private byte[] data_a = new byte[] { 1, 0, 0xF1-256, 3, 8, 0, 0, 0,
|
||||
0, 0, 0, 0x80-256, 0, 0, 0x0D, 0x30 };
|
||||
|
||||
public void testRecordType() throws Exception {
|
||||
NotesAtom na = new NotesAtom(data_a, 0, data_a.length);
|
||||
assertEquals(1009l, na.getRecordType());
|
||||
}
|
||||
public void testFlags() throws Exception {
|
||||
NotesAtom na = new NotesAtom(data_a, 0, data_a.length);
|
||||
assertEquals(0x80000000, na.getSlideID());
|
||||
assertEquals(false, na.getFollowMasterObjects());
|
||||
assertEquals(false, na.getFollowMasterScheme());
|
||||
assertEquals(false, na.getFollowMasterBackground());
|
||||
}
|
||||
|
||||
public void testWrite() throws Exception {
|
||||
NotesAtom na = new NotesAtom(data_a, 0, data_a.length);
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
na.writeOut(baos);
|
||||
byte[] b = baos.toByteArray();
|
||||
|
||||
assertEquals(data_a.length, b.length);
|
||||
for(int i=0; i<data_a.length; i++) {
|
||||
assertEquals(data_a[i],b[i]);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
|
||||
/* ====================================================================
|
||||
Copyright 2002-2004 Apache Software Foundation
|
||||
|
||||
Licensed 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.hslf.record;
|
||||
|
||||
import org.apache.poi.hslf.record.SlideAtom.*;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
||||
/**
|
||||
* Tests that SlideAtom works properly
|
||||
*
|
||||
* @author Nick Burch (nick at torchbox dot com)
|
||||
*/
|
||||
public class TestSlideAtom extends TestCase {
|
||||
// From a real file
|
||||
private byte[] data_a = new byte[] { 1, 0, 0xEF-256, 3, 0x18, 0, 0, 0,
|
||||
0, 0, 0, 0, 0x0F, 0x10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x80-256,
|
||||
0, 1, 0, 0, 7, 0, 0x0C, 0x30 };
|
||||
|
||||
public void testRecordType() throws Exception {
|
||||
SlideAtom sa = new SlideAtom(data_a, 0, data_a.length);
|
||||
assertEquals(1007l, sa.getRecordType());
|
||||
}
|
||||
public void testFlags() throws Exception {
|
||||
SlideAtom sa = new SlideAtom(data_a, 0, data_a.length);
|
||||
|
||||
// First 12 bytes are a SSlideLayoutAtom, checked elsewhere
|
||||
|
||||
// Check the IDs
|
||||
assertEquals(0x80000000, sa.getMasterID());
|
||||
assertEquals(256, sa.getNotesID());
|
||||
|
||||
// Check the flags
|
||||
assertEquals(true, sa.getFollowMasterObjects());
|
||||
assertEquals(true, sa.getFollowMasterScheme());
|
||||
assertEquals(true, sa.getFollowMasterBackground());
|
||||
}
|
||||
public void testSSlideLayoutAtom() throws Exception {
|
||||
SlideAtom sa = new SlideAtom(data_a, 0, data_a.length);
|
||||
SSlideLayoutAtom ssla = sa.getSSlideLayoutAtom();
|
||||
|
||||
assertEquals(0, ssla.getGeometryType());
|
||||
|
||||
// Should also check the placehold IDs at some point
|
||||
}
|
||||
|
||||
public void testWrite() throws Exception {
|
||||
SlideAtom sa = new SlideAtom(data_a, 0, data_a.length);
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
sa.writeOut(baos);
|
||||
byte[] b = baos.toByteArray();
|
||||
|
||||
assertEquals(data_a.length, b.length);
|
||||
for(int i=0; i<data_a.length; i++) {
|
||||
assertEquals(data_a[i],b[i]);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
|
||||
/* ====================================================================
|
||||
Copyright 2002-2004 Apache Software Foundation
|
||||
|
||||
Licensed 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.hslf.record;
|
||||
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
||||
/**
|
||||
* Tests that UserEditAtom works properly
|
||||
*
|
||||
* @author Nick Burch (nick at torchbox dot com)
|
||||
*/
|
||||
public class TestUserEditAtom extends TestCase {
|
||||
// From a real file
|
||||
private byte[] data_a = new byte[] { 0, 0, 0xF5-256, 0x0F, 0x1C, 0, 0, 0,
|
||||
00, 01, 00, 00, 0xD9-256, 18, 00, 03,
|
||||
00, 00, 00, 00, 00, 0x18, 00, 00, 01, 00, 00, 00,
|
||||
05, 00, 00, 00, 01, 00, 0xF6-256, 77 };
|
||||
|
||||
public void testRecordType() throws Exception {
|
||||
UserEditAtom uea = new UserEditAtom(data_a, 0, data_a.length);
|
||||
assertEquals(4085l, uea.getRecordType());
|
||||
}
|
||||
public void testFlags() throws Exception {
|
||||
UserEditAtom uea = new UserEditAtom(data_a, 0, data_a.length);
|
||||
|
||||
assertEquals(256, uea.getLastViewedSlideID() );
|
||||
//assertEquals(0x030018D9, uea.getPPTVersion() );
|
||||
assertEquals(0, uea.getLastUserEditAtomOffset() );
|
||||
assertEquals(0x1800, uea.getPersistPointersOffset() );
|
||||
assertEquals(1, uea.getDocPersistRef() );
|
||||
assertEquals(5, uea.getMaxPersistWritten() );
|
||||
assertEquals((short)1, uea.getLastViewType() );
|
||||
}
|
||||
|
||||
public void testWrite() throws Exception {
|
||||
UserEditAtom uea = new UserEditAtom(data_a, 0, data_a.length);
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
uea.writeOut(baos);
|
||||
byte[] b = baos.toByteArray();
|
||||
|
||||
assertEquals(data_a.length, b.length);
|
||||
for(int i=0; i<data_a.length; i++) {
|
||||
assertEquals(data_a[i],b[i]);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue