ctf: Disable NLS warnings in test plugin
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core.tests / src / org / eclipse / linuxtools / ctf / core / tests / types / FloatDefinitionTest.java
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
7 *
8 * Contributors:
9 * Matthew Khouzam - Initial API and implementation
10 *******************************************************************************/
11
12 package org.eclipse.linuxtools.ctf.core.tests.types;
13
14 import static org.junit.Assert.assertEquals;
15 import static org.junit.Assert.assertNotNull;
16 import static org.junit.Assert.assertTrue;
17
18 import java.nio.ByteOrder;
19
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;
26
27 /**
28 * The class <code>IntegerDefinitionTest</code> contains tests for the class
29 * <code>{@link IntegerDefinition}</code>.
30 *
31 * @author ematkho
32 * @version $Revision: 1.0 $
33 */
34 @SuppressWarnings("javadoc")
35 public class FloatDefinitionTest {
36
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";
42
43 /**
44 * Launch the test.
45 *
46 * @param args
47 * the command line arguments
48 */
49 public static void main(String[] args) {
50 new org.junit.runner.JUnitCore().run(IntegerDefinitionTest.class);
51 }
52
53 /**
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.
56 *
57 * @throws CTFReaderException
58 */
59 @Before
60 public void setUp(){
61 testFloat248();
62 testFloat5311();
63 }
64
65 /**
66 * Perform post-test clean-up.
67 */
68 @After
69 public void tearDown() {
70 // Add additional tear down code here
71 }
72
73 @Test
74 public void testFloat248() {
75 parent = new FloatDeclaration(8, 24, ByteOrder.nativeOrder(), 0);
76 singleFixture = parent.createDefinition(null, fieldName);
77 assertNotNull(singleFixture);
78 }
79
80
81
82 @Test
83 public void testFloat5311() {
84 parent = new FloatDeclaration(11, 53, ByteOrder.nativeOrder(), 0);
85 doubleFixture = parent.createDefinition(null, fieldName);
86 assertNotNull(doubleFixture);
87 }
88
89 @Test
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"));
97 }
98 }
99
100 @Test
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));
107 fixture.read(input);
108 fixture.setValue(2.0);
109 assertTrue(fixture.toString().contains("2"));
110 }
111 }
112
113 @Test
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));
119 fixture.read(input);
120
121 assertEquals(Double.NaN ,fixture.getValue(),0.1);
122 }
123 /**
124 * Run the IntegerDeclaration getDeclaration() method test.
125 */
126 @Test
127 public void testGetDeclaration() {
128 singleFixture.setValue(2.0);
129 FloatDeclaration result = singleFixture.getDeclaration();
130 assertNotNull(result);
131 }
132
133 /**
134 * Run the long getValue() method test.
135 */
136 @Test
137 public void testGetValue() {
138 singleFixture.setValue(2.0);
139 double result = singleFixture.getValue();
140 assertEquals(2.0, result,0.1);
141 }
142
143 /**
144 * Run the void read(BitBuffer) method test.
145 */
146 @Test
147 public void testRead() {
148 singleFixture.setValue(2.0);
149 BitBuffer input = new BitBuffer(java.nio.ByteBuffer.allocateDirect(128));
150 singleFixture.read(input);
151
152 }
153
154 /**
155 * Run the String toString() method test.
156 */
157 @Test
158 public void testToString() {
159 singleFixture.setValue(222.22);
160 String result = singleFixture.toString();
161 assertNotNull(result);
162 }
163 }
This page took 0.033341 seconds and 5 git commands to generate.