Moved existing JUnit tests to junittest/ in preparation for ScalaTest

This commit is contained in:
str4d
2012-07-30 04:04:07 +00:00
parent d27d0bd2e4
commit 48df91f796
101 changed files with 1 additions and 1 deletions

View File

@@ -0,0 +1,28 @@
package net.i2p.data;
/*
* free (adj.): unencumbered; not under the control of others
* Written by jrandom in 2003 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*
*/
import junit.framework.TestCase;
public class Base64Test extends TestCase{
public void testBase64(){
String orig = "you smell";
String encoded = Base64.encode(orig.getBytes());
byte decoded[] = Base64.decode(encoded);
String transformed = new String(decoded);
assertTrue(orig.equals(transformed));
byte all[] = new byte[256];
for (int i = 0; i < all.length; i++)
all[i] = (byte) (0xFF & i);
encoded = Base64.encode(all);
decoded = Base64.decode(encoded);
assertTrue(DataHelper.eq(decoded, all));
}
}

View File

@@ -0,0 +1,40 @@
package net.i2p.data;
/*
* free (adj.): unencumbered; not under the control of others
* Written by jrandom in 2003 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*
*/
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import junit.framework.TestCase;
/**
* Test harness for the boolean structure
*
* @author jrandom
*/
public class BooleanTest extends TestCase{
public void testBoolean() throws Exception{
byte[] temp = null;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataHelper.writeBoolean(baos, Boolean.TRUE);
temp = baos.toByteArray();
Boolean b = null;
ByteArrayInputStream bais = new ByteArrayInputStream(temp);
b = DataHelper.readBoolean(bais);
assertEquals(Boolean.TRUE, b);
}
}

View File

@@ -0,0 +1,28 @@
package net.i2p.data;
/*
* free (adj.): unencumbered; not under the control of others
* Written by jrandom in 2003 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*
*/
/**
* Test harness for loading / storing Hash objects
*
* @author jrandom
*/
public class CertificateTest extends StructureTest {
public DataStructure createDataStructure() throws DataFormatException {
Certificate cert = new Certificate();
byte data[] = new byte[32];
for (int i = 0; i < data.length; i++)
data[i] = (byte)(i%16);
cert.setPayload(data);
cert.setCertificateType(Certificate.CERTIFICATE_TYPE_NULL);
return cert;
}
public DataStructure createStructureToRead() { return new Certificate(); }
}

View File

@@ -0,0 +1,133 @@
package net.i2p.data;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
import junit.framework.TestCase;
import net.i2p.I2PAppContext;
/**
* basic unit tests for the DataHelper
*
*/
public class DataHelperTest extends TestCase{
private I2PAppContext _context;
protected void setUp() {
_context = I2PAppContext.getGlobalContext();
}
/**
* Test to/from/read/writeLong with every 1, 2, and 4 byte value, as
* well as some 8 byte values.
*/
public void testLong() throws Exception{
for (int i = 0; i <= 0xFF; i+=4)
checkLong(1, i);
for (long i = 0; i <= 0xFFFF; i+=16)
checkLong(2, i);
for (long i = 0; i <= 0xFFFFFF; i +=128)
checkLong(3, i);
for (long i = 0; i <= 0xFFFFFFFFl; i+=512)
checkLong(4, i);
// i know, doesnt test (2^63)-(2^64-1)
for (long i = Long.MAX_VALUE - 0xFFFFFFl; i < Long.MAX_VALUE; i++)
checkLong(8, i);
}
private static void checkLong(int numBytes, long value) throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream(numBytes);
DataHelper.writeLong(baos, numBytes, value);
byte written[] = baos.toByteArray();
byte extract[] = DataHelper.toLong(numBytes, value);
assertTrue(extract.length == numBytes);
assertTrue(DataHelper.eq(written, extract));
byte extract2[] = new byte[numBytes];
DataHelper.toLong(extract2, 0, numBytes, value);
assertTrue(DataHelper.eq(extract, extract2));
long read = DataHelper.fromLong(extract, 0, numBytes);
assertTrue(read == value);
ByteArrayInputStream bais = new ByteArrayInputStream(written);
read = DataHelper.readLong(bais, numBytes);
assertTrue(read == value);
read = DataHelper.fromLong(written, 0, numBytes);
assertTrue(read == value);
}
public void testDate() throws Exception{
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
cal.set(Calendar.YEAR, 1970);
cal.set(Calendar.MONTH, 0);
cal.set(Calendar.DAY_OF_MONTH, 1);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
checkDate(cal.getTime());
cal.set(Calendar.SECOND, 1);
checkDate(cal.getTime());
cal.set(Calendar.YEAR, 1999);
cal.set(Calendar.MONTH, 11);
cal.set(Calendar.DAY_OF_MONTH, 31);
cal.set(Calendar.HOUR_OF_DAY, 23);
cal.set(Calendar.MINUTE, 59);
cal.set(Calendar.SECOND, 59);
checkDate(cal.getTime());
cal.set(Calendar.YEAR, 2000);
cal.set(Calendar.MONTH, 0);
cal.set(Calendar.DAY_OF_MONTH, 1);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
checkDate(cal.getTime());
cal.setTimeInMillis(System.currentTimeMillis());
checkDate(cal.getTime());
cal.set(Calendar.SECOND, cal.get(Calendar.SECOND)+10);
checkDate(cal.getTime());
cal.set(Calendar.YEAR, 1969);
cal.set(Calendar.MONTH, 11);
cal.set(Calendar.DAY_OF_MONTH, 31);
cal.set(Calendar.HOUR_OF_DAY, 23);
cal.set(Calendar.MINUTE, 59);
cal.set(Calendar.SECOND, 59);
boolean error = false;
try{
checkDate(cal.getTime());
}catch(Exception e){
error = true;
}
assertTrue(error);
}
private void checkDate(Date when) throws Exception{
byte buf[] = new byte[DataHelper.DATE_LENGTH];
DataHelper.toDate(buf, 0, when.getTime());
byte tbuf[] = DataHelper.toDate(when);
assertTrue(DataHelper.eq(tbuf, buf));
Date time = DataHelper.fromDate(buf, 0);
assertEquals(when.getTime(), time.getTime());
}
public void testCompress() throws Exception{
for (int size = 0; size < 32*1024; size+=32){ // Original had size++, changed value because
// speed was a problem. -Comwiz
byte data[] = new byte[size];
_context.random().nextBytes(data);
byte compressed[] = DataHelper.compress(data);
byte decompressed[] = DataHelper.decompress(compressed);
assertTrue(DataHelper.eq(data, decompressed));
}
}
}

View File

@@ -0,0 +1,72 @@
package net.i2p.data;
/*
* free (adj.): unencumbered; not under the control of others
* Written by jrandom in 2003 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*
*/
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import junit.framework.TestCase;
/**
* @author Comwiz
*/
public class DataStructureImplTest extends TestCase{
DataStructure _struct;
protected void setUp(){
_struct = new DataStructureImpl(){
private int x = 0;
public void writeBytes(OutputStream out) throws IOException, DataFormatException{
if(x++==0)
throw new DataFormatException("let it enfold you", new Exception());
else
throw new IOException();
}
public void readBytes(InputStream in) throws IOException{
throw new IOException();
}
};
}
public void testNulls() throws Exception{
assertNull(_struct.toBase64());
boolean error = false;
try{
_struct.fromBase64(null);
}catch(DataFormatException dfe){
error = true;
}
assertTrue(error);
assertNull(_struct.calculateHash());
error = false;
try{
_struct.fromByteArray(null);
}catch(DataFormatException dfe){
error = true;
}
assertTrue(error);
}
public void testErrors() throws Exception{
boolean error = false;
try{
_struct.fromByteArray("water is poison".getBytes());
}catch(DataFormatException dfe){
error = true;
}
assertTrue(error);
assertNull(_struct.toByteArray());
assertNull(_struct.toByteArray());
}
}

View File

