lttng: Add an Eclipse builder for the doc plugin
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core.tests / src / org / eclipse / linuxtools / tmf / core / tests / ctfadaptor / CtfTmfEventFieldTest.java
CommitLineData
95bf10e7
AM
1/*******************************************************************************
2 * Copyright (c) 2012 Ericsson
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;
24import org.eclipse.linuxtools.ctf.core.event.types.FloatDeclaration;
25import org.eclipse.linuxtools.ctf.core.event.types.FloatDefinition;
26import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
27import org.eclipse.linuxtools.ctf.core.event.types.SequenceDeclaration;
28import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration;
29import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
30import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
81c8e6f7 31import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEventField;
81c8e6f7
MK
32import org.junit.Before;
33import org.junit.Test;
34
35/**
36 * The class <code>CtfTmfEventFieldTest</code> contains tests for the class
37 * <code>{@link CtfTmfEventField}</code>.
38 *
81c8e6f7 39 * @author ematkho
95bf10e7 40 * @version 1.0
81c8e6f7 41 */
68b18f2f 42@SuppressWarnings("nls")
81c8e6f7
MK
43public class CtfTmfEventFieldTest {
44
68b18f2f
AM
45 private static final String ROOT = "root";
46 private static final String SEQ = "seq";
47 private static final String ARRAY = "array";
48 private static final String STR = "str";
49 private static final String FLOAT = "float";
50 private static final String LEN = "len";
51 private static final String INT = "int";
52 private static final String NAME = "test";
81c8e6f7 53
95bf10e7
AM
54 private StructDefinition fixture;
55
95bf10e7
AM
56 /**
57 * Perform pre-test initialization.
58 */
59 @Before
60 public void setUp() {
61 StructDeclaration sDec = new StructDeclaration(1l);
62 StringDeclaration strDec = new StringDeclaration();
63 IntegerDeclaration intDec = new IntegerDeclaration(8, false, 8,
64 ByteOrder.BIG_ENDIAN, Encoding.NONE, null, 8);
65 FloatDeclaration flDec = new FloatDeclaration(8, 24,
66 ByteOrder.BIG_ENDIAN, 8);
67 ArrayDeclaration arrDec = new ArrayDeclaration(2, intDec);
68 SequenceDeclaration seqDec = new SequenceDeclaration(LEN, intDec);
69 sDec.addField(INT, intDec);
70 sDec.addField(LEN, intDec);
71 sDec.addField(FLOAT, flDec);
72 sDec.addField(STR, strDec);
73 sDec.addField(ARRAY, arrDec);
74 sDec.addField(SEQ, seqDec);
75 fixture = sDec.createDefinition(fixture, ROOT);
76 int capacity = 1024;
77 java.nio.ByteBuffer bb = java.nio.ByteBuffer.allocateDirect(capacity);
78 for (int i = 0; i < capacity; i++) {
79 bb.put((byte) 2);
80 }
81 bb.position(20);
82 bb.put((byte) 0);
83 bb.position(0);
84 fixture.read(new BitBuffer(bb));
85 }
86
95bf10e7
AM
87 /**
88 * Run the CtfTmfEventField parseField(Definition,String) method test.
81c8e6f7
MK
89 */
90 @Test
95bf10e7 91 public void testParseField_float() {
68b18f2f
AM
92 FloatDefinition fieldDef = (FloatDefinition) fixture.lookupDefinition(FLOAT);
93 CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, "_" + NAME);
94 assertEquals("test=9.551467814359616E-38", result.toString());
81c8e6f7
MK
95 }
96
97 /**
98 * Run the CtfTmfEventField parseField(Definition,String) method test.
81c8e6f7
MK
99 */
100 @Test
95bf10e7 101 public void testParseField_array() {
68b18f2f
AM
102 Definition fieldDef = fixture.lookupArray(ARRAY);
103 CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
104 assertEquals("test=[2, 2]", result.toString());
81c8e6f7
MK
105 }
106
107 /**
108 * Run the CtfTmfEventField parseField(Definition,String) method test.
81c8e6f7
MK
109 */
110 @Test
95bf10e7 111 public void testParseField_int() {
81c8e6f7
MK
112 Definition fieldDef = fixture.lookupDefinition(INT);
113 CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
68b18f2f 114 assertEquals("test=02", result.toString());
81c8e6f7
MK
115 }
116
117 /**
118 * Run the CtfTmfEventField parseField(Definition,String) method test.
81c8e6f7
MK
119 */
120 @Test
95bf10e7 121 public void testParseField_sequence() {
81c8e6f7
MK
122 Definition fieldDef = fixture.lookupDefinition(SEQ);
123 CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
68b18f2f 124 assertEquals("test=[2, 2]", result.toString());
a6223d74
MK
125 }
126
127 /**
128 * Run the CtfTmfEventField parseField(Definition,String) method test.
129 */
130 @Test
131 public void testParseField_sequence_value() {
132 Definition fieldDef = fixture.lookupDefinition(SEQ);
133 CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
68b18f2f 134 assertEquals("[2, 2]", result.getValue().toString());
81c8e6f7
MK
135 }
136
137 /**
138 * Run the CtfTmfEventField parseField(Definition,String) method test.
81c8e6f7
MK
139 */
140 @Test
95bf10e7 141 public void testParseField_string() {
81c8e6f7
MK
142 Definition fieldDef = fixture.lookupDefinition(STR);
143 CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
68b18f2f 144 assertEquals("test=\ 2\ 2\ 2\ 2\ 2\ 2\ 2\ 2\ 2\ 2\ 2\ 2\ 2\ 2", result.toString());
81c8e6f7 145 }
95bf10e7 146}
This page took 0.034865 seconds and 5 git commands to generate.