forked from I2P_Developers/i2p.i2p
propagate from branch 'i2p.i2p' (head 3002b47d5d20180f84fb6a4f161823bc751989be)
to branch 'i2p.i2p.unittests' (head 97dc8de19916c3d0c7ec42790800c1e23f9ce9e8)
This commit is contained in:
25
build.xml
25
build.xml
@@ -1027,12 +1027,6 @@
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
<target name="updateTest" depends="prepupdate">
|
||||
<ant dir="core/java/" target="jarTest" />
|
||||
<copy file="core/java/build/i2ptest.jar" todir="pkg-temp/lib" />
|
||||
<zip destfile="i2pupdate.zip" basedir="pkg-temp" />
|
||||
</target>
|
||||
|
||||
<target name="prepupdate" depends="build2, prepupdateSmall, prepConsoleDocUpdates, prepCertificates, prep-script-translation">
|
||||
<copy file="build/BOB.jar" todir="pkg-temp/lib/" />
|
||||
<copy file="build/sam.jar" todir="pkg-temp/lib/" />
|
||||
@@ -1277,25 +1271,30 @@
|
||||
</target>
|
||||
<!-- end custom installers -->
|
||||
|
||||
<!-- unit tests -->
|
||||
<target name="updateTest" depends="prepupdate">
|
||||
<ant dir="core/java/" target="jarTest" />
|
||||
<copy file="core/java/build/i2ptest.jar" todir="pkg-temp/lib" />
|
||||
<zip destfile="i2pupdate.zip" basedir="pkg-temp" />
|
||||
</target>
|
||||
<target name="test" depends="buildProperties, jbigi" >
|
||||
<mkdir dir="reports/core/junit/" />
|
||||
<ant dir="core/java/" target="test" />
|
||||
</target>
|
||||
<target name="junit.report" depends="buildProperties" >
|
||||
<ant dir="core/java/" target="junit.report" />
|
||||
</target>
|
||||
<target name="clover.report" depends="buildProperties" >
|
||||
<target name="clover.report" depends="buildProperties" if="with.clover">
|
||||
<ant dir="core/java/" target="clover.report" />
|
||||
</target>
|
||||
<target name="test.report" depends="junit.report, clover.report"/>
|
||||
<target name="cobertura.report" depends="buildProperties" if="with.cobertura">
|
||||
<ant dir="core/java/" target="cobertura.report" />
|
||||
</target>
|
||||
<target name="test.report" depends="junit.report, clover.report, cobertura.report"/>
|
||||
<target name="fulltest" depends="buildProperties" >
|
||||
<ant dir="core/java/" target="fulltest" />
|
||||
<ant dir="router/java/" target="fulltest" />
|
||||
</target>
|
||||
<target name="fullclovertest" depends="buildProperties" >
|
||||
<ant dir="core/java/" target="fullclovertest" />
|
||||
<ant dir="router/java/" target="fullclovertest" />
|
||||
</target>
|
||||
<!-- end unit tests -->
|
||||
|
||||
<target name="testscripts" >
|
||||
<exec executable="tests/scripts/checkcerts.sh" failonerror="true" />
|
||||
|
||||
@@ -28,17 +28,6 @@
|
||||
</javac>
|
||||
</target>
|
||||
|
||||
<target name="compileTest">
|
||||
<mkdir dir="./build" />
|
||||
<mkdir dir="./build/obj" />
|
||||
<!-- junit classes are in ant runtime -->
|
||||
<javac srcdir="./src:./test" debug="true" source="1.5" target="1.5" deprecation="on"
|
||||
includeAntRuntime="true"
|
||||
destdir="./build/obj" >
|
||||
<compilerarg line="${javac.compilerargs}" />
|
||||
</javac>
|
||||
</target>
|
||||
|
||||
<target name="listChangedFiles" if="mtn.available" >
|
||||
<exec executable="mtn" outputproperty="workspace.changes" errorproperty="mtn.error2" failifexecutionfails="false" >
|
||||
<arg value="list" />
|
||||
@@ -73,40 +62,70 @@
|
||||
</uptodate>
|
||||
</target>
|
||||
|
||||
<target name="jarTest" depends="compileTest">
|
||||
<jar destfile="./build/i2ptest.jar" basedir="./build/obj" includes="**/*.class" />
|
||||
</target>
|
||||
<target name="javadoc">
|
||||
<mkdir dir="./build" />
|
||||
<mkdir dir="./build/javadoc" />
|
||||
<javadoc sourcepath="./src:./test" destdir="./build/javadoc" packagenames="*" use="true" splitindex="true" windowtitle="I2P SDK" />
|
||||
</target>
|
||||
<target name="prepareTest" depends="compileTest" if="with.cobertura">
|
||||
|
||||
<!-- unit tests -->
|
||||
<target name="compileTest">
|
||||
<mkdir dir="./build" />
|
||||
<mkdir dir="./build/obj" />
|
||||
<!-- junit and hamcrest classes should be in ant runtime -->
|
||||
<javac srcdir="./src:./test" debug="true" source="1.5" target="1.5" deprecation="on"
|
||||
includeAntRuntime="true"
|
||||
destdir="./build/obj" >
|
||||
<compilerarg line="${javac.compilerargs}" />
|
||||
</javac>
|
||||
</target>
|
||||
<target name="jarTest" depends="compileTest">
|
||||
<jar destfile="./build/i2ptest.jar" basedir="./build/obj" includes="**/*.class" />
|
||||
</target>
|
||||
<!-- preparation of code coverage tool of choice -->
|
||||
<target name="prepareClover" depends="compileTest" if="with.clover">
|
||||
<taskdef resource="clovertasks"/>
|
||||
<mkdir dir="../../reports/core/clover" />
|
||||
<clover-setup initString="../../reports/core/clover/coverage.db"/>
|
||||
</target>
|
||||
<target name="prepareCobertura" depends="compileTest" if="with.cobertura">
|
||||
<taskdef classpath="${with.cobertura}" resource="tasks.properties" onerror="report" />
|
||||
<mkdir dir="./build/obj_test" />
|
||||
<cobertura-instrument todir="./build/obj_test">
|
||||
<mkdir dir="./build/obj_cobertura" />
|
||||
<delete file="./cobertura.ser" />
|
||||
<cobertura-instrument todir="./build/obj_cobertura">
|
||||
<fileset dir="./build/obj">
|
||||
<include name="**/*.class"/>
|
||||
<exclude name="**/*Test.class" />
|
||||
<exclude name="**/AllCoreTests.class" />
|
||||
<exclude name="com/nettgryppa/**/*.class" />
|
||||
<exclude name="freenet/**/*.class" />
|
||||
<exclude name="gnu/**/*.class" />
|
||||
<exclude name="net/metanotion/**/*.class" />
|
||||
<exclude name="org/bouncycastle/**/*.class" />
|
||||
<exclude name="org/xlattice/**/*.class" />
|
||||
</fileset>
|
||||
</cobertura-instrument>
|
||||
</target>
|
||||
<target name="prepareTest" depends="prepareClover, prepareCobertura" />
|
||||
<!-- end preparation of code coverage tool -->
|
||||
<target name="test" depends="clean, compileTest, prepareTest">
|
||||
<mkdir dir="../../reports/core/junit/" />
|
||||
<delete>
|
||||
<fileset dir="../../reports/core/junit">
|
||||
<include name="TEST-*.xml"/>
|
||||
</fileset>
|
||||
</delete>
|
||||
<mkdir dir="../../reports/" />
|
||||
<mkdir dir="../../reports/core/" />
|
||||
<mkdir dir="../../reports/core/junit/" />
|
||||
<junit printsummary="on" fork="yes" maxmemory="384m">
|
||||
<sysproperty key="net.sourceforge.cobertura.datafile" file="./cobertura.ser" />
|
||||
<classpath>
|
||||
<pathelement path="${classpath}" />
|
||||
<pathelement location="./build/obj_test" />
|
||||
<pathelement location="${ant.home}/lib/hamcrest-core.jar" />
|
||||
<pathelement location="${ant.home}/lib/hamcrest-library.jar" />
|
||||
<pathelement location="${ant.home}/lib/hamcrest-integration.jar" />
|
||||
<pathelement location="./build/obj_cobertura" />
|
||||
<pathelement location="./build/obj" />
|
||||
<pathelement location="../../build/jbigi.jar" />
|
||||
<pathelement location="${with.clover}" />
|
||||
<pathelement location="${with.cobertura}" />
|
||||
</classpath>
|
||||
<batchtest todir="../../reports/core/junit/">
|
||||
@@ -114,16 +133,24 @@
|
||||
<include name="**/*Test.java" />
|
||||
<exclude name="**/ElGamalAESEngineTest.java" />
|
||||
<exclude name="**/StructureTest.java" />
|
||||
<!-- temporarily exclude slow tests -->
|
||||
<exclude name="**/HMACSHA256Test.java" />
|
||||
<exclude name="**/SHA1HashTest.java" />
|
||||
<exclude name="**/SHA256Test.java" />
|
||||
<exclude name="**/DataHelperTest.java" />
|
||||
<!-- end of slow tests -->
|
||||
</fileset>
|
||||
</batchtest>
|
||||
<formatter type="xml"/>
|
||||
</junit>
|
||||
<!-- fetch the real hostname of this machine -->
|
||||
<exec executable="hostname" outputproperty="host.name"/>
|
||||
<!-- set if unset -->
|
||||
<property name="host.fakename" value="i2ptester" />
|
||||
<!-- replace hostname that junit inserts into reports with fake one -->
|
||||
<replace dir="../../reports/core/junit/" token="${host.name}" value="${host.fakename}"/>
|
||||
</target>
|
||||
<target name="cobertura" depends="test" if="with.cobertura">
|
||||
<mkdir dir="../../reports/core/cobertura" />
|
||||
<cobertura-report format="xml" srcdir="./src" destdir="../../reports/core/cobertura" />
|
||||
<delete file="./cobertura.ser" />
|
||||
</target>
|
||||
<!-- test reports -->
|
||||
<target name="junit.report">
|
||||
<junitreport todir="../../reports/core/junit">
|
||||
<fileset dir="../../reports/core/junit">
|
||||
@@ -132,8 +159,25 @@
|
||||
<report format="frames" todir="../../reports/core/html/junit"/>
|
||||
</junitreport>
|
||||
</target>
|
||||
<target name="test.report" depends="junit.report"/>
|
||||
<target name="fulltest" depends="test, junit.report" />
|
||||
<target name="clover.report" depends="test" if="with.clover">
|
||||
<clover-report>
|
||||
<current outfile="../../reports/core/html/clover">
|
||||
<format type="html"/>
|
||||
</current>
|
||||
</clover-report>
|
||||
</target>
|
||||
<target name="cobertura.report" depends="test" if="with.cobertura">
|
||||
<mkdir dir="../../reports/core/cobertura" />
|
||||
<cobertura-report format="xml" srcdir="./src" destdir="../../reports/core/cobertura" />
|
||||
<mkdir dir="../../reports/core/html/cobertura" />
|
||||
<cobertura-report format="html" srcdir="./src" destdir="../../reports/core/html/cobertura" />
|
||||
<delete file="./cobertura.ser" />
|
||||
</target>
|
||||
<target name="test.report" depends="junit.report, clover.report, cobertura.report"/>
|
||||
<!-- end test reports -->
|
||||
<target name="fulltest" depends="test, test.report" />
|
||||
<!-- end unit tests -->
|
||||
|
||||
<target name="clean">
|
||||
<delete dir="./build" />
|
||||
</target>
|
||||
|
||||
@@ -28,86 +28,94 @@ import net.i2p.data.Hash;
|
||||
*/
|
||||
public class DatagramTest extends TestCase {
|
||||
private I2PClient _client;
|
||||
|
||||
|
||||
public void setUp(){
|
||||
}
|
||||
|
||||
|
||||
protected void tearDown() {
|
||||
System.gc();
|
||||
}
|
||||
|
||||
|
||||
public void testDatagram() throws Exception{
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
I2PClient client = I2PClientFactory.createClient();
|
||||
Destination d = client.createDestination(out);
|
||||
I2PSession session = client.createSession(new ByteArrayInputStream(out.toByteArray()), null);
|
||||
|
||||
|
||||
I2PDatagramMaker dm = new I2PDatagramMaker(session);
|
||||
byte[] dg = dm.makeI2PDatagram("What's the deal with 42?".getBytes());
|
||||
|
||||
|
||||
I2PDatagramDissector dd = new I2PDatagramDissector();
|
||||
dd.loadI2PDatagram(dg);
|
||||
byte[] x = dd.getPayload();
|
||||
assertTrue(DataHelper.eq(x, "What's the deal with 42?".getBytes()));
|
||||
|
||||
|
||||
x = dd.extractPayload();
|
||||
assertTrue(DataHelper.eq(x, "What's the deal with 42?".getBytes()));
|
||||
|
||||
|
||||
assertEquals(d, dd.getSender());
|
||||
assertEquals(d, dd.extractSender());
|
||||
|
||||
}
|
||||
|
||||
/*public void testMakeNullDatagram() throws Exception{
|
||||
|
||||
public void testMakeNullDatagram() throws Exception{
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
I2PClient client = I2PClientFactory.createClient();
|
||||
Destination d = client.createDestination(out);
|
||||
I2PSession session = client.createSession(new ByteArrayInputStream(out.toByteArray()), null);
|
||||
I2PDatagramMaker dm = new I2PDatagramMaker(session);
|
||||
|
||||
|
||||
byte[] dg = dm.makeI2PDatagram(null);
|
||||
assertNull(dg);
|
||||
}*/
|
||||
|
||||
/*public void testExtractNullDatagram() throws Exception{
|
||||
}
|
||||
|
||||
public void testExtractNullDatagram() throws Exception{
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
I2PClient client = I2PClientFactory.createClient();
|
||||
Destination d = client.createDestination(out);
|
||||
I2PSession session = client.createSession(new ByteArrayInputStream(out.toByteArray()), null);
|
||||
|
||||
|
||||
I2PDatagramDissector dd = new I2PDatagramDissector();
|
||||
dd.loadI2PDatagram(null);
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
public void testBadagram() throws Exception{
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
I2PClient client = I2PClientFactory.createClient();
|
||||
Destination d = client.createDestination(out);
|
||||
I2PSession session = client.createSession(new ByteArrayInputStream(out.toByteArray()), null);
|
||||
DSAEngine dsaEng = DSAEngine.getInstance();
|
||||
|
||||
|
||||
ByteArrayOutputStream dout = new ByteArrayOutputStream();
|
||||
d.writeBytes(dout);
|
||||
dsaEng.sign(Hash.FAKE_HASH.toByteArray(), session.getPrivateKey()).writeBytes(dout);
|
||||
dout.write("blah".getBytes());
|
||||
|
||||
|
||||
byte[] data = dout.toByteArray();
|
||||
I2PDatagramDissector dd = new I2PDatagramDissector();
|
||||
dd.loadI2PDatagram(data);
|
||||
|
||||
|
||||
boolean error = false;
|
||||
try{
|
||||
dd.getPayload();
|
||||
}catch(I2PInvalidDatagramException i2pide){
|
||||
error = true;
|
||||
}
|
||||
|
||||
assertTrue(error);
|
||||
|
||||
error = false;
|
||||
try{
|
||||
dd.getSender();
|
||||
}catch(I2PInvalidDatagramException i2pide){
|
||||
error = true;
|
||||
}
|
||||
|
||||
assertTrue(error);
|
||||
|
||||
error = false;
|
||||
try{
|
||||
dd.getHash();
|
||||
}catch(I2PInvalidDatagramException i2pide){
|
||||
error = true;
|
||||
}
|
||||
assertTrue(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
package net.i2p.client.naming;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.data.DataHelper;
|
||||
import net.i2p.data.Destination;
|
||||
|
||||
|
||||
public class BlockfileNamingServiceTest extends TestCase {
|
||||
BlockfileNamingService _bns;
|
||||
List<String> _names;
|
||||
|
||||
public void setUp() {
|
||||
I2PAppContext ctx = new I2PAppContext();
|
||||
_bns = new BlockfileNamingService(ctx);
|
||||
_names = null;
|
||||
Properties props = new Properties();
|
||||
try {
|
||||
DataHelper.loadProps(props, new File("../../installer/resources/hosts.txt"), true);
|
||||
_names = new ArrayList(props.keySet());
|
||||
Collections.shuffle(_names);
|
||||
} catch (IOException ioe) {
|
||||
_bns.shutdown();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public void tearDown() {
|
||||
_bns.shutdown();
|
||||
File f = new File("hostsdb.blockfile");
|
||||
f.delete();
|
||||
}
|
||||
|
||||
public void testRepeatedLookup() throws Exception{
|
||||
int found = 0;
|
||||
int notfound = 0;
|
||||
int rfound = 0;
|
||||
int rnotfound = 0;
|
||||
for (String name : _names) {
|
||||
Destination dest = _bns.lookup(name);
|
||||
if (dest != null) {
|
||||
found++;
|
||||
String reverse = _bns.reverseLookup(dest);
|
||||
if (reverse != null)
|
||||
rfound++;
|
||||
else
|
||||
rnotfound++;
|
||||
} else {
|
||||
notfound++;
|
||||
}
|
||||
}
|
||||
assertEquals(0, notfound);
|
||||
assertEquals(0, rnotfound);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package net.i2p.client.naming;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.data.Destination;
|
||||
|
||||
|
||||
public class DummyNamingServiceTest extends TestCase {
|
||||
private I2PAppContext _context;
|
||||
|
||||
public void setUp() {
|
||||
_context = new I2PAppContext();
|
||||
}
|
||||
|
||||
public void testLookup() throws Exception{
|
||||
// The good b64 and b32 are the destination of www.i2p2.i2p =)
|
||||
String goodB64 = "-KR6qyfPWXoN~F3UzzYSMIsaRy4quickbrownfoxXSzUQXQdi2Af1TV2UMH3PpPuNu-GwrqihwmLSkPFg4fv4yQQY3E10VeQVuI67dn5vlan3NGMsjqxoXTSHHt7C3nX3szXK90JSoO~tRMDl1xyqtKm94-RpIyNcLXofd0H6b02683CQIjb-7JiCpDD0zharm6SU54rhdisIUVXpi1xYgg2pKVpssL~KCp7RAGzpt2rSgz~RHFsecqGBeFwJdiko-6CYW~tcBcigM8ea57LK7JjCFVhOoYTqgk95AG04-hfehnmBtuAFHWklFyFh88x6mS9sbVPvi-am4La0G0jvUJw9a3wQ67jMr6KWQ~w~bFe~FDqoZqVXl8t88qHPIvXelvWw2Y8EMSF5PJhWw~AZfoWOA5VQVYvcmGzZIEKtFGE7bgQf3rFtJ2FAtig9XXBsoLisHbJgeVb29Ew5E7bkwxvEe9NYkIqvrKvUAt1i55we0Nkt6xlEdhBqg6xXOyIAAAA";
|
||||
String goodB32 = "rjxwbsw4zjhv4zsplma6jmf5nr24e4ymvvbycd3swgiinbvg7oga.b32.i2p";
|
||||
// TODO: Come up with an actual bad b64 and b32
|
||||
String badB64 = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
|
||||
String badB32 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.b32.i2p";
|
||||
|
||||
DummyNamingService ns = new DummyNamingService(_context);
|
||||
|
||||
assertNull(ns.lookup(""));
|
||||
// TODO: Could this case ever come up?
|
||||
//assertNull(ns.lookup(null));
|
||||
|
||||
Destination dGoodB64 = ns.lookup(goodB64);
|
||||
assertNotNull(dGoodB64);
|
||||
// TODO: Check that the b64 is preserved.
|
||||
|
||||
Destination dGoodB32 = ns.lookup(goodB32);
|
||||
assertNotNull(dGoodB32);
|
||||
// TODO: Check that the b32 is preserved.
|
||||
|
||||
// TODO: Come up with an actual bad b64 and b32
|
||||
//assertNull(ns.lookup(badB64));
|
||||
//assertNull(ns.lookup(badB32));
|
||||
|
||||
// DummyNameService only handles b64 and b32 addresses
|
||||
assertNull(ns.lookup("www.i2p2.i2p"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package net.i2p.client.naming;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.data.Destination;
|
||||
|
||||
|
||||
public class SingleFileNamingServiceTest extends TestCase {
|
||||
private I2PAppContext _context;
|
||||
|
||||
public void setUp() {
|
||||
_context = new I2PAppContext();
|
||||
}
|
||||
|
||||
public void tearDown() {
|
||||
File f = new File("testhosts.txt");
|
||||
f.delete();
|
||||
}
|
||||
|
||||
public void testAddRemoveLookup() throws Exception{
|
||||
String testB64 = "-KR6qyfPWXoN~F3UzzYSMIsaRy4quickbrownfoxXSzUQXQdi2Af1TV2UMH3PpPuNu-GwrqihwmLSkPFg4fv4yQQY3E10VeQVuI67dn5vlan3NGMsjqxoXTSHHt7C3nX3szXK90JSoO~tRMDl1xyqtKm94-RpIyNcLXofd0H6b02683CQIjb-7JiCpDD0zharm6SU54rhdisIUVXpi1xYgg2pKVpssL~KCp7RAGzpt2rSgz~RHFsecqGBeFwJdiko-6CYW~tcBcigM8ea57LK7JjCFVhOoYTqgk95AG04-hfehnmBtuAFHWklFyFh88x6mS9sbVPvi-am4La0G0jvUJw9a3wQ67jMr6KWQ~w~bFe~FDqoZqVXl8t88qHPIvXelvWw2Y8EMSF5PJhWw~AZfoWOA5VQVYvcmGzZIEKtFGE7bgQf3rFtJ2FAtig9XXBsoLisHbJgeVb29Ew5E7bkwxvEe9NYkIqvrKvUAt1i55we0Nkt6xlEdhBqg6xXOyIAAAA";
|
||||
Destination testDest = new Destination();
|
||||
testDest.fromBase64(testB64);
|
||||
String testB642 = "24SmhWiRDm-GzpV5Gq2sXhuvPpa1OihY7rkxQO4aHy5qKjr6zmEnZ3xQXdkFJJ0Z1lKy73XRmgCyys02G25Hl3cuxlZ2fNbp6KhOzlRKpOIAWFdSWZNF4Fp7sos0x-a-9fxOWnwwQ9MFcRYwixE~iCZf4JG~-Pd-MHgAuDhIX0P3~GmfUvo~9xPjof1ZsnaOV1zC0XUkHxZA5D6V0Bse~Ptfb66lPNcgBxIEntCStBAy~rTjaA3SdAufG29IRWDscpFq1-D4XPaXHnlXu7n7WdpFEM8WWd3ebUMqnq8XvLL1eqoWYzKCe3aaavC3W6~pJp8cxKl2IKrhvSFatHZ0chRg3B4~ja1Cxmw1psisplSkJqMnF921E6pury0i6GH52XAVoj4iiDY~EAvqDhzG-ThwlzTs~2JKzslwxOrD2ejd-dcKdi4i9xvi2JQ4Ib2Mw2ktaQhuAw3Y9EkqAs7oriQQN8N8dwIoYkJLfvh7ousm0iKJJvMt3s55PccM46SoAAAA";
|
||||
Destination testDest2 = new Destination();
|
||||
testDest2.fromBase64(testB642);
|
||||
|
||||
SingleFileNamingService ns = new SingleFileNamingService(_context, "testhosts.txt");
|
||||
|
||||
// testhosts.txt is empty.
|
||||
assertThat(ns.size(), is(equalTo(0)));
|
||||
assertThat(ns.getEntries(), is(equalTo(Collections.EMPTY_MAP)));
|
||||
assertThat(ns.lookup("test.i2p"), is(nullValue()));
|
||||
assertThat(ns.reverseLookup(testDest), is(nullValue()));
|
||||
|
||||
// First put should add the hostname.
|
||||
ns.put("test.i2p", testDest);
|
||||
assertThat(ns.size(), is(equalTo(1)));
|
||||
assertThat(ns.getEntries().size(), is(equalTo(1)));
|
||||
assertThat(ns.lookup("test.i2p"), is(equalTo(testDest)));
|
||||
assertThat(ns.reverseLookup(testDest), is(equalTo("test.i2p")));
|
||||
|
||||
// Second put should replace the first.
|
||||
ns.put("test.i2p", testDest2);
|
||||
assertThat(ns.size(), is(equalTo(1)));
|
||||
assertThat(ns.lookup("test.i2p"), is(equalTo(testDest2)));
|
||||
assertThat(ns.reverseLookup(testDest2), is(equalTo("test.i2p")));
|
||||
assertThat(ns.lookup("test.i2p"), is(not(equalTo(testDest))));
|
||||
assertThat(ns.reverseLookup(testDest), is(nullValue()));
|
||||
|
||||
// Removing the hostname should give an empty file again.
|
||||
ns.remove("test.i2p");
|
||||
assertThat(ns.lookup("test.i2p"), is(nullValue()));
|
||||
assertThat(ns.reverseLookup(testDest2), is(nullValue()));
|
||||
// Odd quirk - the above lookups don't update size, but getEntries() does...
|
||||
assertThat(ns.size(), is(equalTo(1)));
|
||||
assertThat(ns.getEntries(), is(equalTo(Collections.EMPTY_MAP)));
|
||||
assertThat(ns.size(), is(equalTo(0)));
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,6 @@ public class CryptoTestSuite {
|
||||
suite.addTestSuite(AESInputStreamTest.class);
|
||||
suite.addTestSuite(CryptixAESEngineTest.class);
|
||||
suite.addTestSuite(CryptixRijndael_AlgorithmTest.class);
|
||||
suite.addTestSuite(DHSessionKeyBuilderTest.class);
|
||||
suite.addTestSuite(DSATest.class);
|
||||
suite.addTestSuite(ElGamalTest.class);
|
||||
suite.addTestSuite(HMACSHA256Test.class);
|
||||
@@ -35,4 +34,4 @@ public class CryptoTestSuite {
|
||||
|
||||
return suite;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -372,8 +372,10 @@ public class ElGamalTest extends TestCase{
|
||||
|
||||
public void testYKGen(){
|
||||
RandomSource.getInstance().nextBoolean();
|
||||
I2PAppContext context = new I2PAppContext();
|
||||
YKGenerator ykgen = new YKGenerator(context);
|
||||
for (int i = 0; i < 5; i++) {
|
||||
YKGenerator.getNextYK();
|
||||
ykgen.getNextYK();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,8 @@ public class LeaseTest extends StructureTest {
|
||||
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));
|
||||
@@ -40,7 +41,8 @@ public class LeaseTest extends StructureTest {
|
||||
lease.getNumSuccess();
|
||||
lease.getNumFailure();
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
public void testExpiration() throws Exception{
|
||||
Lease lease = new Lease();
|
||||
assertTrue(lease.isExpired());
|
||||
|
||||
@@ -33,10 +33,37 @@ public class RouterAddressTest extends StructureTest {
|
||||
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 = true;
|
||||
boolean error = false;
|
||||
try{
|
||||
addr.writeBytes(new ByteArrayOutputStream());
|
||||
}catch(DataFormatException dfe){
|
||||
@@ -44,7 +71,7 @@ public class RouterAddressTest extends StructureTest {
|
||||
}
|
||||
assertTrue(error);
|
||||
}
|
||||
|
||||
|
||||
public void testNullEquals(){
|
||||
RouterAddress addr = new RouterAddress();
|
||||
byte data[] = new byte[32];
|
||||
@@ -60,7 +87,7 @@ public class RouterAddressTest extends StructureTest {
|
||||
assertFalse(addr.equals(null));
|
||||
assertFalse(addr.equals(""));
|
||||
}
|
||||
|
||||
|
||||
public void testToString(){
|
||||
RouterAddress addr = new RouterAddress();
|
||||
byte data[] = new byte[32];
|
||||
@@ -73,8 +100,7 @@ public class RouterAddressTest extends StructureTest {
|
||||
options.setProperty("portnum", "1234");
|
||||
addr.setOptions(options);
|
||||
addr.setTransportStyle("Blah");
|
||||
addr.toString();
|
||||
addr.setOptions(null);
|
||||
addr.toString();
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,30 @@ import junit.framework.TestCase;
|
||||
|
||||
|
||||
public class RateStatTest extends TestCase {
|
||||
public void testGettersEtc() throws Exception{
|
||||
long emptyArray[] = new long[0];
|
||||
RateStat rs = new RateStat("test", "test RateStat getters etc", "tests", emptyArray);
|
||||
|
||||
// Test basic getters
|
||||
assertEquals("test", rs.getName());
|
||||
assertEquals("tests", rs.getGroupName());
|
||||
assertEquals("test RateStat getters etc", rs.getDescription());
|
||||
|
||||
// There should be no periods, so other getters should return defaults
|
||||
// TODO: Fix this so it checks that the array is empty rather than comparing objects
|
||||
//assertEquals(rs.getPeriods(), emptyArray);
|
||||
assertEquals(0.0, rs.getLifetimeAverageValue());
|
||||
assertEquals(0, rs.getLifetimeEventCount());
|
||||
assertNull(rs.getRate(2000));
|
||||
|
||||
// Test adding and removing a period
|
||||
assertFalse(rs.containsRate(1000));
|
||||
rs.addRate(1000);
|
||||
assertTrue(rs.containsRate(1000));
|
||||
rs.removeRate(1000);
|
||||
assertFalse(rs.containsRate(1000));
|
||||
}
|
||||
|
||||
public void testRateStat() throws Exception{
|
||||
RateStat rs = new RateStat("moo", "moo moo moo", "cow trueisms", new long[] { 60 * 1000, 60 * 60 * 1000,
|
||||
24 * 60 * 60 * 1000});
|
||||
@@ -30,4 +54,4 @@ public class RateStatTest extends TestCase {
|
||||
assertEquals(rs, loadedRs);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,9 +5,6 @@
|
||||
<target name="builddep">
|
||||
<!-- run from top level build.xml to get dependencies built -->
|
||||
</target>
|
||||
<target name="builddeptest">
|
||||
<ant dir="../../core/java/" target="jarTest" />
|
||||
</target>
|
||||
<condition property="depend.available">
|
||||
<typefound name="depend" />
|
||||
</condition>
|
||||
@@ -42,17 +39,6 @@
|
||||
</javac>
|
||||
</target>
|
||||
|
||||
<target name="compileTest" depends="builddeptest">
|
||||
<mkdir dir="./build" />
|
||||
<mkdir dir="./build/obj" />
|
||||
<!-- junit classes are in ant runtime -->
|
||||
<javac srcdir="./src:./test" debug="true" source="1.5" target="1.5" deprecation="on"
|
||||
includeAntRuntime="true"
|
||||
destdir="./build/obj" classpath="../../core/java/build/i2ptest.jar" >
|
||||
<compilerarg line="${javac.compilerargs}" />
|
||||
</javac>
|
||||
</target>
|
||||
|
||||
<target name="listChangedFiles" if="mtn.available" >
|
||||
<exec executable="mtn" outputproperty="workspace.changes" errorproperty="mtn.error2" failifexecutionfails="false" >
|
||||
<arg value="list" />
|
||||
@@ -89,9 +75,6 @@
|
||||
</uptodate>
|
||||
</target>
|
||||
|
||||
<target name="jarTest" depends="compileTest">
|
||||
<jar destfile="./build/routertest.jar" basedir="./build/obj" includes="**/*.class" />
|
||||
</target>
|
||||
<target name="javadoc">
|
||||
<mkdir dir="./build" />
|
||||
<mkdir dir="./build/javadoc" />
|
||||
@@ -102,41 +85,76 @@
|
||||
splitindex="true"
|
||||
windowtitle="I2P Router" />
|
||||
</target>
|
||||
<target name="test" depends="compileTest">
|
||||
<junit printsummary="on" fork="yes">
|
||||
<classpath>
|
||||
<pathelement path="${classpath}" />
|
||||
<pathelement location="./build/obj" />
|
||||
<pathelement location="../../core/java/build/i2ptest.jar" />
|
||||
<pathelement location="../../installer/lib/jbigi/jbigi.jar" />
|
||||
<pathelement path="${ant.home}/lib/clover.jar"/>
|
||||
</classpath>
|
||||
<batchtest>
|
||||
<fileset dir="./test/">
|
||||
<include name="**/*Test.java" />
|
||||
</fileset>
|
||||
</batchtest>
|
||||
<formatter type="xml"/>
|
||||
</junit>
|
||||
<mkdir dir="../../reports/" />
|
||||
<mkdir dir="../../reports/router/" />
|
||||
|
||||
<!-- unit tests -->
|
||||
<target name="builddeptest">
|
||||
<ant dir="../../core/java/" target="jarTest" />
|
||||
</target>
|
||||
<target name="compileTest" depends="builddeptest">
|
||||
<mkdir dir="./build" />
|
||||
<mkdir dir="./build/obj" />
|
||||
<!-- junit classes are in ant runtime -->
|
||||
<javac srcdir="./src:./test" debug="true" source="1.5" target="1.5" deprecation="on"
|
||||
includeAntRuntime="true"
|
||||
destdir="./build/obj" classpath="../../core/java/build/i2ptest.jar" >
|
||||
<compilerarg line="${javac.compilerargs}" />
|
||||
</javac>
|
||||
</target>
|
||||
<target name="jarTest" depends="compileTest">
|
||||
<jar destfile="./build/routertest.jar" basedir="./build/obj" includes="**/*.class" />
|
||||
</target>
|
||||
<!-- preparation of code coverage tool of choice -->
|
||||
<target name="prepareClover" depends="compileTest" if="with.clover">
|
||||
<taskdef resource="clovertasks"/>
|
||||
<mkdir dir="../../reports/router/clover" />
|
||||
<clover-setup initString="../../reports/router/clover/coverage.db"/>
|
||||
</target>
|
||||
<target name="prepareCobertura" depends="compileTest" if="with.cobertura">
|
||||
<taskdef classpath="${with.cobertura}" resource="tasks.properties" onerror="report" />
|
||||
<mkdir dir="./build/obj_cobertura" />
|
||||
<delete file="./cobertura.ser" />
|
||||
<cobertura-instrument todir="./build/obj_cobertura">
|
||||
<fileset dir="./build/obj">
|
||||
<include name="**/*.class"/>
|
||||
<exclude name="**/*Test.class" />
|
||||
</fileset>
|
||||
</cobertura-instrument>
|
||||
</target>
|
||||
<target name="prepareTest" depends="prepareClover, prepareCobertura" />
|
||||
<!-- end preparation of code coverage tool -->
|
||||
<target name="test" depends="clean, compileTest, prepareTest">
|
||||
<mkdir dir="../../reports/router/junit/" />
|
||||
<delete>
|
||||
<fileset dir="../../reports/router/junit">
|
||||
<include name="TEST-*.xml"/>
|
||||
</fileset>
|
||||
</delete>
|
||||
<copy todir="../../reports/router/junit">
|
||||
<fileset dir=".">
|
||||
<include name="TEST-*.xml"/>
|
||||
</fileset>
|
||||
</copy>
|
||||
<delete>
|
||||
<fileset dir=".">
|
||||
<include name="TEST-*.xml"/>
|
||||
</fileset>
|
||||
</delete>
|
||||
<junit printsummary="on" fork="yes">
|
||||
<sysproperty key="net.sourceforge.cobertura.datafile" file="./cobertura.ser" />
|
||||
<classpath>
|
||||
<pathelement path="${classpath}" />
|
||||
<pathelement location="./build/obj_cobertura" />
|
||||
<pathelement location="./build/obj" />
|
||||
<pathelement location="../../core/java/build/i2ptest.jar" />
|
||||
<pathelement location="../../build/jbigi.jar" />
|
||||
<pathelement location="${with.clover}" />
|
||||
<pathelement location="${with.cobertura}" />
|
||||
</classpath>
|
||||
<batchtest todir="../../reports/router/junit/">
|
||||
<fileset dir="./test/">
|
||||
<include name="**/*Test.java" />
|
||||
</fileset>
|
||||
</batchtest>
|
||||
<formatter type="xml"/>
|
||||
</junit>
|
||||
<!-- fetch the real hostname of this machine -->
|
||||
<exec executable="hostname" outputproperty="host.name"/>
|
||||
<!-- set if unset -->
|
||||
<property name="host.fakename" value="i2ptester" />
|
||||
<!-- replace hostname that junit inserts into reports with fake one -->
|
||||
<replace dir="../../reports/router/junit/" token="${host.name}" value="${host.fakename}"/>
|
||||
</target>
|
||||
<!-- test reports -->
|
||||
<target name="junit.report">
|
||||
<junitreport todir="../../reports/router/junit">
|
||||
<fileset dir="../../reports/router/junit">
|
||||
@@ -145,28 +163,25 @@
|
||||
<report format="frames" todir="../../reports/router/html/junit"/>
|
||||
</junitreport>
|
||||
</target>
|
||||
<target name="clover.report">
|
||||
<taskdef resource="clovertasks"/>
|
||||
<mkdir dir="../../reports/" />
|
||||
<mkdir dir="../../reports/router" />
|
||||
<mkdir dir="../../reports/router/clover" />
|
||||
<clover-setup initString="../../reports/router/clover/coverage.db"/>
|
||||
<target name="clover.report" depends="test" if="with.clover">
|
||||
<clover-report>
|
||||
<current outfile="../../reports/router/html/clover">
|
||||
<format type="html"/>
|
||||
</current>
|
||||
</clover-report>
|
||||
</target>
|
||||
<target name="test.report" depends="junit.report, clover.report"/>
|
||||
<target name="useclover">
|
||||
<taskdef resource="clovertasks"/>
|
||||
<mkdir dir="../../reports/" />
|
||||
<mkdir dir="../../reports/router/" />
|
||||
<mkdir dir="../../reports/router/clover" />
|
||||
<clover-setup initString="../../reports/router/clover/coverage.db"/>
|
||||
<target name="cobertura.report" depends="test" if="with.cobertura">
|
||||
<mkdir dir="../../reports/router/cobertura" />
|
||||
<cobertura-report format="xml" srcdir="./src" destdir="../../reports/router/cobertura" />
|
||||
<mkdir dir="../../reports/router/html/cobertura" />
|
||||
<cobertura-report format="html" srcdir="./src" destdir="../../reports/router/html/cobertura" />
|
||||
<delete file="./cobertura.ser" />
|
||||
</target>
|
||||
<target name="fulltest" depends="cleandep, builddeptest, jarTest, test, junit.report" />
|
||||
<target name="fullclovertest" depends="cleandep, builddeptest, useclover, jarTest, test, test.report" />
|
||||
<target name="test.report" depends="junit.report, clover.report, cobertura.report"/>
|
||||
<!-- end test reports -->
|
||||
<target name="fulltest" depends="cleandep, builddeptest, jarTest, test, test.report" />
|
||||
<!-- end unit tests -->
|
||||
|
||||
<target name="clean">
|
||||
<delete dir="./build" />
|
||||
</target>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package net.i2p.crypto;
|
||||
package net.i2p.router.transport.crypto;
|
||||
|
||||
/*
|
||||
* free (adj.): unencumbered; not under the control of others
|
||||
Reference in New Issue
Block a user