1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 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
.tracecompass
.ctf
.core
.tests
.types
;
14 import static org
.junit
.Assert
.assertEquals
;
15 import static org
.junit
.Assert
.assertNotEquals
;
16 import static org
.junit
.Assert
.assertNotNull
;
17 import static org
.junit
.Assert
.assertTrue
;
19 import java
.nio
.ByteOrder
;
21 import org
.eclipse
.tracecompass
.ctf
.core
.event
.types
.FloatDeclaration
;
22 import org
.junit
.Test
;
24 @SuppressWarnings("javadoc")
25 public class FloatDeclarationTest
{
26 private FloatDeclaration fixture
;
29 public void ctorTest() {
30 for (int i
= 1; i
< 20; i
++) {
31 fixture
= new FloatDeclaration(i
, 32 - i
, ByteOrder
.nativeOrder(), 0);
32 assertNotNull(fixture
);
37 public void getterTest() {
38 fixture
= new FloatDeclaration(8, 24, ByteOrder
.nativeOrder(), 1);
39 assertEquals(fixture
.getAlignment(), 1);
40 assertEquals(fixture
.getByteOrder(), ByteOrder
.nativeOrder());
41 assertEquals(fixture
.getExponent(), 8);
42 assertEquals(fixture
.getMantissa(), 24);
46 public void toStringTest() {
47 fixture
= new FloatDeclaration(8, 24, ByteOrder
.nativeOrder(), 0);
48 assertTrue(fixture
.toString().contains("float"));
55 public void hashcodeTest() {
56 FloatDeclaration floatDeclaration
= new FloatDeclaration(8, 24, ByteOrder
.BIG_ENDIAN
, 0);
57 FloatDeclaration a
= new FloatDeclaration(8, 24, ByteOrder
.BIG_ENDIAN
, 0);
58 FloatDeclaration b
= new FloatDeclaration(8, 24, ByteOrder
.LITTLE_ENDIAN
, 0);
59 assertEquals(a
.hashCode(), floatDeclaration
.hashCode());
60 assertNotEquals(b
.hashCode(), floatDeclaration
.hashCode());
61 assertEquals(floatDeclaration
.hashCode(), floatDeclaration
.hashCode());
68 public void equalsTest() {
69 FloatDeclaration a
= new FloatDeclaration(8, 24, ByteOrder
.BIG_ENDIAN
, 0);
70 FloatDeclaration b
= new FloatDeclaration(8, 24, ByteOrder
.LITTLE_ENDIAN
, 0);
71 FloatDeclaration c
= new FloatDeclaration(8, 24, ByteOrder
.BIG_ENDIAN
, 8);
72 FloatDeclaration d
= new FloatDeclaration(8, 8, ByteOrder
.BIG_ENDIAN
, 0);
73 FloatDeclaration e
= new FloatDeclaration(24, 24, ByteOrder
.BIG_ENDIAN
, 0);
74 FloatDeclaration f
= new FloatDeclaration(8, 24, ByteOrder
.BIG_ENDIAN
, 0);
75 assertNotEquals(a
, null);
76 assertNotEquals(a
, new Object());
77 assertNotEquals(a
, b
);
78 assertNotEquals(a
, c
);
79 assertNotEquals(a
, d
);
80 assertNotEquals(b
, a
);
81 assertNotEquals(c
, a
);
82 assertNotEquals(d
, a
);
83 assertNotEquals(e
, a
);
84 assertNotEquals(a
, e
);