bb.io
Class ParseReader.UnitTest

java.lang.Object
  extended by bb.io.ParseReader.UnitTest
Enclosing class:
ParseReader

public static class ParseReader.UnitTest
extends Object

See the Overview page of the project's javadocs for a general description of this unit test class.


Field Summary
private static String[] lineTerminators
           
private static int numberLines
           
private static int numberTests
           
private static Random random
           
private static String testString
           
 
Constructor Summary
ParseReader.UnitTest()
           
 
Method Summary
private static void doArrayRead(ParseReader parseReader, StringBuilder readStorage)
          Perform the operation of reading a char[] of some random size.
private static void doArrayUnRead(ParseReader parseReader, StringBuilder readStorage)
          Perform the operation of unreading a char[] of some random size.
private static void doConsistencyCheck(ParseReader parseReader, StringBuilder readStorage)
          First checks that parseReader has data left to read.
private static void doManySingleReads(ParseReader parseReader, StringBuilder readStorage)
          Perform the operation of reading a single char some random number of times.
private static void doManySingleUnreads(ParseReader parseReader, StringBuilder readStorage)
          Perform the operation of unreading a single char some random number of times.
private static void doReadLine(ParseReader parseReader, StringBuilder readStorage)
          Perform the operation of reading 1 line of data.
private static void doReadThruToken(ParseReader parseReader, StringBuilder readStorage)
          Tests readThruToken.
private static void doSkip(ParseReader parseReader, StringBuilder readStorage)
          First calls doReadLine so that stream is positioned at the known beginning of a line.
private static void doSkipFully(ParseReader parseReader, StringBuilder readStorage)
          First calls doReadLine so that stream is positioned at the known beginning of a line.
private static void doSkipTillTokenNext(ParseReader parseReader, StringBuilder readStorage)
          Tests skipTillTokenNext.
private static void doSkipWhitespace(ParseReader parseReader, StringBuilder readStorage)
          First calls doReadLine so that stream is positioned at the known beginning of a line.
private static String getNthLineTerminator(int n)
          Returns the value from lineTerminators at index = n % lineTerminators.length.
private static String makeTestString(int length)
          Make a test String which has the property that every line consists of the line number's characters followed by a line termination sequence determined by the getNthLineTerminator method.
private static void printLastSeveralCharsRead(StringBuilder readStorage)
          Confirm that the ParseReader's idea of lineNumber is consistent with the value recorded on the last line read.
 void test_all()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

random

private static final Random random

lineTerminators

private static final String[] lineTerminators

numberLines

private static final int numberLines
See Also:
Constant Field Values

testString

private static final String testString

numberTests

private static final int numberTests
See Also:
Constant Field Values
Constructor Detail

ParseReader.UnitTest

public ParseReader.UnitTest()
Method Detail

test_all

public void test_all()
              throws Exception
Throws:
Exception

makeTestString

private static String makeTestString(int length)
Make a test String which has the property that every line consists of the line number's characters followed by a line termination sequence determined by the getNthLineTerminator method.


getNthLineTerminator

private static String getNthLineTerminator(int n)
Returns the value from lineTerminators at index = n % lineTerminators.length.


doManySingleReads

private static void doManySingleReads(ParseReader parseReader,
                                      StringBuilder readStorage)
                               throws IOException
Perform the operation of reading a single char some random number of times.

Throws:
IOException

doArrayRead

private static void doArrayRead(ParseReader parseReader,
                                StringBuilder readStorage)
                         throws IOException
Perform the operation of reading a char[] of some random size.

Throws:
IOException

doReadLine

private static void doReadLine(ParseReader parseReader,
                               StringBuilder readStorage)
                        throws IOException
Perform the operation of reading 1 line of data.

Throws:
IOException

doConsistencyCheck

private static void doConsistencyCheck(ParseReader parseReader,
                                       StringBuilder readStorage)
                                throws IOException,
                                       ParseException,
                                       RuntimeException
First checks that parseReader has data left to read.

Then confirms that parseReader's idea of lineNumber is consistent with the value on the current line. This implies that this method may only be called when have just read thru a line termination sequence, so that the start of a line is what is immediately next on the stream. For example, this method may always safely be called after calling readLine.

Next, confirms that the line terminator sequence of the current line is correct. If the line terminator sequence is what is expected, then it is read thru so that the stream now points to the start of the next line (i.e. the one following the line that used to be next on the stream when method was called). If a different line terminator sequence is encountered, however, then it is NOT read thru but is left next on the stream.

This method tests the following methods: ready, hasData, getLineNumber, isTokenNext, confirmTokenNext.

Warning: this method assumes that the ParseReader was constructed with the result of makeTestString.

Throws:
RuntimeException - if any discrepancy is encountered
IOException
ParseException

printLastSeveralCharsRead

private static void printLastSeveralCharsRead(StringBuilder readStorage)
Confirm that the ParseReader's idea of lineNumber is consistent with the value recorded on the last line read. Do this by comparing the line number value that have most recently read and stored in the token buffer with what the ParseReader reports.

Also confirm that the line terminator sequence is correct.

Warning: this method assumes that the ParseReader was constructed with the result of makeTestString.


doManySingleUnreads

private static void doManySingleUnreads(ParseReader parseReader,
                                        StringBuilder readStorage)
                                 throws IOException
Perform the operation of unreading a single char some random number of times.

Throws:
IOException

doArrayUnRead

private static void doArrayUnRead(ParseReader parseReader,
                                  StringBuilder readStorage)
                           throws IOException
Perform the operation of unreading a char[] of some random size.

Throws:
IOException

doSkip

private static void doSkip(ParseReader parseReader,
                           StringBuilder readStorage)
                    throws IOException
First calls doReadLine so that stream is positioned at the known beginning of a line. Then calls skip for a number of chars that should precisely be the data on the next line, based on knowing what that line should look like given its number.

Throws:
IOException

doSkipFully

private static void doSkipFully(ParseReader parseReader,
                                StringBuilder readStorage)
                         throws IOException
First calls doReadLine so that stream is positioned at the known beginning of a line. Then calls skipFully for a number of chars that should precisely be the complete next line, based on knowing what that line should look like given its number. Then confirms that the next line after the skip looks like what it is supposed to.

Throws:
IOException

doSkipWhitespace

private static void doSkipWhitespace(ParseReader parseReader,
                                     StringBuilder readStorage)
                              throws IOException,
                                     ParseException
First calls doReadLine so that stream is positioned at the known beginning of a line. Then calls confirmTokenNext for the chars that should precisely be the data on the next line, based on knowing what that line should look like given its number. Then calls skipWhitespace, which should skip precisely over the line termination char(s). Then confirms that skipWhitespace skipped over the correct number of chars.

Throws:
IOException
ParseException

doSkipTillTokenNext

private static void doSkipTillTokenNext(ParseReader parseReader,
                                        StringBuilder readStorage)
                                 throws IOException,
                                        ParseException,
                                        RuntimeException
Tests skipTillTokenNext.

As a token, selects one of the remaining line numbers still ahead on the stream. Because of the need to store the skipped items in readStorage (which is done based on knowing what the tokens should look like), this method may only be called when have just read thru a line termination sequence, so that the start of a line is what is immediately next on the stream. For example, this method may always safely be called after calling readLine.

Throws:
IOException
ParseException
RuntimeException

doReadThruToken

private static void doReadThruToken(ParseReader parseReader,
                                    StringBuilder readStorage)
                             throws IOException,
                                    ParseException,
                                    RuntimeException
Tests readThruToken.

As a token, selects one of the remaining line numbers still ahead on the stream.

Throws:
IOException
ParseException
RuntimeException