1 /*******************************************************************************
2 * Copyright (c) 2012, 2013 Ericsson
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
10 * Matthew Khouzam - Initial generation with CodePro tools
11 * Alexandre Montplaisir - Clean up, consolidate redundant tests
12 *******************************************************************************/
14 package org
.eclipse
.linuxtools
.tmf
.core
.tests
.ctfadaptor
;
16 import static org
.junit
.Assert
.assertEquals
;
18 import java
.nio
.ByteOrder
;
20 import org
.eclipse
.linuxtools
.ctf
.core
.event
.io
.BitBuffer
;
21 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.ArrayDeclaration
;
22 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.Definition
;
23 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.Encoding
;
24 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.EnumDeclaration
;
25 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.FloatDeclaration
;
26 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.FloatDefinition
;
27 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.IntegerDeclaration
;
28 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.SequenceDeclaration
;
29 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.StringDeclaration
;
30 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.StructDeclaration
;
31 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.StructDefinition
;
32 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.VariantDeclaration
;
33 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfTmfEventField
;
34 import org
.junit
.Before
;
35 import org
.junit
.Test
;
38 * The class <code>CtfTmfEventFieldTest</code> contains tests for the class
39 * <code>{@link CtfTmfEventField}</code>.
44 public class CtfTmfEventFieldTest
{
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";
54 private static final String STRUCT
= "struct";
55 private static final String VARIANT
= "variant";
56 private static final String ENUM
= "enum";
58 private StructDefinition fixture
;
61 * Perform pre-test initialization.
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
);
73 StructDeclaration structDec
= new StructDeclaration(32);
74 EnumDeclaration enumDec
= new EnumDeclaration(intDec
);
75 VariantDeclaration varDec
= new VariantDeclaration();
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
);
82 structDec
.addField(STR
,strDec
);
83 structDec
.addField(INT
, intDec
);
84 sDec
.addField(STRUCT
, structDec
);
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
);
91 sDec
.addField(VARIANT
, varDec
);
92 fixture
= sDec
.createDefinition(fixture
, ROOT
);
94 java
.nio
.ByteBuffer bb
= java
.nio
.ByteBuffer
.allocateDirect(capacity
);
95 for (int i
= 0; i
< capacity
; i
++) {
105 fixture
.read(new BitBuffer(bb
));
109 * Run the CtfTmfEventField parseField(Definition,String) method test.
112 public void testParseField_float() {
113 FloatDefinition fieldDef
= (FloatDefinition
) fixture
.lookupDefinition(FLOAT
);
114 CtfTmfEventField result
= CtfTmfEventField
.parseField(fieldDef
, "_" + NAME
);
115 assertEquals("test=9.551467814359616E-38", result
.toString());
119 * Run the CtfTmfEventField parseField(Definition,String) method test.
122 public void testParseField_array() {
123 Definition fieldDef
= fixture
.lookupArray(ARRAY
);
124 CtfTmfEventField result
= CtfTmfEventField
.parseField(fieldDef
, NAME
);
125 assertEquals("test=[02, 02]", result
.toString());
129 * Run the CtfTmfEventField parseField(Definition,String) method test.
132 public void testParseField_int() {
133 Definition fieldDef
= fixture
.lookupDefinition(INT
);
134 CtfTmfEventField result
= CtfTmfEventField
.parseField(fieldDef
, NAME
);
135 assertEquals("test=02", result
.toString());
139 * Run the CtfTmfEventField parseField(Definition,String) method test.
142 public void testParseField_sequence() {
143 Definition fieldDef
= fixture
.lookupDefinition(SEQ
);
144 CtfTmfEventField result
= CtfTmfEventField
.parseField(fieldDef
, NAME
);
145 assertEquals("test=[02, 02]", result
.toString());
149 * Run the CtfTmfEventField parseField(Definition,String) method test.
152 public void testParseField_sequence_value() {
153 Definition fieldDef
= fixture
.lookupDefinition(SEQ
);
154 CtfTmfEventField result
= CtfTmfEventField
.parseField(fieldDef
, NAME
);
155 assertEquals("[2, 2]", result
.getValue().toString());
159 * Run the CtfTmfEventField parseField(Definition,String) method test.
162 public void testParseField_string() {
163 Definition fieldDef
= fixture
.lookupDefinition(STR
);
164 CtfTmfEventField result
= CtfTmfEventField
.parseField(fieldDef
, NAME
);
165 assertEquals("test=\ 2\ 2\ 2\ 2\ 2\ 2\ 2\ 2\ 2\ 2\ 2\ 2\ 2\ 2", result
.toString());
169 * Run the CtfTmfEventField parseField(Definition,String) method 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());
179 * Run the CtfTmfEventField parseField(Definition,String) method 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());
189 * Run the CtfTmfEventField parseField(Definition,String) method test.
192 public void testParseField_variant() {
193 Definition fieldDef
= fixture
.lookupDefinition(VARIANT
);
194 CtfTmfEventField result
= CtfTmfEventField
.parseField(fieldDef
, NAME
);
195 assertEquals("test=float=9.551467814359616E-38", result
.toString());