1 /**
2 *
3 */
4 package org.melati.util.test;
5
6 import java.io.ByteArrayInputStream;
7
8 import org.melati.util.DelimitedBufferedInputStream;
9
10 import junit.framework.TestCase;
11
12 /**
13 * @author timp
14 * @since 28 Jan 2008
15 *
16 */
17 public class DelimitedBufferedInputStreamTest extends TestCase {
18
19 byte[] sink = new byte[10];
20 byte[] arr1 = {30, 31, 32, 33};
21 byte[] arr2 = {32, 33};
22 byte[] arr3 = {32, 34, 33};
23 byte[] arr4 = {32, 33, 34};
24
25 /**
26 * @param name
27 */
28 public DelimitedBufferedInputStreamTest(String name) {
29 super(name);
30 }
31
32 /**
33 * {@inheritDoc}
34 * @see junit.framework.TestCase#setUp()
35 */
36 protected void setUp() throws Exception {
37 super.setUp();
38 }
39
40 /**
41 * {@inheritDoc}
42 * @see junit.framework.TestCase#tearDown()
43 */
44 protected void tearDown() throws Exception {
45 super.tearDown();
46 }
47
48 /**
49 * Test method for {@link org.melati.util.DelimitedBufferedInputStream#DelimitedBufferedInputStream(java.io.InputStream)}.
50 */
51 public void testDelimitedBufferedInputStreamInputStream() {
52 DelimitedBufferedInputStream testDBIS =
53 new DelimitedBufferedInputStream(
54 new ByteArrayInputStream(arr1));
55 assertTrue("arr2 in arr1 (expect 2): " ,
56 testDBIS.indexOf(arr1, arr2, 0) == 2);
57 assertTrue("potentialMatch (expect -1): " ,
58 testDBIS.getPotentialMatch() == -1);
59 assertTrue("arr3 in arr1 (expect -1): " ,
60 testDBIS.indexOf(arr1, arr3, 0) == -1);
61 assertTrue("potentialMatch (expect -1): " ,
62 testDBIS.getPotentialMatch() == -1);
63 assertTrue("arr4 in arr1 (expect -1): ",
64 testDBIS.indexOf(arr1, arr4, 0) == -1);
65 assertTrue("potentialMatch (expect 2): ",
66 testDBIS.getPotentialMatch() == 2);
67 }
68
69 /**
70 * Test method for {@link org.melati.util.DelimitedBufferedInputStream#DelimitedBufferedInputStream(java.io.InputStream, int)}.
71 */
72 public void testDelimitedBufferedInputStreamInputStreamInt() throws Exception {
73 DelimitedBufferedInputStream testDBIS =
74 new DelimitedBufferedInputStream(
75 new ByteArrayInputStream(arr1), 1);
76 assertTrue("reading upto arr3 (expect 4): " ,
77 testDBIS.readToDelimiter(sink, 0, 10, arr3) == 4);
78 }
79
80 /**
81 * Test method for {@link org.melati.util.DelimitedBufferedInputStream#readToDelimiter(byte[], int, int, byte[])}.
82 */
83 public void testReadToDelimiter() throws Exception {
84 DelimitedBufferedInputStream testDBIS =
85 new DelimitedBufferedInputStream(
86 new ByteArrayInputStream(arr1));
87 assertTrue("reading upto arr2 (expect 2): ",
88 testDBIS.readToDelimiter(sink, 0, 10, arr2) == 2);
89 assertTrue("reading upto arr2 again (expect 0): " +
90 testDBIS.readToDelimiter(sink, 0, 10, arr2),
91 testDBIS.readToDelimiter(sink, 0, 10, arr2) == 0);
92 testDBIS = new DelimitedBufferedInputStream(
93 new ByteArrayInputStream(arr1), 1);
94 assertTrue("reading upto arr4 (expect 4): " ,
95 testDBIS.readToDelimiter(sink, 0, 10, arr4) == 4);
96 testDBIS = new DelimitedBufferedInputStream(
97 new ByteArrayInputStream(arr1), 1);
98 assertTrue("reading upto arr4 (expect 3): ",
99 testDBIS.readToDelimiter(sink, 0, 3, arr4) == 3);
100 assertTrue("buf.length is now (expect 3): ",
101 testDBIS.getBufferLength() == 3);
102
103 }
104
105 /**
106 * Test method for {@link org.melati.util.DelimitedBufferedInputStream#indexOf(byte[], byte[], int)}.
107 */
108 public void testIndexOfByteArrayByteArrayInt() {
109 }
110
111 /**
112 * Test method for {@link org.melati.util.DelimitedBufferedInputStream#indexOf(byte[], byte[], int, int)}.
113 */
114 public void testIndexOfByteArrayByteArrayIntInt() {
115 }
116
117 }