diff options
Diffstat (limited to 'test/org/gnunet/construct/VariableSizeArrayTest.java')
-rw-r--r-- | test/org/gnunet/construct/VariableSizeArrayTest.java | 33 |
1 files changed, 33 insertions, 0 deletions
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 | } | ||