1 /*******************************************************************************
2 * Copyright (c) 2012 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
;
17 import static org
.junit
.Assert
.assertNotNull
;
19 import java
.nio
.ByteOrder
;
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
.FloatDeclaration
;
25 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.FloatDefinition
;
26 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.IntegerDeclaration
;
27 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.SequenceDeclaration
;
28 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.StringDeclaration
;
29 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.StructDeclaration
;
30 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.StructDefinition
;
31 import org
.eclipse
.linuxtools
.internal
.ctf
.core
.event
.io
.BitBuffer
;
32 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfTmfEventField
;
33 import org
.junit
.After
;
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"; //$NON-NLS-1$
47 private static final String SEQ
= "seq"; //$NON-NLS-1$
48 private static final String ARRAY
= "array"; //$NON-NLS-1$
49 private static final String STR
= "str"; //$NON-NLS-1$
50 private static final String FLOAT
= "float"; //$NON-NLS-1$
51 private static final String LEN
= "len"; //$NON-NLS-1$
52 private static final String INT
= "int"; //$NON-NLS-1$
53 private static final String NAME
= "test"; //$NON-NLS-1$
55 private StructDefinition fixture
;
61 * the command line arguments
63 public static void main(String
[] args
) {
64 new org
.junit
.runner
.JUnitCore().run(CtfTmfEventFieldTest
.class);
68 * Perform pre-test initialization.
72 StructDeclaration sDec
= new StructDeclaration(1l);
73 StringDeclaration strDec
= new StringDeclaration();
74 IntegerDeclaration intDec
= new IntegerDeclaration(8, false, 8,
75 ByteOrder
.BIG_ENDIAN
, Encoding
.NONE
, null, 8);
76 FloatDeclaration flDec
= new FloatDeclaration(8, 24,
77 ByteOrder
.BIG_ENDIAN
, 8);
78 ArrayDeclaration arrDec
= new ArrayDeclaration(2, intDec
);
79 SequenceDeclaration seqDec
= new SequenceDeclaration(LEN
, intDec
);
80 sDec
.addField(INT
, intDec
);
81 sDec
.addField(LEN
, intDec
);
82 sDec
.addField(FLOAT
, flDec
);
83 sDec
.addField(STR
, strDec
);
84 sDec
.addField(ARRAY
, arrDec
);
85 sDec
.addField(SEQ
, seqDec
);
86 fixture
= sDec
.createDefinition(fixture
, ROOT
);
88 java
.nio
.ByteBuffer bb
= java
.nio
.ByteBuffer
.allocateDirect(capacity
);
89 for (int i
= 0; i
< capacity
; i
++) {
95 fixture
.read(new BitBuffer(bb
));
99 * Perform post-test clean-up.
102 public void tearDown() {
103 // Add additional tear down code here
107 * Run the CtfTmfEventField parseField(Definition,String) method test.
110 public void testParseField_float() {
111 FloatDefinition fieldDef
;
112 fieldDef
= (FloatDefinition
) fixture
.lookupDefinition(FLOAT
);
113 CtfTmfEventField result
= CtfTmfEventField
.parseField(fieldDef
, "_"+NAME
); //$NON-NLS-1$
114 String result2
= CtfTmfEventField
.copyFrom(result
).toString();
115 assertEquals( result2
, "test=9.551467814359616E-38"); //$NON-NLS-1$
119 * Run the CtfTmfEventField parseField(Definition,String) method test.
122 public void testParseField_array() {
123 CtfTmfEventField result
;
124 result
= CtfTmfEventField
.parseField(fixture
.lookupArray(ARRAY
), NAME
);
125 String result2
= CtfTmfEventField
.copyFrom(result
).toString();
126 assertEquals( result2
, "test={ 2, 2}"); //$NON-NLS-1$
130 * Run the CtfTmfEventField parseField(Definition,String) method test.
133 public void testParseField_int() {
134 Definition fieldDef
= fixture
.lookupDefinition(INT
);
135 CtfTmfEventField result
= CtfTmfEventField
.parseField(fieldDef
, NAME
);
136 String result2
=CtfTmfEventField
.copyFrom(result
).toString();
137 assertEquals( result2
, "test=2"); //$NON-NLS-1$
141 * Run the CtfTmfEventField parseField(Definition,String) method test.
144 public void testParseField_sequence() {
145 Definition fieldDef
= fixture
.lookupDefinition(SEQ
);
146 CtfTmfEventField result
= CtfTmfEventField
.parseField(fieldDef
, NAME
);
147 String result2
=CtfTmfEventField
.copyFrom(result
).toString();
148 assertEquals( result2
, "test={ 2, 2}"); //$NON-NLS-1$
152 * Run the CtfTmfEventField parseField(Definition,String) method test.
155 public void testParseField_string() {
156 Definition fieldDef
= fixture
.lookupDefinition(STR
);
157 CtfTmfEventField result
= CtfTmfEventField
.parseField(fieldDef
, NAME
);
158 String result2
=CtfTmfEventField
.copyFrom(result
).toString();
159 assertEquals( result2
, "test=\ 2\ 2\ 2\ 2\ 2\ 2\ 2\ 2\ 2\ 2\ 2\ 2\ 2\ 2"); //$NON-NLS-1$
163 * Test the clone() method.
166 public void testClone() {
167 Definition fieldDef
= fixture
.lookupDefinition(STR
);
168 CtfTmfEventField result
= CtfTmfEventField
.parseField(fieldDef
, NAME
);
169 assertNotNull(result
.clone());