Merge branch 'master'
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core.tests / src / org / eclipse / linuxtools / ctf / core / tests / types / FloatDefinitionTest.java
1 package org.eclipse.linuxtools.ctf.core.tests.types;
2
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertNotNull;
5 import static org.junit.Assert.assertTrue;
6
7 import java.nio.ByteOrder;
8
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;
17
18
19
20 /**
21 * The class <code>IntegerDefinitionTest</code> contains tests for the class
22 * <code>{@link IntegerDefinition}</code>.
23 *
24 * @author ematkho
25 * @version $Revision: 1.0 $
26 */
27
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$
34 /**
35 * Launch the test.
36 *
37 * @param args
38 * the command line arguments
39 */
40 public static void main(String[] args) {
41 new org.junit.runner.JUnitCore().run(IntegerDefinitionTest.class);
42 }
43
44 /**
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.
47 *
48 * @throws CTFReaderException
49 */
50 @Before
51 public void setUp(){
52 testFloat248();
53 testFloat5311();
54 }
55
56 /**
57 * Perform post-test clean-up.
58 */
59 @After
60 public void tearDown() {
61 // Add additional tear down code here
62 }
63
64 @Test
65 public void testFloat248() {
66 parent = new FloatDeclaration(8, 24, ByteOrder.nativeOrder(), 0);
67 singleFixture = parent.createDefinition(null, fieldName);
68 assertNotNull(singleFixture);
69 }
70
71
72
73 @Test
74 public void testFloat5311() {
75 parent = new FloatDeclaration(11, 53, ByteOrder.nativeOrder(), 0);
76 doubleFixture = parent.createDefinition(null, fieldName);
77 assertNotNull(doubleFixture);
78 }
79
80 @Test
81 public void testFloat32Bit(){
82 for(int i = 1; i < 31 ; i++)
83 {
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$
89 }
90 }
91
92 @Test
93 public void testFloat64Bit(){
94 for(int i = 1; i < 63 ; i++)
95 {
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));
100 fixture.read(input);
101 fixture.setValue(2.0);
102 assertTrue(fixture.toString().contains("2")); //$NON-NLS-1$
103 }
104 }
105
106 @Test
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));
112 fixture.read(input);
113
114 assertEquals(Double.NaN ,fixture.getValue(),0.1);
115 }
116 /**
117 * Run the IntegerDeclaration getDeclaration() method test.
118 */
119 @Test
120 public void testGetDeclaration() {
121 singleFixture.setValue(2.0);
122 FloatDeclaration result = singleFixture.getDeclaration();
123 assertNotNull(result);
124 }
125
126 /**
127 * Run the long getValue() method test.
128 */
129 @SuppressWarnings("deprecation")
130 @Test
131 public void testGetValue() {
132 singleFixture.setValue(2.0);
133 double result = singleFixture.getValue();
134 assertEquals(2.0, result,0.1);
135 }
136
137 /**
138 * Run the void read(BitBuffer) method test.
139 */
140 @Test
141 public void testRead() {
142 singleFixture.setValue(2.0);
143 BitBuffer input = new BitBuffer(java.nio.ByteBuffer.allocateDirect(128));
144 singleFixture.read(input);
145
146 }
147
148 /**
149 * Run the String toString() method test.
150 */
151 @Test
152 public void testToString() {
153 singleFixture.setValue(222.22);
154 String result = singleFixture.toString();
155 assertNotNull(result);
156 }
157 }
This page took 0.04787 seconds and 6 git commands to generate.