6f2175b029faaaff09c156380a2cdca61f77f57b
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core.tests / src / org / eclipse / linuxtools / ctf / core / tests / types / IntegerEndiannessTest.java
1 /*******************************************************************************
2 * Copyright (c) 2013 É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 *******************************************************************************/
13
14 package org.eclipse.linuxtools.ctf.core.tests.types;
15
16 import static org.junit.Assert.assertEquals;
17
18 import java.nio.ByteBuffer;
19 import java.nio.ByteOrder;
20
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;
27
28 /**
29 * Endianness test for {@link IntegerDefinition}.
30 *
31 * @author Geneviève Bastien
32 */
33 public class IntegerEndiannessTest {
34
35 private static String name = "testInt";
36 private static String clockName = "clock";
37
38 private ByteBuffer bb;
39 private BitBuffer input;
40
41 /**
42 * Set up the bit-buffer to be used
43 */
44 @Before
45 public void setUp() {
46 bb = java.nio.ByteBuffer.allocateDirect(8);
47 bb.put((byte) 0xab);
48 bb.put((byte) 0xcd);
49 bb.put((byte) 0xef);
50 bb.put((byte) 0x12);
51 bb.put((byte) 0x34);
52 bb.put((byte) 0x56);
53 bb.put((byte) 0x78);
54 bb.put((byte) 0x9a);
55 input = new BitBuffer(bb);
56 }
57
58 /** Read 32-bits BE */
59 @Test
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());
65 }
66
67 /** Read 64-bits BE */
68 @Test
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());
74 }
75
76 /** Read 32-bits LE */
77 @Test
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());
83 }
84
85 /** Read 64-bits LE */
86 @Test
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());
92 }
93 }
This page took 0.034403 seconds and 4 git commands to generate.