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 * Matthew Khouzam - update api (exceptions)
13 *******************************************************************************/
15 package org
.eclipse
.linuxtools
.ctf
.core
.tests
.types
;
17 import static org
.junit
.Assert
.assertEquals
;
19 import java
.nio
.ByteBuffer
;
20 import java
.nio
.ByteOrder
;
22 import org
.eclipse
.jdt
.annotation
.NonNull
;
23 import org
.eclipse
.linuxtools
.ctf
.core
.event
.io
.BitBuffer
;
24 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.Encoding
;
25 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.IntegerDeclaration
;
26 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.IntegerDefinition
;
27 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFReaderException
;
28 import org
.junit
.Before
;
29 import org
.junit
.Test
;
32 * Endianness test for {@link IntegerDefinition}.
34 * @author Geneviève Bastien
36 public class IntegerEndiannessTest
{
38 @NonNull private static final String name
= "testInt";
39 @NonNull private static final String clockName
= "clock";
41 private ByteBuffer bb
;
42 @NonNull private BitBuffer input
= new BitBuffer(java
.nio
.ByteBuffer
.allocate(0));
45 * Set up the bit-buffer to be used
49 bb
= java
.nio
.ByteBuffer
.allocateDirect(8);
58 input
= new BitBuffer(bb
);
64 * @throws CTFReaderException
68 public void test32BE() throws CTFReaderException
{
69 IntegerDeclaration be
= IntegerDeclaration
.createDeclaration(32, true, 1, ByteOrder
.BIG_ENDIAN
, Encoding
.NONE
, clockName
, 8);
70 IntegerDefinition fixture_be
= be
.createDefinition(null, name
, input
);
71 assertEquals(0xabcdef12, fixture_be
.getValue());
77 * @throws CTFReaderException
81 public void test64BE() throws CTFReaderException
{
82 IntegerDeclaration be
= IntegerDeclaration
.createDeclaration(64, true, 1, ByteOrder
.BIG_ENDIAN
, Encoding
.NONE
, clockName
, 8);
83 IntegerDefinition fixture_be
= be
.createDefinition(null, name
, input
);
84 assertEquals(0xabcdef123456789aL
, fixture_be
.getValue());
90 * @throws CTFReaderException
94 public void test32LE() throws CTFReaderException
{
95 IntegerDeclaration le
= IntegerDeclaration
.createDeclaration(32, true, 1, ByteOrder
.LITTLE_ENDIAN
, Encoding
.NONE
, clockName
, 8);
96 IntegerDefinition fixture_le
= le
.createDefinition(null, name
, input
);
97 assertEquals(0x12efcdab, fixture_le
.getValue());
103 * @throws CTFReaderException
107 public void test64LE() throws CTFReaderException
{
108 IntegerDeclaration le
= IntegerDeclaration
.createDeclaration(64, true, 1, ByteOrder
.LITTLE_ENDIAN
, Encoding
.NONE
, clockName
, 8);
109 IntegerDefinition fixture_le
= le
.createDefinition(null, name
, input
);
110 assertEquals(0x9a78563412efcdabL
, fixture_le
.getValue());