@@ -0,0 +1,39 @@
package net.i2p.data;
import junit.framework.Test;
import junit.framework.TestSuite;
public class DataTestSuite {
public static Test suite() {
TestSuite suite = new TestSuite("net.i2p.data.DataTestSuite");
suite.addTestSuite(Base64Test.class);
suite.addTestSuite(BooleanTest.class);
suite.addTestSuite(CertificateTest.class);
suite.addTestSuite(DataHelperTest.class);
suite.addTestSuite(DataStructureImplTest.class);
suite.addTestSuite(DateTest.class);
suite.addTestSuite(DestinationTest.class);
suite.addTestSuite(HashTest.class);
suite.addTestSuite(LeaseSetTest.class);
suite.addTestSuite(LeaseTest.class);
suite.addTestSuite(MappingTest.class);
suite.addTestSuite(PayloadTest.class);
suite.addTestSuite(PrivateKeyTest.class);
suite.addTestSuite(PublicKeyTest.class);
suite.addTestSuite(RouterAddressTest.class);
suite.addTestSuite(RouterIdentityTest.class);
suite.addTestSuite(RouterInfoTest.class);
suite.addTestSuite(SessionKeyTest.class);
suite.addTestSuite(SignatureTest.class);
suite.addTestSuite(SigningPrivateKeyTest.class);
suite.addTestSuite(SigningPublicKeyTest.class);
suite.addTestSuite(StringTest.class);
suite.addTestSuite(TunnelIdTest.class);
suite.addTestSuite(UnsignedIntegerTest.class);
return suite;
}
}

View File

@@ -0,0 +1,42 @@
package net.i2p.data;
/*
* free (adj.): unencumbered; not under the control of others
* Written by jrandom in 2003 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*
*/
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.Date;
import junit.framework.TestCase;
/**
* Test harness for the date structure
*
* @author jrandom
*/
public class DateTest extends TestCase{
public void testDate() throws Exception{
byte[] temp = null;
Date orig = new Date();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataHelper.writeDate(baos, orig);
temp = baos.toByteArray();
Date d = null;
ByteArrayInputStream bais = new ByteArrayInputStream(temp);
d = DataHelper.readDate(bais);
assertEquals(orig, d);
}
}

View File

@@ -0,0 +1,29 @@
package net.i2p.data;
/*
* free (adj.): unencumbered; not under the control of others
* Written by jrandom in 2003 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*
*/
/**
* Test harness for loading / storing Hash objects
*
* @author jrandom
*/
public class DestinationTest extends StructureTest {
public DataStructure createDataStructure() throws DataFormatException {
Destination dest = new Destination();
StructureTest tst = new CertificateTest();
dest.setCertificate((Certificate)tst.createDataStructure());
tst = new PublicKeyTest();
dest.setPublicKey((PublicKey)tst.createDataStructure());
tst = new SigningPublicKeyTest();
dest.setSigningPublicKey((SigningPublicKey)tst.createDataStructure());
return dest;
}
public DataStructure createStructureToRead() { return new Destination(); }
}

View File

@@ -0,0 +1,27 @@
package net.i2p.data;
/*
* free (adj.): unencumbered; not under the control of others
* Written by jrandom in 2003 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*
*/
/**
* Test harness for loading / storing Hash objects
*
* @author jrandom
*/
public class HashTest extends StructureTest {
public DataStructure createDataStructure() throws DataFormatException {
Hash hash = new Hash();
byte data[] = new byte[32];
for (int i = 0; i < data.length; i++)
data[i] = (byte)(i%16);
hash.setData(data);
return hash;
}
public DataStructure createStructureToRead() { return new Hash(); }
}

View File

@@ -0,0 +1,74 @@
package net.i2p.data;
/*
* free (adj.): unencumbered; not under the control of others
* Written by jrandom in 2003 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*
*/
/**
* Test harness for loading / storing Lease objects
*
* @author jrandom
*/
public class LeaseSetTest extends StructureTest {
public DataStructure createDataStructure() throws DataFormatException {
LeaseSet leaseSet = new LeaseSet();
leaseSet.setDestination((Destination)(new DestinationTest()).createDataStructure());
leaseSet.setEncryptionKey((PublicKey)(new PublicKeyTest()).createDataStructure());
leaseSet.setSignature((Signature)(new SignatureTest()).createDataStructure());
leaseSet.setSigningKey((SigningPublicKey)(new SigningPublicKeyTest()).createDataStructure());
//leaseSet.setVersion(42l);
return leaseSet;
}
public DataStructure createStructureToRead() { return new LeaseSet(); }
public void testGetLeaseInvalid() {
// create test subject
LeaseSet subj = new LeaseSet();
// should contain no leases now..
try {
assertNull(subj.getLease(0));
} catch(RuntimeException exc) {
// all good
}
// this shouldn't work either
try {
assertNull(subj.getLease(-1));
} catch(RuntimeException exc) {
// all good
}
}
public void testAddLeaseNull() {
// create test subject
LeaseSet subj = new LeaseSet();
// now add an null lease
try {
subj.addLease(null);
fail("Failed at failing.");
} catch(IllegalArgumentException exc) {
// all good
}
}
public void testAddLeaseInvalid() {
// create test subject
LeaseSet subj = new LeaseSet();
// try to add completely invalid lease(ie. no data)
try {
subj.addLease(new Lease());
fail("Failed at failing.");
} catch(IllegalArgumentException exc) {
// all good
}
}
}

View File

@@ -0,0 +1,97 @@
package net.i2p.data;
/*
* free (adj.): unencumbered; not under the control of others
* Written by jrandom in 2003 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*
*/
import java.io.ByteArrayOutputStream;
import java.util.Date;
/**
* Test harness for loading / storing Lease objects
*
* @author jrandom
*/
public class LeaseTest extends StructureTest {
public DataStructure createDataStructure() throws DataFormatException {
Lease lease = new Lease();
lease.setEndDate(new Date(1000*60*2));
byte h[] = new byte[Hash.HASH_LENGTH];
lease.setGateway(new Hash(h));
StructureTest tst = new TunnelIdTest();
lease.setTunnelId((TunnelId)tst.createDataStructure());
return lease;
}
public DataStructure createStructureToRead() { return new Lease(); }
/* TODO: Delete this if Lease.getNumSuccess() / getNumFailure() get deleted
public void testNumSuccessFail() throws Exception{
Lease lease = new Lease();
lease.setEndDate(new Date(1000*60*2));
byte h[] = new byte[Hash.HASH_LENGTH];
lease.setGateway(new Hash(h));
StructureTest tst = new TunnelIdTest();
lease.setTunnelId((TunnelId)tst.createDataStructure());
lease.getNumSuccess();
lease.getNumFailure();
}
*/
public void testExpiration() throws Exception{
Lease lease = new Lease();
assertTrue(lease.isExpired());
lease.setEndDate(new Date(1000*60*2));
byte h[] = new byte[Hash.HASH_LENGTH];
lease.setGateway(new Hash(h));
StructureTest tst = new TunnelIdTest();
lease.setTunnelId((TunnelId)tst.createDataStructure());
assertTrue(lease.isExpired());
}
public void testNullWrite() throws Exception{
Lease lease = new Lease();
lease.setEndDate(new Date(1000*60*2));
byte h[] = new byte[Hash.HASH_LENGTH];
lease.setGateway(new Hash(h));
lease.setTunnelId(null);
boolean error = false;
try{
lease.writeBytes(new ByteArrayOutputStream());
}catch(DataFormatException dfe){
error = true;
}
assertTrue(error);
lease = new Lease();
lease.setEndDate(new Date(1000*60*2));
h = new byte[Hash.HASH_LENGTH];
lease.setGateway(null);
StructureTest tst = new TunnelIdTest();
lease.setTunnelId((TunnelId)tst.createDataStructure());
error = false;
try{
lease.writeBytes(new ByteArrayOutputStream());
}catch(DataFormatException dfe){
error = true;
}
assertTrue(error);
}
public void testNullEquals() throws Exception{
Lease lease = new Lease();
lease.setEndDate(new Date(1000*60*2));
byte h[] = new byte[Hash.HASH_LENGTH];
lease.setGateway(new Hash(h));
lease.setTunnelId(null);
assertFalse(lease.equals(null));
}
}

View File

@@ -0,0 +1,45 @@
package net.i2p.data;
/*
* free (adj.): unencumbered; not under the control of others
* Written by jrandom in 2003 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*
*/
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.Properties;
import junit.framework.TestCase;
/**
* Test harness for the date structure
*
* @author jrandom
*/
public class MappingTest extends TestCase{
public void testProperties() throws Exception{
byte[] temp = null;
Properties orig = new Properties();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
orig.setProperty("key1", "val1");
orig.setProperty("key2", "val2");
orig.setProperty("key3", "val3");
DataHelper.writeProperties(baos, orig);
temp = baos.toByteArray();
Properties p = null;
ByteArrayInputStream bais = new ByteArrayInputStream(temp);
p = DataHelper.readProperties(bais);
assertEquals(orig, p);
}
}

