Commit | Line | Data |
---|---|---|
866e5b51 FC |
1 | package org.eclipse.linuxtools.ctf.core.tests.io; |
2 | ||
3 | import static org.junit.Assert.assertEquals; | |
4 | import static org.junit.Assert.assertNotNull; | |
5 | ||
6 | import java.nio.ByteBuffer; | |
7 | import java.nio.ByteOrder; | |
8 | ||
486efb2e | 9 | import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; |
866e5b51 FC |
10 | import org.junit.After; |
11 | import org.junit.Before; | |
12 | import org.junit.Test; | |
13 | ||
14 | /** | |
15 | * The class <code>BitBufferTest</code> contains tests for the class | |
16 | * <code>{@link BitBuffer}</code>. | |
8b8e48ed | 17 | * |
866e5b51 FC |
18 | * @author ematkho |
19 | * @version $Revision: 1.0 $ | |
20 | */ | |
21 | public class BitBufferTest { | |
22 | ||
23 | private BitBuffer fixture; | |
24 | ||
25 | /** | |
26 | * Launch the test. | |
8b8e48ed | 27 | * |
866e5b51 FC |
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 | ||
866e5b51 FC |
89 | /** |
90 | * Run the void clear() method test. | |
91 | */ | |
92 | @Test | |
93 | public void testClear() { | |
94 | fixture.clear(); | |
95 | } | |
96 | ||
97 | /** | |
98 | * Run the ByteBuffer getByteBuffer() method test. | |
99 | */ | |
100 | @Test | |
101 | public void testGetByteBuffer() { | |
102 | ByteBuffer result = fixture.getByteBuffer(); | |
103 | ||
104 | assertNotNull(result); | |
105 | assertEquals( | |
106 | "java.nio.HeapByteBuffer[pos=0 lim=0 cap=0]", result.toString()); //$NON-NLS-1$ | |
107 | assertEquals(false, result.isDirect()); | |
108 | assertEquals(true, result.hasArray()); | |
109 | assertEquals(0, result.arrayOffset()); | |
110 | assertEquals(0, result.limit()); | |
111 | assertEquals(0, result.remaining()); | |
112 | assertEquals(0, result.position()); | |
113 | assertEquals(0, result.capacity()); | |
114 | assertEquals(false, result.hasRemaining()); | |
115 | assertEquals(false, result.isReadOnly()); | |
116 | } | |
117 | ||
118 | /** | |
119 | * Run the ByteOrder getByteOrder() method test. | |
120 | */ | |
121 | @Test | |
122 | public void testGetByteOrder() { | |
123 | ByteOrder result = fixture.getByteOrder(); | |
124 | ||
125 | assertNotNull(result); | |
126 | assertEquals("BIG_ENDIAN", result.toString()); //$NON-NLS-1$ | |
127 | } | |
128 | ||
129 | /** | |
130 | * Run the ByteOrder order() method test. | |
131 | */ | |
132 | @Test | |
133 | public void testGetOrder() { | |
8b8e48ed | 134 | ByteOrder result = fixture.getByteOrder(); |
866e5b51 FC |
135 | |
136 | assertNotNull(result); | |
137 | assertEquals("BIG_ENDIAN", result.toString()); //$NON-NLS-1$ | |
138 | } | |
139 | ||
140 | /** | |
141 | * Run the void order(ByteOrder) method test. | |
142 | */ | |
143 | @Test | |
144 | public void testSetOrder() { | |
145 | ByteOrder order = ByteOrder.BIG_ENDIAN; | |
146 | ||
8b8e48ed | 147 | fixture.setByteOrder(order); |
866e5b51 FC |
148 | } |
149 | ||
150 | /** | |
151 | * Run the int position() method test. | |
152 | */ | |
153 | @Test | |
154 | public void testGetPosition() { | |
155 | int result = fixture.position(); | |
156 | ||
157 | assertEquals(1, result); | |
158 | } | |
159 | ||
160 | /** | |
161 | * Run the void position(int) method test. | |
162 | */ | |
163 | @Test | |
164 | public void testSetPosition() { | |
165 | int newPosition = 1; | |
166 | fixture.position(newPosition); | |
167 | } | |
168 | ||
169 | /** | |
170 | * Run the void setByteBuffer(ByteBuffer) method test. | |
171 | */ | |
172 | @Test | |
173 | public void testSetByteBuffer() { | |
174 | ByteBuffer buf = ByteBuffer.allocate(0); | |
175 | fixture.setByteBuffer(buf); | |
176 | } | |
177 | ||
178 | /** | |
179 | * Run the void setByteBuffer(ByteBuffer) method test. | |
180 | */ | |
181 | @Test | |
182 | public void testSetByteBuffer_null() { | |
183 | ByteBuffer buf = null; | |
184 | fixture.setByteBuffer(buf); | |
185 | } | |
186 | ||
187 | /** | |
188 | * Run the void setByteOrder(ByteOrder) method test. | |
189 | */ | |
190 | @Test | |
191 | public void testSetByteOrder() { | |
192 | ByteOrder byteOrder = ByteOrder.BIG_ENDIAN; | |
193 | fixture.setByteOrder(byteOrder); | |
194 | } | |
195 | } |