From 8a32aad6c348d7df155c1cc7b4538c9e5121c34f Mon Sep 17 00:00:00 2001 From: str4d Date: Thu, 16 Feb 2012 00:08:27 +0000 Subject: [PATCH 01/28] Shuffled build targets around to group together ones related to unit tests --- build.xml | 13 +++++++------ core/java/build.xml | 31 +++++++++++++++++-------------- router/java/build.xml | 37 ++++++++++++++++++++----------------- 3 files changed, 44 insertions(+), 37 deletions(-) diff --git a/build.xml b/build.xml index 64157cf9d..3f6c2aee3 100644 --- a/build.xml +++ b/build.xml @@ -980,12 +980,6 @@ - - - - - - @@ -1245,6 +1239,12 @@ + + + + + + @@ -1264,6 +1264,7 @@ + diff --git a/core/java/build.xml b/core/java/build.xml index c3eaf5c07..675ee7144 100644 --- a/core/java/build.xml +++ b/core/java/build.xml @@ -28,17 +28,6 @@ - - - - - - - - - @@ -72,14 +61,26 @@ - - - + + + + + + + + + + + + + @@ -133,6 +134,8 @@ + + diff --git a/router/java/build.xml b/router/java/build.xml index e933086cf..61592a8cf 100644 --- a/router/java/build.xml +++ b/router/java/build.xml @@ -5,9 +5,6 @@ - - - @@ -42,17 +39,6 @@ - - - - - - - - - @@ -86,9 +72,6 @@ - - - @@ -99,6 +82,24 @@ splitindex="true" windowtitle="I2P Router" /> + + + + + + + + + + + + + + + + @@ -164,6 +165,8 @@ + + From d1a03f500f2ef57a26502ae4fd009139c82788da Mon Sep 17 00:00:00 2001 From: str4d Date: Thu, 16 Feb 2012 02:58:25 +0000 Subject: [PATCH 02/28] Moved mkdir above delete in core build.xml and removed mkdir from base build.xml mkdir does nothing if the directory exists, whereas delete fails by default if the directory doesn't exist. Also, mkdir creates parent dirs as needed. --- build.xml | 1 - core/java/build.xml | 4 +--- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/build.xml b/build.xml index 3f6c2aee3..a34e5ae48 100644 --- a/build.xml +++ b/build.xml @@ -1246,7 +1246,6 @@ - diff --git a/core/java/build.xml b/core/java/build.xml index 675ee7144..354172439 100644 --- a/core/java/build.xml +++ b/core/java/build.xml @@ -92,14 +92,12 @@ + - - - From c7d473a7eb82396698d6652f111d9a2a583efea5 Mon Sep 17 00:00:00 2001 From: str4d Date: Sat, 18 Feb 2012 02:13:46 +0000 Subject: [PATCH 03/28] Shuffle round mkdirs and deletes in router build.xml to match core build.xml batchtest has a todir config option that makes manual copying unnecessary. --- router/java/build.xml | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/router/java/build.xml b/router/java/build.xml index 61592a8cf..6f7081c2c 100644 --- a/router/java/build.xml +++ b/router/java/build.xml @@ -101,6 +101,12 @@ + + + + + + @@ -109,31 +115,13 @@ - + - - - - - - - - - - - - - - - - - - From a2217b2b36be11290faf3e5bb62d9342a8460805 Mon Sep 17 00:00:00 2001 From: str4d Date: Mon, 20 Feb 2012 03:44:23 +0000 Subject: [PATCH 04/28] Fiddle with cobertura definitions a bit in core build.xml To run with cobertura, execute the following in "core/java/": ant -Dwith.cobertura=/usr/share/java/cobertura.jar cobertura.report --- core/java/build.xml | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/core/java/build.xml b/core/java/build.xml index 354172439..1b918eb32 100644 --- a/core/java/build.xml +++ b/core/java/build.xml @@ -81,16 +81,20 @@ - + + - - + + + + + @@ -102,7 +106,7 @@ - + @@ -117,11 +121,7 @@ - - - - - + @@ -130,7 +130,15 @@ - + + + + + + + + + From 849c407712e928fda23d93794918b05062ac7604 Mon Sep 17 00:00:00 2001 From: str4d Date: Tue, 21 Feb 2012 04:05:27 +0000 Subject: [PATCH 05/28] Added clover targets to core build.xml as well, so either will work Pass in the absolute location of clover.jar as the with.clover property to activate the clover targets. --- core/java/build.xml | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/core/java/build.xml b/core/java/build.xml index 1b918eb32..d7d5713e3 100644 --- a/core/java/build.xml +++ b/core/java/build.xml @@ -82,6 +82,11 @@ + + + + + @@ -93,7 +98,7 @@ - + @@ -109,6 +114,7 @@ + @@ -130,6 +136,13 @@ + + + + + + + @@ -137,7 +150,7 @@ - + From ceda7c9ca0eea77f9eeefc2573c54a0bd340d466 Mon Sep 17 00:00:00 2001 From: str4d Date: Sat, 25 Feb 2012 01:21:31 +0000 Subject: [PATCH 06/28] Fix jbigi.jar path in test target of router build.xml --- router/java/build.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/router/java/build.xml b/router/java/build.xml index 6f7081c2c..fc0b11ef9 100644 --- a/router/java/build.xml +++ b/router/java/build.xml @@ -112,7 +112,7 @@ - + From c68d53faf343f819a174043f653c4c6f26d01df1 Mon Sep 17 00:00:00 2001 From: str4d Date: Sat, 25 Feb 2012 01:23:17 +0000 Subject: [PATCH 07/28] Removed fullclovertest target from main build.xml Clover usage is triggered by setting with.clover instead. --- build.xml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/build.xml b/build.xml index a34e5ae48..cb4f20561 100644 --- a/build.xml +++ b/build.xml @@ -1259,10 +1259,6 @@ - - - - From c955adf7f62fa5339da2e3182816086929296b6b Mon Sep 17 00:00:00 2001 From: str4d Date: Sat, 25 Feb 2012 01:29:08 +0000 Subject: [PATCH 08/28] Set up report targets properly in main build.xml --- build.xml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/build.xml b/build.xml index cb4f20561..c425ff40e 100644 --- a/build.xml +++ b/build.xml @@ -1251,10 +1251,13 @@ - + - + + + + From 6a26c0b6218eb505af928bbe2c3023b183a327ae Mon Sep 17 00:00:00 2001 From: str4d Date: Sat, 25 Feb 2012 01:43:15 +0000 Subject: [PATCH 09/28] Edited router build.xml to match core build.xml (inc. clover, cobertura stuff) --- router/java/build.xml | 48 +++++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/router/java/build.xml b/router/java/build.xml index fc0b11ef9..562478234 100644 --- a/router/java/build.xml +++ b/router/java/build.xml @@ -100,6 +100,25 @@ + + + + + + + + + + + + + + + + + + + @@ -108,12 +127,15 @@ + + - + + @@ -123,6 +145,7 @@ + @@ -131,28 +154,23 @@ - - - - - - + - - - - - - - + + + + + + + + - From 204440b06b144b0c446af5cab48ada8f7d84a64f Mon Sep 17 00:00:00 2001 From: str4d Date: Sat, 25 Feb 2012 01:46:46 +0000 Subject: [PATCH 10/28] Run full test reports with fulltest target, not just junit report --- core/java/build.xml | 2 +- router/java/build.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/java/build.xml b/core/java/build.xml index d7d5713e3..681614234 100644 --- a/core/java/build.xml +++ b/core/java/build.xml @@ -152,7 +152,7 @@ - + diff --git a/router/java/build.xml b/router/java/build.xml index 562478234..5384bd4e7 100644 --- a/router/java/build.xml +++ b/router/java/build.xml @@ -170,7 +170,7 @@ - + From 4148aa54f3b557825759390bc9c786dcb6dfbd63 Mon Sep 17 00:00:00 2001 From: str4d Date: Sat, 25 Feb 2012 01:48:31 +0000 Subject: [PATCH 11/28] Need to run clean and prepareTest before test in router build.xml --- router/java/build.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/router/java/build.xml b/router/java/build.xml index 5384bd4e7..c448c714a 100644 --- a/router/java/build.xml +++ b/router/java/build.xml @@ -119,7 +119,7 @@ - + From f19ef3e486f22c717498d111ce07f71342d3bf54 Mon Sep 17 00:00:00 2001 From: str4d Date: Sun, 26 Feb 2012 03:01:48 +0000 Subject: [PATCH 12/28] Fix test that would always pass --- core/java/test/net/i2p/data/RouterAddressTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/java/test/net/i2p/data/RouterAddressTest.java b/core/java/test/net/i2p/data/RouterAddressTest.java index aab4a88bb..3e8791e73 100644 --- a/core/java/test/net/i2p/data/RouterAddressTest.java +++ b/core/java/test/net/i2p/data/RouterAddressTest.java @@ -36,7 +36,7 @@ public class RouterAddressTest extends StructureTest { public void testBadWrite() throws Exception{ RouterAddress addr = new RouterAddress(); - boolean error = true; + boolean error = false; try{ addr.writeBytes(new ByteArrayOutputStream()); }catch(DataFormatException dfe){ From e7922c4ded1ff8c5e2c423ac998238e47eff6d81 Mon Sep 17 00:00:00 2001 From: str4d Date: Sun, 26 Feb 2012 04:57:31 +0000 Subject: [PATCH 13/28] Added some tests of setOptions to RouterAddressTest --- .../test/net/i2p/data/RouterAddressTest.java | 33 +++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/core/java/test/net/i2p/data/RouterAddressTest.java b/core/java/test/net/i2p/data/RouterAddressTest.java index 3e8791e73..5ee9c0deb 100644 --- a/core/java/test/net/i2p/data/RouterAddressTest.java +++ b/core/java/test/net/i2p/data/RouterAddressTest.java @@ -33,7 +33,34 @@ 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 = false; @@ -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]; From 22900a0d91d487a3ab87ba4ecf8e9bc2346d0741 Mon Sep 17 00:00:00 2001 From: str4d Date: Sun, 26 Feb 2012 09:30:27 +0000 Subject: [PATCH 14/28] Fixed RouterAddressTest.testToString to actually test the returned String --- core/java/test/net/i2p/data/RouterAddressTest.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/core/java/test/net/i2p/data/RouterAddressTest.java b/core/java/test/net/i2p/data/RouterAddressTest.java index 5ee9c0deb..79bb9bd4d 100644 --- a/core/java/test/net/i2p/data/RouterAddressTest.java +++ b/core/java/test/net/i2p/data/RouterAddressTest.java @@ -100,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(ret, "[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]]"); } } From 24268c5130b3cc06f97ebbccd8397c6493b05e4b Mon Sep 17 00:00:00 2001 From: str4d Date: Mon, 27 Feb 2012 03:26:58 +0000 Subject: [PATCH 15/28] Exclude classes from code coverage report that aren't in net.i2p.* The classes are specifically excluded rather than only including net.i2p.* so that only classes we know we want to exclude get excluded. --- core/java/build.xml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/core/java/build.xml b/core/java/build.xml index 681614234..7bbb3882f 100644 --- a/core/java/build.xml +++ b/core/java/build.xml @@ -95,6 +95,13 @@ + + + + + + + From d436c846acb8b0043cea655268fedc5d15c0c22e Mon Sep 17 00:00:00 2001 From: str4d Date: Mon, 27 Feb 2012 03:29:13 +0000 Subject: [PATCH 16/28] Temporarily exclude slow core tests for dev purposes --- core/java/build.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/core/java/build.xml b/core/java/build.xml index 7bbb3882f..c7ec59b04 100644 --- a/core/java/build.xml +++ b/core/java/build.xml @@ -129,6 +129,12 @@ + + + + + + From a226d25dc6ea306aed389b81bd47a6a536bf7be9 Mon Sep 17 00:00:00 2001 From: str4d Date: Wed, 29 Feb 2012 05:01:21 +0000 Subject: [PATCH 17/28] Test getters etc. in RateStat --- core/java/test/net/i2p/stat/RateStatTest.java | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/core/java/test/net/i2p/stat/RateStatTest.java b/core/java/test/net/i2p/stat/RateStatTest.java index a3869bdc6..fe02a9b08 100644 --- a/core/java/test/net/i2p/stat/RateStatTest.java +++ b/core/java/test/net/i2p/stat/RateStatTest.java @@ -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); } -} \ No newline at end of file +} From 786a261a707028f854ca6656d124b0b44f547a07 Mon Sep 17 00:00:00 2001 From: str4d Date: Wed, 29 Feb 2012 05:34:13 +0000 Subject: [PATCH 18/28] Fixed usage of assertEquals - should be assertEquals(expected, got) --- core/java/test/net/i2p/data/RouterAddressTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/java/test/net/i2p/data/RouterAddressTest.java b/core/java/test/net/i2p/data/RouterAddressTest.java index 79bb9bd4d..dc7bce3d2 100644 --- a/core/java/test/net/i2p/data/RouterAddressTest.java +++ b/core/java/test/net/i2p/data/RouterAddressTest.java @@ -101,6 +101,6 @@ public class RouterAddressTest extends StructureTest { addr.setOptions(options); addr.setTransportStyle("Blah"); String ret = addr.toString(); - assertEquals(ret, "[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]]"); + 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); } } From 9d07bc241cfcb11b8e209011f2bbf8a912e87ca7 Mon Sep 17 00:00:00 2001 From: str4d Date: Fri, 16 Mar 2012 01:41:23 +0000 Subject: [PATCH 19/28] Replace hostname included by junit in reports with "i2ptester" The fake hostname can be overridden by setting the host.fakename property. --- core/java/build.xml | 6 ++++++ router/java/build.xml | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/core/java/build.xml b/core/java/build.xml index c7ec59b04..0f6c393de 100644 --- a/core/java/build.xml +++ b/core/java/build.xml @@ -139,6 +139,12 @@ + + + + + + diff --git a/router/java/build.xml b/router/java/build.xml index c448c714a..26b61032a 100644 --- a/router/java/build.xml +++ b/router/java/build.xml @@ -144,6 +144,12 @@ + + + + + + From f19bc6a4b0bcd3d66822f7f9a26a223a7bf4cb6b Mon Sep 17 00:00:00 2001 From: str4d Date: Fri, 16 Mar 2012 03:08:10 +0000 Subject: [PATCH 20/28] Moved DHSessionKeyBuilderTest to net.i2p.router.transport.crypto --- .../i2p/router/transport}/crypto/DHSessionKeyBuilderTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename {core/java/test/net/i2p => router/java/test/net/i2p/router/transport}/crypto/DHSessionKeyBuilderTest.java (97%) diff --git a/core/java/test/net/i2p/crypto/DHSessionKeyBuilderTest.java b/router/java/test/net/i2p/router/transport/crypto/DHSessionKeyBuilderTest.java similarity index 97% rename from core/java/test/net/i2p/crypto/DHSessionKeyBuilderTest.java rename to router/java/test/net/i2p/router/transport/crypto/DHSessionKeyBuilderTest.java index 0bf6a1f61..44a43d3e9 100644 --- a/core/java/test/net/i2p/crypto/DHSessionKeyBuilderTest.java +++ b/router/java/test/net/i2p/router/transport/crypto/DHSessionKeyBuilderTest.java @@ -1,4 +1,4 @@ -package net.i2p.crypto; +package net.i2p.router.transport.crypto; /* * free (adj.): unencumbered; not under the control of others From bf0b59b3b3184cffd5f0c8c618897ff23a9eb648 Mon Sep 17 00:00:00 2001 From: str4d Date: Fri, 16 Mar 2012 03:18:53 +0000 Subject: [PATCH 21/28] Remove DHSessionKeyBuilderTest from CryptoTestSuite --- core/java/test/net/i2p/crypto/CryptoTestSuite.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/java/test/net/i2p/crypto/CryptoTestSuite.java b/core/java/test/net/i2p/crypto/CryptoTestSuite.java index a29b8a2ff..430080265 100644 --- a/core/java/test/net/i2p/crypto/CryptoTestSuite.java +++ b/core/java/test/net/i2p/crypto/CryptoTestSuite.java @@ -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; } -} \ No newline at end of file +} From 136d77a8aab41e6239ffa68ce1cfdbd234799679 Mon Sep 17 00:00:00 2001 From: str4d Date: Fri, 16 Mar 2012 04:51:55 +0000 Subject: [PATCH 22/28] Fix YKGenerator test - methods no longer static --- core/java/test/net/i2p/crypto/ElGamalTest.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/java/test/net/i2p/crypto/ElGamalTest.java b/core/java/test/net/i2p/crypto/ElGamalTest.java index 7789f99d9..c917219ad 100644 --- a/core/java/test/net/i2p/crypto/ElGamalTest.java +++ b/core/java/test/net/i2p/crypto/ElGamalTest.java @@ -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(); } } -} \ No newline at end of file +} From 67da35ab358154d95d31c98fa608dd8afab536ec Mon Sep 17 00:00:00 2001 From: str4d Date: Fri, 16 Mar 2012 05:08:31 +0000 Subject: [PATCH 23/28] Commented out test for net.i2p.data.Lease.getNumSuccess() / getNumFailure --- core/java/test/net/i2p/data/LeaseTest.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/java/test/net/i2p/data/LeaseTest.java b/core/java/test/net/i2p/data/LeaseTest.java index 15a9366da..bb13c149e 100644 --- a/core/java/test/net/i2p/data/LeaseTest.java +++ b/core/java/test/net/i2p/data/LeaseTest.java @@ -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()); From 377aa9bca19a45ace878f463f97af4edcb0314a4 Mon Sep 17 00:00:00 2001 From: str4d Date: Tue, 20 Mar 2012 00:29:14 +0000 Subject: [PATCH 24/28] In core build.xml, tell junit to look for the hamcrest libraries hamcrest-core.jar, hamcrest-library.jar and hamcrest-integration.jar should be present in $ANT_HOME/lib/ (real or symlinked). --- core/java/build.xml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/java/build.xml b/core/java/build.xml index 425caa5f8..a4d5957c7 100644 --- a/core/java/build.xml +++ b/core/java/build.xml @@ -72,7 +72,7 @@ - + @@ -119,6 +119,9 @@ + + + From bfaf72a5476f6f37f7a103bc0d039c244d739fbf Mon Sep 17 00:00:00 2001 From: str4d Date: Sat, 24 Mar 2012 05:09:31 +0000 Subject: [PATCH 25/28] Added a couple of tests for net.i2p.client.naming --- .../naming/BlockfileNamingServiceTest.java | 65 ++++++++++++++++++ .../client/naming/DummyNamingServiceTest.java | 45 +++++++++++++ .../naming/SingleFileNamingServiceTest.java | 66 +++++++++++++++++++ 3 files changed, 176 insertions(+) create mode 100644 core/java/test/net/i2p/client/naming/BlockfileNamingServiceTest.java create mode 100644 core/java/test/net/i2p/client/naming/DummyNamingServiceTest.java create mode 100644 core/java/test/net/i2p/client/naming/SingleFileNamingServiceTest.java diff --git a/core/java/test/net/i2p/client/naming/BlockfileNamingServiceTest.java b/core/java/test/net/i2p/client/naming/BlockfileNamingServiceTest.java new file mode 100644 index 000000000..b6635cf71 --- /dev/null +++ b/core/java/test/net/i2p/client/naming/BlockfileNamingServiceTest.java @@ -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 _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); + } +} diff --git a/core/java/test/net/i2p/client/naming/DummyNamingServiceTest.java b/core/java/test/net/i2p/client/naming/DummyNamingServiceTest.java new file mode 100644 index 000000000..d523b2b1c --- /dev/null +++ b/core/java/test/net/i2p/client/naming/DummyNamingServiceTest.java @@ -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")); + } +} diff --git a/core/java/test/net/i2p/client/naming/SingleFileNamingServiceTest.java b/core/java/test/net/i2p/client/naming/SingleFileNamingServiceTest.java new file mode 100644 index 000000000..a7411fd62 --- /dev/null +++ b/core/java/test/net/i2p/client/naming/SingleFileNamingServiceTest.java @@ -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))); + } +} From f164951848e7b1c778a5e76e7180d1ab86fb1c60 Mon Sep 17 00:00:00 2001 From: str4d Date: Sat, 24 Mar 2012 08:04:49 +0000 Subject: [PATCH 26/28] Actually test something in DatagramTest.testBadagram, remove excess whitespace --- .../net/i2p/client/datagram/DatagramTest.java | 36 +++++++++++-------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/core/java/test/net/i2p/client/datagram/DatagramTest.java b/core/java/test/net/i2p/client/datagram/DatagramTest.java index c521bc48e..a0a2cd307 100644 --- a/core/java/test/net/i2p/client/datagram/DatagramTest.java +++ b/core/java/test/net/i2p/client/datagram/DatagramTest.java @@ -28,34 +28,33 @@ 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{ @@ -85,29 +84,38 @@ public class DatagramTest extends TestCase { 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); } -} \ No newline at end of file +} From ba3bc9e2ed42b2efe5253676cb77023c36f3420e Mon Sep 17 00:00:00 2001 From: str4d Date: Sat, 24 Mar 2012 11:18:37 +0000 Subject: [PATCH 27/28] Uncommented two Datagram tests that currently throw NullPointerExceptions --- .../test/net/i2p/client/datagram/DatagramTest.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/core/java/test/net/i2p/client/datagram/DatagramTest.java b/core/java/test/net/i2p/client/datagram/DatagramTest.java index a0a2cd307..f85c7a617 100644 --- a/core/java/test/net/i2p/client/datagram/DatagramTest.java +++ b/core/java/test/net/i2p/client/datagram/DatagramTest.java @@ -56,8 +56,8 @@ public class DatagramTest extends TestCase { 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); @@ -66,9 +66,9 @@ public class DatagramTest extends TestCase { 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); @@ -76,8 +76,8 @@ public class DatagramTest extends TestCase { I2PDatagramDissector dd = new I2PDatagramDissector(); dd.loadI2PDatagram(null); - }*/ - + } + public void testBadagram() throws Exception{ ByteArrayOutputStream out = new ByteArrayOutputStream(); I2PClient client = I2PClientFactory.createClient(); From 0cefaba9258a12a99e8edc1d445b72ca2067d660 Mon Sep 17 00:00:00 2001 From: str4d Date: Fri, 30 Mar 2012 04:40:56 +0000 Subject: [PATCH 28/28] More excess whitespace removed --- core/java/test/net/i2p/client/datagram/DatagramTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/java/test/net/i2p/client/datagram/DatagramTest.java b/core/java/test/net/i2p/client/datagram/DatagramTest.java index f85c7a617..04ca0ded7 100644 --- a/core/java/test/net/i2p/client/datagram/DatagramTest.java +++ b/core/java/test/net/i2p/client/datagram/DatagramTest.java @@ -63,7 +63,7 @@ public class DatagramTest extends TestCase { 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); } @@ -73,7 +73,7 @@ public class DatagramTest extends TestCase { 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); }