1 /*******************************************************************************
2 * Copyright (c) 2013 École Polytechnique de Montréal, Ericsson
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
10 * Geneviève Bastien - Initial API and implementation
11 * Alexandre Montplaisir - Split out in separate class
12 *******************************************************************************/
14 package org
.eclipse
.linuxtools
.ctf
.core
.tests
.types
;
16 import static org
.junit
.Assert
.assertEquals
;
18 import java
.nio
.ByteBuffer
;
19 import java
.nio
.ByteOrder
;
21 import org
.eclipse
.linuxtools
.ctf
.core
.event
.io
.BitBuffer
;
22 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.Encoding
;
23 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.IntegerDeclaration
;
24 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.IntegerDefinition
;
25 import org
.junit
.Before
;
26 import org
.junit
.Test
;
29 * Endianness test for {@link IntegerDefinition}.
31 * @author Geneviève Bastien
33 public class IntegerEndiannessTest
{
35 private static String name
= "testInt";
36 private static String clockName
= "clock";
38 private ByteBuffer bb
;
39 private BitBuffer input
;
42 * Set up the bit-buffer to be used
46 bb
= java
.nio
.ByteBuffer
.allocateDirect(8);
55 input
= new BitBuffer(bb
);
58 /** Read 32-bits BE */
60 public void test32BE() {
61 IntegerDeclaration be
= new IntegerDeclaration(32, true, 1, ByteOrder
.BIG_ENDIAN
, Encoding
.NONE
, clockName
, 8);
62 IntegerDefinition fixture_be
= be
.createDefinition(null, name
);
63 fixture_be
.read(input
);
64 assertEquals(0xabcdef12, fixture_be
.getValue());
67 /** Read 64-bits BE */
69 public void test64BE() {
70 IntegerDeclaration be
= new IntegerDeclaration(64, true, 1, ByteOrder
.BIG_ENDIAN
, Encoding
.NONE
, clockName
, 8);
71 IntegerDefinition fixture_be
= be
.createDefinition(null, name
);
72 fixture_be
.read(input
);
73 assertEquals(0xabcdef123456789aL
, fixture_be
.getValue());
76 /** Read 32-bits LE */
78 public void test32LE() {
79 IntegerDeclaration le
= new IntegerDeclaration(32, true, 1, ByteOrder
.LITTLE_ENDIAN
, Encoding
.NONE
, clockName
, 8);
80 IntegerDefinition fixture_le
= le
.createDefinition(null, name
);
81 fixture_le
.read(input
);
82 assertEquals(0x12efcdab, fixture_le
.getValue());
85 /** Read 64-bits LE */
87 public void test64LE() {
88 IntegerDeclaration le
= new IntegerDeclaration(64, true, 1, ByteOrder
.LITTLE_ENDIAN
, Encoding
.NONE
, clockName
, 8);
89 IntegerDefinition fixture_le
= le
.createDefinition(null, name
);
90 fixture_le
.read(input
);
91 assertEquals(0x9a78563412efcdabL
, fixture_le
.getValue());