View File

@@ -0,0 +1,60 @@
package net.i2p.data;
/*
* free (adj.): unencumbered; not under the control of others
* Written by jrandom in 2003 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*
*/
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
/**
* Test harness for loading / storing Payload objects
*
* @author jrandom
*/
public class PayloadTest extends StructureTest{
public DataStructure createDataStructure() throws DataFormatException {
Payload payload = new Payload();
SessionKey key = (SessionKey)(new SessionKeyTest()).createDataStructure();
byte data[] = "Hello, I2P".getBytes();
payload.setUnencryptedData(data);
Hash hash = (Hash)(new HashTest()).createDataStructure();
Destination target = (Destination)(new DestinationTest()).createDataStructure();
payload.setEncryptedData(data);
return payload;
}
public DataStructure createStructureToRead() { return new Payload(); }
public void testStructure() throws Exception{
byte[] temp = null;
DataStructure orig;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
orig = createDataStructure();
orig.writeBytes(baos);
temp = baos.toByteArray();
DataStructure ds;
ByteArrayInputStream bais = new ByteArrayInputStream(temp);
ds = createStructureToRead();
ds.readBytes(bais);
Payload payload = (Payload)ds;
payload.setUnencryptedData(payload.getEncryptedData());
assertEquals(orig, ds);
}
}

View File

@@ -0,0 +1,94 @@
package net.i2p.data;
/*
* free (adj.): unencumbered; not under the control of others
* Written by jrandom in 2003 and released into the Private domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*
*/
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
/**
* Test harness for loading / storing PrivateKey objects
*
* @author jrandom
*/
public class PrivateKeyTest extends StructureTest {
public DataStructure createDataStructure() throws DataFormatException {
PrivateKey privateKey = new PrivateKey();
byte data[] = new byte[PrivateKey.KEYSIZE_BYTES];
for (int i = 0; i < data.length; i++)
data[i] = (byte)(i%16);
privateKey.setData(data);
return privateKey;
}
public DataStructure createStructureToRead() { return new PrivateKey(); }
public void testBase64Constructor() throws Exception{
PrivateKey privateKey = new PrivateKey();
byte data[] = new byte[PrivateKey.KEYSIZE_BYTES];
for (int i = 0; i < data.length; i++)
data[i] = (byte)(i%56);
privateKey.setData(data);
PrivateKey key2 = new PrivateKey(privateKey.toBase64());
assertEquals(privateKey, key2);
}
public void testNullEquals(){
PrivateKey privateKey = new PrivateKey();
byte data[] = new byte[PrivateKey.KEYSIZE_BYTES];
for (int i = 0; i < data.length; i++)
data[i] = (byte)(i%56);
privateKey.setData(data);
assertFalse(privateKey.equals(null));
}
public void testNullData() throws Exception{
PrivateKey privateKey = new PrivateKey();
privateKey.toString();
boolean error = false;
try{
privateKey.writeBytes(new ByteArrayOutputStream());
}catch(DataFormatException dfe){
error = true;
}
assertTrue(error);
}
public void testShortData() throws Exception{
PrivateKey privateKey = new PrivateKey();
byte data[] = new byte[56];
for (int i = 0; i < data.length; i++)
data[i] = (byte)(i);
boolean error = false;
try{
privateKey.setData(data);
privateKey.writeBytes(new ByteArrayOutputStream());
}catch(DataFormatException dfe){
error = true;
}catch(IllegalArgumentException exc) {
error = true;
}
assertTrue(error);
}
public void testShortRead() throws Exception{
PrivateKey privateKey = new PrivateKey();
ByteArrayInputStream in = new ByteArrayInputStream("six times nine equals forty-two".getBytes());
boolean error = false;
try{
privateKey.readBytes(in);
}catch(DataFormatException dfe){
error = true;
}
assertTrue(error);
}
}

View File

@@ -0,0 +1,93 @@
package net.i2p.data;
/*
* free (adj.): unencumbered; not under the control of others
* Written by jrandom in 2003 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*
*/
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
/**
* Test harness for loading / storing PublicKey objects
*
* @author jrandom
*/
public class PublicKeyTest extends StructureTest {
public DataStructure createDataStructure() throws DataFormatException {
PublicKey publicKey = new PublicKey();
byte data[] = new byte[PublicKey.KEYSIZE_BYTES];
for (int i = 0; i < data.length; i++)
data[i] = (byte)(i%16);
publicKey.setData(data);
return publicKey;
}
public DataStructure createStructureToRead() { return new PublicKey(); }
public void testBase64Constructor() throws Exception{
PublicKey publicKey = new PublicKey();
byte data[] = new byte[PublicKey.KEYSIZE_BYTES];
for (int i = 0; i < data.length; i++)
data[i] = (byte)(i%56);
publicKey.setData(data);
PublicKey key2 = new PublicKey(publicKey.toBase64());
assertEquals(publicKey, key2);
}
public void testNullEquals(){
PublicKey publicKey = new PublicKey();
byte data[] = new byte[PublicKey.KEYSIZE_BYTES];
for (int i = 0; i < data.length; i++)
data[i] = (byte)(i%56);
publicKey.setData(data);
assertFalse(publicKey.equals(null));
}
public void testNullData() throws Exception{
PublicKey publicKey = new PublicKey();
publicKey.toString();
boolean error = false;
try{
publicKey.writeBytes(new ByteArrayOutputStream());
}catch(DataFormatException dfe){
error = true;
}
assertTrue(error);
}
public void testShortData() throws Exception{
PublicKey publicKey = new PublicKey();
byte data[] = new byte[56];
for (int i = 0; i < data.length; i++)
data[i] = (byte)(i);
boolean error = false;
try{
publicKey.setData(data);
publicKey.writeBytes(new ByteArrayOutputStream());
}catch(DataFormatException dfe){
error = true;
}catch(IllegalArgumentException exc) {
error = true;
}
assertTrue(error);
}
public void testShortRead() throws Exception{
PublicKey publicKey = new PublicKey();
ByteArrayInputStream in = new ByteArrayInputStream("six times nine equals forty-two".getBytes());
boolean error = false;
try{
publicKey.readBytes(in);
}catch(DataFormatException dfe){
error = true;
}
assertTrue(error);
}
}

View File

@@ -0,0 +1,106 @@
package net.i2p.data;
/*
* free (adj.): unencumbered; not under the control of others
* Written by jrandom in 2003 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*
*/
import java.io.ByteArrayOutputStream;
import java.util.Date;
import java.util.Properties;
/**
* Test harness for loading / storing Hash objects
*
* @author jrandom
*/
public class RouterAddressTest extends StructureTest {
public DataStructure createDataStructure() throws DataFormatException {
RouterAddress addr = new RouterAddress();
byte data[] = new byte[32];
for (int i = 0; i < data.length; i++)
data[i] = (byte)(i%16);
addr.setCost(42);
addr.setExpiration(new Date(1000*60*60*24)); // jan 2 1970
Properties options = new Properties();
options.setProperty("hostname", "localhost");
options.setProperty("portnum", "1234");
addr.setOptions(options);
addr.setTransportStyle("Blah");
return addr;
}
public DataStructure createStructureToRead() { return new RouterAddress(); }
public void testSetNullOptions(){
RouterAddress addr = new RouterAddress();
boolean error = false;
try{
addr.setOptions(null);
}catch(NullPointerException dfe){
error = true;
}
assertTrue(error);
}
public void testSetOptionsAgain(){
RouterAddress addr = new RouterAddress();
Properties options = new Properties();
options.setProperty("hostname", "localhost");
options.setProperty("portnum", "1234");
addr.setOptions(options);
options.setProperty("portnum", "2345");
boolean error = false;
try{
addr.setOptions(options);
}catch(IllegalStateException dfe){
error = true;
}
assertTrue(error);
}
public void testBadWrite() throws Exception{
RouterAddress addr = new RouterAddress();
boolean error = false;
try{
addr.writeBytes(new ByteArrayOutputStream());
}catch(DataFormatException dfe){
error = true;
}
assertTrue(error);
}
public void testNullEquals(){
RouterAddress addr = new RouterAddress();
byte data[] = new byte[32];
for (int i = 0; i < data.length; i++)
data[i] = (byte)(i%16);
addr.setCost(42);
addr.setExpiration(new Date(1000*60*60*24)); // jan 2 1970
Properties options = new Properties();
options.setProperty("hostname", "localhost");
options.setProperty("portnum", "1234");
addr.setOptions(options);
addr.setTransportStyle("Blah");
assertFalse(addr.equals(null));
assertFalse(addr.equals(""));
}
public void testToString(){
RouterAddress addr = new RouterAddress();
byte data[] = new byte[32];
for (int i = 0; i < data.length; i++)
data[i] = (byte)(i%16);
addr.setCost(42);
addr.setExpiration(new Date(1000*60*60*24)); // jan 2 1970
Properties options = new Properties();
options.setProperty("hostname", "localhost");
options.setProperty("portnum", "1234");
addr.setOptions(options);
addr.setTransportStyle("Blah");
String ret = addr.toString();
assertEquals("[RouterAddress: \n\tTransportStyle: Blah\n\tCost: 42\n\tExpiration: Fri Jan 02 00:00:00 UTC 1970\n\tOptions: #: 2\n\t\t[hostname] = [localhost]\n\t\t[portnum] = [1234]]", ret);
}
}

