diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2018-04-12 21:24:18 -0700 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2018-04-12 22:08:03 -0700 |
commit | 2bc041237984bf674ea144ad1a14710c3ed2e47c (patch) | |
tree | 1ac405a266c03fdf4c406fd6cf8d23ea7ea09a05 /main/client/test/src | |
parent | 948b697aa85ccd6062ce1d001703e1c428cfa397 (diff) | |
download | mill-2bc041237984bf674ea144ad1a14710c3ed2e47c.tar.gz mill-2bc041237984bf674ea144ad1a14710c3ed2e47c.tar.bz2 mill-2bc041237984bf674ea144ad1a14710c3ed2e47c.zip |
rename modules scalaworker -> scalalib.worker, client -> main.client
Diffstat (limited to 'main/client/test/src')
-rw-r--r-- | main/client/test/src/mill/main/client/ClientTests.java | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/main/client/test/src/mill/main/client/ClientTests.java b/main/client/test/src/mill/main/client/ClientTests.java new file mode 100644 index 00000000..5ae44d3f --- /dev/null +++ b/main/client/test/src/mill/main/client/ClientTests.java @@ -0,0 +1,61 @@ +package mill.main.client; + +import static org.junit.Assert.assertEquals; +import org.junit.Test; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; + +public class ClientTests { + @Test + public void readWriteInt() throws Exception{ + int[] examples = { + 0, 1, 126, 127, 128, 254, 255, 256, 1024, 99999, 1234567, + Integer.MAX_VALUE, Integer.MAX_VALUE / 2, Integer.MIN_VALUE + }; + for(int example0: examples){ + for(int example: new int[]{-example0, example0}){ + ByteArrayOutputStream o = new ByteArrayOutputStream(); + Util.writeInt(o, example); + ByteArrayInputStream i = new ByteArrayInputStream(o.toByteArray()); + int s = Util.readInt(i); + assertEquals(example, s); + assertEquals(i.available(), 0); + } + } + } + @Test + public void readWriteString() throws Exception{ + String[] examples = { + "", + "hello", + "i am cow", + "i am cow\nhear me moo\ni weight twice as much as you", + "我是一个叉烧包", + }; + for(String example: examples){ + checkStringRoundTrip(example); + } + } + + @Test + public void readWriteBigString() throws Exception{ + int[] lengths = {0, 1, 126, 127, 128, 254, 255, 256, 1024, 99999, 1234567}; + for(int i = 0; i < lengths.length; i++){ + final char[] bigChars = new char[lengths[i]]; + java.util.Arrays.fill(bigChars, 'X'); + checkStringRoundTrip(new String(bigChars)); + } + } + + public void checkStringRoundTrip(String example) throws Exception{ + ByteArrayOutputStream o = new ByteArrayOutputStream(); + Util.writeString(o, example); + ByteArrayInputStream i = new ByteArrayInputStream(o.toByteArray()); + String s = Util.readString(i); + assertEquals(example, s); + assertEquals(i.available(), 0); + } + + +}
\ No newline at end of file |