Add newline awareness to filter and search function of the event view
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core.tests / src / org / eclipse / linuxtools / tmf / core / tests / ctfadaptor / CtfTmfEventFieldTest.java
CommitLineData
95bf10e7 1/*******************************************************************************
61759503 2 * Copyright (c) 2012, 2013 Ericsson
95bf10e7
AM
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Matthew Khouzam - Initial generation with CodePro tools
11 * Alexandre Montplaisir - Clean up, consolidate redundant tests
12 *******************************************************************************/
13
81c8e6f7
MK
14package org.eclipse.linuxtools.tmf.core.tests.ctfadaptor;
15
16import static org.junit.Assert.assertEquals;
81c8e6f7
MK
17
18import java.nio.ByteOrder;
19
486efb2e 20import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
81c8e6f7
MK
21import org.eclipse.linuxtools.ctf.core.event.types.ArrayDeclaration;
22import org.eclipse.linuxtools.ctf.core.event.types.Definition;
23import org.eclipse.linuxtools.ctf.core.event.types.Encoding;
404b264a 24import org.eclipse.linuxtools.ctf.core.event.types.EnumDeclaration;
81c8e6f7
MK
25import org.eclipse.linuxtools.ctf.core.event.types.FloatDeclaration;
26import org.eclipse.linuxtools.ctf.core.event.types.FloatDefinition;
27import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
28import org.eclipse.linuxtools.ctf.core.event.types.SequenceDeclaration;
29import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration;
30import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
31import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
404b264a 32import org.eclipse.linuxtools.ctf.core.event.types.VariantDeclaration;
81c8e6f7 33import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEventField;
81c8e6f7
MK
34import org.junit.Before;
35import org.junit.Test;
36
37/**
38 * The class <code>CtfTmfEventFieldTest</code> contains tests for the class
39 * <code>{@link CtfTmfEventField}</code>.
40 *
81c8e6f7 41 * @author ematkho
95bf10e7 42 * @version 1.0
81c8e6f7
MK
43 */
44public class CtfTmfEventFieldTest {
45
68b18f2f
AM
46 private static final String ROOT = "root";
47 private static final String SEQ = "seq";
48 private static final String ARRAY = "array";
49 private static final String STR = "str";
50 private static final String FLOAT = "float";
51 private static final String LEN = "len";
52 private static final String INT = "int";
53 private static final String NAME = "test";
7a6cee1a 54 private static final String STRUCT = "struct";
404b264a
GB
55 private static final String VARIANT = "variant";
56 private static final String ENUM = "enum";
81c8e6f7 57
95bf10e7
AM
58 private StructDefinition fixture;
59
95bf10e7
AM
60 /**
61 * Perform pre-test initialization.
62 */
63 @Before
64 public void setUp() {
65 StructDeclaration sDec = new StructDeclaration(1l);
66 StringDeclaration strDec = new StringDeclaration();
67 IntegerDeclaration intDec = new IntegerDeclaration(8, false, 8,
68 ByteOrder.BIG_ENDIAN, Encoding.NONE, null, 8);
69 FloatDeclaration flDec = new FloatDeclaration(8, 24,
70 ByteOrder.BIG_ENDIAN, 8);
71 ArrayDeclaration arrDec = new ArrayDeclaration(2, intDec);
72 SequenceDeclaration seqDec = new SequenceDeclaration(LEN, intDec);
7a6cee1a 73 StructDeclaration structDec = new StructDeclaration(32);
404b264a
GB
74 EnumDeclaration enumDec = new EnumDeclaration(intDec);
75 VariantDeclaration varDec = new VariantDeclaration();
95bf10e7
AM
76 sDec.addField(INT, intDec);
77 sDec.addField(LEN, intDec);
78 sDec.addField(FLOAT, flDec);
79 sDec.addField(STR, strDec);
80 sDec.addField(ARRAY, arrDec);
81 sDec.addField(SEQ, seqDec);
7a6cee1a
GB
82 structDec.addField(STR,strDec);
83 structDec.addField(INT, intDec);
84 sDec.addField(STRUCT, structDec);
404b264a
GB
85 enumDec.add(0, 1, LEN);
86 enumDec.add(2, 3, FLOAT);
87 sDec.addField(ENUM, enumDec);
88 varDec.addField(LEN, intDec);
89 varDec.addField(FLOAT, flDec);
90 varDec.setTag(ENUM);
91 sDec.addField(VARIANT, varDec);
95bf10e7 92 fixture = sDec.createDefinition(fixture, ROOT);
7a6cee1a 93 int capacity = 2048;
95bf10e7
AM
94 java.nio.ByteBuffer bb = java.nio.ByteBuffer.allocateDirect(capacity);
95 for (int i = 0; i < capacity; i++) {
96 bb.put((byte) 2);
97 }
98 bb.position(20);
99 bb.put((byte) 0);
7a6cee1a
GB
100 bb.position(40);
101 bb.put((byte) 0);
404b264a
GB
102 bb.position(60);
103 bb.put((byte) 0);
95bf10e7
AM
104 bb.position(0);
105 fixture.read(new BitBuffer(bb));
106 }
107
95bf10e7
AM
108 /**
109 * Run the CtfTmfEventField parseField(Definition,String) method test.
81c8e6f7
MK
110 */
111 @Test
95bf10e7 112 public void testParseField_float() {
68b18f2f
AM
113 FloatDefinition fieldDef = (FloatDefinition) fixture.lookupDefinition(FLOAT);
114 CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, "_" + NAME);
115 assertEquals("test=9.551467814359616E-38", result.toString());
81c8e6f7
MK
116 }
117
118 /**
119 * Run the CtfTmfEventField parseField(Definition,String) method test.
81c8e6f7
MK
120 */
121 @Test
95bf10e7 122 public void testParseField_array() {
68b18f2f
AM
123 Definition fieldDef = fixture.lookupArray(ARRAY);
124 CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
404b264a 125 assertEquals("test=[02, 02]", result.toString());
81c8e6f7
MK
126 }
127
128 /**
129 * Run the CtfTmfEventField parseField(Definition,String) method test.
81c8e6f7
MK
130 */
131 @Test
95bf10e7 132 public void testParseField_int() {
81c8e6f7
MK
133 Definition fieldDef = fixture.lookupDefinition(INT);
134 CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
68b18f2f 135 assertEquals("test=02", result.toString());
81c8e6f7
MK
136 }
137
138 /**
139 * Run the CtfTmfEventField parseField(Definition,String) method test.
81c8e6f7
MK
140 */
141 @Test
95bf10e7 142 public void testParseField_sequence() {
81c8e6f7
MK
143 Definition fieldDef = fixture.lookupDefinition(SEQ);
144 CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
404b264a 145 assertEquals("test=[02, 02]", result.toString());
a6223d74
MK
146 }
147
148 /**
149 * Run the CtfTmfEventField parseField(Definition,String) method test.
150 */
151 @Test
152 public void testParseField_sequence_value() {
153 Definition fieldDef = fixture.lookupDefinition(SEQ);
154 CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
68b18f2f 155 assertEquals("[2, 2]", result.getValue().toString());
81c8e6f7
MK
156 }
157
158 /**
159 * Run the CtfTmfEventField parseField(Definition,String) method test.
81c8e6f7
MK
160 */
161 @Test
95bf10e7 162 public void testParseField_string() {
81c8e6f7
MK
163 Definition fieldDef = fixture.lookupDefinition(STR);
164 CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
68b18f2f 165 assertEquals("test=\ 2\ 2\ 2\ 2\ 2\ 2\ 2\ 2\ 2\ 2\ 2\ 2\ 2\ 2", result.toString());
81c8e6f7 166 }
7a6cee1a
GB
167
168 /**
169 * Run the CtfTmfEventField parseField(Definition,String) method test.
170 */
171 @Test
172 public void testParseField_struct() {
173 Definition fieldDef = fixture.lookupDefinition(STRUCT);
174 CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
175 assertEquals("test=[str=\ 2\ 2\ 2\ 2\ 2\ 2\ 2\ 2\ 2\ 2\ 2\ 2, int=02]", result.toString());
176 }
404b264a
GB
177
178 /**
179 * Run the CtfTmfEventField parseField(Definition,String) method test.
180 */
181 @Test
182 public void testParseField_enum() {
183 Definition fieldDef = fixture.lookupDefinition(ENUM);
184 CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
185 assertEquals("test=float", result.toString());
186 }
187
188 /**
189 * Run the CtfTmfEventField parseField(Definition,String) method test.
190 */
191 @Test
192 public void testParseField_variant() {
193 Definition fieldDef = fixture.lookupDefinition(VARIANT);
194 CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
195 assertEquals("float=9.551467814359616E-38", result.toString());
196 }
95bf10e7 197}
This page took 0.039372 seconds and 5 git commands to generate.