View File

@@ -0,0 +1,110 @@
package net.i2p.data;
/*
* free (adj.): unencumbered; not under the control of others
* Written by jrandom in 2003 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*
*/
import java.io.ByteArrayOutputStream;
/**
* Test harness for loading / storing Hash objects
*
* @author jrandom
*/
public class RouterIdentityTest extends StructureTest {
public DataStructure createDataStructure() throws DataFormatException {
RouterIdentity ident = new RouterIdentity();
Certificate cert = (Certificate)(new CertificateTest()).createDataStructure();
ident.setCertificate(cert);
PublicKey pk = (PublicKey)(new PublicKeyTest()).createDataStructure();
ident.setPublicKey(pk);
SigningPublicKey k = (SigningPublicKey)(new SigningPublicKeyTest()).createDataStructure();
ident.setSigningPublicKey(k);
return ident;
}
public DataStructure createStructureToRead() { return new RouterIdentity(); }
public void testNullCert() throws Exception{
RouterIdentity ident = new RouterIdentity();
ident.setCertificate(null);
PublicKey pk = (PublicKey)(new PublicKeyTest()).createDataStructure();
ident.setPublicKey(pk);
SigningPublicKey k = (SigningPublicKey)(new SigningPublicKeyTest()).createDataStructure();
ident.setSigningPublicKey(k);
boolean error = false;
try{
ident.writeBytes(new ByteArrayOutputStream());
}catch(DataFormatException dfe){
error = true;
}
assertTrue(error);
}
public void testNullPublicKey() throws Exception{
RouterIdentity ident = new RouterIdentity();
Certificate cert = (Certificate)(new CertificateTest()).createDataStructure();
ident.setCertificate(cert);
ident.setPublicKey(null);
SigningPublicKey k = (SigningPublicKey)(new SigningPublicKeyTest()).createDataStructure();
ident.setSigningPublicKey(k);
boolean error = false;
try{
ident.writeBytes(new ByteArrayOutputStream());
}catch(DataFormatException dfe){
error = true;
}
assertTrue(error);
}
public void testNullSigningKey() throws Exception{
RouterIdentity ident = new RouterIdentity();
Certificate cert = (Certificate)(new CertificateTest()).createDataStructure();
ident.setCertificate(cert);
PublicKey pk = (PublicKey)(new PublicKeyTest()).createDataStructure();
ident.setPublicKey(pk);
ident.setSigningPublicKey(null);
boolean error = false;
try{
ident.writeBytes(new ByteArrayOutputStream());
}catch(DataFormatException dfe){
error = true;
}
assertTrue(error);
}
public void testNullEquals() throws Exception{
RouterIdentity ident = new RouterIdentity();
assertFalse(ident.equals(null));
}
public void testCalculatedHash() throws Exception{
RouterIdentity ident = new RouterIdentity();
Certificate cert = (Certificate)(new CertificateTest()).createDataStructure();
ident.setCertificate(cert);
PublicKey pk = (PublicKey)(new PublicKeyTest()).createDataStructure();
ident.setPublicKey(pk);
SigningPublicKey k = (SigningPublicKey)(new SigningPublicKeyTest()).createDataStructure();
ident.setSigningPublicKey(k);
ident.calculateHash();
ident.calculateHash();
ident.calculateHash();
ident.calculateHash();
ident.calculateHash();
}
public void testBadHash() throws Exception{
RouterIdentity ident = new RouterIdentity();
ident.getHash();
}
}

View File

@@ -0,0 +1,73 @@
package net.i2p.data;
/*
* free (adj.): unencumbered; not under the control of others
* Written by jrandom in 2003 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*
*/
import java.util.HashSet;
import java.util.Properties;
import net.i2p.crypto.KeyGenerator;
import net.i2p.util.Log;
/**
* Test harness for loading / storing Hash objects
*
* @author jrandom
*/
public class RouterInfoTest extends StructureTest {
private final static Log _log = new Log(RouterInfoTest.class);
public DataStructure createDataStructure() throws DataFormatException {
RouterInfo info = new RouterInfo();
HashSet addresses = new HashSet();
DataStructure structure = (new RouterAddressTest()).createDataStructure();
addresses.add(structure);
info.setAddresses(addresses);
PublicKey pubKey = null;
SigningPublicKey signingPubKey = null;
PrivateKey privKey = null;
SigningPrivateKey signingPrivKey = null;
Object obj[] = KeyGenerator.getInstance().generatePKIKeypair();
pubKey = (PublicKey)obj[0];
privKey = (PrivateKey)obj[1];
obj = KeyGenerator.getInstance().generateSigningKeypair();
signingPubKey = (SigningPublicKey)obj[0];
signingPrivKey = (SigningPrivateKey)obj[1];
_log.debug("SigningPublicKey: " + signingPubKey);
_log.debug("SigningPrivateKey: " + signingPrivKey);
RouterIdentity ident = new RouterIdentity();
ident.setCertificate(new Certificate(Certificate.CERTIFICATE_TYPE_NULL, null));
ident.setPublicKey(pubKey);
ident.setSigningPublicKey(signingPubKey);
info.setIdentity(ident);
Properties options = new Properties();
for (int i = 0; i < 16; i++) {
options.setProperty("option." + i, "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890$:." + i);
}
options.setProperty("netConnectionSpeed", "OC12");
info.setOptions(options);
HashSet peers = new HashSet();
structure = (new HashTest()).createDataStructure();
peers.add(structure);
info.setPeers(peers);
info.setPublished(System.currentTimeMillis());
//info.setVersion(69);
info.sign(signingPrivKey);
return info;
}
public DataStructure createStructureToRead() { return new RouterInfo(); }
}

View File

@@ -0,0 +1,27 @@
package net.i2p.data;
/*
* free (adj.): unencumbered; not under the control of others
* Written by jrandom in 2003 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*
*/
/**
* Test harness for loading / storing SessionKey objects
*
* @author jrandom
*/
public class SessionKeyTest extends StructureTest {
public DataStructure createDataStructure() throws DataFormatException {
SessionKey key = new SessionKey();
byte data[] = new byte[SessionKey.KEYSIZE_BYTES];
for (int i = 0; i < data.length; i++)
data[i] = (byte)(i%16);
key.setData(data);
return key;
}
public DataStructure createStructureToRead() { return new SessionKey(); }
}

View File

@@ -0,0 +1,27 @@
package net.i2p.data;
/*
* free (adj.): unencumbered; not under the control of others
* Written by jrandom in 2003 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*
*/
/**
* Test harness for loading / storing Signature objects
*
* @author jrandom
*/
public class SignatureTest extends StructureTest {
public DataStructure createDataStructure() throws DataFormatException {
Signature sig = new Signature();
byte data[] = new byte[Signature.SIGNATURE_BYTES];
for (int i = 0; i < data.length; i++)
data[i] = (byte)(i%16);
sig.setData(data);
return sig;
}
public DataStructure createStructureToRead() { return new Signature(); }
}

View File

