cbd23dee0472bfeb2eefb328dca12e07c6881f10
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core.tests / src / org / eclipse / linuxtools / ctf / core / tests / types / SequenceDefinition2Test.java
1 /*******************************************************************************
2 * Copyright (c) 2013 Ericsson
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * Matthew Khouzam - Initial API and implementation
10 *******************************************************************************/
11
12 package org.eclipse.linuxtools.ctf.core.tests.types;
13
14 import static org.junit.Assert.assertNotNull;
15
16 import java.nio.ByteBuffer;
17 import java.nio.ByteOrder;
18
19 import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
20 import org.eclipse.linuxtools.ctf.core.event.types.Definition;
21 import org.eclipse.linuxtools.ctf.core.event.types.Encoding;
22 import org.eclipse.linuxtools.ctf.core.event.types.IDefinition;
23 import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
24 import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
25 import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
26 import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
27 import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
28 import org.eclipse.linuxtools.internal.ctf.core.event.types.ByteArrayDefinition;
29 import org.eclipse.linuxtools.internal.ctf.core.event.types.SequenceDeclaration;
30 import org.junit.Before;
31 import org.junit.Test;
32
33 import com.google.common.collect.ImmutableList;
34
35 /**
36 * The class <code>SequenceDefinition2Test</code> contains tests for the class
37 * <code>{@link SequenceDefinition2}</code>.
38 *
39 * @author ematkho
40 * @version $Revision: 1.0 $
41 */
42 @SuppressWarnings("javadoc")
43 public class SequenceDefinition2Test {
44
45 private ByteArrayDefinition fixture;
46 private final static int seqLen = 15;
47
48 private static ImmutableList<String> wrap(String s) {
49 return ImmutableList.<String> builder().add(s).build();
50 }
51
52 /**
53 * Perform pre-test initialization.
54 *
55 * @throws CTFReaderException
56 */
57 @Before
58 public void setUp() throws CTFReaderException {
59 fixture = initString();
60 }
61
62 private static ByteArrayDefinition initString() throws CTFReaderException {
63 StructDeclaration structDec;
64 StructDefinition structDef;
65
66 int len = 8;
67 IntegerDeclaration id = IntegerDeclaration.createDeclaration(len, false, len,
68 ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, "", 8);
69 String lengthName = "LengthName";
70 structDec = new StructDeclaration(0);
71 structDec.addField(lengthName, id);
72
73 structDef = new StructDefinition(structDec, null, "x", wrap(lengthName), new Definition[] { new IntegerDefinition(id, null, lengthName, seqLen) });
74
75 SequenceDeclaration sd = new SequenceDeclaration(lengthName, id);
76 ByteBuffer allocateDirect = java.nio.ByteBuffer.allocateDirect(seqLen * len);
77 if( allocateDirect == null){
78 throw new IllegalStateException("Failed to allocate memory");
79 }
80 BitBuffer input = new BitBuffer(allocateDirect);
81 for (int i = 0; i < seqLen; i++) {
82 input.putInt(i);
83 }
84
85 ByteArrayDefinition ret = (ByteArrayDefinition) sd.createDefinition(structDef, "TestX", input);
86 assertNotNull(ret);
87 return ret;
88 }
89
90 /**
91 * Run the FixedStringDefinition(SequenceDeclaration,DefinitionScope,String)
92 * constructor test.
93 */
94 @Test
95 public void testFixedStringDefinition() {
96 assertNotNull(fixture);
97 }
98
99 /**
100 * Run the SequenceDeclaration getDeclaration() method test.
101 */
102 @Test
103 public void testGetDeclaration() {
104 SequenceDeclaration result = (SequenceDeclaration) fixture.getDeclaration();
105 assertNotNull(result);
106 }
107
108 /**
109 * Run the Definition getElem(int) method test.
110 */
111 @Test
112 public void testGetElem() {
113 int i = 1;
114 IDefinition result = fixture.getDefinitions().get(i);
115 assertNotNull(result);
116 }
117
118 /**
119 * Run the String toString() method test.
120 */
121 @Test
122 public void testToString() {
123 String result = fixture.toString();
124 assertNotNull(result);
125 }
126
127 }
This page took 0.048336 seconds and 4 git commands to generate.