diff options
Diffstat (limited to 'test')
26 files changed, 618 insertions, 196 deletions
diff --git a/test/org/gnunet/construct/ByteFillMessage.java b/test/org/gnunet/construct/ByteFillMessage.java index fe7716f..090f7d0 100644 --- a/test/org/gnunet/construct/ByteFillMessage.java +++ b/test/org/gnunet/construct/ByteFillMessage.java | |||
@@ -26,7 +26,7 @@ public class ByteFillMessage implements Message { | |||
26 | @UInt32 | 26 | @UInt32 |
27 | public int someValue; | 27 | public int someValue; |
28 | 28 | ||
29 | @ByteFill | 29 | @FillWith @UInt8 |
30 | public byte[] rest; | 30 | public byte[] rest; |
31 | 31 | ||
32 | } | 32 | } |
diff --git a/test/org/gnunet/construct/ConstructTest.java b/test/org/gnunet/construct/ConstructTest.java index c7f9853..8853b1d 100644 --- a/test/org/gnunet/construct/ConstructTest.java +++ b/test/org/gnunet/construct/ConstructTest.java | |||
@@ -13,7 +13,7 @@ public class ConstructTest { | |||
13 | @FrameSize | 13 | @FrameSize |
14 | @UInt32 | 14 | @UInt32 |
15 | public int frameSize; | 15 | public int frameSize; |
16 | @ByteFill | 16 | @FillWith @UInt8 |
17 | public byte[] bytes; | 17 | public byte[] bytes; |
18 | } | 18 | } |
19 | 19 | ||
diff --git a/test/org/gnunet/construct/FillParserTest.java b/test/org/gnunet/construct/FillParserTest.java new file mode 100644 index 0000000..115b567 --- /dev/null +++ b/test/org/gnunet/construct/FillParserTest.java | |||
@@ -0,0 +1,37 @@ | |||
1 | package org.gnunet.construct; | ||
2 | |||
3 | import junit.framework.Assert; | ||
4 | import org.junit.Test; | ||
5 | |||
6 | /** | ||
7 | * ... | ||
8 | * | ||
9 | * @author Florian Dold | ||
10 | */ | ||
11 | public class FillParserTest { | ||
12 | |||
13 | public static class FillTestMessage implements Message { | ||
14 | @FrameSize | ||
15 | @UInt32 | ||
16 | public int size; | ||
17 | @FillWith | ||
18 | public StringTuple[] strings; | ||
19 | } | ||
20 | |||
21 | @Test | ||
22 | public void test_fillParser() { | ||
23 | FillTestMessage m = new FillTestMessage(); | ||
24 | m.strings = new StringTuple[]{new StringTuple("foo", "bar"), new StringTuple("quux", "spam")}; | ||
25 | Construct.patch(m); | ||
26 | System.out.println(m.size); | ||
27 | byte[] data = Construct.toBinary(m); | ||
28 | Assert.assertEquals(m.size, data.length); | ||
29 | |||
30 | FillTestMessage m2 = Construct.parseAs(data, FillTestMessage.class); | ||
31 | |||
32 | Assert.assertEquals(m.strings.length, m2.strings.length); | ||
33 | |||
34 | Assert.assertEquals(m.strings[0], m2.strings[0]); | ||
35 | Assert.assertEquals(m.strings[1], m2.strings[1]); | ||
36 | } | ||
37 | } | ||
diff --git a/test/org/gnunet/construct/FixedSizeTest.java b/test/org/gnunet/construct/FixedSizeTest.java new file mode 100644 index 0000000..573e120 --- /dev/null +++ b/test/org/gnunet/construct/FixedSizeTest.java | |||
@@ -0,0 +1,52 @@ | |||
1 | package org.gnunet.construct; | ||
2 | |||
3 | import junit.framework.Assert; | ||
4 | import org.junit.Test; | ||
5 | |||
6 | /** | ||
7 | * ... | ||
8 | * | ||
9 | * @author Florian Dold | ||
10 | */ | ||
11 | public class FixedSizeTest { | ||
12 | |||
13 | public static class Msg implements Message { | ||
14 | @UInt8 | ||
15 | public int v; | ||
16 | |||
17 | public Msg() { | ||
18 | // default ctor required by Construct | ||
19 | } | ||
20 | |||
21 | public Msg(int v) { | ||
22 | this.v = v; | ||
23 | } | ||
24 | } | ||
25 | |||
26 | public static class FixedSizeTestMessage implements Message { | ||
27 | @FixedSizeArray(length = 4) | ||
28 | public Msg[] msgs; | ||
29 | } | ||
30 | |||
31 | |||
32 | @Test | ||
33 | public void test_fixedNested() { | ||
34 | FixedSizeTestMessage m = new FixedSizeTestMessage(); | ||
35 | m.msgs = new Msg[]{new Msg(1), new Msg(2), new Msg(3), new Msg(4)}; | ||
36 | byte[] bytes = Construct.toBinary(m); | ||
37 | |||
38 | FixedSizeTestMessage m2 = Construct.parseAs(bytes, FixedSizeTestMessage.class); | ||
39 | |||
40 | Assert.assertEquals(m.msgs[0].v, m2.msgs[0].v); | ||
41 | Assert.assertEquals(m.msgs[1].v, m2.msgs[1].v); | ||
42 | Assert.assertEquals(m.msgs[2].v, m2.msgs[2].v); | ||
43 | Assert.assertEquals(m.msgs[3].v, m2.msgs[3].v); | ||
44 | } | ||
45 | |||
46 | @Test(expected = AssertionError.class) | ||
47 | public void test_sizeMismatch() { | ||
48 | FixedSizeTestMessage m = new FixedSizeTestMessage(); | ||
49 | m.msgs = new Msg[]{new Msg(1), new Msg(2)}; | ||
50 | byte[] bytes = Construct.toBinary(m); | ||
51 | } | ||
52 | } | ||
diff --git a/test/org/gnunet/construct/FrameSizeTest.java b/test/org/gnunet/construct/FrameSizeTest.java new file mode 100644 index 0000000..dcce5de --- /dev/null +++ b/test/org/gnunet/construct/FrameSizeTest.java | |||
@@ -0,0 +1,50 @@ | |||
1 | package org.gnunet.construct; | ||
2 | |||
3 | import junit.framework.Assert; | ||
4 | import org.gnunet.util.GnunetMessage; | ||
5 | import org.junit.Test; | ||
6 | |||
7 | /** | ||
8 | * ... | ||
9 | * | ||
10 | * @author Florian Dold | ||
11 | */ | ||
12 | public class FrameSizeTest { | ||
13 | public static class CoordMessage implements Message { | ||
14 | @FrameSize | ||
15 | @UInt32 | ||
16 | public int size; | ||
17 | @UInt32 | ||
18 | public int x; | ||
19 | @UInt8 | ||
20 | public int y; | ||
21 | } | ||
22 | |||
23 | public static class RecursiveMessage implements Message { | ||
24 | @FrameSize | ||
25 | @UInt32 | ||
26 | public int size; | ||
27 | |||
28 | @ZeroTerminatedString | ||
29 | public String data; | ||
30 | |||
31 | @NestedMessage(newFrame = true, optional = true) | ||
32 | public RecursiveMessage rec; | ||
33 | |||
34 | } | ||
35 | |||
36 | @Test | ||
37 | public void test_simple() { | ||
38 | CoordMessage m = new CoordMessage(); | ||
39 | Construct.patch(m); | ||
40 | Assert.assertEquals(9, m.size); | ||
41 | } | ||
42 | |||
43 | |||
44 | //@Test | ||
45 | public void test_recursive_1() { | ||
46 | RecursiveMessage rm = new RecursiveMessage(); | ||
47 | rm.data = "foo"; | ||
48 | Construct.patch(rm); | ||
49 | } | ||
50 | } | ||
diff --git a/test/org/gnunet/construct/QueryMessage.java b/test/org/gnunet/construct/QueryMessage.java index 2accd42..4bf9af5 100644 --- a/test/org/gnunet/construct/QueryMessage.java +++ b/test/org/gnunet/construct/QueryMessage.java | |||
@@ -26,6 +26,6 @@ public class QueryMessage implements Message { | |||
26 | @UInt8 | 26 | @UInt8 |
27 | public int query; | 27 | public int query; |
28 | 28 | ||
29 | @ByteFill | 29 | @FillWith @UInt8 |
30 | public byte[] varsize; | 30 | public byte[] varsize; |
31 | } | 31 | } |
diff --git a/test/org/gnunet/construct/SendMessageTest.java b/test/org/gnunet/construct/SendMessageTest.java new file mode 100644 index 0000000..b95cc78 --- /dev/null +++ b/test/org/gnunet/construct/SendMessageTest.java | |||
@@ -0,0 +1,34 @@ | |||
1 | package org.gnunet.construct; | ||
2 | |||
3 | import org.gnunet.core.SendMessage; | ||
4 | import org.gnunet.util.AbsoluteTime; | ||
5 | import org.gnunet.util.GnunetMessage; | ||
6 | import org.gnunet.util.PeerIdentity; | ||
7 | import org.gnunet.util.TestMessage; | ||
8 | import org.junit.Test; | ||
9 | |||
10 | /** | ||
11 | * Regression test for a message class in org.gnunet.core | ||
12 | * | ||
13 | * todo: should this test be really here? | ||
14 | * | ||
15 | * @author Florian Dold | ||
16 | */ | ||
17 | public class SendMessageTest { | ||
18 | |||
19 | @Test | ||
20 | public void test_patch() { | ||
21 | SendMessage m = new SendMessage(); | ||
22 | m.deadline = AbsoluteTime.FOREVER.asMessage(); | ||
23 | m.peer = new PeerIdentity(); // null identity | ||
24 | m.payloadMessage = new GnunetMessage(); | ||
25 | m.payloadMessage.body = new TestMessage(); | ||
26 | m.payloadMessage.header = new GnunetMessage.Header(); | ||
27 | |||
28 | GnunetMessage container = new GnunetMessage(); | ||
29 | container.body = m; | ||
30 | container.header = new GnunetMessage.Header(); | ||
31 | |||
32 | Construct.patch(container); | ||
33 | } | ||
34 | } | ||
diff --git a/test/org/gnunet/construct/SimpleTestMessage.java b/test/org/gnunet/construct/SimpleTestMessage.java deleted file mode 100644 index e55b3b0..0000000 --- a/test/org/gnunet/construct/SimpleTestMessage.java +++ /dev/null | |||
@@ -1,36 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2011, 2012 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | package org.gnunet.construct; | ||
22 | |||
23 | public class SimpleTestMessage implements Message { | ||
24 | |||
25 | @UInt8 | ||
26 | public short v1; | ||
27 | |||
28 | @UInt8 | ||
29 | public short v2; | ||
30 | |||
31 | @NestedMessage | ||
32 | public SimpleTestMessage2 mn; | ||
33 | |||
34 | @FixedSizeArray(length=5) | ||
35 | public SimpleTestMessage2[] mns; | ||
36 | } | ||
diff --git a/test/org/gnunet/construct/SimpleTestMessage2.java b/test/org/gnunet/construct/SimpleTestMessage2.java deleted file mode 100644 index a6433d6..0000000 --- a/test/org/gnunet/construct/SimpleTestMessage2.java +++ /dev/null | |||
@@ -1,29 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2011, 2012 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | package org.gnunet.construct; | ||
22 | |||
23 | //@MessageId(321) | ||
24 | public class SimpleTestMessage2 implements Message { | ||
25 | |||
26 | @UInt32 | ||
27 | public long value; | ||
28 | |||
29 | } | ||
diff --git a/test/org/gnunet/construct/SizeTestMessage.java b/test/org/gnunet/construct/SizeTestMessage.java deleted file mode 100644 index 4710ede..0000000 --- a/test/org/gnunet/construct/SizeTestMessage.java +++ /dev/null | |||
@@ -1,34 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2011, 2012 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | package org.gnunet.construct; | ||
22 | |||
23 | public class SizeTestMessage implements Message { | ||
24 | |||
25 | @FrameSize | ||
26 | @UInt16 | ||
27 | public long totalSize; | ||
28 | |||
29 | @UInt16 | ||
30 | public long someValue; | ||
31 | |||
32 | @ByteFill | ||
33 | public byte[] rest; | ||
34 | } | ||
diff --git a/test/org/gnunet/construct/StringTest.java b/test/org/gnunet/construct/StringTest.java new file mode 100644 index 0000000..7839f8b --- /dev/null +++ b/test/org/gnunet/construct/StringTest.java | |||
@@ -0,0 +1,50 @@ | |||
1 | package org.gnunet.construct; | ||
2 | |||
3 | import junit.framework.Assert; | ||
4 | import org.junit.Test; | ||
5 | |||
6 | /** | ||
7 | * ... | ||
8 | * | ||
9 | * @author Florian Dold | ||
10 | */ | ||
11 | public class StringTest { | ||
12 | public static class StrMsg implements Message { | ||
13 | @FrameSize | ||
14 | @UInt32 | ||
15 | public int len; | ||
16 | @ZeroTerminatedString(optional = false) | ||
17 | public String str1; | ||
18 | @ZeroTerminatedString(optional = true) | ||
19 | public String str2; | ||
20 | } | ||
21 | |||
22 | |||
23 | @Test | ||
24 | public void test_empty() { | ||
25 | StrMsg m = new StrMsg(); | ||
26 | m.str1 = ""; | ||
27 | m.str2 = ""; | ||
28 | Construct.patch(m); | ||
29 | byte[] data = Construct.toBinary(m); | ||
30 | Assert.assertEquals(4+1+1, data.length); | ||
31 | StrMsg m2 = Construct.parseAs(data, StrMsg.class); | ||
32 | Assert.assertEquals("", m2.str1); | ||
33 | Assert.assertEquals("", m2.str2); | ||
34 | } | ||
35 | |||
36 | @Test | ||
37 | public void test_null() { | ||
38 | StrMsg m = new StrMsg(); | ||
39 | m.str1 = ""; | ||
40 | m.str2 = null; | ||
41 | Construct.patch(m); | ||
42 | byte[] data = Construct.toBinary(m); | ||
43 | Assert.assertEquals(4+1, data.length); | ||
44 | Assert.assertEquals(4+1, m.len); | ||
45 | StrMsg m2 = Construct.parseAs(data, StrMsg.class); | ||
46 | Assert.assertEquals("", m2.str1); | ||
47 | Assert.assertEquals(null, m2.str2); | ||
48 | } | ||
49 | } | ||
50 | |||
diff --git a/test/org/gnunet/construct/StringTuple.java b/test/org/gnunet/construct/StringTuple.java new file mode 100644 index 0000000..085b7a9 --- /dev/null +++ b/test/org/gnunet/construct/StringTuple.java | |||
@@ -0,0 +1,29 @@ | |||
1 | package org.gnunet.construct; | ||
2 | |||
3 | /** | ||
4 | * ... | ||
5 | * | ||
6 | * @author Florian Dold | ||
7 | */ | ||
8 | public class StringTuple implements Message { | ||
9 | @ZeroTerminatedString | ||
10 | public String str1; | ||
11 | @ZeroTerminatedString | ||
12 | public String str2; | ||
13 | |||
14 | public StringTuple() { | ||
15 | // empty default ctor needed by Construct | ||
16 | } | ||
17 | public StringTuple(String str1, String str2) { | ||
18 | this.str1 = str1; | ||
19 | this.str2 = str2; | ||
20 | } | ||
21 | @Override | ||
22 | public boolean equals(Object other) { | ||
23 | if (!(other instanceof StringTuple)) { | ||
24 | return false; | ||
25 | } | ||
26 | StringTuple otherT = (StringTuple) other; | ||
27 | return otherT.str1.equals(this.str1) && otherT.str2.equals(this.str2); | ||
28 | } | ||
29 | } | ||
diff --git a/test/org/gnunet/construct/VarTestMessage.java b/test/org/gnunet/construct/VarTestMessage.java deleted file mode 100644 index 25e5bbc..0000000 --- a/test/org/gnunet/construct/VarTestMessage.java +++ /dev/null | |||
@@ -1,29 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2011, 2012 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | package org.gnunet.construct; | ||
22 | |||
23 | public class VarTestMessage implements Message { | ||
24 | @UInt16 | ||
25 | public long length; | ||
26 | |||
27 | @VariableSizeArray(lengthField="length") | ||
28 | public SimpleTestMessage2[] msgs; | ||
29 | } | ||
diff --git a/test/org/gnunet/construct/VariableSizeArrayTest.java b/test/org/gnunet/construct/VariableSizeArrayTest.java new file mode 100644 index 0000000..f1d19c1 --- /dev/null +++ b/test/org/gnunet/construct/VariableSizeArrayTest.java | |||
@@ -0,0 +1,33 @@ | |||
1 | package org.gnunet.construct; | ||
2 | |||
3 | import junit.framework.Assert; | ||
4 | import org.junit.Test; | ||
5 | |||
6 | /** | ||
7 | * ... | ||
8 | * | ||
9 | * @author Florian Dold | ||
10 | */ | ||
11 | public class VariableSizeArrayTest { | ||
12 | public static class VariableTestMessage implements Message { | ||
13 | @UInt32 | ||
14 | public int num; | ||
15 | @VariableSizeArray(lengthField = "num") | ||
16 | public StringTuple[] msgs; | ||
17 | } | ||
18 | |||
19 | @Test | ||
20 | public void test_variableSizeArray() { | ||
21 | VariableTestMessage m = new VariableTestMessage(); | ||
22 | m.msgs = new StringTuple[]{new StringTuple("foo", "bar"), new StringTuple("quux", "baz"), new StringTuple("spam", "eggs")}; | ||
23 | Construct.patch(m); | ||
24 | Assert.assertEquals(3, m.num); | ||
25 | byte[] data = Construct.toBinary(m); | ||
26 | VariableTestMessage m2 = Construct.parseAs(data, VariableTestMessage.class); | ||
27 | Assert.assertEquals(m2.num, 3); | ||
28 | Assert.assertEquals(m.msgs[0], m2.msgs[0]); | ||
29 | Assert.assertEquals(m.msgs[1], m2.msgs[1]); | ||
30 | Assert.assertEquals(m.msgs[2], m2.msgs[2]); | ||
31 | |||
32 | } | ||
33 | } | ||
diff --git a/test/org/gnunet/core/CoreTest.java b/test/org/gnunet/core/CoreTest.java index e4a9142..5e066ed 100644 --- a/test/org/gnunet/core/CoreTest.java +++ b/test/org/gnunet/core/CoreTest.java | |||
@@ -26,18 +26,15 @@ import org.gnunet.testing.TestingSubsystem; | |||
26 | import org.gnunet.util.*; | 26 | import org.gnunet.util.*; |
27 | import org.grothoff.Runabout; | 27 | import org.grothoff.Runabout; |
28 | import org.junit.Assert; | 28 | import org.junit.Assert; |
29 | import org.junit.Ignore; | ||
30 | import org.junit.Test; | 29 | import org.junit.Test; |
31 | 30 | ||
32 | import static org.junit.Assert.assertTrue; | 31 | import static org.junit.Assert.assertTrue; |
33 | 32 | ||
34 | public class CoreTest { | 33 | public class CoreTest { |
35 | TestingSetup testing = new TestingSetup(); | ||
36 | |||
37 | @Test(timeout = 500) | 34 | @Test(timeout = 500) |
38 | public void test_core_init() { | 35 | public void test_core_init() { |
39 | 36 | ||
40 | TestingSubsystem ts = testing.startSubsystem("core"); | 37 | TestingSubsystem ts = new TestingSubsystem("core"); |
41 | 38 | ||
42 | final Wrapper<Boolean> res = new Wrapper<Boolean>(false); | 39 | final Wrapper<Boolean> res = new Wrapper<Boolean>(false); |
43 | 40 | ||
@@ -68,13 +65,13 @@ public class CoreTest { | |||
68 | @Test(timeout = 5000) | 65 | @Test(timeout = 5000) |
69 | public void test_core_echo() { | 66 | public void test_core_echo() { |
70 | 67 | ||
71 | TestingSubsystem ts = testing.startSubsystem("core"); | 68 | TestingSubsystem ts = new TestingSubsystem("core"); |
72 | 69 | ||
73 | final Wrapper<Boolean> gotResponse = new Wrapper<Boolean>(false); | 70 | final Wrapper<Boolean> gotResponse = new Wrapper<Boolean>(false); |
74 | 71 | ||
75 | final Core core = new Core(ts.getConfiguration()); | 72 | final Core core = new Core(ts.getConfiguration()); |
76 | core.setMessageHandler(new Runabout() { | 73 | core.setMessageHandler(new Runabout() { |
77 | public void visit(TESTMessage t) { | 74 | public void visit(TestMessage t) { |
78 | gotResponse.set(true); | 75 | gotResponse.set(true); |
79 | core.disconnect(); | 76 | core.disconnect(); |
80 | } | 77 | } |
@@ -86,7 +83,7 @@ public class CoreTest { | |||
86 | core.notifyTransmitReady(0, RelativeTime.FOREVER, myIdentity, 4, new MessageTransmitter() { | 83 | core.notifyTransmitReady(0, RelativeTime.FOREVER, myIdentity, 4, new MessageTransmitter() { |
87 | @Override | 84 | @Override |
88 | public void transmit(Connection.MessageSink sink) { | 85 | public void transmit(Connection.MessageSink sink) { |
89 | sink.send(new TESTMessage()); | 86 | sink.send(new TestMessage()); |
90 | } | 87 | } |
91 | 88 | ||
92 | @Override | 89 | @Override |
diff --git a/test/org/gnunet/dht/DHTTest.java b/test/org/gnunet/dht/DHTTest.java index b684aef..6c93356 100644 --- a/test/org/gnunet/dht/DHTTest.java +++ b/test/org/gnunet/dht/DHTTest.java | |||
@@ -33,9 +33,7 @@ public class DHTTest { | |||
33 | public void test_dht_put() { | 33 | public void test_dht_put() { |
34 | final Wrapper<Boolean> putFinished = new Wrapper<Boolean>(true); | 34 | final Wrapper<Boolean> putFinished = new Wrapper<Boolean>(true); |
35 | 35 | ||
36 | TestingSetup testing = new TestingSetup(); | 36 | TestingSubsystem ts = new TestingSubsystem("dht"); |
37 | |||
38 | TestingSubsystem ts = testing.startSubsystem("dht"); | ||
39 | 37 | ||
40 | final DistributedHashTable dht = new DistributedHashTable(ts.getConfiguration()); | 38 | final DistributedHashTable dht = new DistributedHashTable(ts.getConfiguration()); |
41 | dht.put(new HashCode("gnj-test"), new byte[]{1, 2, 3}, 1, EnumSet.noneOf(RouteOption.class), | 39 | dht.put(new HashCode("gnj-test"), new byte[]{1, 2, 3}, 1, EnumSet.noneOf(RouteOption.class), |
diff --git a/test/org/nse/NSETest.java b/test/org/gnunet/nse/NSETest.java index 47e4448..c3e6512 100644 --- a/test/org/nse/NSETest.java +++ b/test/org/gnunet/nse/NSETest.java | |||
@@ -18,9 +18,8 @@ | |||
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | package org.nse; | 21 | package org.gnunet.nse; |
22 | 22 | ||
23 | import org.gnunet.nse.NetworkSizeEstimation; | ||
24 | import org.gnunet.testing.TestingSetup; | 23 | import org.gnunet.testing.TestingSetup; |
25 | import org.gnunet.testing.TestingSubsystem; | 24 | import org.gnunet.testing.TestingSubsystem; |
26 | import org.gnunet.util.AbsoluteTime; | 25 | import org.gnunet.util.AbsoluteTime; |
@@ -38,8 +37,7 @@ public class NSETest { | |||
38 | @Test | 37 | @Test |
39 | public void test_nse() { | 38 | public void test_nse() { |
40 | final Wrapper<Boolean> gotResult = new Wrapper<Boolean>(false); | 39 | final Wrapper<Boolean> gotResult = new Wrapper<Boolean>(false); |
41 | TestingSetup testing = new TestingSetup(); | 40 | TestingSubsystem ts = new TestingSubsystem("nse"); |
42 | TestingSubsystem ts = testing.startSubsystem("nse"); | ||
43 | 41 | ||
44 | final NetworkSizeEstimation nse = new NetworkSizeEstimation(ts.getConfiguration()); | 42 | final NetworkSizeEstimation nse = new NetworkSizeEstimation(ts.getConfiguration()); |
45 | nse.subscribe(new NetworkSizeEstimation.Subscriber() { | 43 | nse.subscribe(new NetworkSizeEstimation.Subscriber() { |
diff --git a/test/org/gnunet/statistics/StatisticsTest.java b/test/org/gnunet/statistics/StatisticsTest.java index ddba478..780a2e1 100644 --- a/test/org/gnunet/statistics/StatisticsTest.java +++ b/test/org/gnunet/statistics/StatisticsTest.java | |||
@@ -27,9 +27,6 @@ import org.gnunet.util.*; | |||
27 | import org.junit.Test; | 27 | import org.junit.Test; |
28 | 28 | ||
29 | public class StatisticsTest { | 29 | public class StatisticsTest { |
30 | TestingSetup testing = new TestingSetup(); | ||
31 | |||
32 | |||
33 | public interface Next { | 30 | public interface Next { |
34 | void next(); | 31 | void next(); |
35 | } | 32 | } |
@@ -64,7 +61,8 @@ public class StatisticsTest { | |||
64 | 61 | ||
65 | @Test(timeout = 1000) | 62 | @Test(timeout = 1000) |
66 | public void test_simple() { | 63 | public void test_simple() { |
67 | final TestingSubsystem ts = testing.startSubsystem("statistics"); | 64 | Program.configureLogging("DEBUG", null); |
65 | final TestingSubsystem ts = new TestingSubsystem("statistics"); | ||
68 | 66 | ||
69 | final Statistics stat = new Statistics(ts.getConfiguration()); | 67 | final Statistics stat = new Statistics(ts.getConfiguration()); |
70 | 68 | ||
@@ -97,7 +95,7 @@ public class StatisticsTest { | |||
97 | 95 | ||
98 | @Test(timeout = 1000) | 96 | @Test(timeout = 1000) |
99 | public void test_statistics_get_set() { | 97 | public void test_statistics_get_set() { |
100 | final TestingSubsystem ts = testing.startSubsystem("statistics"); | 98 | final TestingSubsystem ts = new TestingSubsystem("statistics"); |
101 | 99 | ||
102 | final AssertionList assertions = new AssertionList(); | 100 | final AssertionList assertions = new AssertionList(); |
103 | 101 | ||
@@ -149,7 +147,7 @@ public class StatisticsTest { | |||
149 | 147 | ||
150 | @Test(timeout = 1000) | 148 | @Test(timeout = 1000) |
151 | public void test_watch() { | 149 | public void test_watch() { |
152 | final TestingSubsystem ts = testing.startSubsystem("statistics"); | 150 | final TestingSubsystem ts = new TestingSubsystem("statistics"); |
153 | 151 | ||
154 | final Wrapper<Integer> updates = new Wrapper<Integer>(0); | 152 | final Wrapper<Integer> updates = new Wrapper<Integer>(0); |
155 | 153 | ||
diff --git a/test/org/gnunet/testing/TestingSetupTest.java b/test/org/gnunet/testing/TestingSetupTest.java index b23b543..2bfe0ae 100644 --- a/test/org/gnunet/testing/TestingSetupTest.java +++ b/test/org/gnunet/testing/TestingSetupTest.java | |||
@@ -29,8 +29,7 @@ public class TestingSetupTest { | |||
29 | @Test(timeout = 1000) | 29 | @Test(timeout = 1000) |
30 | public void test_testing() { | 30 | public void test_testing() { |
31 | // could be any service, just use statistics | 31 | // could be any service, just use statistics |
32 | TestingSetup testing = new TestingSetup(); | 32 | TestingSubsystem ts = new TestingSubsystem("statistics"); |
33 | TestingSubsystem ts = testing.startSubsystem("statistics"); | ||
34 | String port = ts.getConfiguration().getValueString("statistics", "PORT"); | 33 | String port = ts.getConfiguration().getValueString("statistics", "PORT"); |
35 | org.junit.Assert.assertTrue(port != null); | 34 | org.junit.Assert.assertTrue(port != null); |
36 | 35 | ||
@@ -39,16 +38,13 @@ public class TestingSetupTest { | |||
39 | 38 | ||
40 | @Test(expected = TestingSetup.SetupException.class) | 39 | @Test(expected = TestingSetup.SetupException.class) |
41 | public void test_no_service() { | 40 | public void test_no_service() { |
42 | TestingSetup testing = new TestingSetup(); | 41 | new TestingSubsystem("foobar _ !!!"); |
43 | testing.startSubsystem("foobar _ !!!"); | ||
44 | } | 42 | } |
45 | 43 | ||
46 | @Test(timeout = 1000) | 44 | @Test(timeout = 1000) |
47 | public void test_restart() { | 45 | public void test_restart() { |
48 | // could be any service, just use statistics | 46 | TestingSubsystem ts = new TestingSubsystem("statistics"); |
49 | TestingSetup testing = new TestingSetup(); | 47 | ts.restart(); |
50 | TestingSubsystem ts = testing.startSubsystem("statistics"); | ||
51 | //ts.restart(); | ||
52 | ts.destroy(); | 48 | ts.destroy(); |
53 | } | 49 | } |
54 | } | 50 | } |
diff --git a/test/org/gnunet/util/ClientServerTest.java b/test/org/gnunet/util/ClientServerTest.java index f073a3c..f8b5d4e 100644 --- a/test/org/gnunet/util/ClientServerTest.java +++ b/test/org/gnunet/util/ClientServerTest.java | |||
@@ -1,10 +1,16 @@ | |||
1 | package org.gnunet.util; | 1 | package org.gnunet.util; |
2 | 2 | ||
3 | import com.google.common.collect.Lists; | ||
4 | import org.gnunet.construct.UInt32; | ||
5 | import org.gnunet.construct.UnionCase; | ||
3 | import org.gnunet.testing.TestingServer; | 6 | import org.gnunet.testing.TestingServer; |
4 | import org.gnunet.testing.TestingSetup; | 7 | import org.gnunet.testing.TestingSetup; |
5 | import org.junit.Assert; | 8 | import org.junit.Assert; |
6 | import org.junit.Test; | 9 | import org.junit.Test; |
7 | 10 | ||
11 | import java.net.*; | ||
12 | import java.util.ArrayList; | ||
13 | |||
8 | /** | 14 | /** |
9 | * ... | 15 | * ... |
10 | * | 16 | * |
@@ -12,20 +18,26 @@ import org.junit.Test; | |||
12 | */ | 18 | */ |
13 | public class ClientServerTest { | 19 | public class ClientServerTest { |
14 | 20 | ||
21 | @Test | ||
22 | public void test_start_stop() { | ||
23 | Program.configureLogging("DEBUG", null); | ||
24 | final TestingServer srv = new TestingServer(); | ||
25 | srv.server.stopListening(); | ||
26 | } | ||
27 | |||
15 | /** | 28 | /** |
16 | * Test if the server receives a message sent by a client. | 29 | * Test if the server receives a message sent by a client. |
17 | */ | 30 | */ |
18 | @Test(timeout = 1000) | 31 | @Test |
19 | public void test_testing_server() { | 32 | public void test_testing_server() { |
20 | final TestingSetup setup = new TestingSetup(); | ||
21 | Program.configureLogging("DEBUG", null); | 33 | Program.configureLogging("DEBUG", null); |
22 | 34 | ||
23 | final TestingServer srv = setup.createServer(); | 35 | final TestingServer srv = new TestingServer(); |
24 | 36 | ||
25 | final Wrapper<Boolean> gotMessage = new Wrapper<Boolean>(false); | 37 | final Wrapper<Boolean> gotMessage = new Wrapper<Boolean>(false); |
26 | 38 | ||
27 | srv.server.setHandler(new Server.MessageRunabout() { | 39 | srv.server.setHandler(new Server.MessageRunabout() { |
28 | public void visit(TESTMessage tm) { | 40 | public void visit(TestMessage tm) { |
29 | gotMessage.set(true); | 41 | gotMessage.set(true); |
30 | srv.server.destroy(); | 42 | srv.server.destroy(); |
31 | } | 43 | } |
@@ -39,7 +51,7 @@ public class ClientServerTest { | |||
39 | @Override | 51 | @Override |
40 | public void transmit(Connection.MessageSink sink) { | 52 | public void transmit(Connection.MessageSink sink) { |
41 | System.out.println("ntr!"); | 53 | System.out.println("ntr!"); |
42 | sink.send(new TESTMessage()); | 54 | sink.send(new TestMessage()); |
43 | } | 55 | } |
44 | 56 | ||
45 | @Override | 57 | @Override |
@@ -57,13 +69,12 @@ public class ClientServerTest { | |||
57 | 69 | ||
58 | /** | 70 | /** |
59 | * Test what happens when a client calls notifyTransmitReady, but does not send | 71 | * Test what happens when a client calls notifyTransmitReady, but does not send |
60 | * a message in the callback but disconnects. | 72 | * a message in the callback and disconnects. |
61 | */ | 73 | */ |
62 | @Test(timeout = 1000) | 74 | @Test(timeout = 1000) |
63 | public void test_premature_disconnect() { | 75 | public void test_premature_disconnect() { |
64 | final TestingSetup setup = new TestingSetup(); | ||
65 | Program.configureLogging("DEBUG", null); | 76 | Program.configureLogging("DEBUG", null); |
66 | final TestingServer srv = setup.createServer(); | 77 | final TestingServer srv = new TestingServer(); |
67 | 78 | ||
68 | srv.server.notifyDisconnect(new Server.DisconnectHandler() { | 79 | srv.server.notifyDisconnect(new Server.DisconnectHandler() { |
69 | @Override | 80 | @Override |
@@ -79,7 +90,7 @@ public class ClientServerTest { | |||
79 | cli.notifyTransmitReady(RelativeTime.FOREVER,true, 0, new MessageTransmitter() { | 90 | cli.notifyTransmitReady(RelativeTime.FOREVER,true, 0, new MessageTransmitter() { |
80 | @Override | 91 | @Override |
81 | public void transmit(Connection.MessageSink sink) { | 92 | public void transmit(Connection.MessageSink sink) { |
82 | sink.send(new TESTMessage()); | 93 | sink.send(new TestMessage()); |
83 | cli.disconnect(); | 94 | cli.disconnect(); |
84 | } | 95 | } |
85 | 96 | ||
@@ -91,4 +102,146 @@ public class ClientServerTest { | |||
91 | } | 102 | } |
92 | }); | 103 | }); |
93 | } | 104 | } |
105 | |||
106 | |||
107 | @Test | ||
108 | public void test_receiveDone() { | ||
109 | Program.configureLogging("DEBUG", null); | ||
110 | final TestingServer srv = new TestingServer(); | ||
111 | |||
112 | final Wrapper<Integer> msgCount = new Wrapper<Integer>(0); | ||
113 | |||
114 | srv.server.setHandler(new Server.MessageRunabout() { | ||
115 | public void visit(TestMessage tm) { | ||
116 | msgCount.set(msgCount.get() + 1); | ||
117 | if (msgCount.get() == 3) { | ||
118 | getSender().receiveDone(false); | ||
119 | srv.server.stopListening(); | ||
120 | } else { | ||
121 | getSender().receiveDone(true); | ||
122 | } | ||
123 | } | ||
124 | }); | ||
125 | |||
126 | Scheduler.run(new Scheduler.Task() { | ||
127 | @Override | ||
128 | public void run(Scheduler.RunContext ctx) { | ||
129 | final Client cli = srv.createClient(); | ||
130 | |||
131 | cli.transmitWhenReady(RelativeTime.FOREVER, new TestMessage(), new Continuation() { | ||
132 | @Override | ||
133 | public void cont(boolean success) { | ||
134 | cli.transmitWhenReady(RelativeTime.FOREVER, new TestMessage(), new Continuation() { | ||
135 | @Override | ||
136 | public void cont(boolean success) { | ||
137 | cli.transmitWhenReady(RelativeTime.FOREVER, new TestMessage(), null); | ||
138 | } | ||
139 | }); | ||
140 | } | ||
141 | }); | ||
142 | } | ||
143 | }); | ||
144 | } | ||
145 | |||
146 | @Test | ||
147 | public void test_acceptFromAddresses() { | ||
148 | Program.configureLogging("DEBUG", null); | ||
149 | |||
150 | InetAddress localhost = null; | ||
151 | try { | ||
152 | localhost = Inet4Address.getLocalHost(); | ||
153 | } catch (UnknownHostException e) { | ||
154 | Assert.fail(); | ||
155 | } | ||
156 | |||
157 | // does this work on all operating systems? | ||
158 | SocketAddress addr = new InetSocketAddress(localhost, 0); | ||
159 | |||
160 | Server server = new Server(Lists.newArrayList(addr), RelativeTime.FOREVER, false); | ||
161 | |||
162 | server.destroy(); | ||
163 | |||
164 | } | ||
165 | |||
166 | |||
167 | @Test | ||
168 | public void test_keep_drop() { | ||
169 | Program.configureLogging("DEBUG", null); | ||
170 | final TestingServer srv = new TestingServer(); | ||
171 | |||
172 | final Wrapper<Integer> msgCount = new Wrapper<Integer>(0); | ||
173 | |||
174 | |||
175 | |||
176 | srv.server.setHandler(new Server.MessageRunabout() { | ||
177 | public void visit(TestMessage tm) { | ||
178 | srv.server.stopListening(); | ||
179 | if (msgCount.get() == 0) { | ||
180 | getSender().keep(); | ||
181 | getSender().drop(); | ||
182 | getSender().receiveDone(true); | ||
183 | } else if (msgCount.get() == 1) { | ||
184 | getSender().receiveDone(false); | ||
185 | |||
186 | } else { | ||
187 | Assert.fail(); | ||
188 | } | ||
189 | |||
190 | msgCount.set(msgCount.get() + 1); | ||
191 | } | ||
192 | }); | ||
193 | |||
194 | Scheduler.run(new Scheduler.Task() { | ||
195 | @Override | ||
196 | public void run(Scheduler.RunContext ctx) { | ||
197 | final Client cli = srv.createClient(); | ||
198 | cli.transmitWhenReady(new TestMessage(), new Continuation() { | ||
199 | @Override | ||
200 | public void cont(boolean success) { | ||
201 | cli.transmitWhenReady(new TestMessage(), null); | ||
202 | } | ||
203 | }); | ||
204 | } | ||
205 | }); | ||
206 | } | ||
207 | |||
208 | |||
209 | |||
210 | /** | ||
211 | * test if markMonitor / soft shutdown works. | ||
212 | */ | ||
213 | @Test | ||
214 | public void test_monitor_clients() { | ||
215 | Program.configureLogging("DEBUG", null); | ||
216 | final TestingServer srv = new TestingServer(); | ||
217 | |||
218 | final Wrapper<Integer> msgCount = new Wrapper<Integer>(0); | ||
219 | |||
220 | srv.server.setHandler(new Server.MessageRunabout() { | ||
221 | public void visit(TestMessage tm) { | ||
222 | if (msgCount.get() == 0) { | ||
223 | getSender().markMonitor(); | ||
224 | getSender().receiveDone(true); | ||
225 | } else if (msgCount.get() == 1) { | ||
226 | srv.server.stopListening(); | ||
227 | getSender().receiveDone(false); | ||
228 | } else { | ||
229 | Assert.fail(); | ||
230 | } | ||
231 | |||
232 | msgCount.set(msgCount.get() + 1); | ||
233 | } | ||
234 | }); | ||
235 | |||
236 | Scheduler.run(new Scheduler.Task() { | ||
237 | @Override | ||
238 | public void run(Scheduler.RunContext ctx) { | ||
239 | final Client cli1 = srv.createClient(); | ||
240 | final Client cli2 = srv.createClient(); | ||
241 | |||
242 | cli1.transmitWhenReady(new TestMessage(), null); | ||
243 | cli2.transmitWhenReady(new TestMessage(), null); | ||
244 | } | ||
245 | }); | ||
246 | } | ||
94 | } | 247 | } |
diff --git a/test/org/gnunet/util/FilePipeExample.java b/test/org/gnunet/util/FilePipeExample.java index 4b72163..94696c9 100644 --- a/test/org/gnunet/util/FilePipeExample.java +++ b/test/org/gnunet/util/FilePipeExample.java | |||
@@ -13,8 +13,9 @@ import java.nio.ByteBuffer; | |||
13 | public class FilePipeExample { | 13 | public class FilePipeExample { |
14 | public static void main(String... args) { | 14 | public static void main(String... args) { |
15 | 15 | ||
16 | Program.configureLogging("DEBUG", null); | ||
16 | 17 | ||
17 | final Scheduler.FilePipe fp = Scheduler.createFilePipe(new File("test.pipe")); | 18 | final Scheduler.FilePipe fp = Scheduler.openFilePipe(new File("test.pipe")); |
18 | 19 | ||
19 | 20 | ||
20 | Scheduler.addRead(RelativeTime.FOREVER, fp.getSource(), new Scheduler.Task() { | 21 | Scheduler.addRead(RelativeTime.FOREVER, fp.getSource(), new Scheduler.Task() { |
diff --git a/test/org/gnunet/util/MeshTest.java b/test/org/gnunet/util/MeshTest.java new file mode 100644 index 0000000..919d812 --- /dev/null +++ b/test/org/gnunet/util/MeshTest.java | |||
@@ -0,0 +1,36 @@ | |||
1 | package org.gnunet.util; | ||
2 | |||
3 | import org.gnunet.mesh.Mesh; | ||
4 | import org.gnunet.testing.TestingSubsystem; | ||
5 | import org.junit.Test; | ||
6 | |||
7 | /** | ||
8 | * ... | ||
9 | * | ||
10 | * @author Florian Dold | ||
11 | */ | ||
12 | public class MeshTest { | ||
13 | |||
14 | @Test | ||
15 | public void test_tunnel_create() { | ||
16 | /* | ||
17 | Program.configureLogging("DEBUG", null); | ||
18 | TestingSubsystem ts = new TestingSubsystem("mesh"); | ||
19 | |||
20 | Mesh m = new Mesh(ts.getConfiguration(), null, null, new RunaboutMessageReceiver() { | ||
21 | public void visit(TestMessage tm) { | ||
22 | |||
23 | } | ||
24 | @Override | ||
25 | public void handleError() { | ||
26 | |||
27 | } | ||
28 | }); | ||
29 | |||
30 | m.createTunnel(null, null); | ||
31 | |||
32 | Sc | ||
33 | Sheduler.run(); | ||
34 | */ | ||
35 | } | ||
36 | } | ||
diff --git a/test/org/gnunet/util/ResolverTest.java b/test/org/gnunet/util/ResolverTest.java index 07f694a..ae56b79 100644 --- a/test/org/gnunet/util/ResolverTest.java +++ b/test/org/gnunet/util/ResolverTest.java | |||
@@ -43,9 +43,7 @@ public class ResolverTest { | |||
43 | final Wrapper<Boolean> finished1 = new Wrapper<Boolean>(true); | 43 | final Wrapper<Boolean> finished1 = new Wrapper<Boolean>(true); |
44 | final Wrapper<Boolean> finished2 = new Wrapper<Boolean>(true); | 44 | final Wrapper<Boolean> finished2 = new Wrapper<Boolean>(true); |
45 | 45 | ||
46 | TestingSetup testing = new TestingSetup(); | 46 | TestingSubsystem ts = new TestingSubsystem("resolver"); |
47 | |||
48 | TestingSubsystem ts = testing.startSubsystem("resolver"); | ||
49 | 47 | ||
50 | 48 | ||
51 | Resolver r = Resolver.getInstance(); | 49 | Resolver r = Resolver.getInstance(); |
diff --git a/test/org/gnunet/util/ServerExample.java b/test/org/gnunet/util/ServerExample.java index be74b61..a344e2a 100644 --- a/test/org/gnunet/util/ServerExample.java +++ b/test/org/gnunet/util/ServerExample.java | |||
@@ -23,7 +23,6 @@ package org.gnunet.util; | |||
23 | import java.net.InetSocketAddress; | 23 | import java.net.InetSocketAddress; |
24 | import java.net.SocketAddress; | 24 | import java.net.SocketAddress; |
25 | import java.util.Arrays; | 25 | import java.util.Arrays; |
26 | import java.util.LinkedList; | ||
27 | 26 | ||
28 | import static org.gnunet.util.Server.*; | 27 | import static org.gnunet.util.Server.*; |
29 | 28 | ||
@@ -43,13 +42,13 @@ public class ServerExample { | |||
43 | RelativeTime.MINUTE, | 42 | RelativeTime.MINUTE, |
44 | false); | 43 | false); |
45 | s.setHandler(new Server.MessageRunabout() { | 44 | s.setHandler(new Server.MessageRunabout() { |
46 | public void visit(TESTMessage tm) { | 45 | public void visit(TestMessage tm) { |
47 | System.out.println("got TEST message"); | 46 | System.out.println("got TEST message"); |
48 | final Server.ClientHandle sender = getSender(); | 47 | final Server.ClientHandle sender = getSender(); |
49 | sender.notifyTransmitReady(4, RelativeTime.FOREVER, new MessageTransmitter() { | 48 | sender.notifyTransmitReady(4, RelativeTime.FOREVER, new MessageTransmitter() { |
50 | @Override | 49 | @Override |
51 | public void transmit(Connection.MessageSink sink) { | 50 | public void transmit(Connection.MessageSink sink) { |
52 | sink.send(new TESTMessage()); | 51 | sink.send(new TestMessage()); |
53 | System.out.println("TEST message sent"); | 52 | System.out.println("TEST message sent"); |
54 | sender.receiveDone(true); | 53 | sender.receiveDone(true); |
55 | } | 54 | } |
diff --git a/test/org/gnunet/util/StringsTest.java b/test/org/gnunet/util/StringsTest.java new file mode 100644 index 0000000..49cbfe9 --- /dev/null +++ b/test/org/gnunet/util/StringsTest.java | |||
@@ -0,0 +1,20 @@ | |||
1 | package org.gnunet.util; | ||
2 | |||
3 | import org.junit.Assert; | ||
4 | import org.junit.Test; | ||
5 | |||
6 | /** | ||
7 | * ... | ||
8 | * | ||
9 | * @author Florian Dold | ||
10 | */ | ||
11 | public class StringsTest { | ||
12 | @Test | ||
13 | public void test_inverse() { | ||
14 | byte[] data = "asdfgASDD$!123".getBytes(); | ||
15 | String str = Strings.dataToString(data); | ||
16 | byte[] data2 = Strings.stringToData(str, data.length); | ||
17 | Assert.assertArrayEquals(data, data2); | ||
18 | } | ||
19 | } | ||
20 | |||
diff --git a/test/org/gnunet/util/getopt/GetoptTest.java b/test/org/gnunet/util/getopt/GetoptTest.java index 81a10a8..e60757e 100644 --- a/test/org/gnunet/util/getopt/GetoptTest.java +++ b/test/org/gnunet/util/getopt/GetoptTest.java | |||
@@ -25,8 +25,8 @@ import org.junit.Assert; | |||
25 | import org.junit.Test; | 25 | import org.junit.Test; |
26 | 26 | ||
27 | class Target { | 27 | class Target { |
28 | @Option( | 28 | @Argument( |
29 | action = OptionAction.STORE_STRING, | 29 | action = ArgumentAction.STORE_STRING, |
30 | shortname = "s", | 30 | shortname = "s", |
31 | longname = "string", | 31 | longname = "string", |
32 | argumentName = "SOME_STRING", | 32 | argumentName = "SOME_STRING", |
@@ -34,16 +34,16 @@ class Target { | |||
34 | ) | 34 | ) |
35 | String someString; | 35 | String someString; |
36 | 36 | ||
37 | @Option( | 37 | @Argument( |
38 | action = OptionAction.SET, | 38 | action = ArgumentAction.SET, |
39 | shortname = "y", | 39 | shortname = "y", |
40 | longname = "set", | 40 | longname = "set", |
41 | description = "enable, default disabled" | 41 | description = "enable, default disabled" |
42 | ) | 42 | ) |
43 | boolean set = false; | 43 | boolean set = false; |
44 | 44 | ||
45 | @Option( | 45 | @Argument( |
46 | action = OptionAction.RESET, | 46 | action = ArgumentAction.RESET, |
47 | shortname = "n", | 47 | shortname = "n", |
48 | longname = "reset", | 48 | longname = "reset", |
49 | description = "disable, default enabled" | 49 | description = "disable, default enabled" |
@@ -51,21 +51,20 @@ class Target { | |||
51 | boolean reset = true; | 51 | boolean reset = true; |
52 | 52 | ||
53 | 53 | ||
54 | @Option( | 54 | @Argument( |
55 | action = OptionAction.INCREMENT, | 55 | action = ArgumentAction.STORE_NUMBER, |
56 | shortname = "i", | ||
57 | longname = "inc", | ||
58 | description = "increment a counter" | ||
59 | ) | ||
60 | int counter = 0; | ||
61 | |||
62 | @Option( | ||
63 | action = OptionAction.STORE_NUMBER, | ||
64 | shortname = "w", | 56 | shortname = "w", |
65 | longname = "value", | 57 | longname = "value", |
66 | description = "some value" | 58 | description = "some value" |
67 | ) | 59 | ) |
68 | int intVal = 0; | 60 | int intVal = 0; |
61 | |||
62 | static int someConstant = 42; | ||
63 | } | ||
64 | |||
65 | class InvalidTarget { | ||
66 | @Argument(action = ArgumentAction.SET, shortname = "foo", longname = "bar", description = "bla bla") | ||
67 | boolean foo; | ||
69 | } | 68 | } |
70 | 69 | ||
71 | public class GetoptTest { | 70 | public class GetoptTest { |
@@ -74,12 +73,7 @@ public class GetoptTest { | |||
74 | Target t = new Target(); | 73 | Target t = new Target(); |
75 | Parser p = new Parser(t); | 74 | Parser p = new Parser(t); |
76 | 75 | ||
77 | t.someString = null; | ||
78 | 76 | ||
79 | // argument after shortopt | ||
80 | p.parse(new String[]{"-s", "foo"}); | ||
81 | Assert.assertEquals("foo", t.someString); | ||
82 | |||
83 | t.someString = null; | 77 | t.someString = null; |
84 | 78 | ||
85 | // argument directly with shortopt | 79 | // argument directly with shortopt |
@@ -88,6 +82,12 @@ public class GetoptTest { | |||
88 | 82 | ||
89 | t.someString = null; | 83 | t.someString = null; |
90 | 84 | ||
85 | // argument after shortopt | ||
86 | p.parse(new String[]{"-s", "foo"}); | ||
87 | Assert.assertEquals("foo", t.someString); | ||
88 | |||
89 | t.someString = null; | ||
90 | |||
91 | p.parse(new String[]{"--string=foo"}); | 91 | p.parse(new String[]{"--string=foo"}); |
92 | Assert.assertEquals("foo", t.someString); | 92 | Assert.assertEquals("foo", t.someString); |
93 | 93 | ||
@@ -186,6 +186,21 @@ public class GetoptTest { | |||
186 | Assert.assertArrayEquals(new String[]{"foo", "bar", "--reset", "baz"}, rest); | 186 | Assert.assertArrayEquals(new String[]{"foo", "bar", "--reset", "baz"}, rest); |
187 | } | 187 | } |
188 | 188 | ||
189 | |||
190 | @Test(expected = Parser.ArgumentError.class) | ||
191 | public void test_missingLongopt() { | ||
192 | Target t = new Target(); | ||
193 | Parser p = new Parser(t); | ||
194 | p.parse(new String[]{"--foobar"}); | ||
195 | } | ||
196 | |||
197 | @Test(expected = Parser.ArgumentError.class) | ||
198 | public void test_missingShortopt_1() { | ||
199 | Target t = new Target(); | ||
200 | Parser p = new Parser(t); | ||
201 | p.parse(new String[]{"-x"}); | ||
202 | } | ||
203 | |||
189 | @Test | 204 | @Test |
190 | public void test_long() { | 205 | public void test_long() { |
191 | Target t = new Target(); | 206 | Target t = new Target(); |
@@ -196,6 +211,9 @@ public class GetoptTest { | |||
196 | rest = p.parse(new String[]{"-w5"}); | 211 | rest = p.parse(new String[]{"-w5"}); |
197 | Assert.assertEquals(5, t.intVal); | 212 | Assert.assertEquals(5, t.intVal); |
198 | 213 | ||
214 | rest = p.parse(new String[]{"-w", "5"}); | ||
215 | Assert.assertEquals(5, t.intVal); | ||
216 | |||
199 | rest = p.parse(new String[]{"--value=6"}); | 217 | rest = p.parse(new String[]{"--value=6"}); |
200 | Assert.assertEquals(6, t.intVal); | 218 | Assert.assertEquals(6, t.intVal); |
201 | 219 | ||
@@ -213,4 +231,57 @@ public class GetoptTest { | |||
213 | } | 231 | } |
214 | Assert.assertTrue(thrown); | 232 | Assert.assertTrue(thrown); |
215 | } | 233 | } |
234 | |||
235 | |||
236 | @Test(expected = Parser.ArgumentError.class) | ||
237 | public void test_missingNumberArgument_short() { | ||
238 | Target t = new Target(); | ||
239 | Parser p = new Parser(t); | ||
240 | |||
241 | p.parse(new String[]{"-w"}); | ||
242 | Assert.assertEquals(5, t.intVal); | ||
243 | } | ||
244 | |||
245 | @Test(expected = Parser.ArgumentError.class) | ||
246 | public void test_missingNumberArgument_long() { | ||
247 | Target t = new Target(); | ||
248 | Parser p = new Parser(t); | ||
249 | |||
250 | |||
251 | p.parse(new String[]{"--w"}); | ||
252 | Assert.assertEquals(5, t.intVal); | ||
253 | } | ||
254 | |||
255 | |||
256 | @Test(expected = Parser.ArgumentError.class) | ||
257 | public void test_invalidNumberFormat() { | ||
258 | Target t = new Target(); | ||
259 | Parser p = new Parser(t); | ||
260 | |||
261 | String[] rest; | ||
262 | |||
263 | rest = p.parse(new String[]{"-w", "abc"}); | ||
264 | Assert.assertEquals(5, t.intVal); | ||
265 | } | ||
266 | |||
267 | |||
268 | @Test | ||
269 | public void test_dashRest() { | ||
270 | Target t = new Target(); | ||
271 | Parser p = new Parser(t); | ||
272 | |||
273 | String[] rest; | ||
274 | |||
275 | rest = p.parse(new String[]{"-w", "123", "-"}); | ||
276 | Assert.assertArrayEquals(new String[]{"-"}, rest); | ||
277 | } | ||
278 | |||
279 | |||
280 | @Test(expected = AssertionError.class) | ||
281 | public void test_invalid() { | ||
282 | InvalidTarget it = new InvalidTarget(); | ||
283 | Parser p = new Parser(it); | ||
284 | |||
285 | p.parse(new String[]{"-foo"}); | ||
286 | } | ||
216 | } | 287 | } |