@@ -0,0 +1,95 @@
package net.i2p.data;
/*
* free (adj.): unencumbered; not under the control of others
* Written by jrandom in 2003 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*
*/
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
/**
* Test harness for loading / storing SigningPrivateKey objects
*
* @author jrandom
*/
public class SigningPrivateKeyTest extends StructureTest {
public DataStructure createDataStructure() throws DataFormatException {
SigningPrivateKey signingPrivateKey = new SigningPrivateKey();
byte data[] = new byte[SigningPrivateKey.KEYSIZE_BYTES];
for (int i = 0; i < data.length; i++)
data[i] = (byte)(i%16);
signingPrivateKey.setData(data);
return signingPrivateKey;
}
public DataStructure createStructureToRead() { return new SigningPrivateKey(); }
public void testBase64Constructor() throws Exception{
SigningPrivateKey signingPrivateKey = new SigningPrivateKey();
byte data[] = new byte[SigningPrivateKey.KEYSIZE_BYTES];
for (int i = 0; i < data.length; i++)
data[i] = (byte)(i%56);
signingPrivateKey.setData(data);
SigningPrivateKey key2 = new SigningPrivateKey(signingPrivateKey.toBase64());
assertEquals(signingPrivateKey, key2);
}
public void testNullEquals(){
SigningPrivateKey signingPrivateKey = new SigningPrivateKey();
byte data[] = new byte[SigningPrivateKey.KEYSIZE_BYTES];
for (int i = 0; i < data.length; i++)
data[i] = (byte)(i%56);
signingPrivateKey.setData(data);
assertFalse(signingPrivateKey.equals(null));
}
public void testNullData() throws Exception{
SigningPrivateKey signingPrivateKey = new SigningPrivateKey();
signingPrivateKey.toString();
boolean error = false;
try{
signingPrivateKey.writeBytes(new ByteArrayOutputStream());
}catch(DataFormatException dfe){
error = true;
}
assertTrue(error);
}
public void testShortData() throws Exception{
SigningPrivateKey signingPrivateKey = new SigningPrivateKey();
byte data[] = new byte[56];
for (int i = 0; i < data.length; i++)
data[i] = (byte)(i);
boolean error = false;
try{
signingPrivateKey.setData(data);
signingPrivateKey.writeBytes(new ByteArrayOutputStream());
}catch(DataFormatException dfe){
error = true;
}catch(IllegalArgumentException exc) {
error = true;
}
assertTrue(error);
}
public void testShortRead() throws Exception{
SigningPrivateKey signingPrivateKey = new SigningPrivateKey();
ByteArrayInputStream in = new ByteArrayInputStream("short".getBytes());
boolean error = false;
try{
signingPrivateKey.readBytes(in);
}catch(DataFormatException dfe){
error = true;
}
assertTrue(error);
}
}

View File

@@ -0,0 +1,95 @@
package net.i2p.data;
/*
* free (adj.): unencumbered; not under the control of others
* Written by jrandom in 2003 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*
*/
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
/**
* Test harness for loading / storing PublicKey objects
*
* @author jrandom
*/
public class SigningPublicKeyTest extends StructureTest {
public DataStructure createDataStructure() throws DataFormatException {
SigningPublicKey publicKey = new SigningPublicKey();
byte data[] = new byte[SigningPublicKey.KEYSIZE_BYTES];
for (int i = 0; i < data.length; i++)
data[i] = (byte)(i%16);
publicKey.setData(data);
return publicKey;
}
public DataStructure createStructureToRead() { return new SigningPublicKey(); }
public void testBase64Constructor() throws Exception{
SigningPublicKey publicKey = new SigningPublicKey();
byte data[] = new byte[SigningPublicKey.KEYSIZE_BYTES];
for (int i = 0; i < data.length; i++)
data[i] = (byte)(i%56);
publicKey.setData(data);
SigningPublicKey key2 = new SigningPublicKey(publicKey.toBase64());
assertEquals(publicKey, key2);
}
public void testNullEquals(){
SigningPublicKey publicKey = new SigningPublicKey();
byte data[] = new byte[SigningPublicKey.KEYSIZE_BYTES];
for (int i = 0; i < data.length; i++)
data[i] = (byte)(i%56);
publicKey.setData(data);
assertFalse(publicKey.equals(null));
}
public void testNullData() throws Exception{
SigningPublicKey publicKey = new SigningPublicKey();
publicKey.toString();
boolean error = false;
try{
publicKey.writeBytes(new ByteArrayOutputStream());
}catch(DataFormatException dfe){
error = true;
}
assertTrue(error);
}
public void testShortData() throws Exception{
SigningPublicKey publicKey = new SigningPublicKey();
byte data[] = new byte[56];
for (int i = 0; i < data.length; i++)
data[i] = (byte)(i);
boolean error = false;
try{
publicKey.setData(data);
publicKey.writeBytes(new ByteArrayOutputStream());
}catch(DataFormatException dfe){
error = true;
}catch(IllegalArgumentException exc) {
error = true;
}
assertTrue(error);
}
public void testShortRead() throws Exception{
SigningPublicKey publicKey = new SigningPublicKey();
ByteArrayInputStream in = new ByteArrayInputStream("six times nine equals forty-two".getBytes());
boolean error = false;
try{
publicKey.readBytes(in);
}catch(DataFormatException dfe){
error = true;
}
assertTrue(error);
}
}

View File

@@ -0,0 +1,96 @@
package net.i2p.data;
/*
* free (adj.): unencumbered; not under the control of others
* Written by jrandom in 2003 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*
*/
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import junit.framework.TestCase;
/**
* Test harness for the simple data structure
*
* @author welterde
*/
public class SimpleDataStructureTest extends TestCase {
public void testSetDataImmutable() throws Exception {
// create new test subject
TestStruct struct = new TestStruct();
// try to set null object.. should not fail..
struct.setData(null);
// set data to something
struct.setData(new byte[3]);
// now setting it to null should fail
try {
struct.setData(null);
fail("Should not have allowed us to change this..");
} catch(RuntimeException exc) {
// all good
}
// setting it to something non-null should fail as well.
try {
struct.setData(new byte[3]);
fail("Should not have allowed us to change this..");
} catch(RuntimeException exc) {
// all good
}
}
public void testReadBytesImmutable() throws Exception {
// create new test subject
TestStruct struct = new TestStruct();
// load some data using setData
struct.setData(new byte[3]);
// now try to load via readBytes
try {
struct.readBytes(null);
fail("blah blah blah..");
} catch(RuntimeException exc) {
// all good
}
}
public void testToBase64Safe() throws Exception {
// create new test subject
TestStruct struct = new TestStruct();
// now try to get the Base64.. should not throw an exception, but should not be an empty string either
assertNull(struct.toBase64());
}
public void testCalculateHashSafe() throws Exception {
// create new test subject
TestStruct struct = new TestStruct();
// now try to get the hash.. should not throw an exception
assertNull(struct.calculateHash());
}
public void testHashCodeSafe() throws Exception {
// create new test subject
TestStruct struct = new TestStruct();
// just make sure it doesn't explode in our face
struct.hashCode();
}
public class TestStruct extends SimpleDataStructure {
public int length() {
return 3;
}
}
}

View File

@@ -0,0 +1,40 @@
package net.i2p.data;
/*
* free (adj.): unencumbered; not under the control of others
* Written by jrandom in 2003 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*
*/
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import junit.framework.TestCase;
/**
* Test harness for the date structure
*
* @author jrandom
*/
public class StringTest extends TestCase{
public void testString() throws Exception{
byte[] temp = null;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataHelper.writeString(baos, "Hello, I2P");
temp = baos.toByteArray();
String s = null;
ByteArrayInputStream bais = new ByteArrayInputStream(temp);
s = DataHelper.readString(bais);
assertEquals(s, "Hello, I2P");
}
}

View File

@@ -0,0 +1,48 @@
package net.i2p.data;
/*
* free (adj.): unencumbered; not under the control of others
* Written by jrandom in 2003 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*
*/
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import junit.framework.TestCase;
/**
* Utility class for wrapping data structure tests
*
* @author jrandom
*/
public abstract class StructureTest extends TestCase{
public abstract DataStructure createDataStructure() throws DataFormatException;
public abstract DataStructure createStructureToRead();
public void testStructure() throws Exception{
byte[] temp = null;
DataStructure orig;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
orig = createDataStructure();
orig.writeBytes(baos);
temp = baos.toByteArray();
DataStructure ds;
ByteArrayInputStream bais = new ByteArrayInputStream(temp);
ds = createStructureToRead();
ds.readBytes(bais);
assertEquals(orig, ds);
}
}

View File

@@ -0,0 +1,24 @@
package net.i2p.data;
/*
* free (adj.): unencumbered; not under the control of others
* Written by jrandom in 2003 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*
*/
/**
* Test harness for loading / storing TunnelId objects
*
* @author jrandom
*/
public class TunnelIdTest extends StructureTest {
public DataStructure createDataStructure() throws DataFormatException {
TunnelId id = new TunnelId();
id.setTunnelId(42);
return id;
}
public DataStructure createStructureToRead() { return new TunnelId(); }
}

