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
CommitLineData
3edb91f3 1/*******************************************************************************
ed902a2b 2 * Copyright (c) 2013, 2014 École Polytechnique de Montréal, Ericsson
3edb91f3
GB
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
db8e8f7d 12 * Matthew Khouzam - update api (exceptions)
3edb91f3
GB
13 *******************************************************************************/
14
f357bcd4 15package org.eclipse.tracecompass.ctf.core.tests.types;
3edb91f3
GB
16
17import static org.junit.Assert.assertEquals;
18
19import java.nio.ByteBuffer;
20import java.nio.ByteOrder;
21
a4fa4e36 22import org.eclipse.jdt.annotation.NonNull;
680f9173 23import org.eclipse.tracecompass.ctf.core.CTFException;
f357bcd4
AM
24import org.eclipse.tracecompass.ctf.core.event.io.BitBuffer;
25import org.eclipse.tracecompass.ctf.core.event.types.Encoding;
26import org.eclipse.tracecompass.ctf.core.event.types.IntegerDeclaration;
27import org.eclipse.tracecompass.ctf.core.event.types.IntegerDefinition;
3edb91f3
GB
28import org.junit.Before;
29import org.junit.Test;
30
31/**
32 * Endianness test for {@link IntegerDefinition}.
33 *
34 * @author Geneviève Bastien
35 */
36public class IntegerEndiannessTest {
37
aefc5c83
MK
38 private static final @NonNull String name = "testInt";
39 private static final @NonNull String clockName = "clock";
3edb91f3
GB
40
41 private ByteBuffer bb;
aefc5c83
MK
42
43 private @NonNull BitBuffer input = new BitBuffer();
3edb91f3
GB
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);
aefc5c83
MK
51 final ByteBuffer byb = bb;
52 if (byb == null) {
53 throw new IllegalStateException("Failed to allocate memory");
54 }
3edb91f3
GB
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);
aefc5c83
MK
63
64 input = new BitBuffer(byb);
3edb91f3
GB
65 }
66
db8e8f7d
AM
67 /**
68 * Read 32-bits BE
69 *
680f9173 70 * @throws CTFException
db8e8f7d
AM
71 * error
72 */
3edb91f3 73 @Test
680f9173 74 public void test32BE() throws CTFException {
a4fa4e36
MK
75 IntegerDeclaration be = IntegerDeclaration.createDeclaration(32, true, 1, ByteOrder.BIG_ENDIAN, Encoding.NONE, clockName, 8);
76 IntegerDefinition fixture_be = be.createDefinition(null, name, input);
3edb91f3
GB
77 assertEquals(0xabcdef12, fixture_be.getValue());
78 }
79
db8e8f7d
AM
80 /**
81 * Read 64-bits BE
82 *
680f9173 83 * @throws CTFException
db8e8f7d
AM
84 * error
85 */
3edb91f3 86 @Test
680f9173 87 public void test64BE() throws CTFException {
a4fa4e36
MK
88 IntegerDeclaration be = IntegerDeclaration.createDeclaration(64, true, 1, ByteOrder.BIG_ENDIAN, Encoding.NONE, clockName, 8);
89 IntegerDefinition fixture_be = be.createDefinition(null, name, input);
3edb91f3
GB
90 assertEquals(0xabcdef123456789aL, fixture_be.getValue());
91 }
92
db8e8f7d
AM
93 /**
94 * Read 32-bits LE
95 *
680f9173 96 * @throws CTFException
db8e8f7d
AM
97 * error
98 */
3edb91f3 99 @Test
680f9173 100 public void test32LE() throws CTFException {
a4fa4e36
MK
101 IntegerDeclaration le = IntegerDeclaration.createDeclaration(32, true, 1, ByteOrder.LITTLE_ENDIAN, Encoding.NONE, clockName, 8);
102 IntegerDefinition fixture_le = le.createDefinition(null, name, input);
3edb91f3
GB
103 assertEquals(0x12efcdab, fixture_le.getValue());
104 }
105
db8e8f7d
AM
106 /**
107 * Read 64-bits LE
108 *
680f9173 109 * @throws CTFException
db8e8f7d
AM
110 * error
111 */
3edb91f3 112 @Test
680f9173 113 public void test64LE() throws CTFException {
a4fa4e36
MK
114 IntegerDeclaration le = IntegerDeclaration.createDeclaration(64, true, 1, ByteOrder.LITTLE_ENDIAN, Encoding.NONE, clockName, 8);
115 IntegerDefinition fixture_le = le.createDefinition(null, name, input);
3edb91f3
GB
116 assertEquals(0x9a78563412efcdabL, fixture_le.getValue());
117 }
118}
This page took 0.091633 seconds and 5 git commands to generate.