ctf: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / ctf / org.eclipse.tracecompass.ctf.core.tests / src / org / eclipse / tracecompass / ctf / core / tests / types / IntegerEndiannessTest.java
1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 École Polytechnique de Montréal, Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Geneviève Bastien - Initial API and implementation
11 * Alexandre Montplaisir - Split out in separate class
12 * Matthew Khouzam - update api (exceptions)
13 *******************************************************************************/
14
15 package org.eclipse.tracecompass.ctf.core.tests.types;
16
17 import static org.junit.Assert.assertEquals;
18
19 import java.nio.ByteBuffer;
20 import java.nio.ByteOrder;
21
22 import org.eclipse.jdt.annotation.NonNull;
23 import org.eclipse.tracecompass.ctf.core.CTFException;
24 import org.eclipse.tracecompass.ctf.core.event.io.BitBuffer;
25 import org.eclipse.tracecompass.ctf.core.event.types.Encoding;
26 import org.eclipse.tracecompass.ctf.core.event.types.IntegerDeclaration;
27 import org.eclipse.tracecompass.ctf.core.event.types.IntegerDefinition;
28 import org.junit.Before;
29 import org.junit.Test;
30
31 /**
32 * Endianness test for {@link IntegerDefinition}.
33 *
34 * @author Geneviève Bastien
35 */
36 public class IntegerEndiannessTest {
37
38 private static final @NonNull String name = "testInt";
39 private static final @NonNull String clockName = "clock";
40
41 private ByteBuffer bb;
42
43 private @NonNull BitBuffer input = new BitBuffer();
44
45 /**
46 * Set up the bit-buffer to be used
47 */
48 @Before
49 public void setUp() {
50 bb = java.nio.ByteBuffer.allocateDirect(8);
51 final ByteBuffer byb = bb;
52 if (byb == null) {
53 throw new IllegalStateException("Failed to allocate memory");
54 }
55 bb.put((byte) 0xab);
56 bb.put((byte) 0xcd);
57 bb.put((byte) 0xef);
58 bb.put((byte) 0x12);
59 bb.put((byte) 0x34);
60 bb.put((byte) 0x56);
61 bb.put((byte) 0x78);
62 bb.put((byte) 0x9a);
63
64 input = new BitBuffer(byb);
65 }
66
67 /**
68 * Read 32-bits BE
69 *
70 * @throws CTFException
71 * error
72 */
73 @Test
74 public void test32BE() throws CTFException {
75 IntegerDeclaration be = IntegerDeclaration.createDeclaration(32, true, 1, ByteOrder.BIG_ENDIAN, Encoding.NONE, clockName, 8);
76 IntegerDefinition fixture_be = be.createDefinition(null, name, input);
77 assertEquals(0xabcdef12, fixture_be.getValue());
78 }
79
80 /**
81 * Read 64-bits BE
82 *
83 * @throws CTFException
84 * error
85 */
86 @Test
87 public void test64BE() throws CTFException {
88 IntegerDeclaration be = IntegerDeclaration.createDeclaration(64, true, 1, ByteOrder.BIG_ENDIAN, Encoding.NONE, clockName, 8);
89 IntegerDefinition fixture_be = be.createDefinition(null, name, input);
90 assertEquals(0xabcdef123456789aL, fixture_be.getValue());
91 }
92
93 /**
94 * Read 32-bits LE
95 *
96 * @throws CTFException
97 * error
98 */
99 @Test
100 public void test32LE() throws CTFException {
101 IntegerDeclaration le = IntegerDeclaration.createDeclaration(32, true, 1, ByteOrder.LITTLE_ENDIAN, Encoding.NONE, clockName, 8);
102 IntegerDefinition fixture_le = le.createDefinition(null, name, input);
103 assertEquals(0x12efcdab, fixture_le.getValue());
104 }
105
106 /**
107 * Read 64-bits LE
108 *
109 * @throws CTFException
110 * error
111 */
112 @Test
113 public void test64LE() throws CTFException {
114 IntegerDeclaration le = IntegerDeclaration.createDeclaration(64, true, 1, ByteOrder.LITTLE_ENDIAN, Encoding.NONE, clockName, 8);
115 IntegerDefinition fixture_le = le.createDefinition(null, name, input);
116 assertEquals(0x9a78563412efcdabL, fixture_le.getValue());
117 }
118 }
This page took 0.035192 seconds and 5 git commands to generate.