View File

@@ -0,0 +1,39 @@
package net.i2p.data;
/*
* free (adj.): unencumbered; not under the control of others
* Written by jrandom in 2003 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*
*/
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import junit.framework.TestCase;
/**
* Test harness for the date structure
*
* @author jrandom
*/
public class UnsignedIntegerTest extends TestCase{
public void testLong() throws Exception{
byte[] temp = null;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataHelper.writeLong(baos, 4, 42);
temp = baos.toByteArray();
long l;
ByteArrayInputStream bais = new ByteArrayInputStream(temp);
l = DataHelper.readLong(bais, 4);
assertEquals(42, l);
}
}

View File

@@ -0,0 +1,27 @@
package net.i2p.data.i2cp;
/*
* free (adj.): unencumbered; not under the control of others
* Written by jrandom in 2003 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*
*/
import net.i2p.data.StructureTest;
import net.i2p.data.DataStructure;
import net.i2p.data.DataFormatException;
/**
* Test harness for loading / storing Hash objects
*
* @author jrandom
*/
public class AbuseReasonTest extends StructureTest {
public DataStructure createDataStructure() throws DataFormatException {
AbuseReason res = new AbuseReason();
res.setReason("Because they're mean");
return res;
}
public DataStructure createStructureToRead() { return new AbuseReason(); }
}

View File

@@ -0,0 +1,27 @@
package net.i2p.data.i2cp;
/*
* free (adj.): unencumbered; not under the control of others
* Written by jrandom in 2003 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*
*/
import net.i2p.data.StructureTest;
import net.i2p.data.DataStructure;
import net.i2p.data.DataFormatException;
/**
* Test harness for loading / storing Hash objects
*
* @author jrandom
*/
public class AbuseSeverityTest extends StructureTest {
public DataStructure createDataStructure() throws DataFormatException {
AbuseSeverity sev = new AbuseSeverity();
sev.setSeverity(64);
return sev;
}
public DataStructure createStructureToRead() { return new AbuseSeverity(); }
}

View File

@@ -0,0 +1,26 @@
package net.i2p.data.i2cp;
/*
* free (adj.): unencumbered; not under the control of others
* Written by str4d in 2012 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*
*/
import net.i2p.data.StructureTest;
import net.i2p.data.DataStructure;
import net.i2p.data.DataFormatException;
/**
* Test harness for loading / storing BandwidthLimitsMessage objects
*
* @author str4d
*/
public class BandwidthLimitsMessageTest extends StructureTest {
public DataStructure createDataStructure() throws DataFormatException {
BandwidthLimitsMessage msg = new BandwidthLimitsMessage(10240, 1024);
return msg;
}
public DataStructure createStructureToRead() { return new BandwidthLimitsMessage(); }
}

View File

@@ -0,0 +1,36 @@
package net.i2p.data.i2cp;
/*
* free (adj.): unencumbered; not under the control of others
* Written by jrandom in 2003 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*
*/
import net.i2p.data.StructureTest;
import net.i2p.data.DataStructure;
import net.i2p.data.DataFormatException;
import net.i2p.data.PrivateKey;
import net.i2p.data.PrivateKeyTest;
import net.i2p.data.SigningPrivateKey;
import net.i2p.data.SigningPrivateKeyTest;
import net.i2p.data.LeaseSet;
import net.i2p.data.LeaseSetTest;
/**
* Test harness for loading / storing CreateLeaseSetMessage objects
*
* @author jrandom
*/
public class CreateLeaseSetMessageTest extends StructureTest {
public DataStructure createDataStructure() throws DataFormatException {
CreateLeaseSetMessage msg = new CreateLeaseSetMessage();
msg.setPrivateKey((PrivateKey)(new PrivateKeyTest()).createDataStructure());
msg.setSigningPrivateKey((SigningPrivateKey)(new SigningPrivateKeyTest()).createDataStructure());
msg.setLeaseSet((LeaseSet)(new LeaseSetTest()).createDataStructure());
msg.setSessionId((SessionId)(new SessionIdTest()).createDataStructure());
return msg;
}
public DataStructure createStructureToRead() { return new CreateLeaseSetMessage(); }
}

View File

@@ -0,0 +1,27 @@
package net.i2p.data.i2cp;
/*
* free (adj.): unencumbered; not under the control of others
* Written by jrandom in 2003 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*
*/
import net.i2p.data.StructureTest;
import net.i2p.data.DataStructure;
import net.i2p.data.DataFormatException;
/**
* Test harness for loading / storing Hash objects
*
* @author jrandom
*/
public class CreateSessionMessageTest extends StructureTest {
public DataStructure createDataStructure() throws DataFormatException {
CreateSessionMessage msg = new CreateSessionMessage();
msg.setSessionConfig((SessionConfig)(new SessionConfigTest()).createDataStructure());
return msg;
}
public DataStructure createStructureToRead() { return new CreateSessionMessage(); }
}

View File

@@ -0,0 +1,26 @@
package net.i2p.data.i2cp;
/*
* free (adj.): unencumbered; not under the control of others
* Written by str4d in 2012 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*
*/
import net.i2p.data.StructureTest;
import net.i2p.data.DataStructure;
import net.i2p.data.DataFormatException;
/**
* Test harness for loading / storing DestLookupMessage objects
*
* @author str4d
*/
public class DestLookupMessageTest extends StructureTest {
public DataStructure createDataStructure() throws DataFormatException {
DestLookupMessage msg = new DestLookupMessage();
return msg;
}
public DataStructure createStructureToRead() { return new DestLookupMessage(); }
}

View File

@@ -0,0 +1,26 @@
package net.i2p.data.i2cp;
/*
* free (adj.): unencumbered; not under the control of others
* Written by str4d in 2012 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*
*/
import net.i2p.data.StructureTest;
import net.i2p.data.DataStructure;
import net.i2p.data.DataFormatException;
/**
* Test harness for loading / storing DestReplyMessage objects
*
* @author str4d
*/
public class DestReplyMessageTest extends StructureTest {
public DataStructure createDataStructure() throws DataFormatException {
DestReplyMessage msg = new DestReplyMessage();
return msg;
}
public DataStructure createStructureToRead() { return new DestReplyMessage(); }
}

View File

@@ -0,0 +1,27 @@
package net.i2p.data.i2cp;
/*
* free (adj.): unencumbered; not under the control of others
* Written by jrandom in 2003 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*
*/
import net.i2p.data.StructureTest;
import net.i2p.data.DataStructure;
import net.i2p.data.DataFormatException;
/**
* Test harness for loading / storing Hash objects
*
* @author jrandom
*/
public class DestroySessionMessageTest extends StructureTest {
public DataStructure createDataStructure() throws DataFormatException {
DestroySessionMessage msg = new DestroySessionMessage();
msg.setSessionId((SessionId)(new SessionIdTest()).createDataStructure());
return msg;
}
public DataStructure createStructureToRead() { return new DestroySessionMessage(); }
}

View File

@@ -0,0 +1,27 @@
package net.i2p.data.i2cp;
/*
* free (adj.): unencumbered; not under the control of others
* Written by jrandom in 2003 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*
*/
import net.i2p.data.StructureTest;
import net.i2p.data.DataStructure;
import net.i2p.data.DataFormatException;
/**
* Test harness for loading / storing Hash objects
*
* @author jrandom
*/
public class DisconnectMessageTest extends StructureTest {
public DataStructure createDataStructure() throws DataFormatException {
DisconnectMessage msg = new DisconnectMessage();
msg.setReason("Because I say so");
return msg;
}
public DataStructure createStructureToRead() { return new DisconnectMessage(); }
}

View File

@@ -0,0 +1,26 @@
package net.i2p.data.i2cp;
/*
* free (adj.): unencumbered; not under the control of others
* Written by str4d in 2012 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*
*/
import net.i2p.data.StructureTest;
import net.i2p.data.DataStructure;
import net.i2p.data.DataFormatException;
/**
* Test harness for loading / storing GetBandwidthLimitsMessage objects
*
* @author str4d
*/
public class GetBandwidthLimitsMessageTest extends StructureTest {
public DataStructure createDataStructure() throws DataFormatException {
GetBandwidthLimitsMessage msg = new GetBandwidthLimitsMessage();
return msg;
}
public DataStructure createStructureToRead() { return new GetBandwidthLimitsMessage(); }
}

View File

