Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 11745a81f1ec0403824928fe0bd7852b05c18ec4 (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
package org.eclipse.linuxtools.ctf.core.tests.types;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.nio.ByteOrder;

import org.eclipse.linuxtools.ctf.core.event.types.Definition;
import org.eclipse.linuxtools.ctf.core.event.types.Encoding;
import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.SequenceDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.SequenceDefinition;
import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

/**
 * The class <code>SequenceDefinitionTest</code> contains tests for the class
 * <code>{@link SequenceDefinition}</code>.
 *
 * @author ematkho
 * @version $Revision: 1.0 $
 */
public class SequenceDefinitionTest {

    private SequenceDefinition fixture;
    private final static int seqLen = 15;

    /**
     * Launch the test.
     *
     * @param args
     *            the command line arguments
     */
    public static void main(String[] args) {
        new org.junit.runner.JUnitCore().run(SequenceDefinitionTest.class);
    }

    /**
     * Perform pre-test initialization.
     * @throws CTFReaderException 
     */
    @Before
    public void setUp() throws CTFReaderException {
        StructDeclaration structDec;
        StructDefinition structDef;

        IntegerDeclaration id = new IntegerDeclaration(8, false, 8,
                ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, null);
        String lengthName = "LengthName"; //$NON-NLS-1$
        structDec = new StructDeclaration(0);
        structDec.addField(lengthName, id);
        structDef = new StructDefinition(structDec, null, "x"); //$NON-NLS-1$

        structDef.lookupInteger(lengthName).setValue(seqLen);
        SequenceDeclaration sd = new SequenceDeclaration(lengthName, id);
        fixture = new SequenceDefinition(sd, structDef, "TestX"); //$NON-NLS-1$
        BitBuffer input = new BitBuffer(
                java.nio.ByteBuffer.allocateDirect(seqLen * 8));
        for (int i = 0; i < seqLen; i++) {
            input.putInt(i);
        }
        fixture.read(input);
        assert (fixture != null);
    }

    /**
     * Perform post-test clean-up.
     */
    @After
    public void tearDown() {
        // Add additional tear down code here
    }

    private static SequenceDefinition initNonString() throws CTFReaderException {
        StructDeclaration structDec;
        StructDefinition structDef;

        int len = 32;
        IntegerDeclaration id = new IntegerDeclaration(len, false, len,
                ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, null);
        String lengthName = "LengthName"; //$NON-NLS-1$
        structDec = new StructDeclaration(0);
        structDec.addField(lengthName, id);
        structDef = new StructDefinition(structDec, null, "x"); //$NON-NLS-1$

        structDef.lookupInteger(lengthName).setValue(seqLen);
        SequenceDeclaration sd = new SequenceDeclaration(lengthName, id);
        SequenceDefinition ret = new SequenceDefinition(sd, structDef, "TestX"); //$NON-NLS-1$
        BitBuffer input = new BitBuffer(
                java.nio.ByteBuffer.allocateDirect(seqLen * len));
        for (int i = 0; i < seqLen; i++) {
            input.putInt(i);
        }
        ret.read(input);
        assertNotNull(ret);
        return ret;
    }

    /**
     * Run the SequenceDefinition(SequenceDeclaration,DefinitionScope,String)
     * constructor test.
     */
    @Test
    public void testSequenceDefinition() {
        assertNotNull(fixture);
    }

    /**
     * Run the SequenceDeclaration getDeclaration() method test.
     */
    @Test
    public void testGetDeclaration() {
        SequenceDeclaration result = fixture.getDeclaration();
        assertNotNull(result);
    }

    /**
     * Run the Definition getElem(int) method test.
     */
    @Test
    public void testGetElem() {
        int i = 1;
        Definition result = fixture.getElem(i);
        assertNotNull(result);
    }

    /**
     * Run the int getLength() method test.
     */
    @Test
    public void testGetLength() {
        int result = fixture.getLength();

        assertEquals(seqLen, result);
    }

    /**
     * Run the boolean isString() method test.
     */
    @Test
    public void testIsString() {
        boolean result = fixture.isString();
        assertTrue(result);
    }

    /**
     * Run the void read(BitBuffer) method test.
     */
    @Test
    public void testRead() {
        BitBuffer input = new BitBuffer(java.nio.ByteBuffer.allocateDirect(128));
        fixture.read(input);
    }

    /**
     * Run the String toString() method test.
     */
    @Test
    public void testToString() {
        String result = fixture.toString();
        assertNotNull(result);
    }

    /**
     * Run the String toString() method test.
     */
    @Test
    public void testToString_nonString() throws Exception {
        SequenceDefinition nonStringFixture = initNonString();
        String result = nonStringFixture.toString();
        assertNotNull(result);
    }
}

Back to the top