TestCStringpublic class TestCString extends TestCase Tests that CString works properly |
Fields Summary |
---|
private byte[] | data_a | private byte[] | data_b |
Methods Summary |
---|
public void | testChange()
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 void | testCount()
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 void | testRecordType()
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 void | testText()
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 void | testWrite()
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]);
}
|
|