@@ -0,0 +1,26 @@
package net.i2p.data.i2cp;
/*
* free (adj.): unencumbered; not under the control of others
* Written by str4d in 2012 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*
*/
import net.i2p.data.StructureTest;
import net.i2p.data.DataStructure;
import net.i2p.data.DataFormatException;
/**
* Test harness for loading / storing GetDateMessage objects
*
* @author str4d
*/
public class GetDateMessageTest extends StructureTest {
public DataStructure createDataStructure() throws DataFormatException {
GetDateMessage msg = new GetDateMessage("0.8.13-0");
return msg;
}
public DataStructure createStructureToRead() { return new GetDateMessage(); }
}

View File

@@ -0,0 +1,40 @@
package net.i2p.data.i2cp;
import junit.framework.Test;
import junit.framework.TestSuite;
public class I2CPTestSuite {
public static Test suite() {
TestSuite suite = new TestSuite("net.i2p.data.i2cp.I2CPTestSuite");
suite.addTestSuite(AbuseReasonTest.class);
suite.addTestSuite(AbuseSeverityTest.class);
suite.addTestSuite(BandwidthLimitsMessageTest.class);
suite.addTestSuite(CreateLeaseSetMessageTest.class);
suite.addTestSuite(CreateSessionMessageTest.class);
suite.addTestSuite(DestLookupMessageTest.class);
suite.addTestSuite(DestReplyMessageTest.class);
suite.addTestSuite(DestroySessionMessageTest.class);
suite.addTestSuite(DisconnectMessageTest.class);
suite.addTestSuite(GetBandwidthLimitsMessageTest.class);
suite.addTestSuite(GetDateMessageTest.class);
suite.addTestSuite(MessageIdTest.class);
suite.addTestSuite(MessagePayloadMessageTest.class);
suite.addTestSuite(MessageStatusMessageTest.class);
suite.addTestSuite(ReceiveMessageBeginMessageTest.class);
suite.addTestSuite(ReceiveMessageEndMessageTest.class);
suite.addTestSuite(ReconfigureSessionMessageTest.class);
suite.addTestSuite(ReportAbuseMessageTest.class);
suite.addTestSuite(RequestLeaseSetMessageTest.class);
suite.addTestSuite(SendMessageExpiresMessageTest.class);
suite.addTestSuite(SendMessageMessageTest.class);
suite.addTestSuite(SessionConfigTest.class);
suite.addTestSuite(SessionIdTest.class);
suite.addTestSuite(SessionStatusMessageTest.class);
suite.addTestSuite(SetDateMessageTest.class);
return suite;
}
}

View File

@@ -0,0 +1,27 @@
package net.i2p.data.i2cp;
/*
* free (adj.): unencumbered; not under the control of others
* Written by jrandom in 2003 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*
*/
import net.i2p.data.StructureTest;
import net.i2p.data.DataStructure;
import net.i2p.data.DataFormatException;
/**
* Test harness for loading / storing Hash objects
*
* @author jrandom
*/
public class MessageIdTest extends StructureTest {
public DataStructure createDataStructure() throws DataFormatException {
MessageId id = new MessageId();
id.setMessageId(101);
return id;
}
public DataStructure createStructureToRead() { return new MessageId(); }
}

View File

@@ -0,0 +1,55 @@
package net.i2p.data.i2cp;
/*
* free (adj.): unencumbered; not under the control of others
* Written by jrandom in 2003 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*
*/
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import net.i2p.data.StructureTest;
import net.i2p.data.DataStructure;
import net.i2p.data.DataFormatException;
import net.i2p.data.Payload;
import net.i2p.data.PayloadTest;
/**
* Test harness for loading / storing SendMessageMessage objects
*
* @author jrandom
*/
public class MessagePayloadMessageTest extends StructureTest {
public DataStructure createDataStructure() throws DataFormatException {
MessagePayloadMessage msg = new MessagePayloadMessage();
msg.setMessageId(123);
msg.setPayload((Payload)(new PayloadTest()).createDataStructure());
msg.setSessionId(321);
return msg;
}
public DataStructure createStructureToRead() { return new MessagePayloadMessage(); }
public void testStructure() throws Exception{
byte[] temp = null;
DataStructure orig;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
orig = createDataStructure();
orig.writeBytes(baos);
temp = baos.toByteArray();
DataStructure ds;
ByteArrayInputStream bais = new ByteArrayInputStream(temp);
ds = createStructureToRead();
ds.readBytes(bais);
((MessagePayloadMessage)ds).getPayload().setUnencryptedData(((MessagePayloadMessage)ds).getPayload().getEncryptedData());
assertEquals(orig, ds);
}
}

View File

@@ -0,0 +1,31 @@
package net.i2p.data.i2cp;
/*
* free (adj.): unencumbered; not under the control of others
* Written by jrandom in 2003 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*
*/
import net.i2p.data.StructureTest;
import net.i2p.data.DataStructure;
import net.i2p.data.DataFormatException;
/**
* Test harness for loading / storing MessageStatusMessage objects
*
* @author jrandom
*/
public class MessageStatusMessageTest extends StructureTest {
public DataStructure createDataStructure() throws DataFormatException {
MessageStatusMessage msg = new MessageStatusMessage();
msg.setSessionId(42);
msg.setMessageId(41);
msg.setSize(1024*1024*42L);
msg.setStatus(MessageStatusMessage.STATUS_AVAILABLE);
msg.setNonce(1);
return msg;
}
public DataStructure createStructureToRead() { return new MessageStatusMessage(); }
}

View File

@@ -0,0 +1,28 @@
package net.i2p.data.i2cp;
/*
* free (adj.): unencumbered; not under the control of others
* Written by jrandom in 2003 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*
*/
import net.i2p.data.StructureTest;
import net.i2p.data.DataStructure;
import net.i2p.data.DataFormatException;
/**
* Test harness for loading / storing Hash objects
*
* @author jrandom
*/
public class ReceiveMessageBeginMessageTest extends StructureTest {
public DataStructure createDataStructure() throws DataFormatException {
ReceiveMessageBeginMessage msg = new ReceiveMessageBeginMessage();
msg.setSessionId(321);
msg.setMessageId(123);
return msg;
}
public DataStructure createStructureToRead() { return new ReceiveMessageBeginMessage(); }
}

View File

@@ -0,0 +1,28 @@
package net.i2p.data.i2cp;
/*
* free (adj.): unencumbered; not under the control of others
* Written by jrandom in 2003 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*
*/
import net.i2p.data.StructureTest;
import net.i2p.data.DataStructure;
import net.i2p.data.DataFormatException;
/**
* Test harness for loading / storing Hash objects
*
* @author jrandom
*/
public class ReceiveMessageEndMessageTest extends StructureTest {
public DataStructure createDataStructure() throws DataFormatException {
ReceiveMessageEndMessage msg = new ReceiveMessageEndMessage();
msg.setSessionId(321);
msg.setMessageId(123);
return msg;
}
public DataStructure createStructureToRead() { return new ReceiveMessageEndMessage(); }
}

View File

@@ -0,0 +1,28 @@
package net.i2p.data.i2cp;
/*
* free (adj.): unencumbered; not under the control of others
* Written by str4d in 2012 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*
*/
import net.i2p.data.StructureTest;
import net.i2p.data.DataStructure;
import net.i2p.data.DataFormatException;
/**
* Test harness for loading / storing ReconfigureSessionMessage objects
*
* @author str4d
*/
public class ReconfigureSessionMessageTest extends StructureTest {
public DataStructure createDataStructure() throws DataFormatException {
ReconfigureSessionMessage msg = new ReconfigureSessionMessage();
msg.setSessionId((SessionId)(new SessionIdTest()).createDataStructure());
msg.setSessionConfig((SessionConfig)(new SessionConfigTest()).createDataStructure());
return msg;
}
public DataStructure createStructureToRead() { return new ReconfigureSessionMessage(); }
}

View File

@@ -0,0 +1,30 @@
package net.i2p.data.i2cp;
/*
* free (adj.): unencumbered; not under the control of others
* Written by jrandom in 2003 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*
*/
import net.i2p.data.StructureTest;
import net.i2p.data.DataStructure;
import net.i2p.data.DataFormatException;
/**
* Test harness for loading / storing Hash objects
*
* @author jrandom
*/
public class ReportAbuseMessageTest extends StructureTest {
public DataStructure createDataStructure() throws DataFormatException {
ReportAbuseMessage msg = new ReportAbuseMessage();
msg.setMessageId((MessageId)(new MessageIdTest()).createDataStructure());
msg.setReason((AbuseReason)(new AbuseReasonTest()).createDataStructure());
msg.setSessionId((SessionId)(new SessionIdTest()).createDataStructure());
msg.setSeverity((AbuseSeverity)(new AbuseSeverityTest()).createDataStructure());
return msg;
}
public DataStructure createStructureToRead() { return new ReportAbuseMessage(); }
}

