aboutsummaryrefslogtreecommitdiff
path: root/test/org/gnunet/construct/ConstructTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'test/org/gnunet/construct/ConstructTest.java')
-rw-r--r--test/org/gnunet/construct/ConstructTest.java52
1 files changed, 52 insertions, 0 deletions
diff --git a/test/org/gnunet/construct/ConstructTest.java b/test/org/gnunet/construct/ConstructTest.java
index 470df5e..c7f9853 100644
--- a/test/org/gnunet/construct/ConstructTest.java
+++ b/test/org/gnunet/construct/ConstructTest.java
@@ -3,6 +3,8 @@ package org.gnunet.construct;
3import org.junit.Assert; 3import org.junit.Assert;
4import org.junit.Test; 4import org.junit.Test;
5 5
6import java.util.Random;
7
6/** 8/**
7 * @author Florian Dold 9 * @author Florian Dold
8 */ 10 */
@@ -27,4 +29,54 @@ public class ConstructTest {
27 Assert.assertArrayEquals(new byte[]{0,1,2,3}, msg_r.bytes); 29 Assert.assertArrayEquals(new byte[]{0,1,2,3}, msg_r.bytes);
28 } 30 }
29 31
32
33 @Test
34 public void test_IntMessage() {
35 IntMessage im = new IntMessage();
36 Random r = new Random();
37 im.i1 = r.nextLong();
38 im.i2 = r.nextLong();
39 im.i3 = r.nextLong();
40 im.i4 = r.nextLong();
41 im.i5 = r.nextLong();
42 im.i6 = r.nextLong();
43 im.i7 = r.nextLong();
44 im.i8 = r.nextLong();
45
46 byte[] data = Construct.toBinary(im);
47
48 IntMessage im_new = Construct.parseAs(data, IntMessage.class);
49
50 Assert.assertEquals((1+2+4+8)*2, data.length);
51 Assert.assertEquals((1+2+4+8)*2, Construct.getStaticSize(im));
52 }
53
54 @Test(expected = AssertionError.class)
55 public void test_PrivateMemberMessage() {
56 PrivateMemberMessage m1 = new PrivateMemberMessage();
57 byte[] data = Construct.toBinary(m1);
58 PrivateMemberMessage m2 = Construct.parseAs(data, PrivateMemberMessage.class);
59 }
60
61
62 @Test
63 public void test_variable_size() {
64 VariableSizeMessage m1 = new VariableSizeMessage();
65 m1.n1 = 2;
66 m1.n2 = 3;
67 m1.a1 = new int[]{42,43};
68 m1.a2 = new int[]{1,2,1000};
69
70 byte[] data = Construct.toBinary(m1);
71
72 VariableSizeMessage m2 = Construct.parseAs(data, VariableSizeMessage.class);
73
74 Assert.assertEquals(m1.n1, m2.n1);
75 Assert.assertEquals(m1.n2, m2.n2);
76 Assert.assertArrayEquals(m1.a1, m2.a1);
77 Assert.assertArrayEquals(m1.a2, m2.a2);
78 }
79
80
30} 81}
82