aboutsummaryrefslogtreecommitdiff
path: root/test/org/gnunet/construct/FillParserTest.java
blob: 115b567f5baf4bb08557cd47ac7b19f6879e3815 (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
34
35
36
37
package org.gnunet.construct;

import junit.framework.Assert;
import org.junit.Test;

/**
 * ...
 *
 * @author Florian Dold
 */
public class FillParserTest {

    public static class FillTestMessage implements Message {
        @FrameSize
        @UInt32
        public int size;
        @FillWith
        public StringTuple[] strings;
    }

    @Test
    public void test_fillParser() {
        FillTestMessage m = new FillTestMessage();
        m.strings = new StringTuple[]{new StringTuple("foo", "bar"), new StringTuple("quux", "spam")};
        Construct.patch(m);
        System.out.println(m.size);
        byte[] data = Construct.toBinary(m);
        Assert.assertEquals(m.size, data.length);

        FillTestMessage m2 = Construct.parseAs(data, FillTestMessage.class);

        Assert.assertEquals(m.strings.length, m2.strings.length);

        Assert.assertEquals(m.strings[0], m2.strings[0]);
        Assert.assertEquals(m.strings[1], m2.strings[1]);
    }
}