aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2012-03-18 13:42:47 +0000
committerFlorian Dold <florian.dold@gmail.com>2012-03-18 13:42:47 +0000
commit91e9ff6764a701db7118b5188b35ac3b3ad7e09d (patch)
tree26a65b936c2f9275c9ac1817ec292b6859309eb8 /test
parentf7c985b8c3752516a1327e4f990c100235003422 (diff)
downloadgnunet-java-91e9ff6764a701db7118b5188b35ac3b3ad7e09d.tar.gz
gnunet-java-91e9ff6764a701db7118b5188b35ac3b3ad7e09d.zip
* refactored the Construct library to use ByteBuffer internally, some other fixes to the construct library
* clients can now handle disconnects correctly, implemented in NSE * started implementation of the DHT api
Diffstat (limited to 'test')
-rw-r--r--test/org/gnunet/construct/ConstructTest.java30
-rw-r--r--test/org/gnunet/construct/UnionTest.java10
2 files changed, 27 insertions, 13 deletions
diff --git a/test/org/gnunet/construct/ConstructTest.java b/test/org/gnunet/construct/ConstructTest.java
index a160f1b..e0e7b85 100644
--- a/test/org/gnunet/construct/ConstructTest.java
+++ b/test/org/gnunet/construct/ConstructTest.java
@@ -4,28 +4,34 @@ import org.junit.Assert;
4import org.junit.Test; 4import org.junit.Test;
5 5
6import java.math.BigInteger; 6import java.math.BigInteger;
7import java.nio.ByteBuffer;
7 8
8public class ConstructTest { 9public class ConstructTest {
9 10
10 11
11 @Test 12 @Test
12 public void test_ByteFillMessage() { 13 public void test_ByteFillMessage() {
13 System.out.println("testing ByteFillMessage");
14 14
15 ByteFillMessage bfm = new ByteFillMessage(); 15 ByteFillMessage bfm = new ByteFillMessage();
16 bfm.header = new MessageHeader(); 16 bfm.header = new MessageHeader();
17 bfm.someValue = 42; 17 bfm.someValue = 42;
18 bfm.rest = new byte[] {1,2,3,4,5,6,7,100}; 18 bfm.rest = new byte[] {1,2,3,4,5,6,7,100, 8};
19 19
20 Construct.patchSizeFields(bfm); 20 Construct.patch(bfm);
21 21
22 bfm.header.messageSize = Construct.getSize(bfm); 22 bfm.header.messageSize = Construct.getSize(bfm);
23
24 bfm.header.messageType = 42;
23 25
24 System.out.println(bfm.header.messageSize); 26 System.out.println(bfm.header.messageSize);
25 27
26 byte[] data = Construct.toBinary(bfm); 28 byte[] data = Construct.toBinary(bfm);
29
30 Assert.assertEquals(Construct.getSize(bfm), data.length);
31
32 System.out.println("data size: " + data.length);
27 33
28 ByteFillMessage bfm2 = Construct.parseAs(data, 0, ByteFillMessage.class); 34 ByteFillMessage bfm2 = Construct.parseAs(ByteBuffer.wrap(data), ByteFillMessage.class);
29 35
30 Assert.assertArrayEquals(bfm.rest, bfm2.rest); 36 Assert.assertArrayEquals(bfm.rest, bfm2.rest);
31 } 37 }
@@ -43,7 +49,7 @@ public class ConstructTest {
43 49
44 byte[] a = Construct.toBinary(vtm); 50 byte[] a = Construct.toBinary(vtm);
45 51
46 VarTestMessage vtm2 = Construct.parseAs(a, 0, VarTestMessage.class); 52 VarTestMessage vtm2 = Construct.parseAs(ByteBuffer.wrap(a), VarTestMessage.class);
47 53
48 Assert.assertEquals(vtm2.length, 5); 54 Assert.assertEquals(vtm2.length, 5);
49 for (int i = 0; i < 5; ++i) { 55 for (int i = 0; i < 5; ++i) {
@@ -66,7 +72,7 @@ public class ConstructTest {
66 } 72 }
67 73
68 byte[] a = Construct.toBinary(stm); 74 byte[] a = Construct.toBinary(stm);
69 SimpleTestMessage stm2 = Construct.parseAs(a, 0, 75 SimpleTestMessage stm2 = Construct.parseAs(ByteBuffer.wrap(a),
70 SimpleTestMessage.class); 76 SimpleTestMessage.class);
71 77
72 Assert.assertEquals(stm.v1, stm2.v1); 78 Assert.assertEquals(stm.v1, stm2.v1);
@@ -93,7 +99,7 @@ public class ConstructTest {
93 strm.num2 = 80; 99 strm.num2 = 80;
94 100
95 byte[] a = Construct.toBinary(strm); 101 byte[] a = Construct.toBinary(strm);
96 StringMessage strm2 = Construct.parseAs(a, 0, StringMessage.class); 102 StringMessage strm2 = Construct.parseAs(ByteBuffer.wrap(a), StringMessage.class);
97 103
98 for (byte b : a) { 104 for (byte b : a) {
99 System.out.print((char) b); 105 System.out.print((char) b);
@@ -114,13 +120,13 @@ public class ConstructTest {
114 qm.varsize = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 120 qm.varsize = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
115 14, 15 }; 121 14, 15 };
116 122
117 Construct.patchSizeFields(qm); 123 Construct.patch(qm);
118 124
119 byte[] a = Construct.toBinary(qm); 125 byte[] a = Construct.toBinary(qm);
120 126
121 Assert.assertEquals(a.length, qm.header.messageSize); 127 Assert.assertEquals(a.length, qm.header.messageSize);
122 128
123 QueryMessage qm2 = Construct.parseAs(a, 0, QueryMessage.class); 129 QueryMessage qm2 = Construct.parseAs(ByteBuffer.wrap(a), QueryMessage.class);
124 130
125 Assert.assertEquals(qm.header.messageSize, qm2.header.messageSize); 131 Assert.assertEquals(qm.header.messageSize, qm2.header.messageSize);
126 Assert.assertEquals(qm.header.messageType, qm2.header.messageType); 132 Assert.assertEquals(qm.header.messageType, qm2.header.messageType);
@@ -136,11 +142,11 @@ public class ConstructTest {
136 stm.someValue = 42; 142 stm.someValue = 42;
137 stm.rest = new byte[] { 1, 2, 3, 4, 5 }; 143 stm.rest = new byte[] { 1, 2, 3, 4, 5 };
138 144
139 Construct.patchSizeFields(stm); 145 Construct.patch(stm);
140 146
141 byte[] a = Construct.toBinary(stm); 147 byte[] a = Construct.toBinary(stm);
142 148
143 SizeTestMessage stm2 = Construct.parseAs(a, 0, SizeTestMessage.class); 149 SizeTestMessage stm2 = Construct.parseAs(ByteBuffer.wrap(a), SizeTestMessage.class);
144 150
145 Assert.assertEquals(stm.someValue, stm2.someValue); 151 Assert.assertEquals(stm.someValue, stm2.someValue);
146 Assert.assertEquals(stm.totalSize, stm2.totalSize); 152 Assert.assertEquals(stm.totalSize, stm2.totalSize);
@@ -157,7 +163,7 @@ public class ConstructTest {
157 163
158 byte[] a = Construct.toBinary(h1); 164 byte[] a = Construct.toBinary(h1);
159 165
160 MessageHeader h2 = Construct.parseAs(a, 0, MessageHeader.class); 166 MessageHeader h2 = Construct.parseAs(ByteBuffer.wrap(a), MessageHeader.class);
161 167
162 byte[] b = Construct.toBinary(h2); 168 byte[] b = Construct.toBinary(h2);
163 169
diff --git a/test/org/gnunet/construct/UnionTest.java b/test/org/gnunet/construct/UnionTest.java
index ba74a8b..68c97b8 100644
--- a/test/org/gnunet/construct/UnionTest.java
+++ b/test/org/gnunet/construct/UnionTest.java
@@ -1,8 +1,11 @@
1package org.gnunet.construct; 1package org.gnunet.construct;
2 2
3 3
4import org.junit.Assert;
4import org.junit.Test; 5import org.junit.Test;
5 6
7import java.nio.ByteBuffer;
8
6public class UnionTest { 9public class UnionTest {
7 public static interface TestUnion extends MessageUnion {} 10 public static interface TestUnion extends MessageUnion {}
8 11
@@ -37,8 +40,13 @@ public class UnionTest {
37 byte[] a = Construct.toBinary(utm); 40 byte[] a = Construct.toBinary(utm);
38 41
39 System.out.println(a.length); 42 System.out.println(a.length);
43 System.out.println(Construct.getSize(utm));
44
45
46 UnionTestMessage utm2 = Construct.parseAs(ByteBuffer.wrap(a), UnionTestMessage.class);
47
40 48
41 UnionTestMessage utm2 = Construct.parseAs(a, 0, UnionTestMessage.class); 49 Assert.assertEquals(((TestUnionCase0) utm.instance).val, ((TestUnionCase0) utm2.instance).val);
42 50
43 } 51 }
44} 52}