Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/quite/humla-spongycastle.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/test/java/org/spongycastle/util/io/test/BufferingOutputStreamTest.java')
-rw-r--r--core/src/test/java/org/spongycastle/util/io/test/BufferingOutputStreamTest.java68
1 files changed, 68 insertions, 0 deletions
diff --git a/core/src/test/java/org/spongycastle/util/io/test/BufferingOutputStreamTest.java b/core/src/test/java/org/spongycastle/util/io/test/BufferingOutputStreamTest.java
new file mode 100644
index 00000000..faaaa532
--- /dev/null
+++ b/core/src/test/java/org/spongycastle/util/io/test/BufferingOutputStreamTest.java
@@ -0,0 +1,68 @@
+package org.spongycastle.util.io.test;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.security.SecureRandom;
+
+import org.spongycastle.util.io.BufferingOutputStream;
+import org.spongycastle.util.test.SimpleTest;
+
+public class BufferingOutputStreamTest
+ extends SimpleTest
+{
+ public String getName()
+ {
+ return "BufferingStreamTest";
+ }
+
+ public void performTest()
+ throws Exception
+ {
+ SecureRandom random = new SecureRandom();
+
+ for (int i = 1; i != 256; i++)
+ {
+ byte[] data = new byte[i];
+
+ random.nextBytes(data);
+
+ checkStream(data, 16);
+ checkStream(data, 33);
+ checkStream(data, 128);
+ }
+ }
+
+ private void checkStream(byte[] data, int bufsize)
+ throws IOException
+ {
+ ByteArrayOutputStream bOut = new ByteArrayOutputStream();
+ BufferingOutputStream bfOut = new BufferingOutputStream(bOut, bufsize);
+
+ for (int i = 0; i != 10; i++)
+ {
+ bfOut.write(data[0]);
+ bfOut.write(data, 1, data.length - 1);
+ }
+
+ bfOut.close();
+
+ byte[] output = bOut.toByteArray();
+
+ for (int i = 0; i != 10; i++)
+ {
+ for (int j = 0; j != data.length; j++)
+ {
+ if (output[i * data.length + j] != data[j])
+ {
+ fail("data mismatch!");
+ }
+ }
+ }
+ }
+
+ public static void main(
+ String[] args)
+ {
+ runTest(new BufferingOutputStreamTest());
+ }
+}