Menu

[21d594]: / test / java / nginx / clojure / HackUtilsTest.java  Maximize  Restore  History

Download this file

51 lines (39 with data), 1.2 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
package nginx.clojure;
import static org.junit.Assert.*;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class HackUtilsTest {
Charset utf8 = Charset.forName("utf-8");
@Before
public void setUp() throws Exception {
}
@After
public void tearDown() throws Exception {
}
@Test
public void testDecode() {
String ss = "abcdefg";
String dss = HackUtils.decode(ByteBuffer.wrap(ss.getBytes(utf8)), utf8, CharBuffer.allocate(100));
assertEquals(ss, dss);
dss = HackUtils.decode(ByteBuffer.wrap(ss.getBytes(utf8)), utf8, CharBuffer.allocate(1));
assertEquals(ss, dss);
}
@Test
public void testEncode() {
ByteBuffer bb = HackUtils.encodeLowcase("ABCDEFG", utf8, ByteBuffer.allocate(100));
assertEquals("abcdefg", new String(bb.array(), 0, bb.remaining()));
}
@Test
public void testDecodeValid() {
ByteBuffer bb = ByteBuffer.allocate(8);
bb.put("goodvery".getBytes());
bb.flip();
CharBuffer cb = CharBuffer.allocate(2);
System.out.println(HackUtils.decodeValid(bb, utf8, cb));
System.out.println(bb.remaining());
}
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.