Commit | Line | Data |
---|---|---|
51209785 MK |
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 | ||
51209785 MK |
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() { | |
07002e0a MK |
66 | parent = new FloatDeclaration(8, 24, ByteOrder.nativeOrder(), 0); |
67 | singleFixture = parent.createDefinition(null, fieldName); | |
51209785 MK |
68 | assertNotNull(singleFixture); |
69 | } | |
70 | ||
71 | ||
72 | ||
73 | @Test | |
74 | public void testFloat5311() { | |
07002e0a MK |
75 | parent = new FloatDeclaration(11, 53, ByteOrder.nativeOrder(), 0); |
76 | doubleFixture = parent.createDefinition(null, fieldName); | |
51209785 MK |
77 | assertNotNull(doubleFixture); |
78 | } | |
79 | ||
80 | @Test | |
81 | public void testFloat32Bit(){ | |
82 | for(int i = 1; i < 31 ; i++) | |
83 | { | |
07002e0a MK |
84 | parent = new FloatDeclaration(i, 32-i, ByteOrder.nativeOrder(), 0); |
85 | fixture = parent.createDefinition(null, fieldName); | |
51209785 MK |
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 | { | |
07002e0a MK |
96 | parent = new FloatDeclaration(i, 64-i, ByteOrder.nativeOrder(), 0); |
97 | fixture = parent.createDefinition(null, fieldName); | |
51209785 MK |
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(){ | |
07002e0a MK |
108 | parent = new FloatDeclaration(12, 32, ByteOrder.nativeOrder(), 0); |
109 | fixture = parent.createDefinition(null, fieldName); | |
51209785 MK |
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 | */ | |
51209785 MK |
129 | @Test |
130 | public void testGetValue() { | |
131 | singleFixture.setValue(2.0); | |
132 | double result = singleFixture.getValue(); | |
133 | assertEquals(2.0, result,0.1); | |
134 | } | |
135 | ||
136 | /** | |
137 | * Run the void read(BitBuffer) method test. | |
138 | */ | |
139 | @Test | |
140 | public void testRead() { | |
141 | singleFixture.setValue(2.0); | |
142 | BitBuffer input = new BitBuffer(java.nio.ByteBuffer.allocateDirect(128)); | |
143 | singleFixture.read(input); | |
144 | ||
145 | } | |
146 | ||
147 | /** | |
148 | * Run the String toString() method test. | |
149 | */ | |
150 | @Test | |
151 | public void testToString() { | |
152 | singleFixture.setValue(222.22); | |
153 | String result = singleFixture.toString(); | |
154 | assertNotNull(result); | |
155 | } | |
156 | } |