blob: f1d19c1b20ee6a85160287c39c6ae839b42f803e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
package org.gnunet.construct;
import junit.framework.Assert;
import org.junit.Test;
/**
* ...
*
* @author Florian Dold
*/
public class VariableSizeArrayTest {
public static class VariableTestMessage implements Message {
@UInt32
public int num;
@VariableSizeArray(lengthField = "num")
public StringTuple[] msgs;
}
@Test
public void test_variableSizeArray() {
VariableTestMessage m = new VariableTestMessage();
m.msgs = new StringTuple[]{new StringTuple("foo", "bar"), new StringTuple("quux", "baz"), new StringTuple("spam", "eggs")};
Construct.patch(m);
Assert.assertEquals(3, m.num);
byte[] data = Construct.toBinary(m);
VariableTestMessage m2 = Construct.parseAs(data, VariableTestMessage.class);
Assert.assertEquals(m2.num, 3);
Assert.assertEquals(m.msgs[0], m2.msgs[0]);
Assert.assertEquals(m.msgs[1], m2.msgs[1]);
Assert.assertEquals(m.msgs[2], m2.msgs[2]);
}
}
|