View File

@@ -0,0 +1,35 @@
package net.i2p.data.i2cp;
/*
* free (adj.): unencumbered; not under the control of others
* Written by jrandom in 2003 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*
*/
import java.util.Date;
import net.i2p.data.StructureTest;
import net.i2p.data.DataStructure;
import net.i2p.data.DataFormatException;
import net.i2p.data.Hash;
import net.i2p.data.TunnelId;
import net.i2p.data.TunnelIdTest;
/**
* Test harness for loading / storing RequestLeaseSetMessage objects
*
* @author jrandom
*/
public class RequestLeaseSetMessageTest extends StructureTest {
public DataStructure createDataStructure() throws DataFormatException {
RequestLeaseSetMessage msg = new RequestLeaseSetMessage();
msg.setSessionId((SessionId)(new SessionIdTest()).createDataStructure());
msg.setEndDate(new Date(1000*60*60*12));
byte h[] = new byte[Hash.HASH_LENGTH];
msg.addEndpoint(new Hash(h), (TunnelId)(new TunnelIdTest()).createDataStructure());
return msg;
}
public DataStructure createStructureToRead() { return new RequestLeaseSetMessage(); }
}

View File

@@ -0,0 +1,67 @@
package net.i2p.data.i2cp;
/*
* free (adj.): unencumbered; not under the control of others
* Written by str4d in 2012 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*
*/
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import net.i2p.data.StructureTest;
import net.i2p.data.DataStructure;
import net.i2p.data.DataFormatException;
import net.i2p.data.Destination;
import net.i2p.data.DestinationTest;
import net.i2p.data.Payload;
import net.i2p.data.PayloadTest;
import net.i2p.data.DateAndFlags;
import net.i2p.data.DateAndFlagsTest;
/**
* Test harness for loading / storing SendMessageExpiresMessage objects
*
* @author str4d
*/
public class SendMessageExpiresMessageTest extends StructureTest {
public DataStructure createDataStructure() throws DataFormatException {
SendMessageExpiresMessage msg = new SendMessageExpiresMessage();
msg.setDestination((Destination)(new DestinationTest()).createDataStructure());
msg.setPayload((Payload)(new PayloadTest()).createDataStructure());
msg.setSessionId((SessionId)(new SessionIdTest()).createDataStructure());
msg.setNonce(1);
DateAndFlags daf = (DateAndFlags)(new DateAndFlagsTest()).createDataStructure();
msg.setExpiration(daf.getDate());
msg.setFlags(daf.getFlags());
return msg;
}
public DataStructure createStructureToRead() { return new SendMessageExpiresMessage(); }
public void testStructure() throws Exception{
byte[] temp = null;
DataStructure orig;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
orig = createDataStructure();
orig.writeBytes(baos);
temp = baos.toByteArray();
DataStructure ds;
ByteArrayInputStream bais = new ByteArrayInputStream(temp);
ds = createStructureToRead();
ds.readBytes(bais);
((SendMessageExpiresMessage)ds).getPayload().setUnencryptedData(((SendMessageExpiresMessage)ds).getPayload().getEncryptedData());
assertEquals(orig, ds);
}
}

View File

@@ -0,0 +1,62 @@
package net.i2p.data.i2cp;
/*
* free (adj.): unencumbered; not under the control of others
* Written by jrandom in 2003 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*
*/
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import net.i2p.data.StructureTest;
import net.i2p.data.DataStructure;
import net.i2p.data.DataFormatException;
import net.i2p.data.Destination;
import net.i2p.data.DestinationTest;
import net.i2p.data.Payload;
import net.i2p.data.PayloadTest;
/**
* Test harness for loading / storing SendMessageMessage objects
*
* @author jrandom
*/
public class SendMessageMessageTest extends StructureTest {
public DataStructure createDataStructure() throws DataFormatException {
SendMessageMessage msg = new SendMessageMessage();
msg.setDestination((Destination)(new DestinationTest()).createDataStructure());
msg.setPayload((Payload)(new PayloadTest()).createDataStructure());
msg.setSessionId((SessionId)(new SessionIdTest()).createDataStructure());
msg.setNonce(1);
return msg;
}
public DataStructure createStructureToRead() { return new SendMessageMessage(); }
public void testStructure() throws Exception{
byte[] temp = null;
DataStructure orig;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
orig = createDataStructure();
orig.writeBytes(baos);
temp = baos.toByteArray();
DataStructure ds;
ByteArrayInputStream bais = new ByteArrayInputStream(temp);
ds = createStructureToRead();
ds.readBytes(bais);
((SendMessageMessage)ds).getPayload().setUnencryptedData(((SendMessageMessage)ds).getPayload().getEncryptedData());
assertEquals(orig, ds);
}
}

View File

@@ -0,0 +1,41 @@
package net.i2p.data.i2cp;
/*
* free (adj.): unencumbered; not under the control of others
* Written by jrandom in 2003 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*
*/
import java.util.Properties;
import net.i2p.data.StructureTest;
import net.i2p.data.DataStructure;
import net.i2p.data.DataFormatException;
import net.i2p.data.Destination;
import net.i2p.data.DestinationTest;
import net.i2p.data.Signature;
import net.i2p.data.SignatureTest;
import net.i2p.data.SigningPrivateKey;
import net.i2p.data.SigningPrivateKeyTest;
/**
* Test harness for loading / storing Hash objects
*
* @author jrandom
*/
public class SessionConfigTest extends StructureTest {
public DataStructure createDataStructure() throws DataFormatException {
SessionConfig cfg = new SessionConfig((Destination)(new DestinationTest()).createDataStructure());
cfg.setSignature((Signature)(new SignatureTest()).createDataStructure());
Properties options = new Properties();
options.setProperty("routerHost", "localhost");
options.setProperty("routerPort", "54321");
options.setProperty("routerSecret", "blah");
cfg.setOptions(options);
cfg.signSessionConfig((SigningPrivateKey)(new SigningPrivateKeyTest()).createDataStructure());
return cfg;
}
public DataStructure createStructureToRead() { return new SessionConfig(); }
}

View File

@@ -0,0 +1,27 @@
package net.i2p.data.i2cp;
/*
* free (adj.): unencumbered; not under the control of others
* Written by jrandom in 2003 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*
*/
import net.i2p.data.StructureTest;
import net.i2p.data.DataStructure;
import net.i2p.data.DataFormatException;
/**
* Test harness for loading / storing SessionId objects
*
* @author jrandom
*/
public class SessionIdTest extends StructureTest {
public DataStructure createDataStructure() throws DataFormatException {
SessionId id = new SessionId();
id.setSessionId(7);
return id;
}
public DataStructure createStructureToRead() { return new SessionId(); }
}

View File

@@ -0,0 +1,28 @@
package net.i2p.data.i2cp;
/*
* free (adj.): unencumbered; not under the control of others
* Written by jrandom in 2003 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*
*/
import net.i2p.data.StructureTest;
import net.i2p.data.DataStructure;
import net.i2p.data.DataFormatException;
/**
* Test harness for loading / storing SessionStatusMessage objects
*
* @author jrandom
*/
public class SessionStatusMessageTest extends StructureTest {
public DataStructure createDataStructure() throws DataFormatException {
SessionStatusMessage msg = new SessionStatusMessage();
msg.setSessionId((SessionId)(new SessionIdTest()).createDataStructure());
msg.setStatus(SessionStatusMessage.STATUS_CREATED);
return msg;
}
public DataStructure createStructureToRead() { return new SessionStatusMessage(); }
}

View File

@@ -0,0 +1,26 @@
package net.i2p.data.i2cp;
/*
* free (adj.): unencumbered; not under the control of others
* Written by str4d in 2012 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*
*/
import net.i2p.data.StructureTest;
import net.i2p.data.DataStructure;
import net.i2p.data.DataFormatException;
/**
* Test harness for loading / storing SetDateMessage objects
*
* @author str4d
*/
public class SetDateMessageTest extends StructureTest {
public DataStructure createDataStructure() throws DataFormatException {
SetDateMessage msg = new SetDateMessage("0.8.13-0");
return msg;
}
public DataStructure createStructureToRead() { return new SetDateMessage(); }
}