- Fix most of the I2CP message junit test failures caused by the removal of equals().

Still a few left where the test is overridden.
- Fix DestLookupMessage test failure caused by missing data.
This commit is contained in:
zzz
2013-01-03 12:13:48 +00:00
parent 9d77cd7761
commit 4730690978
2 changed files with 17 additions and 3 deletions

View File

@@ -21,7 +21,10 @@ import junit.framework.TestCase;
public abstract class StructureTest extends TestCase{
/** create a populated structure for writing */
public abstract DataStructure createDataStructure() throws DataFormatException;
/** create an unpopulated structure for reading */
public abstract DataStructure createStructureToRead();
public void testStructure() throws Exception{
@@ -42,7 +45,13 @@ public abstract class StructureTest extends TestCase{
ds = createStructureToRead();
ds.readBytes(bais);
assertEquals(orig, ds);
// Not all classes implement equals, so write out again
//assertEquals(orig, ds);
ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
ds.writeBytes(baos2);
byte[] temp2 = baos2.toByteArray();
assert(DataHelper.eq(temp, temp2));
}
}
}

View File

@@ -11,6 +11,8 @@ package net.i2p.data.i2cp;
import net.i2p.data.StructureTest;
import net.i2p.data.DataStructure;
import net.i2p.data.DataFormatException;
import net.i2p.data.Hash;
import net.i2p.util.RandomSource;
/**
* Test harness for loading / storing DestLookupMessage objects
@@ -19,7 +21,10 @@ import net.i2p.data.DataFormatException;
*/
public class DestLookupMessageTest extends StructureTest {
public DataStructure createDataStructure() throws DataFormatException {
DestLookupMessage msg = new DestLookupMessage();
byte h[] = new byte[Hash.HASH_LENGTH];
RandomSource.getInstance().nextBytes(h);
Hash hash = new Hash(h);
DestLookupMessage msg = new DestLookupMessage(hash);
return msg;
}
public DataStructure createStructureToRead() { return new DestLookupMessage(); }