common: Annotate some methods in ByteBuffer
[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 bb.put((byte) 0xab);
53 bb.put((byte) 0xcd);
54 bb.put((byte) 0xef);
55 bb.put((byte) 0x12);
56 bb.put((byte) 0x34);
57 bb.put((byte) 0x56);
58 bb.put((byte) 0x78);
59 bb.put((byte) 0x9a);
60
61 input = new BitBuffer(byb);
62 }
63
64 /**
65 * Read 32-bits BE
66 *
67 * @throws CTFException
68 * error
69 */
70 @Test
71 public void test32BE() throws CTFException {
72 IntegerDeclaration be = IntegerDeclaration.createDeclaration(32, true, 1, ByteOrder.BIG_ENDIAN, Encoding.NONE, clockName, 8);
73 IntegerDefinition fixture_be = be.createDefinition(null, name, input);
74 assertEquals(0xabcdef12, fixture_be.getValue());
75 }
76
77 /**
78 * Read 64-bits BE
79 *
80 * @throws CTFException
81 * error
82 */
83 @Test
84 public void test64BE() throws CTFException {
85 IntegerDeclaration be = IntegerDeclaration.createDeclaration(64, true, 1, ByteOrder.BIG_ENDIAN, Encoding.NONE, clockName, 8);
86 IntegerDefinition fixture_be = be.createDefinition(null, name, input);
87 assertEquals(0xabcdef123456789aL, fixture_be.getValue());
88 }
89
90 /**
91 * Read 32-bits LE
92 *
93 * @throws CTFException
94 * error
95 */
96 @Test
97 public void test32LE() throws CTFException {
98 IntegerDeclaration le = IntegerDeclaration.createDeclaration(32, true, 1, ByteOrder.LITTLE_ENDIAN, Encoding.NONE, clockName, 8);
99 IntegerDefinition fixture_le = le.createDefinition(null, name, input);
100 assertEquals(0x12efcdab, fixture_le.getValue());
101 }
102
103 /**
104 * Read 64-bits LE
105 *
106 * @throws CTFException
107 * error
108 */
109 @Test
110 public void test64LE() throws CTFException {
111 IntegerDeclaration le = IntegerDeclaration.createDeclaration(64, true, 1, ByteOrder.LITTLE_ENDIAN, Encoding.NONE, clockName, 8);
112 IntegerDefinition fixture_le = le.createDefinition(null, name, input);
113 assertEquals(0x9a78563412efcdabL, fixture_le.getValue());
114 }
115 }
This page took 0.032297 seconds and 5 git commands to generate.