Commit | Line | Data |
---|---|---|
4bd7f2db AM |
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 | ||
f357bcd4 | 12 | package org.eclipse.tracecompass.ctf.core.tests.types; |
51209785 MK |
13 | |
14 | import static org.junit.Assert.assertEquals; | |
e00e6663 | 15 | import static org.junit.Assert.assertNotEquals; |
51209785 MK |
16 | import static org.junit.Assert.assertNotNull; |
17 | import static org.junit.Assert.assertTrue; | |
18 | ||
19 | import java.nio.ByteOrder; | |
20 | ||
f357bcd4 | 21 | import org.eclipse.tracecompass.ctf.core.event.types.FloatDeclaration; |
51209785 MK |
22 | import org.junit.Test; |
23 | ||
be6df2d8 | 24 | @SuppressWarnings("javadoc") |
51209785 MK |
25 | public class FloatDeclarationTest { |
26 | private FloatDeclaration fixture; | |
27 | ||
51209785 MK |
28 | @Test |
29 | public void ctorTest() { | |
e00e6663 MK |
30 | for (int i = 1; i < 20; i++) { |
31 | fixture = new FloatDeclaration(i, 32 - i, ByteOrder.nativeOrder(), 0); | |
51209785 MK |
32 | assertNotNull(fixture); |
33 | } | |
34 | } | |
35 | ||
36 | @Test | |
37 | public void getterTest() { | |
056ebaf1 | 38 | fixture = new FloatDeclaration(8, 24, ByteOrder.nativeOrder(), 1); |
e00e6663 MK |
39 | assertEquals(fixture.getAlignment(), 1); |
40 | assertEquals(fixture.getByteOrder(), ByteOrder.nativeOrder()); | |
41 | assertEquals(fixture.getExponent(), 8); | |
42 | assertEquals(fixture.getMantissa(), 24); | |
51209785 MK |
43 | } |
44 | ||
45 | @Test | |
46 | public void toStringTest() { | |
07002e0a | 47 | fixture = new FloatDeclaration(8, 24, ByteOrder.nativeOrder(), 0); |
4a9c1f07 | 48 | assertTrue(fixture.toString().contains("float")); |
51209785 | 49 | } |
e00e6663 MK |
50 | |
51 | /** | |
52 | * Test the hashcode | |
53 | */ | |
54 | @Test | |
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); | |
e00e6663 MK |
59 | assertEquals(a.hashCode(), floatDeclaration.hashCode()); |
60 | assertNotEquals(b.hashCode(), floatDeclaration.hashCode()); | |
61 | } | |
62 | ||
63 | /** | |
64 | * Test the equals | |
65 | */ | |
66 | @Test | |
67 | public void equalsTest() { | |
68 | FloatDeclaration a = new FloatDeclaration(8, 24, ByteOrder.BIG_ENDIAN, 0); | |
69 | FloatDeclaration b = new FloatDeclaration(8, 24, ByteOrder.LITTLE_ENDIAN, 0); | |
70 | FloatDeclaration c = new FloatDeclaration(8, 24, ByteOrder.BIG_ENDIAN, 8); | |
71 | FloatDeclaration d = new FloatDeclaration(8, 8, ByteOrder.BIG_ENDIAN, 0); | |
72 | FloatDeclaration e = new FloatDeclaration(24, 24, ByteOrder.BIG_ENDIAN, 0); | |
73 | FloatDeclaration f = new FloatDeclaration(8, 24, ByteOrder.BIG_ENDIAN, 0); | |
74 | assertNotEquals(a, null); | |
75 | assertNotEquals(a, new Object()); | |
76 | assertNotEquals(a, b); | |
77 | assertNotEquals(a, c); | |
78 | assertNotEquals(a, d); | |
79 | assertNotEquals(b, a); | |
80 | assertNotEquals(c, a); | |
81 | assertNotEquals(d, a); | |
82 | assertNotEquals(e, a); | |
83 | assertNotEquals(a, e); | |
84 | ||
85 | assertEquals(a, f); | |
86 | assertEquals(f, a); | |
87 | assertEquals(a, a); | |
88 | } | |
51209785 | 89 | } |