diff options
author | Florian Dold <florian.dold@gmail.com> | 2013-09-11 11:28:31 +0000 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2013-09-11 11:28:31 +0000 |
commit | 67e978773774a0e7ef1f23209b884847837224ad (patch) | |
tree | 633cc5ac65e4d913bd265c1859fe126dccb8414d /src/test/java/org | |
parent | 71cb959dba98a0be8743ee87d8f8084cdbecf62c (diff) | |
download | gnunet-java-67e978773774a0e7ef1f23209b884847837224ad.tar.gz gnunet-java-67e978773774a0e7ef1f23209b884847837224ad.zip |
- fix scheduler
- thread-safe scheduler
- work on voting
Diffstat (limited to 'src/test/java/org')
-rw-r--r-- | src/test/java/org/gnunet/testbed/TestbedTest.java | 58 | ||||
-rw-r--r-- | src/test/java/org/gnunet/util/CryptoECCTest.java | 19 |
2 files changed, 62 insertions, 15 deletions
diff --git a/src/test/java/org/gnunet/testbed/TestbedTest.java b/src/test/java/org/gnunet/testbed/TestbedTest.java index 4e1af03..732e4d4 100644 --- a/src/test/java/org/gnunet/testbed/TestbedTest.java +++ b/src/test/java/org/gnunet/testbed/TestbedTest.java | |||
@@ -1,22 +1,22 @@ | |||
1 | package org.gnunet.testbed; | 1 | package org.gnunet.testbed; |
2 | 2 | ||
3 | 3 | ||
4 | import org.gnunet.testbed.callbacks.ControllerEventCallback; | ||
5 | import org.gnunet.testbed.callbacks.ControllerStatusCallback; | ||
6 | import org.gnunet.testbed.callbacks.PeerCreateCallback; | ||
4 | import org.gnunet.testing.TestingFixture; | 7 | import org.gnunet.testing.TestingFixture; |
5 | import org.gnunet.util.Configuration; | 8 | import org.gnunet.util.Configuration; |
6 | import org.gnunet.util.Program; | 9 | import org.gnunet.util.Program; |
7 | import org.gnunet.util.Scheduler; | ||
8 | import org.gnunet.util.Wrapper; | 10 | import org.gnunet.util.Wrapper; |
9 | import org.junit.Assert; | 11 | import org.junit.Assert; |
10 | import org.junit.Test; | 12 | import org.junit.Test; |
11 | 13 | ||
12 | public class TestbedTest extends TestingFixture { | 14 | public class TestbedTest extends TestingFixture { |
13 | 15 | ||
14 | |||
15 | @Test | 16 | @Test |
16 | public void test_controller_proc() { | 17 | public void test_controller_proc() { |
17 | final Wrapper<Boolean> success = new Wrapper<Boolean>(false); | 18 | final Wrapper<Boolean> success = new Wrapper<Boolean>(false); |
18 | new Program() { | 19 | new Program("-LDEBUG") { |
19 | |||
20 | @Override | 20 | @Override |
21 | public void run() { | 21 | public void run() { |
22 | // use local peer's config, does that really make sense? | 22 | // use local peer's config, does that really make sense? |
@@ -31,11 +31,59 @@ public class TestbedTest extends TestingFixture { | |||
31 | @Override | 31 | @Override |
32 | public void onStartupFailure() { | 32 | public void onStartupFailure() { |
33 | Assert.fail(); | 33 | Assert.fail(); |
34 | //To change body of implemented methods use File | Settings | File Templates. | ||
35 | } | 34 | } |
36 | }); | 35 | }); |
37 | } | 36 | } |
38 | }.start(); | 37 | }.start(); |
39 | Assert.assertTrue(success.get()); | 38 | Assert.assertTrue(success.get()); |
40 | } | 39 | } |
40 | |||
41 | |||
42 | |||
43 | |||
44 | @Test | ||
45 | public void test_peer_create() { | ||
46 | new Program("-LDEBUG") { | ||
47 | ControllerProc cp; | ||
48 | Host h; | ||
49 | Controller c; | ||
50 | |||
51 | class CEC extends ControllerEventCallback { | ||
52 | } | ||
53 | |||
54 | class PCB implements PeerCreateCallback { | ||
55 | @Override | ||
56 | public void onPeerCreated(Controller.Peer peer) { | ||
57 | System.out.println("peer created!"); | ||
58 | c.disconnect(); | ||
59 | cp.stop(); | ||
60 | } | ||
61 | |||
62 | @Override | ||
63 | public void onError(String errorMessage) { | ||
64 | Assert.fail(); | ||
65 | } | ||
66 | } | ||
67 | |||
68 | @Override | ||
69 | public void run() { | ||
70 | // use local peer's config, does that really make sense? | ||
71 | h = new Host(null, null, getConfiguration(), 0); | ||
72 | cp = new ControllerProc(); | ||
73 | cp.start("127.0.0.1", h, new ControllerStatusCallback() { | ||
74 | @Override | ||
75 | public void onStartupSuccess(Configuration cfg) { | ||
76 | System.out.println("startup success"); | ||
77 | c = new Controller(h, 1 | 2 | 4 | 8 | 32, new CEC()); | ||
78 | // FIXME: use config from resource | ||
79 | c.createPeer(h, getConfiguration(), new PCB()); | ||
80 | } | ||
81 | @Override | ||
82 | public void onStartupFailure() { | ||
83 | Assert.fail(); | ||
84 | } | ||
85 | }); | ||
86 | } | ||
87 | }.start(); | ||
88 | } | ||
41 | } | 89 | } |
diff --git a/src/test/java/org/gnunet/util/CryptoECCTest.java b/src/test/java/org/gnunet/util/CryptoECCTest.java index cc88409..c4c85d2 100644 --- a/src/test/java/org/gnunet/util/CryptoECCTest.java +++ b/src/test/java/org/gnunet/util/CryptoECCTest.java | |||
@@ -14,7 +14,7 @@ public class CryptoECCTest { | |||
14 | public void test_sign_success() { | 14 | public void test_sign_success() { |
15 | Random r = new Random(); | 15 | Random r = new Random(); |
16 | // the test uses random data, repeat it multiple times! | 16 | // the test uses random data, repeat it multiple times! |
17 | for (int i = 0; i < 10; i++) { | 17 | for (int i = 0; i < 5; i++) { |
18 | byte[] msg = new byte[16]; | 18 | byte[] msg = new byte[16]; |
19 | r.nextBytes(msg); | 19 | r.nextBytes(msg); |
20 | 20 | ||
@@ -22,11 +22,11 @@ public class CryptoECCTest { | |||
22 | privateKey.d = new byte[32]; | 22 | privateKey.d = new byte[32]; |
23 | r.nextBytes(privateKey.d); | 23 | r.nextBytes(privateKey.d); |
24 | CryptoECC.PublicKey publicKey = CryptoECC.computePublicKey(privateKey); | 24 | CryptoECC.PublicKey publicKey = CryptoECC.computePublicKey(privateKey); |
25 | 25 | System.out.println("gen"); | |
26 | CryptoECC.Signature sig = CryptoECC.sign(msg, privateKey, publicKey); | 26 | CryptoECC.Signature sig = CryptoECC.sign(msg, privateKey, publicKey); |
27 | 27 | System.out.println("sign"); | |
28 | boolean valid = CryptoECC.verify(sig, msg, publicKey); | 28 | boolean valid = CryptoECC.verify(sig, msg, publicKey); |
29 | 29 | System.out.println("verify"); | |
30 | Assert.assertTrue(valid); | 30 | Assert.assertTrue(valid); |
31 | } | 31 | } |
32 | } | 32 | } |
@@ -38,21 +38,20 @@ public class CryptoECCTest { | |||
38 | public void test_sign_failure() { | 38 | public void test_sign_failure() { |
39 | Random r = new Random(); | 39 | Random r = new Random(); |
40 | // the test uses random data, repeat it multiple times! | 40 | // the test uses random data, repeat it multiple times! |
41 | for (int i = 0; i < 10; i++) { | 41 | for (int i = 0; i < 5; i++) { |
42 | byte[] msg = new byte[16]; | 42 | byte[] msg = new byte[16]; |
43 | r.nextBytes(msg); | 43 | r.nextBytes(msg); |
44 | |||
45 | CryptoECC.PrivateKey privateKey = new CryptoECC.PrivateKey(); | 44 | CryptoECC.PrivateKey privateKey = new CryptoECC.PrivateKey(); |
46 | privateKey.d = new byte[32]; | 45 | privateKey.d = new byte[32]; |
47 | r.nextBytes(privateKey.d); | 46 | r.nextBytes(privateKey.d); |
48 | CryptoECC.PublicKey publicKey = CryptoECC.computePublicKey(privateKey); | 47 | CryptoECC.PublicKey publicKey = CryptoECC.computePublicKey(privateKey); |
49 | 48 | System.out.println("gen"); | |
50 | CryptoECC.Signature sig = CryptoECC.sign(msg, privateKey, publicKey); | 49 | CryptoECC.Signature sig = CryptoECC.sign(msg, privateKey, publicKey); |
51 | 50 | System.out.println("sign"); | |
51 | // corrupt the message | ||
52 | msg[0] = (byte) (msg[0] + 1); | 52 | msg[0] = (byte) (msg[0] + 1); |
53 | |||
54 | boolean valid = CryptoECC.verify(sig, msg, publicKey); | 53 | boolean valid = CryptoECC.verify(sig, msg, publicKey); |
55 | 54 | System.out.println("verify"); | |
56 | Assert.assertFalse(valid); | 55 | Assert.assertFalse(valid); |
57 | } | 56 | } |
58 | } | 57 | } |