Add test coverage for PrintStream autoflushing behavior.

The new tests check that after print/write-ing to a PrintStream,
the underlying OutputStream gets flush()ed if and only if
autoFlush is set to true, and that at least one of those flush()
calls happens after the last byte was written.

As documented, PrintStream.checkError() flushes regardless of
the autoFlush configuration.

During testing, it appeared that PrintStream.print()/println()/write()
calls result in exactly n + 1 invocations of flush(), where n is the
number of \n characters written. This seems a little generous, but is
within spec and matches RI behavior. The test was written to spec and
doesn't assert the particular number of calls to flush().

Test: make cts && cts-tradefed run cts -m CtsLibcoreTestCases -t \
   org.apache.harmony.tests.java.io.PrintStreamTest
Change-Id: I4eeed19630a0a50af5a6dbc94d1e9fe6e11d0f31
1 file changed