Contribute native CTF Parser (bug370499)
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core.tests / src / org / eclipse / linuxtools / ctf / core / tests / io / BitBufferTest.java
CommitLineData
866e5b51
FC
1package org.eclipse.linuxtools.ctf.core.tests.io;
2
3import static org.junit.Assert.assertEquals;
4import static org.junit.Assert.assertNotNull;
5
6import java.nio.ByteBuffer;
7import java.nio.ByteOrder;
8
9import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
10import org.junit.After;
11import org.junit.Before;
12import org.junit.Test;
13
14/**
15 * The class <code>BitBufferTest</code> contains tests for the class
16 * <code>{@link BitBuffer}</code>.
17 *
18 * @author ematkho
19 * @version $Revision: 1.0 $
20 */
21public class BitBufferTest {
22
23 private BitBuffer fixture;
24
25 /**
26 * Launch the test.
27 *
28 * @param args
29 * the command line arguments
30 */
31 public static void main(String[] args) {
32 new org.junit.runner.JUnitCore().run(BitBufferTest.class);
33 }
34
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
46 /**
47 * Perform post-test clean-up.
48 */
49 @After
50 public void tearDown() {
51 // Add additional tear down code here
52 }
53
54 /**
55 * Run the BitBuffer() constructor test.
56 */
57 @Test
58 public void testBitBuffer() {
59 BitBuffer result = new BitBuffer();
60
61 assertNotNull(result);
62 assertEquals(0, result.position());
63 assertEquals(null, result.getByteBuffer());
64 }
65
66 /**
67 * Run the BitBuffer(ByteBuffer) constructor test.
68 */
69 @Test
70 public void testBitBuffer_fromByteBuffer() {
71 ByteBuffer buf = ByteBuffer.allocate(0);
72 BitBuffer result = new BitBuffer(buf);
73
74 assertNotNull(result);
75 assertEquals(0, result.position());
76 }
77
78 /**
79 * Run the boolean canRead(int) method test.
80 */
81 @Test
82 public void testCanRead_1param() {
83 int length = 1;
84 boolean result = fixture.canRead(length);
85
86 assertEquals(false, result);
87 }
88
89 /**
90 * Run the boolean canRead(int,int) method test.
91 */
92 @Test
93 public void testCanRead_2params() {
94 int index = 1;
95 int length = 1;
96 boolean result = fixture.canRead(index, length);
97
98 assertEquals(false, result);
99 }
100
101 /**
102 * Run the void clear() method test.
103 */
104 @Test
105 public void testClear() {
106 fixture.clear();
107 }
108
109 /**
110 * Run the ByteBuffer getByteBuffer() method test.
111 */
112 @Test
113 public void testGetByteBuffer() {
114 ByteBuffer result = fixture.getByteBuffer();
115
116 assertNotNull(result);
117 assertEquals(
118 "java.nio.HeapByteBuffer[pos=0 lim=0 cap=0]", result.toString()); //$NON-NLS-1$
119 assertEquals(false, result.isDirect());
120 assertEquals(true, result.hasArray());
121 assertEquals(0, result.arrayOffset());
122 assertEquals(0, result.limit());
123 assertEquals(0, result.remaining());
124 assertEquals(0, result.position());
125 assertEquals(0, result.capacity());
126 assertEquals(false, result.hasRemaining());
127 assertEquals(false, result.isReadOnly());
128 }
129
130 /**
131 * Run the ByteOrder getByteOrder() method test.
132 */
133 @Test
134 public void testGetByteOrder() {
135 ByteOrder result = fixture.getByteOrder();
136
137 assertNotNull(result);
138 assertEquals("BIG_ENDIAN", result.toString()); //$NON-NLS-1$
139 }
140
141 /**
142 * Run the ByteOrder order() method test.
143 */
144 @Test
145 public void testGetOrder() {
146 ByteOrder result = fixture.order();
147
148 assertNotNull(result);
149 assertEquals("BIG_ENDIAN", result.toString()); //$NON-NLS-1$
150 }
151
152 /**
153 * Run the void order(ByteOrder) method test.
154 */
155 @Test
156 public void testSetOrder() {
157 ByteOrder order = ByteOrder.BIG_ENDIAN;
158
159 fixture.order(order);
160 }
161
162 /**
163 * Run the int position() method test.
164 */
165 @Test
166 public void testGetPosition() {
167 int result = fixture.position();
168
169 assertEquals(1, result);
170 }
171
172 /**
173 * Run the void position(int) method test.
174 */
175 @Test
176 public void testSetPosition() {
177 int newPosition = 1;
178 fixture.position(newPosition);
179 }
180
181 /**
182 * Run the void setByteBuffer(ByteBuffer) method test.
183 */
184 @Test
185 public void testSetByteBuffer() {
186 ByteBuffer buf = ByteBuffer.allocate(0);
187 fixture.setByteBuffer(buf);
188 }
189
190 /**
191 * Run the void setByteBuffer(ByteBuffer) method test.
192 */
193 @Test
194 public void testSetByteBuffer_null() {
195 ByteBuffer buf = null;
196 fixture.setByteBuffer(buf);
197 }
198
199 /**
200 * Run the void setByteOrder(ByteOrder) method test.
201 */
202 @Test
203 public void testSetByteOrder() {
204 ByteOrder byteOrder = ByteOrder.BIG_ENDIAN;
205 fixture.setByteOrder(byteOrder);
206 }
207}
This page took 0.031879 seconds and 5 git commands to generate.