ctf: Make events immutable
[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 * Matthew Khouzam - update api (exceptions)
13 *******************************************************************************/
14
15 package org.eclipse.linuxtools.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.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;
30
31 /**
32 * Endianness test for {@link IntegerDefinition}.
33 *
34 * @author Geneviève Bastien
35 */
36 public class IntegerEndiannessTest {
37
38 @NonNull private static final String name = "testInt";
39 @NonNull private static final String clockName = "clock";
40
41 private ByteBuffer bb;
42 @NonNull private BitBuffer input = new BitBuffer(java.nio.ByteBuffer.allocate(0));
43
44 /**
45 * Set up the bit-buffer to be used
46 */
47 @Before
48 public void setUp() {
49 bb = java.nio.ByteBuffer.allocateDirect(8);
50 bb.put((byte) 0xab);
51 bb.put((byte) 0xcd);
52 bb.put((byte) 0xef);
53 bb.put((byte) 0x12);
54 bb.put((byte) 0x34);
55 bb.put((byte) 0x56);
56 bb.put((byte) 0x78);
57 bb.put((byte) 0x9a);
58 input = new BitBuffer(bb);
59 }
60
61 /**
62 * Read 32-bits BE
63 *
64 * @throws CTFReaderException
65 * error
66 */
67 @Test
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());
72 }
73
74 /**
75 * Read 64-bits BE
76 *
77 * @throws CTFReaderException
78 * error
79 */
80 @Test
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());
85 }
86
87 /**
88 * Read 32-bits LE
89 *
90 * @throws CTFReaderException
91 * error
92 */
93 @Test
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());
98 }
99
100 /**
101 * Read 64-bits LE
102 *
103 * @throws CTFReaderException
104 * error
105 */
106 @Test
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());
111 }
112 }
This page took 0.051665 seconds and 5 git commands to generate.