1 package org
.eclipse
.linuxtools
.ctf
.core
.tests
.types
;
3 import static org
.junit
.Assert
.assertEquals
;
4 import static org
.junit
.Assert
.assertNotNull
;
5 import static org
.junit
.Assert
.assertTrue
;
7 import java
.nio
.ByteOrder
;
9 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.FloatDeclaration
;
10 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.FloatDefinition
;
11 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.IntegerDefinition
;
12 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFReaderException
;
13 import org
.eclipse
.linuxtools
.internal
.ctf
.core
.event
.io
.BitBuffer
;
14 import org
.junit
.After
;
15 import org
.junit
.Before
;
16 import org
.junit
.Test
;
21 * The class <code>IntegerDefinitionTest</code> contains tests for the class
22 * <code>{@link IntegerDefinition}</code>.
25 * @version $Revision: 1.0 $
28 public class FloatDefinitionTest
{
29 private FloatDefinition fixture
;
30 private FloatDefinition singleFixture
;
31 private FloatDefinition doubleFixture
; //all the way.
32 private FloatDeclaration parent
;
33 private static final String fieldName
= "float"; //$NON-NLS-1$
38 * the command line arguments
40 public static void main(String
[] args
) {
41 new org
.junit
.runner
.JUnitCore().run(IntegerDefinitionTest
.class);
45 * Perform pre-test initialization. We know the structDef won't be null (or
46 * else the tests will fail), so we can safely suppress the warning.
48 * @throws CTFReaderException
57 * Perform post-test clean-up.
60 public void tearDown() {
61 // Add additional tear down code here
65 public void testFloat248() {
66 parent
= new FloatDeclaration(8, 24, ByteOrder
.nativeOrder(), 0);
67 singleFixture
= parent
.createDefinition(null, fieldName
);
68 assertNotNull(singleFixture
);
74 public void testFloat5311() {
75 parent
= new FloatDeclaration(11, 53, ByteOrder
.nativeOrder(), 0);
76 doubleFixture
= parent
.createDefinition(null, fieldName
);
77 assertNotNull(doubleFixture
);
81 public void testFloat32Bit(){
82 for(int i
= 1; i
< 31 ; i
++)
84 parent
= new FloatDeclaration(i
, 32-i
, ByteOrder
.nativeOrder(), 0);
85 fixture
= parent
.createDefinition(null, fieldName
);
86 assertNotNull(fixture
);
87 fixture
.setValue(2.0);
88 assertTrue(fixture
.toString().contains("2")); //$NON-NLS-1$
93 public void testFloat64Bit(){
94 for(int i
= 1; i
< 63 ; i
++)
96 parent
= new FloatDeclaration(i
, 64-i
, ByteOrder
.nativeOrder(), 0);
97 fixture
= parent
.createDefinition(null, fieldName
);
98 assertNotNull(fixture
);
99 BitBuffer input
= new BitBuffer(java
.nio
.ByteBuffer
.allocateDirect(128));
101 fixture
.setValue(2.0);
102 assertTrue(fixture
.toString().contains("2")); //$NON-NLS-1$
107 public void testFloat48Bit(){
108 parent
= new FloatDeclaration(12, 32, ByteOrder
.nativeOrder(), 0);
109 fixture
= parent
.createDefinition(null, fieldName
);
110 assertNotNull(fixture
);
111 BitBuffer input
= new BitBuffer(java
.nio
.ByteBuffer
.allocateDirect(128));
114 assertEquals(Double
.NaN
,fixture
.getValue(),0.1);
117 * Run the IntegerDeclaration getDeclaration() method test.
120 public void testGetDeclaration() {
121 singleFixture
.setValue(2.0);
122 FloatDeclaration result
= singleFixture
.getDeclaration();
123 assertNotNull(result
);
127 * Run the long getValue() method test.
130 public void testGetValue() {
131 singleFixture
.setValue(2.0);
132 double result
= singleFixture
.getValue();
133 assertEquals(2.0, result
,0.1);
137 * Run the void read(BitBuffer) method test.
140 public void testRead() {
141 singleFixture
.setValue(2.0);
142 BitBuffer input
= new BitBuffer(java
.nio
.ByteBuffer
.allocateDirect(128));
143 singleFixture
.read(input
);
148 * Run the String toString() method test.
151 public void testToString() {
152 singleFixture
.setValue(222.22);
153 String result
= singleFixture
.toString();
154 assertNotNull(result
);