FileDocCategorySizeDatePackage
TestComment2000Atom.javaAPI DocApache Poi 3.0.14857Sun Mar 11 12:59:32 GMT 2007org.apache.poi.hslf.record

TestComment2000Atom

public class TestComment2000Atom extends TestCase
Tests that Comment2000Atom works properly.
author
Nick Burch (nick at torchbox dot com)

Fields Summary
private byte[]
data_a
private byte[]
data_b
private SimpleDateFormat
sdf
Constructors Summary
Methods Summary
public voidtestChange()

		Comment2000Atom ca = new Comment2000Atom(data_a, 0, data_a.length);

		// Change the number
		ca.setNumber(5);
		
		// Change the date
		Date new_date = sdf.parse("2006-01-24 21:25:03.725");
		ca.setDate(new_date);
		
		// Change the x and y
		ca.setXOffset(0x0A);
		ca.setYOffset(0x0E);

		// Check bytes are now the same
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		ca.writeOut(baos);
		byte[] b = baos.toByteArray();
		
		// Should now be the same
		assertEquals(data_b.length, b.length);
		for(int i=0; i<data_b.length; i++) {
			assertEquals(data_b[i],b[i]);
		}
	
public voidtestCreate()

    	Comment2000Atom a = new Comment2000Atom();
    	
    	// Set number, x and y
    	a.setNumber(1);
    	a.setXOffset(0x92);
    	a.setYOffset(0x92);
    	
    	// Set the date
		Date date_a = sdf.parse("2006-01-24 10:26:15.205");
		a.setDate(date_a);
		
		// Check it's now the same as a
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		a.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]);
		}
    
public voidtestGetDate()

		Comment2000Atom ca = new Comment2000Atom(data_a, 0, data_a.length);
		Comment2000Atom cb = new Comment2000Atom(data_b, 0, data_b.length);

    	// A is 2006-01-24 (2nd day of week) 10:26:15.205
		Date exp_a = sdf.parse("2006-01-24 10:26:15.205");
		// B is 2006-01-24 (2nd day of week) 21:25:03.725
		Date exp_b = sdf.parse("2006-01-24 21:25:03.725");
		
		assertEquals(exp_a, ca.getDate());
		assertEquals(exp_b, cb.getDate());
    
public voidtestGetNums()

		Comment2000Atom ca = new Comment2000Atom(data_a, 0, data_a.length);
		Comment2000Atom cb = new Comment2000Atom(data_b, 0, data_b.length);

    	// A is number 1
		assertEquals(1, ca.getNumber());
    	// B is number 5
		assertEquals(5, cb.getNumber());
    
public voidtestGetPos()

		Comment2000Atom ca = new Comment2000Atom(data_a, 0, data_a.length);
		Comment2000Atom cb = new Comment2000Atom(data_b, 0, data_b.length);

		// A is at 0x92, 0x92
		assertEquals(0x92, ca.getXOffset());
		assertEquals(0x92, ca.getYOffset());
		
		// B is at 0x0A, 0x0E
		assertEquals(0x0A, cb.getXOffset());
		assertEquals(0x0E, cb.getYOffset());
    
public voidtestRecordType()

	
         
		Comment2000Atom ca = new Comment2000Atom(data_a, 0, data_a.length);
		assertEquals(12001l, ca.getRecordType());
	
public voidtestWrite()

		Comment2000Atom ca = new Comment2000Atom(data_a, 0, data_a.length);
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		ca.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]);
		}