-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathBufferUtilsTest.java
More file actions
85 lines (76 loc) · 2.1 KB
/
BufferUtilsTest.java
File metadata and controls
85 lines (76 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
* Copyright (C) 2013 Klaus Reimer <[email protected]>
* See LICENSE.md for licensing information.
*/
package org.usb4java;
import static org.junit.Assert.assertEquals;
import java.lang.reflect.Constructor;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
import java.nio.LongBuffer;
import org.junit.Test;
import org.usb4java.BufferUtils;
/**
* Tests the {@link BufferUtils} class.
*
* @author Klaus Reimer ([email protected])
*/
public class BufferUtilsTest
{
/**
* Tests the {@link BufferUtils#allocateByteBuffer(int)} method.
*/
@Test
public void testAllocateByteBuffer()
{
ByteBuffer buffer = BufferUtils.allocateByteBuffer(13);
assertEquals(13, buffer.limit());
}
/**
* Tests the {@link BufferUtils#allocateIntBuffer()} method.
*/
@Test
public void testAllocateIntBuffer()
{
IntBuffer buffer = BufferUtils.allocateIntBuffer();
assertEquals(1, buffer.limit());
}
/**
* Tests the {@link BufferUtils#allocateLongBuffer()} method.
*/
@Test
public void testAllocateLongBuffer()
{
LongBuffer buffer = BufferUtils.allocateLongBuffer();
assertEquals(1, buffer.limit());
}
/**
* Tests the {@link BufferUtils#slice(ByteBuffer, int, int)} method.
*/
@Test
public void testSlice()
{
ByteBuffer buffer = BufferUtils.allocateByteBuffer(10);
buffer.put(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
buffer.rewind();
ByteBuffer sliced = BufferUtils.slice(buffer, 2, 3);
assertEquals(3, sliced.remaining());
assertEquals(3, sliced.get());
assertEquals(4, sliced.get());
assertEquals(5, sliced.get());
}
/**
* Ensure constructor is private.
*
* @throws Exception
* When constructor test fails.
*/
@Test
public void testPrivateConstructor() throws Exception
{
assertEquals(0, BufferUtils.class.getConstructors().length);
Constructor<?> c = BufferUtils.class.getDeclaredConstructor();
c.setAccessible(true);
c.newInstance();
}
}