X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2Ftest_code%2FBufferedInputStreamTest.java;fp=src%2Fbe%2Fnikiroo%2Futils%2Ftest_code%2FBufferedInputStreamTest.java;h=e2fc80bf38275b666fdf8f892eece519e1d80537;hb=6ef54b36380b9d123bbdb6b4056cf64b7489225e;hp=0000000000000000000000000000000000000000;hpb=33895a7b06d1a8a7c3555da06b215ab1085ac4df;p=nikiroo-utils.git diff --git a/src/be/nikiroo/utils/test_code/BufferedInputStreamTest.java b/src/be/nikiroo/utils/test_code/BufferedInputStreamTest.java new file mode 100644 index 0000000..e2fc80b --- /dev/null +++ b/src/be/nikiroo/utils/test_code/BufferedInputStreamTest.java @@ -0,0 +1,46 @@ +package be.nikiroo.utils.test_code; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; + +import be.nikiroo.utils.BufferedInputStream; +import be.nikiroo.utils.IOUtils; +import be.nikiroo.utils.test.TestCase; +import be.nikiroo.utils.test.TestLauncher; + +public class BufferedInputStreamTest extends TestLauncher { + public BufferedInputStreamTest(String[] args) { + super("BufferedInputStream test", args); + + addTest(new TestCase("Simple InputStream reading") { + @Override + public void test() throws Exception { + byte[] expected = new byte[] { 42, 12, 0, 127 }; + BufferedInputStream in = new BufferedInputStream( + new ByteArrayInputStream(expected)); + checkArrays(this, "FIRST", in, expected); + } + }); + + addTest(new TestCase("Simple byte array reading") { + @Override + public void test() throws Exception { + byte[] expected = new byte[] { 42, 12, 0, 127 }; + BufferedInputStream in = new BufferedInputStream(expected); + checkArrays(this, "FIRST", in, expected); + } + }); + } + + static void checkArrays(TestCase test, String prefix, InputStream in, + byte[] expected) throws Exception { + byte[] actual = IOUtils.toByteArray(in); + test.assertEquals("The " + prefix + + " resulting array has not the correct number of items", + expected.length, actual.length); + for (int i = 0; i < actual.length; i++) { + test.assertEquals("Item " + i + " (0-based) is not the same", + expected[i], actual[i]); + } + } +}