Tmf rcp: Add the UST feature to the tracing RCP product
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core.tests / src / org / eclipse / linuxtools / ctf / core / tests / io / BitBufferTest.java
CommitLineData
4bd7f2db
AM
1/*******************************************************************************
2 * Copyright (c) 2013 Ericsson
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * Matthew Khouzam - Initial API and implementation
10 *******************************************************************************/
11
866e5b51
FC
12package org.eclipse.linuxtools.ctf.core.tests.io;
13
14import static org.junit.Assert.assertEquals;
15import static org.junit.Assert.assertNotNull;
16
17import java.nio.ByteBuffer;
18import java.nio.ByteOrder;
19
486efb2e 20import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
866e5b51
FC
21import org.junit.Before;
22import org.junit.Test;
23
24/**
25 * The class <code>BitBufferTest</code> contains tests for the class
26 * <code>{@link BitBuffer}</code>.
8b8e48ed 27 *
866e5b51
FC
28 * @author ematkho
29 * @version $Revision: 1.0 $
30 */
31public class BitBufferTest {
32
33 private BitBuffer fixture;
34
866e5b51
FC
35 /**
36 * Perform pre-test initialization.
37 */
38 @Before
39 public void setUp() {
40 fixture = new BitBuffer(java.nio.ByteBuffer.allocateDirect(128));
41 fixture.setByteOrder(ByteOrder.BIG_ENDIAN);
42 fixture.setByteBuffer(ByteBuffer.allocate(0));
43 fixture.position(1);
44 }
45
866e5b51
FC
46 /**
47 * Run the BitBuffer() constructor test.
48 */
49 @Test
50 public void testBitBuffer() {
51 BitBuffer result = new BitBuffer();
52
53 assertNotNull(result);
54 assertEquals(0, result.position());
55 assertEquals(null, result.getByteBuffer());
56 }
57
58 /**
59 * Run the BitBuffer(ByteBuffer) constructor test.
60 */
61 @Test
62 public void testBitBuffer_fromByteBuffer() {
63 ByteBuffer buf = ByteBuffer.allocate(0);
64 BitBuffer result = new BitBuffer(buf);
65
66 assertNotNull(result);
67 assertEquals(0, result.position());
68 }
69
70 /**
71 * Run the boolean canRead(int) method test.
72 */
73 @Test
74 public void testCanRead_1param() {
75 int length = 1;
76 boolean result = fixture.canRead(length);
77
78 assertEquals(false, result);
79 }
80
866e5b51
FC
81 /**
82 * Run the void clear() method test.
83 */
84 @Test
85 public void testClear() {
86 fixture.clear();
87 }
88
89 /**
90 * Run the ByteBuffer getByteBuffer() method test.
91 */
92 @Test
93 public void testGetByteBuffer() {
94 ByteBuffer result = fixture.getByteBuffer();
95
96 assertNotNull(result);
4a9c1f07 97 assertEquals("java.nio.HeapByteBuffer[pos=0 lim=0 cap=0]", result.toString());
866e5b51
FC
98 assertEquals(false, result.isDirect());
99 assertEquals(true, result.hasArray());
100 assertEquals(0, result.arrayOffset());
101 assertEquals(0, result.limit());
102 assertEquals(0, result.remaining());
103 assertEquals(0, result.position());
104 assertEquals(0, result.capacity());
105 assertEquals(false, result.hasRemaining());
106 assertEquals(false, result.isReadOnly());
107 }
108
109 /**
110 * Run the ByteOrder getByteOrder() method test.
111 */
112 @Test
113 public void testGetByteOrder() {
114 ByteOrder result = fixture.getByteOrder();
115
116 assertNotNull(result);
4a9c1f07 117 assertEquals("BIG_ENDIAN", result.toString());
866e5b51
FC
118 }
119
120 /**
121 * Run the ByteOrder order() method test.
122 */
123 @Test
124 public void testGetOrder() {
8b8e48ed 125 ByteOrder result = fixture.getByteOrder();
866e5b51
FC
126
127 assertNotNull(result);
4a9c1f07 128 assertEquals("BIG_ENDIAN", result.toString());
866e5b51
FC
129 }
130
131 /**
132 * Run the void order(ByteOrder) method test.
133 */
134 @Test
135 public void testSetOrder() {
136 ByteOrder order = ByteOrder.BIG_ENDIAN;
137
8b8e48ed 138 fixture.setByteOrder(order);
866e5b51
FC
139 }
140
141 /**
142 * Run the int position() method test.
143 */
144 @Test
145 public void testGetPosition() {
146 int result = fixture.position();
147
148 assertEquals(1, result);
149 }
150
151 /**
152 * Run the void position(int) method test.
153 */
154 @Test
155 public void testSetPosition() {
156 int newPosition = 1;
157 fixture.position(newPosition);
158 }
159
160 /**
161 * Run the void setByteBuffer(ByteBuffer) method test.
162 */
163 @Test
164 public void testSetByteBuffer() {
165 ByteBuffer buf = ByteBuffer.allocate(0);
166 fixture.setByteBuffer(buf);
167 }
168
169 /**
170 * Run the void setByteBuffer(ByteBuffer) method test.
171 */
172 @Test
173 public void testSetByteBuffer_null() {
174 ByteBuffer buf = null;
175 fixture.setByteBuffer(buf);
176 }
177
178 /**
179 * Run the void setByteOrder(ByteOrder) method test.
180 */
181 @Test
182 public void testSetByteOrder() {
183 ByteOrder byteOrder = ByteOrder.BIG_ENDIAN;
184 fixture.setByteOrder(byteOrder);
185 }
186}
This page took 0.03982 seconds and 5 git commands to generate.