1 /*******************************************************************************
2 * Copyright (c) 2013 Ericsson
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
9 * Matthew Khouzam - Initial API and implementation
10 *******************************************************************************/
12 package org
.eclipse
.linuxtools
.ctf
.core
.tests
.types
;
14 import static org
.junit
.Assert
.assertEquals
;
15 import static org
.junit
.Assert
.assertNotNull
;
16 import static org
.junit
.Assert
.assertTrue
;
18 import java
.nio
.ByteOrder
;
20 import org
.eclipse
.linuxtools
.ctf
.core
.event
.io
.BitBuffer
;
21 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.FloatDeclaration
;
22 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.FloatDefinition
;
23 import org
.junit
.After
;
24 import org
.junit
.Before
;
25 import org
.junit
.Test
;
28 * The class <code>IntegerDefinitionTest</code> contains tests for the class
29 * <code>{@link IntegerDefinition}</code>.
32 * @version $Revision: 1.0 $
34 @SuppressWarnings("javadoc")
35 public class FloatDefinitionTest
{
37 private FloatDefinition fixture
;
38 private FloatDefinition singleFixture
;
39 private FloatDefinition doubleFixture
; //all the way.
40 private FloatDeclaration parent
;
41 private static final String fieldName
= "float";
47 * the command line arguments
49 public static void main(String
[] args
) {
50 new org
.junit
.runner
.JUnitCore().run(IntegerDefinitionTest
.class);
54 * Perform pre-test initialization. We know the structDef won't be null (or
55 * else the tests will fail), so we can safely suppress the warning.
57 * @throws CTFReaderException
66 * Perform post-test clean-up.
69 public void tearDown() {
70 // Add additional tear down code here
74 public void testFloat248() {
75 parent
= new FloatDeclaration(8, 24, ByteOrder
.nativeOrder(), 0);
76 singleFixture
= parent
.createDefinition(null, fieldName
);
77 assertNotNull(singleFixture
);
83 public void testFloat5311() {
84 parent
= new FloatDeclaration(11, 53, ByteOrder
.nativeOrder(), 0);
85 doubleFixture
= parent
.createDefinition(null, fieldName
);
86 assertNotNull(doubleFixture
);
90 public void testFloat32Bit(){
91 for(int i
= 1; i
< 31 ; i
++) {
92 parent
= new FloatDeclaration(i
, 32-i
, ByteOrder
.nativeOrder(), 0);
93 fixture
= parent
.createDefinition(null, fieldName
);
94 assertNotNull(fixture
);
95 fixture
.setValue(2.0);
96 assertTrue(fixture
.toString().contains("2"));
101 public void testFloat64Bit(){
102 for(int i
= 1; i
< 63 ; i
++) {
103 parent
= new FloatDeclaration(i
, 64-i
, ByteOrder
.nativeOrder(), 0);
104 fixture
= parent
.createDefinition(null, fieldName
);
105 assertNotNull(fixture
);
106 BitBuffer input
= new BitBuffer(java
.nio
.ByteBuffer
.allocateDirect(128));
108 fixture
.setValue(2.0);
109 assertTrue(fixture
.toString().contains("2"));
114 public void testFloat48Bit(){
115 parent
= new FloatDeclaration(12, 32, ByteOrder
.nativeOrder(), 0);
116 fixture
= parent
.createDefinition(null, fieldName
);
117 assertNotNull(fixture
);
118 BitBuffer input
= new BitBuffer(java
.nio
.ByteBuffer
.allocateDirect(128));
121 assertEquals(Double
.NaN
,fixture
.getValue(),0.1);
124 * Run the IntegerDeclaration getDeclaration() method test.
127 public void testGetDeclaration() {
128 singleFixture
.setValue(2.0);
129 FloatDeclaration result
= singleFixture
.getDeclaration();
130 assertNotNull(result
);
134 * Run the long getValue() method test.
137 public void testGetValue() {
138 singleFixture
.setValue(2.0);
139 double result
= singleFixture
.getValue();
140 assertEquals(2.0, result
,0.1);
144 * Run the void read(BitBuffer) method test.
147 public void testRead() {
148 singleFixture
.setValue(2.0);
149 BitBuffer input
= new BitBuffer(java
.nio
.ByteBuffer
.allocateDirect(128));
150 singleFixture
.read(input
);
155 * Run the String toString() method test.
158 public void testToString() {
159 singleFixture
.setValue(222.22);
160 String result
= singleFixture
.toString();
161 assertNotNull(result
);