@Test public void testSeekerFindResume() { byte[] marker = {0, 1, 2, 3}; byte[] buffer; Seeker s; s = new Seeker(marker); buffer = new byte[] {0, 0, 0, 0, 0, 0, 0, 0}; assertEquals(-1, s.find(buffer, buffer.length)); buffer = new byte[] {1, 2, 3, 0, 0, 0, 0, 0}; assertEquals(2, s.find(buffer, buffer.length)); buffer = new byte[] {0, 0, 0, 0, 0, 0, 1, 2}; assertEquals(-1, s.find(buffer, buffer.length)); buffer = new byte[] {3, 0, 1, 2, 3, 0, 1, 2}; assertEquals(0, s.find(buffer, buffer.length)); buffer = new byte[] {0}; assertEquals(-1, s.find(buffer, buffer.length)); buffer = new byte[] {1}; assertEquals(-1, s.find(buffer, buffer.length)); buffer = new byte[] {2}; assertEquals(-1, s.find(buffer, buffer.length)); buffer = new byte[] {3}; assertEquals(0, s.find(buffer, buffer.length)); }
@Test public void testSeekerFindAllLocations() { byte[] marker = {1, 1, 2}; byte[] allOnes = new byte[] {1, 1, 1, 1}; byte[] findIn = new byte[] {1, 1, 1, 1}; Seeker s = new Seeker(marker); for (int i = 0; i < findIn.length; i++) { assertEquals(-1, s.find(allOnes, allOnes.length)); findIn[i] = 2; assertEquals(i, s.find(findIn, findIn.length)); findIn[i] = 1; } }
// Tests for Seeker. @Test public void testSeekerFind() { byte[] marker = {0, 1, 2, 3}; byte[] buffer; Seeker s; s = new Seeker(marker); buffer = new byte[] {0, 1, 2, 3, 4, 5, 6, 7}; assertEquals(3, s.find(buffer, buffer.length)); buffer = new byte[] {0, 0, 0, 0, 0, 1, 2, 3}; assertEquals(7, s.find(buffer, buffer.length)); buffer = new byte[] {0, 1, 2, 0, 0, 1, 2, 3}; assertEquals(7, s.find(buffer, buffer.length)); buffer = new byte[] {0, 1, 2, 3}; assertEquals(3, s.find(buffer, buffer.length)); }
@Test public void testSeekerUsesBufferLength() { byte[] marker = {0, 0, 1}; byte[] buffer; Seeker s; s = new Seeker(marker); buffer = new byte[] {0, 0, 0, 1}; assertEquals(-1, s.find(buffer, 3)); s = new Seeker(marker); buffer = new byte[] {0, 0}; assertEquals(-1, s.find(buffer, 1)); buffer = new byte[] {1, 0}; assertEquals(-1, s.find(buffer, 1)); s = new Seeker(marker); buffer = new byte[] {0, 2}; assertEquals(-1, s.find(buffer, 1)); buffer = new byte[] {0, 2}; assertEquals(-1, s.find(buffer, 1)); buffer = new byte[] {1, 2}; assertEquals(0, s.find(buffer, 1)); }
@Test public void testSeekerFindPartial() { byte[] marker = {0, 0, 1}; byte[] buffer; Seeker s; s = new Seeker(marker); buffer = new byte[] {0, 0, 0, 1}; assertEquals(3, s.find(buffer, buffer.length)); marker = new byte[] {1, 1, 1, 2}; s = new Seeker(marker); buffer = new byte[] {1, 1, 1, 1, 1}; assertEquals(-1, s.find(buffer, buffer.length)); buffer = new byte[] {1, 1, 2}; assertEquals(2, s.find(buffer, buffer.length)); buffer = new byte[] {1, 1, 1, 1, 1}; assertEquals(-1, s.find(buffer, buffer.length)); buffer = new byte[] {2, 1, 1, 1, 2}; assertEquals(0, s.find(buffer, buffer.length)); }