FileDocCategorySizeDatePackage
TestChunks.javaAPI DocApache Poi 3.0.19952Thu Jun 21 22:08:22 BST 2007org.apache.poi.hdgf.chunks

TestChunks

public class TestChunks extends TestCase

Fields Summary
public static final byte[]
data_a
public static final byte[]
data_b
Constructors Summary
Methods Summary
public voidtestAnotherChunk()

		ChunkFactory cf = new ChunkFactory(11);
		
		// Go for the 2nd chunk in the stream
		int offset = 0;
		Chunk chunk = cf.createChunk(data_b, offset);
		offset += chunk.getOnDiskSize();
		chunk = cf.createChunk(data_b, offset);
		
		assertNotNull(chunk.getHeader());
		assertNotNull(chunk.getTrailer());
		assertNotNull(chunk.getSeparator());
		
		// Should be 19 + length + 8 + 4 big
		assertEquals(32, chunk.getHeader().getLength());
		assertEquals(32+19+8+4, chunk.getOnDiskSize());
		
		// Type is 104, or 0x68
		assertEquals(104, chunk.getHeader().getType());
		assertEquals(0x68, chunk.getHeader().getType());
		
		// Should have two virtual chunk commands, a
		//  10 (Unknown) and an 18
		assertEquals(2, chunk.commandDefinitions.length);
		assertEquals(0, chunk.getCommands().length);
		
		assertEquals(10, chunk.commandDefinitions[0].getType());
		assertEquals(0, chunk.commandDefinitions[0].getOffset());
		assertEquals("Unknown 0x68", chunk.commandDefinitions[0].getName());
		
		assertEquals(18, chunk.commandDefinitions[1].getType());
		assertEquals(0, chunk.commandDefinitions[1].getOffset());
		assertEquals("0", chunk.commandDefinitions[1].getName());
	
public voidtestChunkHeaderA()


	     
		ChunkFactory cf = new ChunkFactory(11);
		ChunkHeader h = 
			ChunkHeader.createChunkHeader(11, data_a, 0);
		
		assertTrue(h instanceof ChunkHeaderV11);
		ChunkHeaderV11 header = (ChunkHeaderV11)h;
		
		assertEquals(70, header.getType());
		assertEquals(-1, header.getId());
		assertEquals(2, header.getUnknown1());
		assertEquals(68, header.getLength());
		assertEquals(0, header.getUnknown2());
		assertEquals(0, header.getUnknown3());
		
		assertTrue(header.hasTrailer());
		assertTrue(header.hasSeparator());
	
public voidtestChunkHeaderB()

		ChunkFactory cf = new ChunkFactory(11);
		ChunkHeader h = 
			ChunkHeader.createChunkHeader(11, data_b, 0);
		
		assertTrue(h instanceof ChunkHeaderV11);
		ChunkHeaderV11 header = (ChunkHeaderV11)h;
		
		assertEquals(70, header.getType());
		assertEquals(-1, header.getId());
		assertEquals(3, header.getUnknown1());
		assertEquals(68, header.getLength());
		assertEquals(0, header.getUnknown2());
		assertEquals(0, header.getUnknown3());
		
		assertTrue(header.hasTrailer());
		assertTrue(header.hasSeparator());
	
public voidtestManyChunks()

		ChunkFactory cf = new ChunkFactory(11);
		Chunk chunk;
		int offset = 0;
		
		chunk = cf.createChunk(data_a, offset);
		assertNotNull(chunk.getHeader());
		assertNotNull(chunk.getTrailer());
		assertNotNull(chunk.getSeparator());
		offset += chunk.getOnDiskSize();
		
		chunk = cf.createChunk(data_a, offset);
		assertNotNull(chunk.getHeader());
		assertNotNull(chunk.getTrailer());
		assertNotNull(chunk.getSeparator());
		offset += chunk.getOnDiskSize();
		
		// Has a separator but no trailer
		chunk = cf.createChunk(data_a, offset);
		assertNotNull(chunk.getHeader());
		assertNull(chunk.getTrailer());
		assertNotNull(chunk.getSeparator());
		offset += chunk.getOnDiskSize();
		
		chunk = cf.createChunk(data_a, offset);
		assertNotNull(chunk.getHeader());
		assertNull(chunk.getTrailer());
		assertNotNull(chunk.getSeparator());
		offset += chunk.getOnDiskSize();
		
		chunk = cf.createChunk(data_a, offset);
		assertNotNull(chunk.getHeader());
		assertNull(chunk.getTrailer());
		assertNotNull(chunk.getSeparator());
		offset += chunk.getOnDiskSize();
	
public voidtestOneChunk()

		ChunkFactory cf = new ChunkFactory(11);
		cf.createChunk(data_a, 0);
		cf.createChunk(data_b, 0);
		
		Chunk chunk = cf.createChunk(data_a, 0);
		assertNotNull(chunk.getHeader());
		assertNotNull(chunk.getTrailer());
		assertNotNull(chunk.getSeparator());
		
		// Should be 19 + length + 8 + 4 big
		assertEquals(68, chunk.getHeader().getLength());
		assertEquals(68+19+8+4, chunk.getOnDiskSize());
		
		// Type is 70, or 0x46
		assertEquals(70, chunk.getHeader().getType());
		assertEquals(0x46, chunk.getHeader().getType());
		
		// Should have two virtual chunk commands, a
		//  10 (page sheet) and an 18
		assertEquals(2, chunk.commandDefinitions.length);
		assertEquals(0, chunk.getCommands().length);
		
		assertEquals(10, chunk.commandDefinitions[0].getType());
		assertEquals(0, chunk.commandDefinitions[0].getOffset());
		assertEquals("PageSheet", chunk.commandDefinitions[0].getName());
		
		assertEquals(18, chunk.commandDefinitions[1].getType());
		assertEquals(0, chunk.commandDefinitions[1].getOffset());
		assertEquals("0", chunk.commandDefinitions[1].getName());