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

TestCString

public class TestCString extends TestCase
Tests that CString works properly
author
Nick Burch (nick at torchbox dot com)

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

		CString ca = new CString(data_a, 0, data_a.length);
		ca.setText("Comments");
		ca.setCount(0x10);
		
		try {
			for(int i=0; i<data_a.length; i++) {
				assertEquals(data_a[i],data_b[i]);
			}
			fail();
		} catch(Error e) {
			// Good, they're not 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 voidtestCount()

		CString ca = new CString(data_a, 0, data_a.length);
		assertEquals(0, ca.getCount());
		CString cb = new CString(data_b, 0, data_a.length);
		assertEquals(0x10, cb.getCount());
		
		ca.setCount(28);
		assertEquals(28, ca.getCount());
	
public voidtestRecordType()

	
         
		CString ca = new CString(data_a, 0, data_a.length);
		assertEquals(4026l, ca.getRecordType());
		CString cb = new CString(data_b, 0, data_a.length);
		assertEquals(4026l, cb.getRecordType());
	
public voidtestText()

		CString ca = new CString(data_a, 0, data_a.length);
		assertEquals("Hogwarts", ca.getText());
		CString cb = new CString(data_b, 0, data_a.length);
		assertEquals("Comments", cb.getText());
		
		ca.setText("FooBar");
		assertEquals("FooBar", ca.getText());
	
public voidtestWrite()

		CString ca = new CString(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]);
		}
		
		CString cb = new CString(data_b, 0, data_a.length);
		ByteArrayOutputStream baosB = new ByteArrayOutputStream();
		cb.writeOut(baosB);
		b = baosB.toByteArray();

		assertEquals(data_b.length, b.length);
		for(int i=0; i<data_b.length; i++) {
			assertEquals(data_b[i],b[i]);
		}